Reputation: 779
I'm using this plugin : https://github.com/litehelpers/Cordova-sqlite-storage
I'm getting above issue in my project while doing DB transactions. Actually there so many transactions in my project at same time from js as well as java end.
Below is my code (just one query) :
function createTable(latWS,longWS,empId) {
window.sqlitePlugin.openDatabase({name: 'test.db', location: 'default'}, function(db) {
db.transaction(function(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS test (loc_emp_lat, loc_emp_long, loc_emp_accuracy, loc_emp_local_time)');
}, function(err) {
console.log('Open database ERROR: ' + JSON.stringify(err));
});
});
setTimeout(insertIntoLogTable(latWS,longWS,empId),500);
}
I have checked, it is not going in error message.
I'm using version : cordova-sqlite-storage 1.4.7 "Cordova sqlite storage plugin"
My Cordova Android version is : 4.1.1
Upvotes: 7
Views: 5851
Reputation: 2532
I had the same problem with react-native-sqlite-storage (which is based on Cordova-sqlite-storage) on Android.
The createFromLocation
parameter was responsible for messing things up. Using only the name
parameter is sufficient on both platforms.
This is what I'm using, on both Android and iOS:
SQLite.openDatabase({ name: "dbname.sqlite"});
On Android 7.0, the database will be saved to /data/data/com.mypackage/databases/dbname.sqlite
.
Upvotes: 4
Reputation: 7
You need to use a delay before creating table, example:
window.sqlitePlugin.openDatabase({name: 'test.db', location: 'default'});
setTimeout(function(){
tx.executeSql('CREATE TABLE IF NOT EXISTS test (loc_emp_lat, loc_emp_long, loc_emp_accuracy, loc_emp_local_time)');
},4000);
Upvotes: -2