简体   繁体   English

应用安装问题后,Phonegap / coredava首次运行sqlite

[英]first time running sqlite after app install issue with phonegap/coredava

I am developing an APP using phonegap/coredava while trying to create an access database for the first time after app is installed I am unable to access database but on second run everything working fine how can I fix this my javascript code is below 我正在使用phonegap / coredava开发一个APP,同时尝试在安装应用程序后首次创建访问数据库,但无法访问数据库,但是第二次运行一切正常,如何修复此JavaScript代码如下

    var dbsize=4*1024;
    document.addEventListener("deviceready", onDeviceReady, false);
    var dbShell = window.openDatabase("mydb", "1.0", "my db", dbsize); 
    function onDeviceReady(){
        dbShell.transaction(defaultPopulatedb,errorDF,successDF);
    }
    function defaultPopulatedb(tx){ //creating tables for the first time
    tx.executeSql('CREATE TABLE IF NOT EXISTS Userlocation (id INTEGER PRIMARY KEY AUTOINCREMENT, Location TEXT NOT NULL, Locationvalue TEXT NOT NULL)',[],checkfirst,errorTB);
    }
    function checkfirst(tx) 
    {
    tx.executeSql('SELECT * FROM Userlocation',[],chevals,errorDFS);        }
    }
    function chevals(tx,result)
    {     
     var len =result.rows.length;
        if(!len){
        tx.executeSql('INSERT INTO Userlocation(Location,Locationvalue) VALUES ("default","default")',[],added,erdf);
        }
    }
    function errorDFS()
   {
     alert("error");
   }
    function added()
   {
     alert("added");
   }
    function erdf()
   {
     alert("error adding default");
   }
    function errorTB()
   {
     alert("error table");
   }

I met this problem once too. 我也遇到过这个问题。 You can just simply try{...} catch (ex){...} and ignores the first exception. 您只需尝试{...}捕获(ex){...}并忽略第一个异常。

Actually, there is a great data access framework for phonegap. 实际上, 一个出色的数据访问框架可用于phonegap。

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

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