Hi guys,
I want to show what I’m saving at my Database in the screen.
But, it’s not working when I run it in my device.
I’m not sure where the trouble is… if it’s in the creation of the database, if it’s in the set, in the get or in the display.
Because of the SQlite I’m running it at my device via USB with “ionic cordova run android --device”, and I don’t know if there’s a way to see the console.log in it or the data itself. Is there?
Anyone can help me?
Thanks in advance!
Home.html:
...
<ion-content padding>
<ion-item>
<ion-label>Digite o numero da mesa :</ion-label>
<ion-input type="number" name="numeroMesa" [(ngModel)]="numeroMesa"></ion-input>
</ion-item>
<p></p>
<button ion-button full button color='light' (click)="criarMesa()">Adicionar mesa no sistema</button>
<p></p>
<ion-list *ngIf="mesas">
<ion-item *ngFor="let mesa of mesas">
<ion-label fixed>Status: {{ mesa }} </ion-label>
</ion-item>
</ion-list>
<button ion-button full button color='light' (click)="statusMesas()">Exibir mesas disponiveis</button>
</ion-content>
and Home.ts
const statusDisp: string = 'disponivel';
...
export class HomePage {
mesas: any[] = [];
numeroMesa: number;
db: SQLiteObject;
constructor(public navCtrl: NavController, private sqlite: SQLite) {
this.createDatabaseFile();
}
private createDatabaseFile(): void{
this.sqlite.create({
name: 'data.db',
location: 'default'
})
.then((db: SQLiteObject) => {
console.log('BdD Criado!');
this.db = db;
this.criarTabelas();
})
.catch(e => console.log(e));
}
private criarTabelas(): void{
this.db.executeSql('CREATE TABLE IF NOT EXISTS MesaStatus (numMesa INTEGER PRIMARY KEY,status TEXT);', {})
.then(() => {
console.log('Tabela de Mesa-Status Criada!');
this.db.executeSql('create table IF NOT EXISTS Pedidos(codMesa INTEGER PRIMARY KEY AUTOINCREMENT , numMesa INTEGER, pedido TEXT, valorPedido REAL);', {})
.then(() => console.log('Tabela Pedidos criada !'))
.catch(e => console.log(e));
})
.catch(e => console.log(e));
}
//criar uma nova mesa inserindo um numero
public criarMesa(){
console.log('Mesa salva -> '+ this.numeroMesa );
this.db.executeSql('insert into Status(numesa, status) values (?,?) );',[this.numeroMesa, statusDisp])
.then(() => console.log('Inserido na base !'))
.catch(e => console.log(e));
alert('Mesa inserida no sistema: '+ this.numeroMesa + ' status: '+ statusDisp);
}
//get and show the status of all tables (ocupada, disponivel)
public statusMesas(){
//alert("iniciado statusMesas")
this.db.executeSql('SELECT * FROM MesaStatus', [])
.then((data)=>{
if (data==null){
alert("Banco vazio!!!")
return;
}
if (data.rows){
//alert("iniciado data.rows")
if (data.rows.length){
alert(data.rows.length)
for( var i=0; i < data.rows.length; i++){
//alert(data.rows.item(i));
this.mesas.push(data.rows.item(i));
//alert(this.mesas.push(data.rows.item(i)));
}
}
}
})
}
}