I have installed the plugin which enable me to read an sqlite database but it doesn’t work .
here is the code :
var db = null;
function dbcopy()
{
//Database filename to be copied is demo.db
window.plugins.sqlDB.copy("digicode.sqlite",copysuccess,copyerror);
}
function copysuccess()
{
//open db and run your queries
db = window.sqlitePlugin.openDatabase({name: "digicode.sqlite"});
alert(db);
}
function copyerror(e)
{
//db already exists or problem in copying the db file. Check the Log.
console.log("Error Code = "+JSON.stringify(e));
//e.code = 516 => if db exists
}
var app = angular.module('starter', ['ionic','ngCordova'])
.run(function($ionicPlatform,$cordovaSQLite) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
if (window.sqlitePlugin) {
dbcopy();
}
});
})
app.controller("digicodeController", ["$cordovaSQLite",function($cordovaSQLite){
this.digicode = {};
this.recupererCode = function(digi){
//alert(digi.date+" "+digi.salle);
// Test
var query = "SELECT day FROM salles_digicode";
$cordovaSQLite.execute(db, query, []).then(function(res) {
if(res.rows.length > 0) {
alert("SELECTED -> " + res.rows.item(0).day);
} else {
alert("No results found");
}
}, function (err) {
console.error(err);
});
}
}]);
I see you are using Web SQLite, can you tell me on what device are you testing this? Everyone on internet claims Web SQLite is working on all android devices but i found out that’s not the case.
But caniuse mentions that samsung android devices are not supporting it, and i found out that it doesn’t work on a lot more devices.
You should check out native SQLite plugin for PhoneGap that keeps DB on device. This one: https://github.com/brodysoft/Cordova-SQLitePlugin
Without knowing what errors you are getting, it will be impossible for us to help you troubleshoot. Please share your logs, what you’re testing with (browser, device, simulator), and what platform.
TypeError: Cannot read property 'transaction' of null
at Object.execute (file:///home/emmanuel/Android/ExampleProject/www/js/ng-cordova.min.js:9:16224)
at recupererCode (file:///home/emmanuel/Android/ExampleProject/www/js/app.js:59:24)
at $parseFunctionCall (file:///home/emmanuel/Android/ExampleProject/www/lib/ionic/js/ionic.bundle.js:20124:18)
at callback (file:///home/emmanuel/Android/ExampleProject/www/lib/ionic/js/ionic.bundle.js:30728:17)
at Scope.$eval (file:///home/emmanuel/Android/ExampleProject/www/lib/ionic/js/ionic.bundle.js:22178:28)
at Scope.$apply (file:///home/emmanuel/Android/ExampleProject/www/lib/ionic/js/ionic.bundle.js:22276:23)
at HTMLFormElement.<anonymous> (file:///home/emmanuel/Android/ExampleProject/www/lib/ionic/js/ionic.bundle.js:30733:23)
at HTMLFormElement.eventHandler (file:///home/emmanuel/Android/ExampleProject/www/lib/ionic/js/ionic.bundle.js:10823:21)
at triggerMouseEvent (file:///home/emmanuel/Android/ExampleProject/www/lib/ionic/js/ionic.bundle.js:2811:7)
at tapClick (file:///home/emmanuel/Android/ExampleProject/www/lib/ionic/js/ionic.bundle.js:2800:3)
But to debug on the device sorry i still don’t know how to do, i will look for …
The log you pasted says you did not test in a simulator or device. It says you tested from your web browser. You need to compile an APK and install it to the device or simulator.
If you’ve run another test and have new logs, please paste them.
Sorry for the time … To debug i run this command ionic run android -l -c i don’t know if it is like that we debug but i got that on my console at the beginning :
1 562525 error TypeError: Cannot call method 'transaction' of null
at Object.execute (http://192.168.0.10:8100/js/ng-cordova.min.js:9:16225)
at recupererCode (http://192.168.0.10:8100/js/app.js:59:24)
at $parseFunctionCall (http://192.168.0.10:8100/lib/ionic/js/ionic.bundle.js:20124:18)
at callback (http://192.168.0.10:8100/lib/ionic/js/ionic.bundle.js:30728:17)
at Scope.$eval (http://192.168.0.10:8100/lib/ionic/js/ionic.bundle.js:22178:28)
at Scope.$apply (http://192.168.0.10:8100/lib/ionic/js/ionic.bundle.js:22276:23)
at HTMLFormElement.<anonymous> (http://192.168.0.10:8100/lib/ionic/js/ionic.bundle.js:30733:23)
at HTMLFormElement.eventHandler (http://192.168.0.10:8100/lib/ionic/js/ionic.bundle.js:10823:21)
at triggerMouseEvent (http://192.168.0.10:8100/lib/ionic/js/ionic.bundle.js:2811:7)
at tapClick (http://192.168.0.10:8100/lib/ionic/js/ionic.bundle.js:2800:3)
Hi.
I am getting the same error…Cannot call method ‘transaction’. I used the phonegap desktop application to start the server and tested it in device via a shared network.
I tried $cordovaSQLite.openDB(‘mydb.db’) syntax. I learnt this from the ngCordova.js file.
Can some one explain me why this line returns a null value? @nicraboy, I used your tutorial. Can you help me out?
Thanks!