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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Web and WebWorks Development

Reply
New Contributor
Arlon
Posts: 3
Registered: ‎09-23-2011
My Carrier: Vodacom SA

Re: html5 database

Hi everybody

 

I am new to Blackberry Webworks, I have been using it for about 3 months.
I recently came across an "unknown database error occurs" error that I do not understand. I have checked my SQL statement and it looks perfect to me. And this is a lot more strange to me because everything was perfectly working. I created at first two tables that I successfully populated, without any error. All the transactions to the database were correctly performed. But when I tried to create a third table, I got that error. And after a while, I was getting a "not authorized" for the same code. 

Would you please help me to solve this issue? I am currently developing for the Curve 8520 OS version 5.

Here is the code: 

 

var db = null;
function initialize ()

{   

DB();

        createProductTable();

}


function readTable ()

{

    try

    {

        if (db != null)

        {

            //alert("Not null");

            db.readTransaction

            (

                function (tx)

              {

                    tx.executeSql("SELECT * FROM colours", [],

                        function (tx, results)

                        {

                            alert("Size: " + results.rows.length);

                        }, 

                        function (tx, err)

                        {

                            alert("Error on reading: " + err.message);

                        } 

                  )

                },

                function (error)

                {

                    alert("Error2 on reading: " + error.message);

                },

                function ()

                {

                    alert("Success");

                }

            );

        }

    }

    catch (exc)

    {

        alert("Exception: " + exc);

    }

}
function openDB ()

{

var size = 2 * 1024 * 1024;
var databaseInstance = null;
try

{

databaseInstance = openDatabase("Sample", "1.0", "Sample", size);

}

catch (e)

{

        alert("Error: " + e.message);

}
return databaseInstance;

}
function DB ()

{

    db = openDB();

}
function createProductTable ()

{

    if (db == null)

    {

        db = openDB();

    }

   if (db == null)

    {

        alert("Failed to initialize database...");

        return;

    }

   db.readTransaction

    (

        function (tx)

        {

            //tx.executeSql("DROP TABLE IF EXISTS products");

            tx.executeSql("CREATE TABLE IF NOT EXISTS colours (name TEXT, code TEXT)", [],

                function (tx, results)

                {

                },

                function (tx, err)

                {

                    alert("Error on creating: " + err.message);

                }

            );

        },

        function (error)

        {

            alert("Error2 on creating: " + getErrorName(error) + " " + error.code);

        },

        function ()

        {

            alert("SUCCESS...");

            readTable();

        }

    );

}
function getErrorName (err)

{

    switch(err.code)

    {

        case err.DATABASE_ERR: 

          //The statement failed for database reasons not covered by any other error code.

          return "DATABASE";

        case err.VERSION_ERR:

          return "DATABASE VERSION";

        case err.TOO_LARGE_ERR:

  return "RESULT TOO LARGE";

        case err.QUOTA_ERR:

          return "QUOTA EXCEEDED";

        case err.SYNTAX_ERR:

          return "SYNTAX";

        case err.CONSTRAINT_ERR:

  return "CONSTRAINT";

       case err.TIMEOUT_ERR:

 return "TIMEOUT";

       default:

         return "UNKNOWN";

    }

}

 

Thanks...

Arlon TM 

 

Please use plain text.