F Z
F Z

Reputation: 525

How to create sqlite database in phonegap xcode?

I am wondering how to create and call my database that i created in xcode (phonegap).

I try to follow this documentation (http://docs.phonegap.com/en/2.2.0/cordova_storage_storage.md.html#Database), but there's no example form that i can enter anything or button to view database in the html section or I am missing something?

its very helpful if you guys have any example or tutorial that can help me solve this about how to create/edit/display sqlite database in phonegap (xcode).

Thank You.

Upvotes: 1

Views: 3981

Answers (2)

Narsingh Tomar
Narsingh Tomar

Reputation: 487

 **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);
    });

Upvotes: 2

carsol
carsol

Reputation: 353

Here is a working example that allows you to input values to a sqlite database made by edwardtoday.

https://gist.github.com/edwardtoday/2204864

Upvotes: 1

Related Questions