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

Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.

New Contributor
Posts: 4
Registered: ‎08-23-2010
My Device: Curve 8520
My Carrier: A1
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, Simulator Version


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">
    <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, ""]);


                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!");

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

            db.transaction(function (tx) {
                tx.executeSql("UPDATE userdata SET value = ? WHERE key = ? ", [data, 1]);
<body onload="setupData()">
    <input type="text" id="storageField" /><input type="button" value="Store" onclick="store();" />
    <br />
    <textarea style="width: 100%;" rows="10" id="txt"></textarea>



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
New Contributor
Posts: 4
Registered: ‎08-23-2010
My Device: Curve 8520
My Carrier: A1

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


Thank you!

Posts: 34
Registered: ‎10-27-2010
My Device: Not Specified

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



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?





Posts: 10
Registered: ‎01-29-2009
My Device: Torch

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



All devices come with an SD card in the box.



Adam Abramski
Product Manager for WebWorks Platform
Handheld Division