Hello all, first i’m a newbie, I’m having some issues in copying SQLite database ( or maybe read it ), i’ve already tried a lots of codes but without any result, all what i want is to do a login page that verify user/password, at first i want to verify the connection, i used some alerts to ensure that, but no one of them show, please i need your help,
sometime i got an error that says " TypeError: Cannot read property ‘transaction’ of null "
i’d installed :
- sqlite
- cordova-plugin-dbcopy
- and ng-cordova.min.js
i’ve tried many methodes that i found in the Internet but no one works for me
(sorry for my English guys)
app.js
`
db = null;
angular.module('starter', ['ionic', 'ngCordova', 'starter.controllers', 'starter.services'])
.run(function ($ionicPlatform, $cordovaSQLite) {
$ionicPlatform.ready(function () {
if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if (window.StatusBar) {
StatusBar.styleDefault();
}
/* DATABASE INTEGRATION */
if (window.sqlitePlugin !== undefined) {
// copy the database
window.plugins.sqlDB.copy("utilisateurs.db", 1,
function () {
// copy success, if not yet been copied
// set "db" as the database
db = window.sqlitePlugin.openDatabase({ name: "utilisateurs.db", location: 2, createFromLocation: 1 });
alert("SUCCES");
}, function () {
// copy error, if it has already been copied
// set "db" as the database
db = window.openDatabase("utilisateurs.db", "1.0", "Database", 200000);
alert("ERROR");
});
} else {
alert("not loaded");
}
});
})`
controllers.js
.controller('ngController', function ($scope) {
$scope.selectAll = function () {
// db is your database defined before
db.transaction(function (tx) {
// running a sql querie
tx.executeSql("SELECT id, utilisateur FROM utilisateurs", [], function (tx, res) {
var len = res.rows.length;
for (var i = 0; i < len; i++) { // loop as many times as there are row results
alert(res.rows.item(i).id + ' ' + res.rows.item(i).utilisateur); // showing the results
}
}, function (e) {
alert("ERROR: " + e.message);
});
});
};
})