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
zantoro
Posts: 14
Registered: ‎09-14-2012
My Device: Bold 9700
My Carrier: Bouygues
Accepted Solution

Database returns no error but doesn't delete the table

Hello,

I'm developing an app that uses a database (SQLite). I would like to delete and recreate a table in the database (this table is sort of a cache).

When I execute the following code, I get no error but from Chrome/Ripple -> Resources -> "Web SQL" I still see the old table structure,

Do you have any idea what the problem might be or how can I troubleshoot it?

		db.transaction(
			function (tx) {
				tx.executeSql('DROP TABLE IF EXISTS users',[],function (tx, res) {}, function (tx, err) {alert(err.message)});
				tx.executeSql('CREATE TABLE users (firstname, lastname, phonenumber, emailadd, company)',[],function (tx, res) {}, function (tx, err) {alert(err.message)});
				for (var i = 0; i < oPerson.length; i++) {
					tx.executeSql('INSERT INTO users (firstname, lastname, phonenumber, emailadd, company) VALUES ("' + oPerson[i].Firstname + '", "' + oPerson[i].Lastname + '", "' + oPerson[i].Phonenumber + '", "' + '", "' + oPerson[i].Emailadd + '", "' + oPerson[i].Company + '")');
					iUsers = iUsers + 1;
				}
			}
			
		);

 Thanks a lot,

Roberto.

 

Please use plain text.
Developer
jamesgibbons
Posts: 26
Registered: ‎06-01-2010
My Device: Dev Alpha, PlayBook

Re: Database returns no error but doesn't delete the table

Hi Roberto,

 

 

There was an issue with your INSERT INTO string where you provided an extra value that did not exist as a database column. Change

 

 oPerson[i].Phonenumber + '", "' + '", "' + oPerson[i].Emailadd 

to 

 

 oPerson[i].Phonenumber + '", "' +  oPerson[i].Emailadd 

 

Here is some complete code that should run:

 

var db = openDatabase('mydb', '2.0', 'Test DB', 4 * 1024 * 1024);
var iUsers = 0;
var oPerson = [{Firstname: 'Joe',
	Lastname: 'Smith',
	Phonenumber: '1800CALLJOE',
	emailadd: 'joe.Smith@photoj.am',
	Company: 'Photojam'},
	{Firstname: 'Jack',
	Lastname: 'Smith',
	Phonenumber: '1800JACK999',
	emailadd: 'jack.Smith@photoj.am',
	Company: 'Photojam'}
	];
db.transaction(
			function (tx) {
				tx.executeSql('DROP TABLE IF EXISTS users',[],function (tx, res) {}, function (tx, err) {alert(err.message)});
				tx.executeSql('CREATE TABLE users (firstname, lastname, phonenumber, emailadd, company)',[],function (tx, res) {}, function (tx, err) {alert(err.message)});
				for (var i = 0; i < oPerson.length; i++) {
					tx.executeSql('INSERT INTO users (firstname, lastname, phonenumber, emailadd, company) VALUES ("' + oPerson[i].Firstname + '", "' + oPerson[i].Lastname + '", "' + oPerson[i].Phonenumber + '", "' + oPerson[i].Emailadd + '", "' + oPerson[i].Company + '")');
					iUsers = iUsers + 1;
				}
			}
			
		);

 

 Let me know if there are any issues!

 

Cheers,

 

James

___________________________________________________________
My latest Blackberry 10 app Audiobooks! :smileyhappy:

My latest PlayBook app Photojam!

Find me on Twitter: GoGibbons
Please use plain text.
Contributor
zantoro
Posts: 14
Registered: ‎09-14-2012
My Device: Bold 9700
My Carrier: Bouygues

Re: Database returns no error but doesn't delete the table

That's perfect... Thanks!

 

Please use plain text.