1

I have a SQLITE database on my iOS project, which I can access from my native IOS code. I can access it and read data from it.

You can see the way i'm doing it and my project structure in the following pic: enter image description here

And i try to do the same using Phonegap:

   var db;
   var shortName = 'myTestDb.db';
   var version = '1.0';
   var displayName = 'myTestDb';
   var maxSize = 65535;


   // list the values in the database to the screen using jquery to
   //update the #lbUsers element
   function ListDBValues() {

       if (!window.openDatabase) {
           alert('Databases are not supported in this browser.');
           return;
       }
       $('#myDbElements').html('');

       db.transaction(function(transaction) {
           transaction.executeSql("SELECT FIRST_NAME FROM dbo_RE_USER;", [],
           function(transaction, result) {
               console.log("result");                                 
               if (result != null && result.rows != null) {
                   console.log("result is not null");
                   for (var i = 0; i < result.rows.length; i++) {
                       var row = result.rows.item(i);
                       //console.log(row);
                      debugObject(row);


                    $('#myDbElements').append('<br>' + row["FIRST_NAME"]);// + " " + row.LAST_NAME );
                   }
               }
            PrecApp.I_SCROLL.refresh();   
           },errorHandler);

       },errorHandler,nullHandler);        
       return;
   }

   function debugObject(obj) {
    console.log("ROW:");        
    for (n in obj)
//            alert(n + ":" + obj[n]);
        console.log(n + ":" + obj[n]);
   }

But it can't find my dbo_re_users table. Why?

4

1 回答 1

1

The database opened in JavaScript is an entirely different database - it has the same name, but is not in the app bundle, which is read only.

If you need to access a specific database file, you will need to use a plugin.

于 2012-11-21T13:08:22.947 回答