2016-10-20 25 views
0

我使用此代碼執行$cordovaSQLite插入。

var qst_master_content_data= { 
          qst_cnt_id :content.qst_cnt_id, 
          question_id :content.question_id, 
          qst_cnt_text :content.qst_cnt_text, 
          qst_cnt_options :content.qst_cnt_options, 
          qst_story:content.qst_story, 
          explanation :content.explanation, 
          lang_id :content.lang_id, 
          img_id :content.img_id, 
          dt_update :content.dt_update 

         }; 
var query = "INSERT INTO qst_master_content ("+ 
           "qst_cnt_id, "+ 
           "question_id, "+ 
           "qst_cnt_text, "+ 
           "qst_cnt_options, "+ 
           "qst_story, "+ 
           "explanation, "+ 
           "lang_id, "+ 
           "img_id, "+ 
           "dt_update "+ 
           ") VALUES (?,?,?,?,?,?,?,?,?)"; 
        $cordovaSQLite.execute(db, query, qst_master_content_data).then(function(res) 
        { 
         console.log(res); 
        }, 
        function(err) 
        { 
         console.log(err); 
        } 

不幸的是插入未成功插入。 我試圖使用qst_master_cotent = [1,2,3];那麼它會沒事的。 但是這不會使我的代碼在該格式上重複使用。它應該是:

var qst_master_content_data= { 
          qst_cnt_id :content.qst_cnt_id, 
          question_id :content.question_id, 
          qst_cnt_text :content.qst_cnt_text, 
          qst_cnt_options :content.qst_cnt_options, 
          qst_story:content.qst_story, 
          explanation :content.explanation, 
          lang_id :content.lang_id, 
          img_id :content.img_id, 
          dt_update :content.dt_update 

         }; 

這樣我可以在將來操縱數據。我該怎麼做?

回答

0

要小心變量名稱。您的參數對象名稱是qst_master_cotent。 它應該是這樣的:

$cordovaSQLite.execute(db, query, qst_master_cotent) 
0

使用這段代碼

 var db = window.sqlitePlugin.openDatabase({ 
       name: "your.db" 
      }); 
      db.transaction(populateClientDB, error, success); 

     function populateClientDB(tx) { 
      tx.executeSql("INSERT INTO qst_master_content (qst_cnt_id, question_id, qst_cnt_text, qst_cnt_options, qst_story, explanation, lang_id, img_id, dt_update) \n\ 
        VALUES (?,?,?,?,?,?,?,?,?)", [qst_master_cotent.qst_cnt_id, qst_master_cotent.question_id, qst_master_cotent.qst_cnt_text, qst_master_cotent.qst_cnt_options, qst_master_cotent.qst_story, qst_master_cotent.explanation, qst_master_cotent.lang_id, qst_master_cotent.img_id, qst_master_cotent.dt_update], function(tx, res) { 
       console.log("insertId: " + res.insertId + " -- probably 1"); 
       console.log("rowsAffected: " + res.rowsAffected + " -- should be 1"); 
      }); 
     } 

     function error(error) { 
      console.log(error); 
     } 

     function success() { 

     } 

感謝

+0

我知道這樣,我的意思是我希望我自己的陣列中的問題。 – Nere

+0

也許,你正在得到問題,因爲它的(鍵,值)對象 –

+0

是的,但它是像[1,2,3,..]這樣的參數數組上的唯一方式嗎? – Nere

相關問題