我有一个最多包含 3 个字符串的 c++ 容器,而且很多时候只有一个字符串。
我需要为容器中的每个字符串从 sqlite dB 获取一个 int 值,我想知道是否有比准备好的语句更快的方法?
我现在的方式
int Idx{}; // set to 0
std::for_each(container.begin(), container.end(), [](string& item) {
sqlite3_prepared_v2(
db,
("SELECT categoryId FROM table WHERE item='" + item + "'").c_str(),
-1,
&stmt,
NULL
);
sqlite3_step(stmt); // goto the first result
Idx += sqlite3_column_int(stmt, 0); // add to my Idx
sqlite3_finalize(stmt); // finalize
};