我声明如下。
const QString createSQL = "CREATE TABLE customer (x INTEGER PRIMARY KEY ASC, y, z);" ;
我还有一个变量
QString name="name1";
我需要将表“customer”的名称更改为 name1。如何将变量插入到上述 sqlite 查询中?
最佳答案
这是直接从文档中提取的。
// Execute query with positional binding using named placeholders
QVariantList contactValues;
contactValues << 1 << "Mike" << "Chepesky";
DataAccessReply reply = sc.executeAndWait(
"insert into contact (id, firstname, lastname) values (:id, :firstname, :lastname)",
contactValues);
和
// Execute query with positional binding using positional (?) placeholders
QVariantList contactValues;
contactValues << 1 << "Mike" << "Chepesky";
DataAccessReply reply = sc.executeAndWait(
"insert into contact (id, firstname, lastname) values (?, ?, ?)",
contactValues);
关于c++ - 将变量插入 SQLite 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20719177/