如何填充参数$cordovaSQLite作为我自己的数组

How to populate Parameter in $cordovaSQLite as my own array

本文关键字:cordovaSQLite 我自己 数组 自己的 参数 何填充 填充      更新时间:2023-09-26

我使用这些代码来执行$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
                         };

以便将来可以对数据进行操作。我怎么能做到呢?

注意变量名。参数对象名称是qst_master_content。应该是这样的:

$cordovaSQLite.execute(db, query, qst_master_cotent)

使用这段代码

       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() {
        }

谢谢