2016-10-20 5 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

関連する問題