使用prepared语句和sqlite事务语句
Using prepared statement with sqlite transaction statement
我试图在sqlite中插入大量数据,为了获得性能,我使用transaction
语句。我的代码如下所示:CSV解析器;
query.exec("BEGIN TRANSACTION;");
while (!file.atEnd())
{
line = file.readLine();
if (line == "")
continue;
parser << line.toStdString(); // Feed the line to the parser
// Now extract the columns from the line
parser >> sCol1 >> sCol2 >> sCol3 >> sCol4;
// Method one to insert data
sqlQuery = "INSERT INTO Person(phone, name, firstname, lastname) VALUES ("
"'" + QString(sCol1.c_str()) +
"','" + QString(sCol2.c_str()) +
"','" + QString(sCol4.c_str()) +
"','" + QString(sCol3.c_str()) + "')";
//query.exec(sqlQuery);
// Method two to insert data
query.prepare("INSERT INTO Person(phone, name, firstname, lastname) VALUES (:phone, :name, firstname, :lastname");
query.bindValue(":phone", QString(sCol1.c_str()));
query.bindValue(":name", QString(sCol2.c_str()));
query.bindValue(":firstname", QString(sCol4.c_str()));
query.bindValue(":lastname", QString(sCol3.c_str()));
query.exec();
cout << query.lastError().text().toStdString();
}
query.exec("END TRANSACTION;");
如果我使用第一种方法,插入的数据会很好,但如果文本包含像"这样的charcarter,则稍后可能会出现问题。为了避免这种情况,我切换到准备好的语句,这是一个新问题,没有插入数据。我看到的唯一错误:
参数计数不匹配参数计数不一致参数计数不匹配参数计数不匹配参数数目不匹配参数计数不匹配参数计数不匹配我在这里失踪了吗?
我想知道这是否是原因:
query.prepare("INSERT INTO Person(phone, name, firstname, lastname)
VALUES (:phone, :name, firstname, :lastname");
^^^
missing close paren inside the string^^^
相关文章:
- 我的简单if-else语句是如何无法访问的代码
- 有一个打印语句的函数是一种糟糕的编程实践吗
- 线程,如果else语句,都是错误的上下文切换后,会发生什么
- 为什么是0;C++中的有效语句
- Insert函数不适用于2 if语句C++
- If语句未被求值C++
- C++嵌套if语句,基本货币交换
- 多个If语句与使用逻辑运算符计算条件的单个语句的比较
- 是否可以使用if constexpr删除控制流语句
- 无法理解此 return 语句的功能,没有它就会发生运行时错误
- 我似乎对if/else的基本语句有问题:/
- 当调用switch语句中的函数时(即使函数不包含循环),似乎是永不结束的循环的问题
- If语句在c++中被忽略
- 比较if语句中的数组值和int值
- 以在Qt中的IF语句中设置时间延迟
- Craps游戏问题,忽略if语句
- 条件语句,用于验证事务模块(.cpp)标头中#define(d)整数提供的范围
- Firebird C 客户端 API:语句、事务和游标生命周期
- PostgreSQL 是否计算嵌套的 BEGIN 和 END 语句,即使它不支持自治事务?
- 使用prepared语句和sqlite事务语句