Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49164

Sqlite does not work when compile to real android device

$
0
0

@sandiramadhan wrote:

Hey everyone, i'm new in ionic framework
I created simple app using ionic and sqlite for local storage, when i'm running on browser its work fine, but after i compile it to real android device, the sqlite is not work fine

this is my connections code
`var app = angular.module('starter', ['ionic','ngCordova'])

.run(function($ionicPlatform, $cordovaSQLite,$ionicPopup) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
if (window.cordova) {
db = $cordovaSQLite.openDB({ name: "my.db", location: "default" }); // Mobile
$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS todo_table (id integer primary key, todo_name text, date text)");
} else {
db = window.openDatabase("my.db", '1', 'my', 200000); // browser
$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS todo_table (id integer primary key, todo_name text, date text)");
};
});
});`

And this is simple query to get all from database
$scope.allGet = function() {
var query = "SELECT * FROM todo_table ORDER BY id DESC";
$cordovaSQLite.execute(db,query).then(function(result){
if ($scope.dataTodos=='') {
for (var i = 0 ; i < result.rows.length ; i++) {
$scope.dataTodos.push(result.rows[i]);
};
} else {
$scope.dataTodos = [];
for (var i = 0 ; i < result.rows.length; i++) {
$scope.dataTodos.push(result.rows[i]);
};
console.log($scope.dataTodos[0].todo_name);
var congrats = $ionicPopup.alert({
title : 'Congratulations!',
template : '<b>'+$scope.dataTodos[0].todo_name+'</b> is your first data'
});
};
$scope.todos= $scope.dataTodos;
}, function(error){
console.log(error);
});
}

Is there a mistake on my codes ?

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 49164

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>