I'm trying to test the sqlite
database of an app also in the browser, but using web sql
, I got to research and test some things, but so far nothing has worked. My% cc_defile is thus, and when I run the application on the emulator / device the only error that appears is Can not read property 'id' of undefined , although it correctly displays the category id, I do not understand why this error is appearing on the console.
In the browser the error is this: Can not read property 'transaction' of undefined , and indicates that the error is in the line that has controller.js
, in controller $cordovaSQLite.execute
.
controller.js
marketApp.controller("ConfigCtrl", function($rootScope, $ionicPlatform, $location, $cordovaSQLite) {
$ionicPlatform.ready(function() {
if(window.cordova) {
var db = $rootScope.db = $cordovaSQLite.openDB({name: "market", location: "default"});
$location.path("/home");
} else {
var db = window.openDatabase("market", "1.0", "mark", 100 * 1024 * 1024);
$location.path("/home");
}
db.transaction(populateDB);
});
function populateDB(tx) {
tx.executeSql("DROP TABLE IF EXISTS tblCategories");
tx.executeSql("CREATE TABLE IF NOT EXISTS tblCategories (id integer primary key, category_name text)");
tx.executeSql("CREATE TABLE IF NOT EXISTS tblPlaces (id integer primary key, category_id integer, place_name text)");
tx.executeSql("INSERT INTO tblCategories (category_name) VALUES (?)", ["Academias"]);
tx.executeSql("INSERT INTO tblCategories (category_name) VALUES (?)", ["Bares e Restaurantes"]);
tx.executeSql("INSERT INTO tblCategories (category_name) VALUES (?)", ["Farmácias"]);
}
});
marketApp.controller("HomeCtrl", function($scope, $ionicPlatform, $cordovaSQLite) {
$scope.categories = [];
$ionicPlatform.ready(function() {
var query = "SELECT id, category_name FROM tblCategories";
$cordovaSQLite.execute($scope.db, query, []).then(function(res) {
if(res.rows.length > 0) {
for(var i = 0; res.rows.length; i++) {
$scope.categories.push({category_id: res.rows.item(i).id, category_name: res.rows.item(i).category_name});
}
}
}, function(err) {
console.log(err);
});
});
});
I would like to be able to test in the browser because it is faster, but if there is any other way to do this type of test without having to always be building the app, it will also be useful for me.