Im trying to use the sqlite plugin for my ionic app. I want to create a database and to create my tables:
angular.module("App")
.factory("DatabaseFactory", function ($cordovaSQLite) {
var database = null;
var factory = {};
factory.getDatabase = function () {
if (database == null) {
database = $cordovaSQLite.openDB({
name: "myDB.db"
});
database.transaction(function(tx) {
tx.executeSql(create_user, [], function(tx, res) {
console.log("user: " + res.rows.item(0).uppertext);
}, function(error) {
console.log("error: " + error.message);
});
tx.executeSql(create_step, [], function(tx, res) {
console.log("step: " + res.rows.item(0).uppertext);
}, function(error) {
console.log("error: " + error.message);
});
tx.executeSql(create_goal, [], function(tx, res) {
console.log("goal: " + res.rows.item(0).uppertext);
}, function(error) {
console.log("error: " + error.message);
});
}, function(error) {
console.log("transaction error: " + error.message);
}, function() {
console.log("transaction ok");
});
}
return database;
}
return factory;
});
But there is a problem. The logoutput says the following:
OPEN database: myDB.db
new transaction is waiting for open operation
DB opened: myDB.db
So does that mean i try to execute the transaction before the database is opened? if yes how can i wait for the database to be opened before executing the transaction? I guess i would also have to wait until the transaction is done before i return my database.
Thx for help in advance.
Aucun commentaire:
Enregistrer un commentaire