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
New Contributor
crazy-weasel
Posts: 4
Registered: ‎08-23-2010
My Device: Curve 8520
Accepted Solution

OS5 HTML5 to Gears - openDatabase fails - Database undefined

 

Hi there..

 

Today I tried to create a simple widget with some database interaction. I started with reading some articles on the blackberry developer pages and found some interesting resources. Especially that gears support was dropped with OS6.  My future widgets should run on OS5 and OS6 devices, so I followed the instructions at Supporting Gears using HTML5 in BlackBerry Widget applications.

 

After reading some stuff on this WebSQL Api I tried to create a small widget, which stores a simple text-entry in the Database. I tried the WebSQL Code in my normal desktop browser (Opera) and it worked, but not when I test it in the BlackBerry simulator.

 

I set up my widget as described in the "How to Avoid Recompiling a BlackBerry Widget During Development" tutorial.

 

In my widget, the "openDatabase" call fails, altough this function exists. I tried to get some error information with a try-catch block, but the call fails "silently". After investigating this function (displaying its content in a textarea) I found creation of an Database-Object inside an try-catch block.

 

When I try to create such Database object for myself, it throws the following exception: ReferenceError: "Database" is not defined.

 

Do you have any ideas?

 

I'm running the widget in an Curve 8520 Simulator, OS Version 5.0.0.509, Simulator Version 2.13.0.97.

 

If you need further information, please ask!

 

Thank you for your help, and I hope my english isnt too bad. (It's not my native language)

 

Here is my html and javascript code:

 

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html>
<head>
    <title>Test</title>
    <script type="text/javascript" src="http://mydomain.tld/scripts/html5_init.js" id="html5_init"></script>
    <script type="text/javascript" src="http://mydomain.tld/scripts/html5_worker.js"></script>
    <!-- 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() {

            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>

 

 

Please use plain text.
Retired
tneil
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: OS5 HTML5 to Gears - openDatabase fails - Database undefined

[ Edited ]

Are you simulating an SD Card being inserted in the simulator?  A SQLite database on 5.0 must either be stored on an inserted SD Card or a built in eMMC card.  A built in eMMC card is only on the Storm devices and Bold 9000.

 

If you simulate an SD card on your curve simulator, the database should be created

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.
New Contributor
crazy-weasel
Posts: 4
Registered: ‎08-23-2010
My Device: Curve 8520

Re: OS5 HTML5 to Gears - openDatabase fails - Database undefined

 

Thank you!

Please use plain text.
Contributor
Sefi
Posts: 34
Registered: ‎10-27-2010
My Device: Not Specified

Re: OS5 HTML5 to Gears - openDatabase fails - Database undefined

Tim,

 

So what you are saying is that in order to have SQLite working my end users MUST have an SD card?  Do they typically come with one?

 

Thanks,

 

-Sefi

Please use plain text.
Retired
abramski
Posts: 10
Registered: ‎01-29-2009
My Device: Torch

Re: OS5 HTML5 to Gears - openDatabase fails - Database undefined

Hi,

 

All devices come with an SD card in the box.

 

Adam

Adam Abramski
Product Manager for WebWorks Platform
Handheld Division
Please use plain text.