Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-2085

Database Deleted when I open childbrowser

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Won't Fix
    • 2.1.0, 2.2.0
    • 2.6.0
    • cordova-android
    • None
    • Android, Phonegap,

    Description

      Created an app where on the first page, user creates and enters values into a table, upon success, he is sent to a second page which Contains a link to Google using Childbrowser as well as a button to show content of database.

      If user clicks button to show content of database immediately he gets to page 2, the result is as expected but if he should click button to childbrowser, when he closes and clicks the result button, it states table does not exist returning Error: Undefined

      However, if user goes back to page one and recreates the whole table as well as enter the values, then clicks childbrowser, return and click return button, it starts working.

      All subsequent visits also work provided you do not clear data/cache.

      Below is a code that can be used to reproduce this:

      ----------------------------------------------------------------------------Main.html (Page1)
      ----------------------------------------------------------------------------
      <!DOCTYPE HTML>
      <html>
      <head>
      <meta name="viewport" content="user-scalable=no,width=device-width" />
      <meta http-equiv="Content-type" content="text/html; charset=utf-8">
      <script src="cordova-2.1.0.js" type="text/javascript"></script>
      <script type="text/javascript" charset="utf-8" src="main.js"></script>
      <script src="jquery-1.8.2.min.js" type="text/javascript"></script>
      <script src="jquery.mobile-1.2.0.min.js" type="text/javascript"></script>

      <link rel="stylesheet" href="jquery.mobile-1.2.0.css" type="text/css" media="screen" title="no title" charset="utf-8">

      <script type="text/javascript">
      var DBObject;
      function DoDBFunctionality() {
      try

      { DBObject = window.openDatabase("TestDB", "1.0", "TestDataBase",1024 * 1024 * 2); }

      catch (ex)

      { alert("in catch" + ex.message); }

      DBObject.transaction(insertIntoDB,onError,onSuccess);

      function insertIntoDB(tx)

      { var name = "Vaibhav"; //tx.executeSql('DROP TABLE IF EXISTS TestTable'); tx.executeSql('CREATE TABLE IF NOT EXISTS TestTable (id unique PRIMARY KEY, data)'); tx.executeSql('INSERT INTO TestTable (data) VALUES ("First row")'); tx.executeSql('INSERT INTO TestTable (data) VALUES ("Second row")'); //alert("In Insert Function"); }

      function onSuccess()

      { alert("Insertion in DB is successfull"); window.open("index1.html"); }

      /*

      • If DB throws an Error
        */

      function onError(err)

      { alert("Error is : " +err.message); }

      }
      </script>
      <style>

      </style>
      </head>
      <body >

      <h1>Hello DB</h1>
      <input type="submit" name="DB" value="DB" onclick="DoDBFunctionality()" />
      </body>
      </html>
      ----------------------------------------------------------------------------

      ----------------------------------------------------------------------------
      Index1.html(page2)
      ----------------------------------------------------------------------------
      <!DOCTYPE HTML>
      <html>
      <head>
      <meta name="viewport" content="user-scalable=no,width=device-width" />
      <meta http-equiv="Content-type" content="text/html; charset=utf-8">
      <script src="cordova-2.1.0.js" type="text/javascript"></script>
      <script type="text/javascript" charset="utf-8" src="main.js"></script>
      <script src="jquery-1.8.2.min.js" type="text/javascript"></script>
      <script src="jquery.mobile-1.2.0.min.js" type="text/javascript"></script>

      <link rel="stylesheet" href="jquery.mobile-1.2.0.css" type="text/css" media="screen" title="no title" charset="utf-8">
      <script src="childbrowser.js" type="text/javascript"></script>
      <script type="text/javascript">

      var DBObject //= window.openDatabase("TestDB", "1.0", "TestDataBase",1024 * 1024 * 2);

      function CB() {

      /*
      *To open Childbrowser window in application
      */

      var url = "http://www.google.com";
      window.plugins.childBrowser.showWebPage( url,

      {showLocationBar: true}

      );
      //window.plugins.childBrowser.onClose();
      window.plugins.childBrowser.onClose = closed;
      }

      function closed()

      { //location.reload(); //window.openDatabase("TestDB", "1.0", "TestDataBase",1024 * 1024 * 2); }

      function CallDB() {
      try

      { DBObject = window.openDatabase("TestDB", "1.0", "TestDataBase",1024 * 1024 * 2); }

      catch (ex)

      { alert("in catch" + ex.message); }

      DBRetrieve();
      }
      function DBRetrieve() {
      DBObject.transaction(retrieveIntoDB,onError,onSuccess);

      function retrieveIntoDB(tx)

      { tx.executeSql('SELECT * FROM TestTable',[],querySuccess1, onError); }

      function querySuccess1(tx,results)
      {
      /* alert("Returned rows = " + results.rows.length);
      // this will be true since it was a select statement and so rowsAffected was 0
      if (!results.rowsAffected)

      { alert('No rows affected!'); return false; }

      alert("Last inserted row ID = " + results.insertId);*/
      var len = results.rows.length;
      alert("Demo table: " + len + " rows found.");
      for (var i=0; i<len; i++)

      { alert("Row = " + i + " ID = " + results.rows.item(i).id + " Data = " + results.rows.item(i).data); }

      }
      function onSuccess() {

      }

      function onError(err)

      { alert("Error is : " +err.message); }

      }

      function nextpage()

      { CallDB(); }

      </script>
      <style>

      </style>
      </head>
      <body >

      <h1>Hello ChildBrowser</h1>
      <input type="submit" name="CB" value="CB" onclick="CB()" />
      <br/>
      <input type="submit" value="DBRetrieve" onclick="nextpage()" />
      </body>
      </html>
      ----------------------------------------------------------------------------

      I have tested this on Phonegap 2.1 and 2.2.

      I have also tested this on Android 4.0, 4.2 and been able to reproduce on both.

      Thanks, I look forward to your quick response.

      Ismael O. Jimoh

      Attachments

        1. ShareSocial.zip
          1.55 MB
          Ismael Olusola Jimoh
        2. Screenshot_2013-02-15-16-39-38.png
          26 kB
          Ismael Olusola Jimoh
        3. Screenshot_2013-02-15-16-39-30.png
          57 kB
          Ismael Olusola Jimoh
        4. Screenshot_2013-02-15-16-39-24.png
          23 kB
          Ismael Olusola Jimoh
        5. Screenshot_2013-02-15-16-39-17.png
          24 kB
          Ismael Olusola Jimoh
        6. Screenshot_2013-02-15-16-39-11.png
          26 kB
          Ismael Olusola Jimoh
        7. Screenshot_2013-02-15-16-39-05.png
          17 kB
          Ismael Olusola Jimoh
        8. Screenshot_2013-02-15-16-27-00.png
          22 kB
          Ismael Olusola Jimoh
        9. Screenshot_2013-02-15-16-26-50.png
          40 kB
          Ismael Olusola Jimoh
        10. Screenshot_2013-02-15-16-26-31.png
          18 kB
          Ismael Olusola Jimoh
        11. Screenshot_2013-02-15-16-26-21.png
          20 kB
          Ismael Olusola Jimoh
        12. Screenshot_2013-02-15-16-22-23.png
          18 kB
          Ismael Olusola Jimoh
        13. Screenshot_2013-02-15-16-22-13.png
          41 kB
          Ismael Olusola Jimoh
        14. Screenshot_2013-02-15-16-21-37.png
          21 kB
          Ismael Olusola Jimoh
        15. Screenshot_2013-02-15-16-21-21.png
          13 kB
          Ismael Olusola Jimoh
        16. 2013-01-03-15-58-59-568.png
          28 kB
          Ismael Olusola Jimoh
        17. 2013-01-03-15-58-51-725.png
          25 kB
          Ismael Olusola Jimoh
        18. 2013-01-03-15-58-37-306.png
          29 kB
          Ismael Olusola Jimoh
        19. 2013-01-03-15-58-30-526.png
          23 kB
          Ismael Olusola Jimoh
        20. 2013-01-03-15-58-23-263.png
          27 kB
          Ismael Olusola Jimoh
        21. 2013-01-03-15-57-54-341.png
          268 kB
          Ismael Olusola Jimoh
        22. 2013-01-03-15-57-40-449.png
          23 kB
          Ismael Olusola Jimoh
        23. 2013-01-03-15-57-30-553.png
          30 kB
          Ismael Olusola Jimoh
        24. 2013-01-03-15-57-20-843.png
          30 kB
          Ismael Olusola Jimoh
        25. 2013-01-03-15-57-10-684.png
          23 kB
          Ismael Olusola Jimoh
        26. 2013-01-03-15-57-03-482.png
          27 kB
          Ismael Olusola Jimoh
        27. 2013-01-03-15-56-57-152.png
          17 kB
          Ismael Olusola Jimoh
        28. Phonegap2_3_Test.rar
          1.66 MB
          Ismael Olusola Jimoh

        Activity

          People

            bowserj Joey Robert Bowser
            akoredenitan Ismael Olusola Jimoh
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: