Ionic 3: Update SQLite documentation
See original GitHub issueBug Report
Ionic Info
✔ Gathering environment info - done!
Ionic:
ionic (Ionic CLI) : 4.1.2 (/usr/lib/node_modules/ionic)
Ionic Framework : ionic-angular 3.9.2
@ionic/app-scripts : 3.2.0
Cordova:
cordova (Cordova CLI) : 8.0.0
Cordova Platforms : android 7.0.0
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.2, cordova-plugin-ionic-webview 2.1.4, (and 5 other plugins)
System:
Android SDK Tools : 26.1.1 (/home/another/Android/Sdk)
NodeJS : v10.10.0 (/usr/bin/node)
npm : 6.4.1
OS : Linux 4.15
Describe the Bug Following the SQLite plugin usage instructions found at https://ionicframework.com/docs/native/sqlite/ drives to an error.
Steps to Reproduce
Started a new project with ionic start sqlitetest blank
.
Followed the instructions found in the documentation mentioned before and added this code to the default home.ts
:
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { SQLite, SQLiteObject } from '@ionic-native/sqlite';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(public navCtrl: NavController, private sqlite: SQLite) {}
ionViewDidLoad() {
console.log('EXECUTING ionViewDidLoad');
this.sqlite
.create({
name: 'data.db',
location: 'default'
})
.then((db: SQLiteObject) => {
db.executeSql('create table danceMoves(name VARCHAR(32))', {})
.then(() => console.log('Executed creation SQL'))
.catch(e => console.log('Error executing creation SQL: ' + JSON.stringify(e)));
})
.catch(e => console.log('Error opening DB: ' + JSON.stringify(e)));
}
}
Executed ionic cordova emulate android -lc
and got a typescript error:
Related Code
I tried removing that offending parameter {}
since it’s optional. I executed it again and got these log messages:
[app-scripts] [19:22:04] build finished in 4.94 s
[app-scripts] [19:22:06] console.log: Angular is running in the development mode. Call enableProdMode() to enable the production
[app-scripts] mode.
[app-scripts] [19:22:06] console.log: EXECUTING ionViewDidLoad
[app-scripts] [19:22:06] console.log: OPEN database: data.db
[app-scripts] [19:22:06] console.log: OPEN database: data.db - OK
[app-scripts] [19:22:06] console.log: Ionic Native: deviceready event fired after 1119 ms
[app-scripts] [19:22:06] console.log: Error executing creation SQL: {"rows":{"length":0},"rowsAffected":0}
Finally, I tried to change that parameter to []
, uninstalled the app, redeployed it, and it worked:
[cordova] INSTALL SUCCESS
[cordova] LAUNCH SUCCESS
[app-scripts] [19:24:39] console.log: Angular is running in the development mode. Call enableProdMode() to enable the production
[app-scripts] mode.
[app-scripts] [19:24:39] console.log: EXECUTING ionViewDidLoad
[app-scripts] [19:24:39] console.log: OPEN database: data.db
[app-scripts] [19:24:39] console.log: OPEN database: data.db - OK
[app-scripts] [19:24:39] console.log: Ionic Native: deviceready event fired after 1072 ms
[app-scripts] [19:24:39] console.log: Executed creation SQL
Expected Behavior The documentation is obsolete and I think SQLite is a pretty important plugin so it should be updated.
Additional Context
I’m opening this issue because I started a project before and I couldn’t make SQLite work, so finally I had to change my app to use ionic-storage
instead, despite its way of working isn’t optimal for the application I’m currently developing. Please, update the documentation so no other programmer has the same problem I had.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6
try changing the {} to [] {} is not a known datatype
Issue moved to: https://github.com/ionic-team/ionic-v3/issues/116