想象一下,我有以下 SQLite 表定义:
create table test (id integer primary key, info integer);
以及以下条目:
id | info
----------
1 | 10
2 | 20
3 | 30
我想使用 Qt 的QSqlQuery类来prepare()查询和使用该bindValue()函数。
我想要达到的目标是
insert into test values (
( select id from test where ROWID = last_insert_rowid() )+100,
666
);
为了得到:
id | info
----------
1 | 10
2 | 20
3 | 30
103 | 666
虽然这可以exec()通过QSqlQuery qry对象直接 ing 语句,但这
//qry is set up correctly.
qry.prepare("insert into test values (?,?);");
qry.bindValue(0, "select id from test where ROWID = last_insert_rowid() )+100");
qry.bindValue(1,666);
qry.exec();
不起作用(数据类型不匹配)。
1)我怎样才能让它通过使用来工作bindValue()?
2)不使用实现相同行为的最简洁方法是什么last_insert_rowid()?
id3)如果表到目前为止没有行,上面的代码会返回什么值?零?