gpt4 book ai didi

QtSql 多查询执行

转载 作者:行者123 更新时间:2023-12-04 17:03:02 25 4
gpt4 key购买 nike

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

这些可以绑定(bind)在一个 中吗?查询.exec() ?

最佳答案

我猜你正试图批量执行你的查询。是的,qt 支持这种情况。

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

关于QtSql 多查询执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9747862/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com