Hello guys, I need your help to fix my problem. Now I’m working on ionic framework and SQLite database. I need to save data from JSON format into SQLite mobile database. JSON data come from web service which are from external server. This is some example JSON data I create :
[{"id":"6","fullname":"sadad","ic_no":"12313","private_phone":"2221","office_phone":"4443","position":"fff","email":"af@gmail.com","password":"12345"}]
This is my controller.js
.controller('AppCtrl', function($scope,$ionicPlatform,$location,$http,$ionicHistory,$cordovaSQLite) {
$ionicHistory.nextViewOptions({
disableAnimate:true,
disableBack:true
});
$ionicPlatform.ready(function(){
//$scope.loginData = {};
$scope.sync = [];
$scope.doLogin =function(){
if(window.Connection) {
//no connection to internet no sync process happen
if(navigator.connection.type == Connection.NONE) {
$location.path('/app/playlists');
}
//connection available sync process will execute
else{
$http.get('https://ip-server/pokok_apps/kdma/fetch.php')
.success(function(data){
$scope.li = data;
$scope.debtdata = angular.fromJson($scope.li);
var query = "INSERT INTO user_kdma (id,fullname,ic_no,private_phone,office_phone,position,email,password) VALUES (?,?,?,?,?,?,?,?)";
$cordovaSQLite.execute(db, query, [$scope.debtdata]).then(function(res) {
$scope.sync.push({id: $scope.debtdata.id,fullname: $scope.debtdata.fullname,ic_no: $scope.debtdata.ic_no,private_phone: $scope.debtdata.private_phone,office_phone: $scope.debtdata.office_phone,position: $scope.debtdata.position,email: $scope.debtdata.email,password: $scope.debtdata.password});
console.log("insertId: " + res.insertId);
}, function (err) {
console.error(err);
});
//$location.path('/app/browse');
})
.error(function(data){
alert('error');
});
}
}
}
});
})
This is my structure database in SQLite mobile
CREATE TABLE IF NOT EXISTS user_kdma (id integer primary key autoincrement, fullname text null,ic_no text null,private_phone text null, office_phone text null, position text null, email text null, password int null)
After I run at android emulator, I got this error on adb logcat when I press some button to make that code execute.
V/sqlg ( 3590): prepare db 0x7fca821fad08 sql BEGIN
V/sqlg ( 3590): sqlc_st_finish 0x7fca82301dc8
V/sqlg ( 3590): prepare db 0x7fca821fad08 sql INSERT INTO user_kdma (id,fullname,ic_no,private_phone,office_phone,position,email,password) VALUES (?,?,?,?,?,?,?,?)
V/sqlg ( 3590): sqlc_st_bind_text_native 0x7fca82301f08 1 [object Object]
W/System.err( 3590): java.sql.SQLException: step failed with error: 20
W/System.err( 3590): at io.liteglue.SQLiteGlueConnection$SQLGStatement.step(SQLiteGlueConnection.java:132)
W/System.err( 3590): at io.liteglue.SQLitePlugin$SQLiteDatabaseNDK.executeSqlStatementNDK(SQLitePlugin.java:514)
W/System.err( 3590): at io.liteglue.SQLitePlugin$SQLiteDatabaseNDK.executeSqlBatch(SQLitePlugin.java:434)
W/System.err( 3590): at io.liteglue.SQLitePlugin$DBRunner.run(SQLitePlugin.java:618)
W/System.err( 3590): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
W/System.err( 3590): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
W/System.err( 3590): at java.lang.Thread.run(Thread.java:818)
V/executeSqlBatch( 3590): SQLitePlugin.executeSql[Batch](): Error=step failed with error: 20
V/sqlg ( 3590): sqlc_st_finish 0x7fca82301f08
W/System.err( 3590): java.sql.SQLException: finish failed with error: 20
W/System.err( 3590): at io.liteglue.SQLiteGlueConnection$SQLGStatement.dispose(SQLiteGlueConnection.java:217)
W/System.err( 3590): at io.liteglue.SQLitePlugin$SQLiteDatabaseNDK.executeSqlStatementNDK(SQLitePlugin.java:521)
W/System.err( 3590): at io.liteglue.SQLitePlugin$SQLiteDatabaseNDK.executeSqlBatch(SQLitePlugin.java:434)
W/System.err( 3590): at io.liteglue.SQLitePlugin$DBRunner.run(SQLitePlugin.java:618)
W/System.err( 3590): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
W/System.err( 3590): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
W/System.err( 3590): at java.lang.Thread.run(Thread.java:818)
V/executeSqlBatch( 3590): SQLitePlugin.executeSql[Batch](): Error=finish failed with error: 20
V/sqlg ( 3590): prepare db 0x7fca821fad08 sql ROLLBACK
V/sqlg ( 3590): sqlc_st_finish 0x7fca82301f08
D/SystemWebChromeClient( 3590): file:///android_asset/www/plugins/cordova-plugin-console/www/console-via-logger.js: Line 173 : [object Object]
I/chromium( 3590): [INFO:CONSOLE(173)] "[object Object]", source: file:///android_asset/www/plugins/cordova-plugin-console/www/console-via-logger.js (173)
D/PluginManager( 3590): exec() call to unknown plugin: Console
So, anyone else can help me to fix this problem ? Sorry, bad english.
Thanks in advance.