gpt4 book ai didi

c++ - 将变量插入 SQLite 查询

转载 作者:太空宇宙 更新时间:2023-11-04 11:42:58 26 4
gpt4 key购买 nike

我声明如下。

 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/

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