@Zeitoun wrote:
So Hello there,
I’m working on a database project and I’m using Sqlite for this.
The problem is that: on the iOS simulator I get this error when try to add an item to the Database but I’m sure that this column exists{"code":5,"message":"table ITEMS has no column named name"}(the code below is the sql instruction in order to create the table)
CREATE TABLE IF NOT EXISTS `ITEMS` ( `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, `quto` INTEGER NOT NULL, `name` TEXT NOT NULL, `date` TEXT NOT NULLIf you could help me, I would be grateful.
You will find below all my code for this database
By the way I’m running Ionic 3import { Component } from '@angular/core'; import { NavController } from 'ionic-angular'; import { SQLite, SQLiteObject } from '@ionic-native/sqlite'; const DATABASE_NAME: string = 'data.db'; @Component({ selector: 'page-contact', templateUrl: 'contact.html' }) export class ContactPage { private db: SQLiteObject; items: string[] = []; titleItem: string; qutoItem: number; dateItem: string; constructor(public navCtrl: NavController, private sqlite: SQLite) { this.createDataBase(); } private createDataBase(): void { this.sqlite.create({ name: DATABASE_NAME , location: 'default' }) .then((db: SQLiteObject) => { console.log('BDD créé'); this.db = db; this.createTable(); }) .catch(e => console.log(e)); } private createTable(): void { this.db.executeSql("CREATE TABLE IF NOT EXISTS `ITEMS` ( `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, `quto` INTEGER NOT NULL, `name` TEXT NOT NULL, `date` TEXT NOT NULL )", {}) .then(() => console.log('table créée')) .catch(e => console.log(e)); } public addItem(){ console.log('Titre' + this.titleItem); console.log('quto' + this.qutoItem); console.log('date' + this.dateItem); this.db.executeSql("INSERT INTO `ITEMS` (quto, name, date) VALUES ("+this.qutoItem+", \'"+this.titleItem+"\', \'"+this.dateItem+"\') ", {}) .then(() => console.log('item ajouté')) .catch(e => console.log(e)); } public showItem(){ this.items = []; this.db.executeSql('SELECT * FROM `ITEMS`', {}) .then((data) => { if(data == null) { return; } if(data.rows) { if(data.rows.length > 0) { for(var i = 0; i < data.rows.length; i++) { this.items.push(data.rows.item(i).name); this.items.push(data.rows.item(i).quto); this.items.push(data.rows.item(i).date); } } } }); } }Thanks a lot !
Posts: 1
Participants: 1