Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Contributor
kingsha
Posts: 23
Registered: ‎07-11-2011
My Device: Beginner Developer

HTML5 database crashes application on OS6?

[ Edited ]

Hi there. I am trying to build an application that will work on both OS5 and OS6. I am trying to store some data to local memory using databases. I have successfully implemented this in OS5 using the html5_init.js file which converts it into gears. The problem is that is does not work for OS6.

 

Each time I try to run the application, it crashes. The blackberry simulator just stops responding. I have experienced this in simulators 9800 (v.534) and 9700 (v.570). I do simulate an SD card as that is required for databases.

 

Here is a dummed down version of the code which fails.

 

config.xml

<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns="http://www.w3.org/ns/widgets" 
   xmlns:rim="http://www.blackberry.com/ns/widgets" 
   version="1.0.0.0" rim:header="IESOAPP">
   
   <name>MAAG</name>
   
   <description>MAAG test appplication.</description>
   
   <author>thats me</author>
   
   <content src="sample.html"/>
   
   <access uri="http://hello.ca" subdomains="true" />
	
</widget>

 

sample.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html>
<head>
    <title>Test</title>

    <!-- path to the script files changed for codepresentation -->
    <meta name="viewport" id="viewport" content="initial-scale=1.0,user-scalable=no" />
    <meta name="x-blackberry-defaultHoverEffect" content="false" />
    <script type="text/javascript">
        var db = null;

        function setupData() {	
			alert('am setting it up!');
            try {
                db = openDatabase("TestDB", '1.0', 'Test', 50 * 1024);
                // db = new Database("TestDB"); // fails with the mentioned exception (not defined)
                if (db) {
                    db.transaction(function (tx) {
                        tx.executeSql("CREATE TABLE IF NOT EXISTS userdata (key int unique,  value text)");
                        tx.executeSql("SELECT value FROM userdata WHERE key = ?", [1], function (tx, results) {
                            if (results.rows.length == 1) {
                                document.getElementById("storageField").value = results.rows.item(0).value;
                            }
                            else {
                                tx.executeSql("INSERT INTO userdata (key, value) VALUES (?, ?)", [1, ""]);
                            }
                            alert("loaded");
                        });
                    });
                }
                else {
                    document.getElementById("txt").value += "\r\nNo DB\r\nopenDatabase:\r\n" + openDatabase;
                }
            }
            catch (err) {
                document.getElementById("txt").value += err;
            }
        }

        function store()
        {
            if (!db)
            {
                alert("No DB!");
                return;
            }

            var data = document.getElementById("storageField").value;

            db.transaction(function (tx) {
                tx.executeSql("UPDATE userdata SET value = ? WHERE key = ? ", [data, 1]);
            });
        }
    </script>

</head>
<body onload="setupData()">
<div>
    <input type="text" id="storageField" /><input type="button" value="Store" onclick="store();" />
    <br />
    <textarea style="width: 100%;" rows="10" id="txt"></textarea>
    
</div>
</body>
</html>

 

Can someone please help me to resolve this issue. I really need to save to local memory in both OS versions and this should work in OS6.

 

Please use plain text.
Contributor
kingsha
Posts: 23
Registered: ‎07-11-2011
My Device: Beginner Developer

Re: HTML5 database crashes application on OS6?

Anyone try this and see that it crashes? Maybe there is an error in the code?
Please use plain text.
Contributor
hababut
Posts: 41
Registered: ‎07-21-2011
My Device: Superberry

Re: HTML5 database crashes application on OS6?

I tried it on the 6.0.0.570 Asia simulator and it crashes. I've also tried it on the 7.0 sim that comes bundled with our releases and it's working fine, so there's a bug in those sim releases. All I can suggest is trying another 6.0 simulator until you find one that works.
----------------------------------------------------------------------------------------------
I kode for cudos! Or was it the other way around?
Please use plain text.
Contributor
bbooks
Posts: 16
Registered: ‎09-15-2011
My Device: curve

Re: HTML5 database crashes application on OS6?

I am having this problem. My application uses sqlite database and it crashes the app, it works most of the time but eventually when the app accesses the database the app crashes and when I try to restart it never starts again, I have to remove battery and reset the phone. I am running it on a torch with os6.0. When I reset the phone it works for a bit and then eventually crashes again. I am testing on an actual device. The same application runes on my curve with the 5.0 os and no problems. Has anyone else solved this problem? I am using the latest SDK 2.01. Help. I will have to scrap the whole project if I cant get this fixed.

Please use plain text.
BlackBerry Development Advisor (Retired)
jeffheifetz
Posts: 518
Registered: ‎07-18-2011
My Device: Bold

Re: HTML5 database crashes application on OS6?

kingsha -You do not have all your transactions chained so there's no guarantee that the database has been created before the next transaction is fired. Admittedly that shouldn't crash the app though.

 

bbooks- what versions of the simulator are you using?

 



1.Please resolve your thread by clicking the "Accept as Solution" button below the post which solved your problem!
2. If any post helps you please click the button below the post(s)
Please use plain text.
Contributor
bbooks
Posts: 16
Registered: ‎09-15-2011
My Device: curve

Re: HTML5 database crashes application on OS6?

I am not using  simulator. I am testing on actual devices. I have found that the simulators take longer to load and test than on actual device. I am now trying to upgrade to sdk 2.0.1.1 to see if this solves problem. I read somewhere that this has fixed some memory leak problems.

Please use plain text.
Contributor
bbooks
Posts: 16
Registered: ‎09-15-2011
My Device: curve

Re: HTML5 database crashes application on OS6?

I read here http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/Device-memory-is-Low-issue-for-a... that this is a bb os6 memory leak problem. The browserfield used in the webworks not allowing GC to clean up memory. Seems that the fix is to wait for rim people to fix it in new sdk!! This is a real show stopper for our app. I think that this problem should be published more as no apps can be released into the wild knowing that it will eventually crash.:Censored: So only solution is to wait for fix or go the java route.

 

I tried sdk 2.0.1.1 still same problem!

Please use plain text.
Developer
abarber
Posts: 189
Registered: ‎08-13-2008
My Device: Not Specified

Re: HTML5 database crashes application on OS6?

Hi Guys

 

HTML5 database are asynchronous.

 

You can't call transactions for select statements in the same thread as creating the database tables.

The tables may not be created yet.

 

So the following will casue errors in v6 devices.

tx.executeSql("CREATE TABLE IF NOT EXISTS userdata (key int unique,  value text)");
                        tx.executeSql("SELECT value FROM userdata WHERE key = ?", [1], function (tx, results) {
                            if (results.rows.length == 1) {
                                document.getElementById("storageField").value = results.rows.item(0).value;
                            }
                            else {
                                tx.executeSql("INSERT INTO userdata (key, value) VALUES (?, ?)", [1, ""]);
                            }
                            alert("loaded");
                        });

 

You need to call the select on the callback of the creation of tables.

 

You also need to handle database errors.

 

 

 

e.g.

 

As an example of async and callbacks check this out

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html>
<head>
    <title>Test</title>

    <!-- path to the script files changed for codepresentation -->
    <meta name="viewport" id="viewport" content="initial-scale=1.0,user-scalable=no" />
    <meta name="x-blackberry-defaultHoverEffect" content="false" />
    <script type="text/javascript">
        var db = null;

        function setupData() { 
   alert('am setting it up!');
            try {
                db = openDatabase("TestDB", '1.0', 'Test', 50 * 1024);
                // db = new Database("TestDB"); // fails with the mentioned exception (not defined)
                if (db) {
     db.transaction(function(tx){
      tx.executeSql("CREATE TABLE IF NOT EXISTS userdata (key int unique,  value text)", [],DataHandler,errorHandler);
     },
      tx_errorHandler
     ,
      tx_DB_Select 
     );     
                }
                else {
                    document.getElementById("txt").value += "\r\nNo DB\r\nopenDatabase:\r\n" + openDatabase;
                }
            }
            catch (err) {
                document.getElementById("txt").value += err;
            }
        }
  
  function errorHandler(transaction, error){
      try {
          alert('errorHandler-message:' + error.message + '. code:' + error.code + '.');
      }
      catch(e){
          alert('errorHandler-error:' + e.message + '.');
      }
  }  

  function DataHandler(transaction, results){
      try {
             if (results.rows.length == 1) {
                 document.getElementById("storageField").value = results.rows.item(0).value;
                 }
                 else {
                  //tx.executeSql("INSERT INTO userdata (key, value) VALUES (?, ?)", [1, ""]);
                 }
                 alert("loaded");    
      }
      catch(e){
          alert('DataHandler-error:' + e.message + '.');
      }
  }
  
  function tx_errorHandler(error){
      try {
          alert('tx_errorHandler-message:' + error.message + '. code:' + error.code + '.');
      }
      catch(e){
          alert('tx_errorHandler-error:' + e.message + '.');
      }
  }
  
  function tx_DB_Select(){
      try {
    db.transaction(function(tx){
     tx.executeSql("SELECT value FROM userdata WHERE key = ?", [1],DataHandler,errorHandler);
    },
     tx_errorHandler
    ,
     tx_DataHandler 
    );
      }
      catch(e){
          alert('tx_DB_Select-error:' + e.message + '.');
      }
  } 
  
  function tx_DataHandler(){
      try {
    
      }
      catch(e){
          alert('tx_DataHandler-error:' + e.message + '.');
      }
  }       

        function store()
        {
            if (!db)
            {
                alert("No DB!");
                return;
            }

            var data = document.getElementById("storageField").value;

            db.transaction(function (tx) {
                tx.executeSql("UPDATE userdata SET value = ? WHERE key = ? ", [data, 1]);
            });
        }
    </script>

</head>
<body onload="setupData()">
<div>
    <input type="text" id="storageField" /><input type="button" value="Store" onclick="store();" />
    <br />
    <textarea style="width: 100%;" rows="10" id="txt"></textarea>
   
</div>
</body>
</html>

 

Cheers

 

Andrew

 

Please use plain text.
Contributor
bbooks
Posts: 16
Registered: ‎09-15-2011
My Device: curve

Re: HTML5 database crashes application on OS6?

Thanks for your code abarber.

I am doing something similar in my code and still experience memory leak error. As I said before the error I believe  is rooted in a memory leak problem associated with webworks on the 6.0 os. The webworks does not release all the memory it should when the application is closed. We encountered the problem when stress testing application before  launching it. If the application is opened and closed a number of times it will eventually crash with low memory error. This occurs not only with app that use database. It seems to occur with most apps with images and or DOM manipulation etc.. It seems that rim is aware of the problem and are trying to fix it. We have had to shelved the project until rim releases fix.

 

Can anyone else try to stress test their app on Os 6 and see if they experience the same.

 

Regards

Please use plain text.
Contributor
bbooks
Posts: 16
Registered: ‎09-15-2011
My Device: curve

Re: HTML5 database crashes application on OS6?

Good news / Bad news

 

Good news: Rim knows about memory leak problem and say they have a fix that they are testing that will trick webkit into releasing memory, that should fix problem. You will have to recompile your app with a new sdk.

 

Bad news: the fix will not be available until mid October.

Please use plain text.