gpt4 book ai didi

c++ - 准备好的语句中的 SQLITE_MISUSE

转载 作者:行者123 更新时间:2023-11-28 06:12:38 25 4
gpt4 key购买 nike

我在以下代码中收到 SQLITE_MISUSE 错误,我想知道这是否可能是由于将表名作为绑定(bind)参数引起的? SQLITE_MISUE 有哪些不同的原因?

const char sqlNeuralStateInsert[] =
"INSERT INTO ?1(LAYER_ID, NEURON_ID, INPUT_ID, VALUE)"
"VALUES(?2, ?3, ?4, ?5);";
sqlite3_stmt* stmt1;
rc = sqlite3_prepare_v2(db, sqlNeuralStateInsert, -1, &stmt1, NULL);
if(rc){
//!< Failed to prepare insert statement
}
sqlite3_bind_text(stmt1, 1, this->getNName().c_str(), -1, SQLITE_STATIC);
for(uint32_t i = 0; i < m_nlayers; i++){
sqlite3_bind_int(stmt1, 2, i); // Layer id
for(uint32_t j = 0; j < m_layers[i]->getNeuronCount(); j++){
std::vector<double> weights = m_layers[i]->getWeights(j);
sqlite3_bind_int(stmt1, 3, j); // Neuron id
for(uint32_t k = 0; k < weights.size(); k++){
sqlite3_bind_int(stmt1, 4, k);
sqlite3_bind_double(stmt1, 5, weights[k]);
rc = sqlite3_step(stmt1);
printf("%d\n", rc);
}
}
}
sqlite3_finalize(stmt1);

最佳答案

你是对的; you cannot bind the table name :

Generally one cannot use SQL parameters/placeholders for database identifiers (tables, columns, views, schemas, etc.) or database functions (e.g., CURRENT_DATE), but instead only for binding literal values.

您可以通过对表名进行硬编码来简单地检验这个假设。

关于c++ - 准备好的语句中的 SQLITE_MISUSE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30947330/

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