使用phonegap在Sqlite中插入和选择多行时出现问题

时间:2014-03-27 16:27:07

标签: javascript jquery sqlite jquery-mobile cordova

我是Sqlite和java脚本的新手。我在sqlite数据库中插入和选择多行时感到震惊。任何人都可以帮助我,我如何插入和选择多行?我的代码如下,

var db = window.sqlitePlugin.openDatabase("Database", "1.0", "Demo", -1);
db.transaction(function(tx) {
    tx.executeSql('DROP TABLE IF EXISTS test_table');
    tx.executeSql('CREATE TABLE IF NOT EXISTS test_table (id integer primary key, data text, data_num integer)');
    tx.executeSql("INSERT INTO test_table (data, data_num) VALUES (?,?)", ["test", 100], function(tx, res) {
        console.log("insertId: " + res.insertId + " -- probably 1"); // check #18/#38 is fixed
        alert("insertId: " + res.insertId + " -- should be valid");
        db.transaction(function(tx) {
            tx.executeSql("SELECT data_num from test_table;", [], function(tx, res) {
                console.log("res.rows.length: " + res.rows.length + " -- should be 1");
                alert("res.rows.item(0).data_num: " + res.rows.item(i).data_num + " -- should be 100");
            });
        });
    }, function(e) {
        console.log("ERROR: " + e.message);
    });
});  

如何从一个java脚本函数插入值,如何从另一个函数中检索值是否可能?如果是,任何人都可以建议一些好的教程或解释相同。

0 个答案:

没有答案