C++ (Qt)bool MainWindow::createConnection(){ QDir dir("data"); QString fileName = dir.absolutePath().replace("/","\\") + "\\accounts.mdb"; db = QSqlDatabase::addDatabase("QODBC"); db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=" + fileName); if(!db.open()) { QMessageBox::critical(this,tr("Ошибка"),db.lastError().text()); return false; } return true;}
C++ (Qt)bool copy(int rf_IDSmetiCopy){QSqlDatabase db = QSqlDatabase::database(); { QSqlDatabase dbase = QSqlDatabase::cloneDatabase(db,"other"); if(!dbase.open()) { QMessageBox::critical(this,tr("Ошибка"),dbase.lastError().text()); return false; } dbase.transaction(); QSqlQuery query(dbase); if(!query.exec(tr("INSERT ...")) { QMessageBox::critical(this,tr("Ошибка SQL"),query.lastError().text()); dbase.rollback(); return false; } query.clear(); query.exec("INSERT"); if(query.lastError().isValid()){ QMessageBox::critical(this,tr("Ошибка SQL"),query.lastError().text()); dbase.rollback(); return false; } emit copyEndTabl(); //i t.d. dbase.commit(); dbase.close(); } QSqlDatabase::removeDatabase("other"); return true;}
C++ (Qt)QSqlDatabase db = QSqlDatabase::database();db.open();