1

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.

2 Answers 2

2
 **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);
    });
Sign up to request clarification or add additional context in comments.

Comments

1

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.