简体   繁体   English

Phonegap / Cordova WebSql事务未触发

[英]Phonegap/Cordova WebSql transaction not firing

I'm using cordova's latest version (3.5) and I want to save some data using WebSQL but when I call database.transaction(query,success,error) it does nothing. 我正在使用cordova的最新版本(3.5),并且想使用WebSQL保存一些数据,但是当我调用database.transaction(query,success,error)时,它什么也没做。 Both my sucess method and error method have alert() to notify error or success but none of them fire. 我的成功方法和错误方法都具有alert()来通知错误或成功,但是均未触发。

Here's my code: 这是我的代码:

    function onDeviceReady(){
        var db = window.openDatabase("Database", 1, "PhoneGap Demo");
        db.transaction(populateDB, errorCB, successCB);
    }

    function populateDB(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 errorCB(err) {
        alert("Error processing SQL: "+err.code);
    }

    function successCB() {
        alert("success!");
    }

As I said the alert boxes are not being displayed. 如我所说,警报框未显示。 What could be the problem? 可能是什么问题呢? For more information: I'm using Cordova 3.5 and being tested on an iPhone simulator. 有关更多信息: 我正在使用Cordova 3.5并正在iPhone模拟器上进行测试。 I executed the code on chrome with my laptop and seems to work. 我用笔记本电脑在chrome上执行了代码,似乎可以正常工作。

Environment : cordova 3.4 环境:科尔多瓦3.4
device : Emulator ( Nexus 7) 设备:仿真器(Nexus 7)
OS : Android KitKat 4.4 操作系统:Android KitKat 4.4
I just checked your code and got the error "Insufficient Number of arguments" on line 我刚刚检查了您的代码,并在网上看到错误“参数数量不足”

var db = window.openDatabase("Database", 1, "PhoneGap Demo");

As per the API doc there should be four arguments, I changed the code to 根据API文档,应该有四个参数,我将代码更改为

var db = window.openDatabase("Database", "1.0", "PhoneGap Demo", 1000);

and it worked. 而且有效。 The last argument is the initial size of the database in bytes. 最后一个参数是数据库的初始大小(以字节为单位)。

Hope the above solution works for iPhone as well. 希望以上解决方案也适用于iPhone。

I used console.log() call as well as alert() for debugging. 我使用console.log()调用以及alert()进行调试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM