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
lawillas
Posts: 17
Registered: ‎06-18-2012
My Device: Bold 9900
My Carrier: Globacom

HTML5 Database not working

I'm tryna create a database and store some data in it. When I test my code on my blackberry 9900, it alerts me that the database was created successfully and that the table I wanna create too was created successfully. The problem is, whenever I want to do an insert or a select, i get an error that the database table does not exist. Please is there a problem with HTML5 database and BB Web Works. Here's a sneak into my code.

 

function createDB(){
if(window.openDatabase){
globalVar.db = window.openDatabase("TestDB8","1.0","Notification storage",5*1024*1024, onDBCreate);
}else{
alert("This device does not have HTML5 database support");
}
}

 

function onDBCreate(database){
database.transaction(function(tx){
tx.executeSql('CREATE TABLE notification(`id` INTEGER PRIMARY KEY AUTOINCREMENT , `subject` varchar(255), `message` varchar(4000), `time` datetime, `status` tinyint(1) DEFAULT 0)',[],
function(tx, res){
alert("Database Table notification was successfully created");
},
function(tx, err){
alert("Error creating table: "+err.message);
}
);
}
);
}

 

 

globalVar.db.transaction(function(tx){
tx.executeSql('INSERT INTO notification(`subject`,`message`,`time`,`user_id`,`status`) VALUES(?,?,?,?,?)',[subject,message,time,globalVar.userid,0],
function(tx,res){
alert('Notification was added successfully');
},
function(tx,err){
alert('Couldnt add notification: '+err.message);
}
);
}
);

 

 

globalVar.db.readTransaction(function(t){
t.executeSql('SELECT count(*) AS c FROM notification', [], function(t, r){
var len = r.rows[0].c;
alert("Total notifications: "+len);
},
function(t, e){
alert("Can't read records: "+e.message); 
}

);
});

 

Please can someone tell me what's wrong. I read through the documentation closely and followed the instructions there.

Please use plain text.
Contributor
Ryanthegiantlion
Posts: 17
Registered: ‎08-23-2012
My Device: developer
My Carrier: n/a

Re: HTML5 Database not working

[ Edited ]

From the api

we see:

void transaction (callback: function(transaction : SQLTransaction), [errorCallback: function(error : SQLError)], [successCallback: function()]) 

 
Your success and error callbacks are the wrong way round . . . 

 

BTW: A gotcha that cought me out when testing this that I didnt see in th docs is that the blackberry must be unplugged from usb after deployment for testing (at least on OS 5.0). Access to the SD card is required and there is no access when the the phone is connected via USB.

 

Edit: I suspect your create table is erroneously reporting success when it is actually failing because the table is already created and the inserts are erroneously reporting a fail when they are actually succeeding . . .

Please use plain text.