开发者

How does this Javascript/SQLite code work on Android/Eclipse/PhoneGap?

开发者 https://www.devze.com 2023-02-15 11:23 出处:网络
It appears that this person was able to perform SQLite queries using Javascript on an HT开发者_如何学GoML page. However, I\'ve added it to my Android SDK/Eclipse/PhoneGap project and don\'t see it wor

It appears that this person was able to perform SQLite queries using Javascript on an HT开发者_如何学GoML page. However, I've added it to my Android SDK/Eclipse/PhoneGap project and don't see it working. I've added the js file also.

The page shows up with the field and button on an Android phone, but tapping the button does not show the text underneath, like his code shows. I don't get any error messages.

I wonder if there is something to declare or Android database permissions to state, but I can't find any.

Am I wrong to think this should work on Android? If not, what could be missing?


That depends from the browser, not from the API/SDK the device uses.

It uses the local storage functionality of the HTML5 standard of the browser.

see this example A Simple TODO list using HTML5 WebDatabases


 **html**

 <input id="show" type="button" value="Show">

 **js**

 function globalError(tx, error)
   {
     alert("Error: " + error.message);
   }

 var db = window.openDatabase('TabOrder', '', 'Bar Tab Orders', 2500000);
 db.transaction(function(tx) {
 tx.executeSql('DROP TABLE IF EXISTS SubmiteData;', null, null, globalError);
 tx.executeSql('CREATE TABLE IF NOT EXISTS SubmiteData (SubmiteDataId integer 
 primary  key, UserId text, AuthNo number, LocId number,ProdId number, 
 CardId number, OrgLat text, OrgLng text, OrgTime text)', 
          null, 
          function()
          {
            SubmiteData("USER1",12345678,23434, 21212, 220232,
            "9", "45", "23/06/2014");

          },
          globalError);
   });

   function SubmiteData(UserId, AuthNo, LocId,ProdId, CardId, OrgLat, OrgLng, OrgTime){
   db.transaction(function(tx){
   tx.executeSql('INSERT INTO SubmiteData(UserId, AuthNo, LocId, ProdId, CardId, 
   OrgLat, OrgLng, OrgTime) VALUES (?,?,?,?,?,?,?,?)', [UserId, AuthNo, LocId,
   ProdId, CardId, OrgLat, OrgLng, OrgTime], 
            null,
            globalError
           );
   });
 }


  function read(UserId, AuthNo, LocId,ProdId, CardId, OrgLat, OrgLng, OrgTime){

 db.transaction(function(tx) {
 tx.executeSql('SELECT * FROM SubmiteData',
         [],
         function(tx, results)
         { 
           for (var i=0; i<results.rows.length; i++) 
           {   
               var row=results.rows.item(i);
              // alert("Id: " + row['UserId']);
              var stringout = "LocId: " + row['LocId'] + "\n"; 
               alert(stringout); 
           } 
         },                
         globalError
        );
    });
  };

 $(function()
  {
    $('#show').click(read);
  });
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号