litehelpers / Cordova-SQLitePlugin-legacy-WP-broken-bug666

This version is no longer supported, see Cordova-sqlite-legacy-build-support. May be affected by data risk in litehelpers/Cordova-sqlite-storage#666.
4 stars 8 forks source link

Unable to get property 'transaction' of undefined or null reference #6

Open riturajfico opened 10 years ago

riturajfico commented 10 years ago

When I tried accessing the database via following code: var db = sqlitePlugin.openDatabase('SampleDataBase.sqlite3', '1.0', 'Sample', 2 * 1024 * 1024); db.transaction(function(tx) { tx.executeSql('CREATE TABLE IF NOT EXISTS table1 (key integer, name text)'); }); I got error "Error: System.ArgumentException: Must be specified" I later found that it was due to fact that even before the database is opened, the next statement is trying to execute the sql. So, I modified the code, including the sql execution statement in success callback of the opendatabase function:

var db = sqlitePlugin.openDatabase('SampleDataBase.sqlite3', '1.0', 'Sample', 2 * 1024 * 1024, function(){ db.transaction(function(tx) { tx.executeSql('CREATE TABLE IF NOT EXISTS table1 (key integer, name text)'); }); });

But now I am getting following error 80% of the time: "Error in error callback:TypeError: Unable to get property 'transaction' of undefined or null reference ". The error clearly implies that db is null. But I cannot find the cause of this error. Is anything wrong in the way I included the sql execution in success callback.