Hello, I try to work with SQLite in my App.
When I run the App on my Android Device I get this error:
11-30 14:20:05.472: W/System.err(32613): java.sql.SQLException: sqlite3_prepare_v2 failure: near “INT”: syntax error
11-30 14:20:05.472: W/System.err(32613): at io.liteglue.SQLiteGlueConnection.prepareStatement(SQLiteGlueConnection.java:46)
11-30 14:20:05.472: W/System.err(32613): at io.sqlc.SQLiteConnectorDatabase.executeSQLiteStatement(SQLiteConnectorDatabase.java:193)
11-30 14:20:05.472: W/System.err(32613): at io.sqlc.SQLiteConnectorDatabase.executeSqlBatch(SQLiteConnectorDatabase.java:114)
11-30 14:20:05.472: W/System.err(32613): at io.sqlc.SQLitePlugin$DBRunner.run(SQLitePlugin.java:340)
11-30 14:20:06.172: I/chromium(32613): [INFO:CONSOLE(10)] "ResperLog: Unable to execute sql: ", source: file:///android_asset/www/build/main.js (10)
The database exist and it open it:
11-30 14:20:05.452: I/chromium(32613): [INFO:CONSOLE(175)] “OPEN database: resper.db”, source: file:///android_asset/www/plugins/cordova-sqlite-storage/www/SQLitePlugin.js (175)
11-30 14:20:05.482: I/chromium(32613): [INFO:CONSOLE(179)] “OPEN database: resper.db - OK”, source: file:///android_asset/www/plugins/cordova-sqlite-storage/www/SQLitePlugin.js (179)
I dont find the syntax error in my code:
import { Component, ViewChild } from '@angular/core';
import { Nav, Platform, ToastController } from 'ionic-angular';
import { StatusBar, Splashscreen, SQLite } from 'ionic-native';
import { Page1 } from '../pages/page1/page1';
import { Page2 } from '../pages/page2/page2';
@Component({
templateUrl: 'app.html'
})
export class MyApp {
@ViewChild(Nav) nav: Nav;
rootPage: any = Page1;
pages: Array<{title: string, component: any}>;
public db: SQLite;
constructor(public platform: Platform, public toastCtrl: ToastController) {
this.initializeApp();
this.pages = [
{ title: 'Page One', component: Page1 },
{ title: 'Page Two', component: Page2 }
];
}
initializeApp() {
this.platform.ready().then(() => {
StatusBar.styleDefault();
Splashscreen.hide();
this.db = new SQLite();
this.db.openDatabase({
name: 'resper.db',
location: 'default'
}).then(() => {
this.db.executeSql('CREATE TABLE IF NOT EXISTS versions(id INT PRIMARY KEY, name TEXT, nr INT', {}).then(() => {
console.error('ResperLog: Created Database');
}, (err) => {
console.error('ResperLog: Unable to execute sql: ', err);
});
}, (err) => {
console.error('ResperLog: Unable to open database: ', err);
});
});
}
openPage(page) {
this.nav.setRoot(page.component);
}
}