我正在使用SQLite,插入表中 . Folowwing
QSqlQuery testQuery(QString("INSERT INTO test(testcol) VALUES(?)"));
testQuery.bindValue(0, someQStringObg);
testQuery.exec();
有效,但是
QSqlQuery testQuery(QString("INSERT INTO test(testcol) VALUES(:val)"));
testQuery.bindValue(":val", someQStringObg);
testQuery.exec();
别 . testQuery.lastError() . text()返回 No query Unable to fetch row
不知道为什么会这样,但真的想知道 .
1 回答
请使用prepare作为official example:
出错的原因是查询是在绑定到相应的占位符之前执行的 . 您可以看到constructor documentation的相关部分: