2015-06-19 286 views
0

我在下面的代碼中收到SQLITE_MISUSE錯誤,並且想知道是否可能是由於表名是一個綁定參數導致的?什麼是SQLITE_MISUE的一些不同的原因?已準備好的語句中的SQLITE_MISUSE

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); 

回答

1

你是對的; you cannot bind the table name

通常一個不能使用SQL參數/對數據庫標識符(表,列,視圖,模式等)或數據庫功能(例如,CURRENT_DATE),而是僅用於結合文字值的佔位符。

你可以有平凡通過硬編碼表名測試這個假設。

+0

那我該如何綁定數據庫標識符呢? – HSchmale

+1

@ HSchmale:不確定「你不能」的哪一部分不清楚?無論如何,如果所有這些表都具有相同的模式,爲什麼他們不是_one_表,而'?1'是列?一般來說,如果您認爲表格名稱需要動態顯示,則表明您的設計存在問題,這也是不支持的原因之一。 –

+0

那麼什麼是更好的設計,如果我想立即創建表格,然後插入它。 – HSchmale