You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "Ismael Olusola Jimoh (JIRA)" <ji...@apache.org> on 2013/02/15 10:11:13 UTC

[jira] [Commented] (CB-2085) Database Deleted when I open childbrowser

    [ https://issues.apache.org/jira/browse/CB-2085?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13579051#comment-13579051 ] 

Ismael Olusola Jimoh commented on CB-2085:
------------------------------------------

Hi Joe,

Here is what I noticed,

When I build app freshly on my device, it would always return an error if I go into inAppBrowser on first run.

However on subsequent runs, it seems to work just fine.

I am attaching the code for this below:

--Main.html--
@@@
<!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 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('CREATE TABLE IF NOT EXISTS TestTable (Name)');
			tx.executeSql("INSERT INTO TestTable(Name) VALUES ('"+name+"')");
			
		}

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

		function onError(err) 
		{
			alert("Error is : " +err.message);
		}
	}
	</script>
	
  </head>
  <body >

     <h1>Hello DB</h1>
	 <input type="submit" name="DB" value="DB" onclick="DoDBFunctionality()" />
  </body>
</html>
@@@
--index1.html--
@@@
<!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.4.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 type="text/javascript">
   
    function CB() 
    {
		window.open('http://www.google.com', '_blank', 'location=no');
	
    }
   	 
    function nextpage() 
    {
       window.open("index2.html");
    }
       
    </script>
  
  </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>
@@@
--index2.html--
@@@
<!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.4.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 type="text/javascript">
    var DBObject;
    document.addEventListener("deviceready", onLoad, false);
    
    function onLoad() {
        try 
        {
            DBObject = window.openDatabase("TestDB", "1.0", "TestDataBase",100000);
        } 
        catch (ex)
        {
            alert("in catch" + ex.message);
        }
        DBRetrieve();
    }
        function DBRetrieve()
        {
        	DBObject.transaction(retrieveIntoDB,onError,onSuccess);

	        function retrieveIntoDB(tx) 
	        {
	            tx.executeSql('SELECT Name FROM TestTable',[],querySuccess1, onError);
	        }
	        function querySuccess1(tx,results) 
	        {     
	           alert(results.rows.length);
	        }       
        	function onSuccess() {
            
        	}

        	function onError(err) 
        	{
           	 alert("Error is : " +err.message+" "+err.code);
        	}
    }
    </script>
    <style>
    
    </style>
  </head>
  <body>

  <h1>database</h1>
  
</body>
</html>
@@@

To reproduce again you could always clear the apps cache and upon running, the said error would always be reproduced but as mentioned above, this only happens once.

Testing this with PhoneGap 2.4 on Android 4.0.4 and 4.2(Nexus 7) and could reproduce.

Thanks Ismael
                
> Database Deleted when I open childbrowser
> -----------------------------------------
>
>                 Key: CB-2085
>                 URL: https://issues.apache.org/jira/browse/CB-2085
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Android
>    Affects Versions: 2.1.0, 2.2.0
>         Environment: Android, Phonegap,
>            Reporter: Ismael Olusola Jimoh
>            Assignee: Joe Bowser
>             Fix For: 2.4.0
>
>         Attachments: 2013-01-03-15-56-57-152.png, 2013-01-03-15-57-03-482.png, 2013-01-03-15-57-10-684.png, 2013-01-03-15-57-20-843.png, 2013-01-03-15-57-30-553.png, 2013-01-03-15-57-40-449.png, 2013-01-03-15-57-54-341.png, 2013-01-03-15-58-23-263.png, 2013-01-03-15-58-30-526.png, 2013-01-03-15-58-37-306.png, 2013-01-03-15-58-51-725.png, 2013-01-03-15-58-59-568.png, Phonegap2_3_Test.rar, Screenshot_2013-02-15-16-21-21.png, Screenshot_2013-02-15-16-21-37.png, Screenshot_2013-02-15-16-22-13.png, Screenshot_2013-02-15-16-22-23.png, Screenshot_2013-02-15-16-26-21.png, Screenshot_2013-02-15-16-26-31.png, Screenshot_2013-02-15-16-26-50.png, Screenshot_2013-02-15-16-27-00.png, Screenshot_2013-02-15-16-39-05.png, Screenshot_2013-02-15-16-39-11.png, Screenshot_2013-02-15-16-39-17.png, Screenshot_2013-02-15-16-39-24.png, Screenshot_2013-02-15-16-39-30.png, Screenshot_2013-02-15-16-39-38.png, ShareSocial.zip
>
>
> 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

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira