在 sqlite3 中批量插入的更好方法C++
Better way to bulk insert in sqlite3 C++
我批量插入要执行的语句。我可以创建一个包含所有插入语句的 sql 字符串并执行一次,例如,
std::string sql_string = "";
int i;
for(i=0;i<1000; i++) {
Transaction transaction = transactions[i];
std::string tx_sql = CREATE_SQL_STRING(transaction, lastTxId); // "INSERT INTO (...) VALUES (...);"
sql_string = sql_string+tx_sql;
lastTxId++;
}
sqlite3_exec(db, sql_string.c_str(), callback, 0, &zErrMsg);
有没有其他性能更好的方法来使用 sqlite3 c++ API 进行批量插入?
插入对安全并不重要。只考虑性能。我应该使用预准备语句吗?
最重要的是:将所有插入放入单个事务中。
有关性能的更多详细信息,请参阅官方文档:https://sqlite.org/speed.html(有点过时(
有关最新信息,我会重新评论 https://medium.com/@JasonWyatt/squeezing-performance-from-sqlite-insertions-971aff98eef2
至于准备好的陈述:我不确定性能,但始终使用它们是一个很好的做法。
相关文章:
- 初始化具有非默认构造函数的std::数组项的更好方法
- Protobuf中重复字段的问题.使用重复字段进行序列化/反序列化的更好方法是什么?
- 编写按初始值循环的循环的更好方法是什么
- 用 c++ 为游戏制作"bullet"的更好方法?
- 在CMakeLists中包含目录的更好方法.txt
- 将QDomDocument数据用作文本的更好方法
- C++ - 创建具有相同字符的特定大小的以 null 结尾的 c 样式字符串的更好方法
- 在 sqlite3 中批量插入的更好方法C++
- 设计许多单例代码结构的更好方法
- 使用继承的类模板避免公共成员不可见和源代码膨胀/重复的更好方法
- 在初始化列表中初始化数组的更好方法
- 将对象从一个 std::d eque 移动到另一个的更好方法
- 请告诉我在巴泽尔拥有多平台工作空间的更好方法
- 构造具有大量数据的对象的更好方法(C++)
- 从2D矢量中找出最小尺寸的向量元素的更好方法
- 在C++中创建不可变对象的更好方法
- 在构造函数中组织初始值设定项列表的更好方法
- std::copy with return values - 防止"expression: string iterators incompatible"的更好方法?
- 删除数组成员的更好方法是什么?
- 在C 中操作数据的更好方法是什么