我在下面的代码中遇到SQLITE_MISUSE错误,我想知道是否可能是因为表名是绑定参数引起的? 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);
答案 0 :(得分:1)
你是对的; you cannot bind the table name:
通常,不能对数据库标识符(表,列,视图,模式等)或数据库函数(例如
CURRENT_DATE
)使用SQL参数/占位符,而是仅用于绑定文字值。
您可以通过对表名进行硬编码来平凡地测试此假设。