I’m getting an error after I built up my app SQlite can’t create,insert or select the error is:
[object object]
my ionic version:
cli packages:
@ionic/cli-utils: 1.19.2
ionic (Ionic CLI): 3.20.0
global packages:
cordova (Cordova CLI):8.0.0
local packgaes:
@ionic/app-scripts:3.1.9
cordova Platforms:android 7.0.0
Ionic Framework: ionic-angular 3.9.2
system:
Node: v8.10.0
npm:5.6.0
OS:Windows 7
my code:
import { Injectable } from "@angular/core";
import { SQLite, SQLiteObject } from '@ionic-native/sqlite';
import { AlertController } from "ionic-angular";
@Injectable()
export class SQLiteModel {
boxCost: number = 120;
workerarray: any = [];
constructor(
private sqlite: SQLite,
private alert: AlertController,
) { }
errorAlert(error: any) {
let erorralert = this.alert.create({
title: 'there is an error',
message: error,
buttons: [
{
text: 'ok',
handler: data => {
console.log('Cancel clicked');
}
}]
})
erorralert.present();
}
addworker(workername) {
this.sqlite.create({
name: 'boxesdata.db',
location: 'default'
})
.then((db: SQLiteObject) => {
db.executeSql('INSERT INTO Workers VALUES(NULL,?)', [
workername,
])
.then(res => console.log(res))
.catch(e => {
this.errorAlert(e);
});
})
.catch(e => {
this.errorAlert(e);
});
}
getworkers() {
this.sqlite.create({
name: 'boxesdata.db',
location: 'default'
})
.then((db: SQLiteObject) => {
db.executeSql('CREATE TABLE IF NOT EXITS Workers(Id INTEGER PRIMARY KEY, name TEXT)', {})
.then(res => console.log('Executed SQL'))
.catch(e => {
this.errorAlert(e);
});
db.executeSql('SELECT * FROM Workers ORDER BY id DESC', {})
.then(res => {
this.workerarray = [];
for (var i = 0; i < res.rows.length; i++) {
this.workerarray.push(
{
id:res.rows.item(i).id,
name: res.rows.item(i).name
})
}
})
.catch(e => {
this.errorAlert(e);
});
})
.catch(e => {
this.errorAlert(e);
});
}
addwork() {
this.sqlite.create({
name: 'boxesdata.db',
location: 'default'
})
.then((db: SQLiteObject) => {
db.executeSql('CREATE TABLE ${``} IF NOT EXITS(id PRIMARY KEY, name TEXT)', {})
.then(() => console.log('Executed SQL'))
.catch(e => {
this.errorAlert(e);
});
})
.catch(e => {
this.errorAlert(e);
});
}
deleteworker(id) {
this.sqlite.create({
name: 'boxesdata.db',
location: 'default'
})
.then((db: SQLiteObject) => {
db.executeSql('DELETE FROM Workers WHERE id=?', [id])
.then(() => console.log('Executed SQL'))
.catch(e => {
this.errorAlert(e);
});
})
.catch(e => {
this.errorAlert(e);
});
}
getwork() {
}
editwork() {
}
}