Frage

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

Can these be bind in a single query.exec() ?

War es hilfreich?

Lösung

I guess you are trying to execute in a batch your query. Yes, qt supports this scenario.

bool QSqlQuery::execBatch ( BatchExecutionMode mode = ValuesAsRows )

Executes a previously prepared SQL query in a batch. All the bound parameters have to be lists of variants. If the database doesn't support batch executions, the driver will simulate it using conventional exec() calls. Returns true if the query is executed successfully; 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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top