我有如下声明。

 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);

documentation/source

关于c++ - 在SQLite查询中插入变量,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20719177/

10-12 23:57