PhoneGap&通过Javascript连接到SQLite数据库

时间:2013-04-17 14:57:23

标签: javascript ios sqlite cordova phonegap-build

我是PhoneGap的新手,我正在建立连接到现有SQLite数据库的问题。以下是我的代码。通过日志条目和警报,我注意到javascript正在运行它,但很明显我的openDatabase调用没有完全正确设置。我得到的错误是“错误:无法准备声明(1没有这样的表:人)(代码5)”

if(openDatabase){
                 db = openDatabase('popfon.sqlite'
                                    , '1.0'
                                    , 'Database Description'
                                    , 200000;
    }
                  //Alert the user to upgrade their browser
                  else {
                  alert('Databases not supported. Please get a proper browser');
                  }
  $JQuery("#theButton").click(function(){getData()});

function getData(){
    //Create an empty results string
    var strResults = '';
    //Open a new transaction
    db.transaction(function(tx){
                   //Select a wildcard from the database
                   var theQuery = "SELECT * FROM person where OfficialName like '%law%'"
                   alert(theQuery);
                   tx.executeSql(theQuery
                                 ,[]
                                 //Callback function with transaction and
                                 //results objects
                                 ,function(tx, results){
                                 //Count the results rows
                                 var rowsCount = results.rows.length;
                               //  alert("rowsCount: "+rowsCount);
                                 //Loop the rows
                                 for (var i = 0; i < rowsCount; i++){
                                 //Build a results string, notice the
                                 //column names are called
                                 strResults += 'Your Name is'
                                 + results.rows.item(i).personName
                                 + ' Your ID is '
                                 + results.rows.item(i).personId
                                 + ' Your age is '
                                 + results.rows.item(i).personAge
                                 + ' Your favourite colour is '
                                 + results.rows.item(i).personColour
                                 + '';
                                 }
                                 //Fill the results DIV
                                 $('.results').html(strResults);
                                 }
                                 ,errorHandler);
                   });
}

0 个答案:

没有答案