void CreateTableDialog::on_buttonBox_accepted() { if (isAlter) { db.exec(createTempString); if (db.lastError().isValid()) { QMessageBox::critical(this, tr("Error"), tr("Table Error:\n%1").arg(db.lastError().text())); return; } db.exec(insertTempString); if (db.lastError().isValid()) { QMessageBox::critical(this, tr("Error"), tr("Table Error:\n%1").arg(db.lastError().text())); return; } db.exec(QString("DROP TABLE `%1`;").arg(ui->txtTableName->text())); if (db.lastError().isValid()) { QMessageBox::critical(this, tr("Error"), tr("Table Error:\n%1").arg(db.lastError().text())); return; } } QSqlQuery qu(getSQL(), db); if (!qu.lastError().isValid()) { if (isAlter) { QString newColumnList = ""; for (int i = 0; i < columnList.count(); ++i) { QString colValue = columnList.at(i); if (gridColumns.contains(colValue)) { newColumnList += colValue + ", "; } } newColumnList = newColumnList.remove(newColumnList.count() - 2, 2); QString newInsert = "INSERT INTO `" + ui->txtTableName->text(); newInsert += "` ("; newInsert += newColumnList; newInsert += ") SELECT "; newInsert += newColumnList; newInsert += " FROM TEMP_TABLE;"; db.exec(newInsert); if (db.lastError().isValid()) { QMessageBox::critical(this, tr("Error"), tr("Table Error:\n%1").arg(db.lastError().text())); return; } db.exec("DROP TABLE TEMP_TABLE;"); if (db.lastError().isValid()) { QMessageBox::critical(this, tr("Error"), tr("Table Error:\n%1").arg(db.lastError().text())); return; } } this->accept(); } else { QMessageBox::critical(this, tr("Error"), tr("Table Error:\n%1").arg(qu.lastError().text())); return; } }
FRESULT writeResult(char test[], int result){ char timeString[20]; getSQL(timeString); // Load time at which the test occurred f_mount(0, &FileSystemObject); if (f_open(&logFile, "/tictoc.csv", FA_WRITE | FA_OPEN_EXISTING)){ // File does not exist yet, try to create it and write the header FRESULT res = f_open(&logFile, "/tictoc.csv", FA_WRITE | FA_CREATE_NEW); if(res) return res; // File opening failed! f_printf(&logFile, "time,device,test,result\n"); // Write header } f_lseek(&logFile, f_size(&logFile)); // Make sure we are at the end of the file f_printf(&logFile, "%s,watch,%s,%d\n",timeString,test,result); // Write line of data f_sync(&logFile); // Make sure file is synched f_close(&logFile); return f_mount(0,0); }