void Transactions::putData(QStringList data, QString name){ QSqlDatabase db = QSqlDatabase::addDatabase( "QSQLITE" ); db.setDatabaseName( "data.db" ); db.open(); // QSqlQuery qry; // qry.prepare( "CREATE TABLE "+name+" (id INTEGER PRIMARY KEY AUTOINCREMENT, val VARCHAR(10))" ); // qry.exec(); // for(int i=0; i<data.size();++i) // { // QString val=data.at(i); // qry.prepare( "INSERT INTO "+name+" (val) VALUES ('"+val+"')" ); // qry.exec(); // } QSqlQuery qry; qry.prepare( "CREATE TABLE "+name+" (id INTEGER PRIMARY KEY AUTOINCREMENT, val VARCHAR(10))" ); qry.exec(); qry.prepare( "INSERT INTO "+name+" (val) VALUES (?)" ); QVariantList names; for(int i=0; i<data.size();++i) names.append(data.at(i)); qry.addBindValue(names); qry.execBatch(); db.close();}
INSERT INTO table(val) VALUES(...), (...) ...
void Transactions::putData(QStringList data, QString name){ QSqlDatabase db = QSqlDatabase::addDatabase( "QSQLITE" ); db.setDatabaseName( "data.db" ); db.open(); db.transaction(); // вставка сколько угодно строк db.commit(); db.close();}
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");QSqlDriver * driver = db.driver();qDebug() << driver->hasFeature( QSqlDriver::BatchOperations ); // false