无法使用 Phonegap 在 SQLite 数据库中创建表

发布于 2024-12-09 14:41:32 字数 949 浏览 0 评论 0原文

我尝试使用phonegap 连接到数据库。似乎数据库已打开,但我无法在数据库中创建表。数据库创建后执行似乎停止了。使用 db.transaction 的下一步不起作用。

代码 -

function createDB() {
    alert("in createDB...");
    var db = window.openDatabase("Database60", "1.0", "Phonegap Demo60", 200000);
    alert("after openDatabase...");

    db.transaction(
            function(tx)
            {
                    alert("in function(tx)...")
                    tx.executeSql('DROP TABLE IF EXISTS DEMO');
                    tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)');
                    tx.executeSql('INSERT INTO DEMO (id, data) VALUES (1, "First row")');
                    tx.executeSql('INSERT INTO DEMO (id, data) VALUES (2, "Second row")');                  
                 },
            function(tx, err)
            {
                    alert("Error processing SQL: "+err);
            }
            )

    alert("after table creation...");
} 

I tried to connect to a database using phonegap. It seems that the database gets opened, but I am not able to create a table in the database. The execution seems to be stopped after the database creation. The next step using db.transaction is not working.

Code -

function createDB() {
    alert("in createDB...");
    var db = window.openDatabase("Database60", "1.0", "Phonegap Demo60", 200000);
    alert("after openDatabase...");

    db.transaction(
            function(tx)
            {
                    alert("in function(tx)...")
                    tx.executeSql('DROP TABLE IF EXISTS DEMO');
                    tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)');
                    tx.executeSql('INSERT INTO DEMO (id, data) VALUES (1, "First row")');
                    tx.executeSql('INSERT INTO DEMO (id, data) VALUES (2, "Second row")');                  
                 },
            function(tx, err)
            {
                    alert("Error processing SQL: "+err);
            }
            )

    alert("after table creation...");
} 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怀中猫帐中妖 2024-12-16 14:41:32

尝试使用草坪椅。最方便的包装纸。

try using lawnchair. most convenient of wrappers.

谁对谁错谁最难过 2024-12-16 14:41:32
//this creates the database 

db.transaction(populateDB, transaction_error, populateDB_success);

function populateDB(tx) {
tx.executeSql('DROP TABLE IF EXISTS Registration');
var sql = "CREATE TABLE IF NOT EXISTS Registration (" + " id INTEGER PRIMARY KEY AUTOINCREMENT," + "name VARCHAR(50), " + "address VARCHAR(50),"+" age INTEGER(2), "+" birthdate DATE, "+" gender VARCHAR(10), "+" hobbies VARCHAR(100), "+" email VARCHAR(50),"+" uname VARCHAR(50),"+" pwd VARCHAR(50))";

tx.executeSql(sql);

tx.executeSql("INSERT INTO Registration  (name,address,age,birthdate,gender,hobbies,email,uname,pwd) VALUES ('"+ v1 +"','"+ v2 +"','"+ v3 +"','"+ v4 +"','"+ v5 +"','"+ v6 +"','"+ v7 +"','"+ v8 +"','"+ v9 +"')");}

function transaction_error(tx, error) {
alert("Database Error: " + error);
}

function populateDB_success() {
dbCreated = true;
alert("Successfully inserted");
db.transaction(queryDB, errorCB);
}


This works for me.Try this. May be helpful to you.

谢谢。

//this creates the database 

db.transaction(populateDB, transaction_error, populateDB_success);

function populateDB(tx) {
tx.executeSql('DROP TABLE IF EXISTS Registration');
var sql = "CREATE TABLE IF NOT EXISTS Registration (" + " id INTEGER PRIMARY KEY AUTOINCREMENT," + "name VARCHAR(50), " + "address VARCHAR(50),"+" age INTEGER(2), "+" birthdate DATE, "+" gender VARCHAR(10), "+" hobbies VARCHAR(100), "+" email VARCHAR(50),"+" uname VARCHAR(50),"+" pwd VARCHAR(50))";

tx.executeSql(sql);

tx.executeSql("INSERT INTO Registration  (name,address,age,birthdate,gender,hobbies,email,uname,pwd) VALUES ('"+ v1 +"','"+ v2 +"','"+ v3 +"','"+ v4 +"','"+ v5 +"','"+ v6 +"','"+ v7 +"','"+ v8 +"','"+ v9 +"')");}

function transaction_error(tx, error) {
alert("Database Error: " + error);
}

function populateDB_success() {
dbCreated = true;
alert("Successfully inserted");
db.transaction(queryDB, errorCB);
}


This works for me.Try this. May be helpful to you.

Thanks.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文