Executing multiple QtSql queries

... query.exec("insert into person values(104, 'Roberto', 'Robitaille')"); query.exec("insert into person values(105, 'Maria', 'Papadopoulos')"); ... 

Is it possible to link them in one query.exec () ?

+4
source share
1 answer

I think you are trying to execute a batch request. Yes, qt supports this scenario.

 bool QSqlQuery::execBatch ( BatchExecutionMode mode = ValuesAsRows ) 

Executes a pre-prepared SQL query in a package. All related parameters should be option lists. If the database does not support package execution, the driver will simulate it using regular exec () calls. Returns true if the request is successful; otherwise returns false.

  QSqlQuery q; q.prepare("insert into myTable values (?, ?)"); QVariantList ints; ints << 1 << 2 << 3 << 4; q.addBindValue(ints); QVariantList names; names << "Harald" << "Boris" << "Trond" << QVariant(QVariant::String); q.addBindValue(names); if (!q.execBatch()) qDebug() << q.lastError(); 

http://doc.qt.io/archives/qt-4.7/qsqlquery.html#execBatch

+12
source

Source: https://habr.com/ru/post/1401954/


All Articles