Hello,
today i tried to use sqlite with ionic but i failed.
I added the plugin:
<plugin name="cordova-sqlite-storage" spec="https://github.com/litehelpers/Cordova-sqlite-storage.git" />
And created a factory to open a database and create the 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;
});
Unfortunately this does not seem to work because when i run my app and init my database the output is the following:
OPEN database: myDB.db
new transaction is waiting for open operation
DB opened: myDB.db
I cant figure out what the probem is. Maybe someone has ideas.