2014-11-02 176 views
2

這是我的index.html我不知道問題出在哪裏,但是這段代碼不會爲我創建任何數據庫幫助請求或remarque可能是有用的。用cordova在sqlite中創建數據庫

<script type="text/javascript" charset="utf-8"> 
     document.addEventListener("deviceready", onDeviceReady, false); 
     function onDeviceReady() { 
       var db = window.openDatabase("test", "2.0", "Test DB", 1000000);  
       alert(window.openDatabase("test", "1.0", "Test DB", 1000000) +' kolll') 
       db.transaction(populateDB, errorCB, successCB); 
       } 

     // create table 
     function populateDB(tx) { 
     tx.executeSql('DROP TABLE IF EXISTS test_table'); 
     tx.executeSql('CREATE TABLE IF NOT EXISTS test_table (ROLLING INT, firstname text, lastname text, numphone text)'); 
     tx.executeSql("INSERT INTO test_table VALUES('adam', 'smith', '887884')"); 
     tx.executeSql("INSERT INTO test_table VALUES('david', 'ooo', '15588')"); 
     } 
     function errorCB(err) { 
        console.log("Error processing SQL: " + err.code); 

     alert('DATABASE NOT CREATED '); 
     } 
     // Success error callback 

     function successCB() { 
        alert('DATABASE CREATED '); 

     } 
</script> 

thank you 

回答

0

您正在使用不同版本(2.0和1.0)創建數據庫兩次。

1.var db = window.openDatabase("test", "2.0", "Test DB", 1000000); 

2.alert(window.openDatabase("test", "1.0", "Test DB", 1000000) +' kolll') 

您需要更改onDeviceReady()內部的警報呼叫。例如

function onDeviceReady() { 
    alert('Calling onDeviceReady'); 

    var db = window.openDatabase("test", "2.0", "Test DB", 1000000);  
    alert('window.openDatabase called' + ' kolll'); 

    db.transaction(populateDB, errorCB, successCB); 

} 

上面的改變有希望應該創建數據庫和表。