angular.module('starter.services', []) .factory('$database',['$cordovaSQLite', function($cordovaSQLite) { var self = this; self.db = null; var query; //this updateTable function is for ilustrative use here, it can be changed to manage all queries indeed. updateTable=function (table, column, value, condition) { if(!condition){ query = "UPDATE " + table + " SET " + column + " = " + value; } else{ query = "UPDATE " + table + " SET " + column + " = " + value + " WHERE " + condition; } return $cordovaSQLite.execute(self.db,query,[]). then(function(result) { console.log(query); query=null; return result; },function(error) { console.error(error); query=null; return error; }); }; return { initDB: function() { if(window.cordova){ //self.db = sqlitePlugin.openDatabase({name: "data.db", location: 2, createFromLocation: 1}); self.db = $cordovaSQLite.openDB("pokedex.db"); } else { self.db = window.openDatabase('pokedex.db','1','my',800*1024); // only available when WebSQL is available in Browser } console.log('Database opened'); return self.db; }, setBuys: function(itemName,itemBild,itemBildtext,itemKaufdatum,itemappimgpath,itemappimgpublicpath) { query="INSERT INTO buys (Name, Bild, Bildtext, Kaufdatum, appimgpath, appimgpublicpath) VALUES (?,?,?,?,?,?);"; return $cordovaSQLite.execute(self.db,query,[itemName,itemBild,itemBildtext,itemKaufdatum,itemappimgpath,itemappimgpublicpath]). then(function(result) { console.log("Gespeichert"); query=null; }, function(error) { console.error(error); }); }, deleteBuy: function(id) { query="DELETE FROM buys WHERE ID = ?;"; return $cordovaSQLite.execute(self.db,query,[id]). then(function(result) { console.log("Gelöscht"); query=null; }, function(error) { console.error(error); }); }, getAllBuys: function(){ var ArrayQ=[]; query="SELECT * FROM buys order by id DESC"; return $cordovaSQLite.execute(self.db,query). then(function(result) { for(j=0;j