Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ionic 3: Update SQLite documentation #15584

Closed
sirarthurnell opened this issue Sep 13, 2018 · 6 comments
Closed

Ionic 3: Update SQLite documentation #15584

sirarthurnell opened this issue Sep 13, 2018 · 6 comments
Labels
ionitron: v3 moves the issue to the ionic-v3 repository

Comments

@sirarthurnell
Copy link

Bug 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:

captura de pantalla de 2018-09-13 19-18-32

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.

@ionitron-bot ionitron-bot bot added the triage label Sep 13, 2018
@torsorensen
Copy link

I don't know if you're aware but you can make ionic-storage use SQLite when running on actual devices by simply adding the SQLite plugin.

From the docs:

"When running in a native app context, Storage will prioritize using SQLite, as it's one of the most stable and widely used file-based databases, and avoids some of the pitfalls of things like localstorage and IndexedDB, such as the OS deciding to clear out such data in low disk-space situations.

First, if you'd like to use SQLite, install the cordova-sqlite-storage plugin:

ionic cordova plugin add cordova-sqlite-storage"

@sirarthurnell
Copy link
Author

sirarthurnell commented Sep 13, 2018

@torsorensen I know it. It's not that what I'm talking about. With SQLite you can send queries to the DB and receive a filtered set of records. But with ionic-storage you only have a key-value style of saving and retrieving objects.

@janpio
Copy link

janpio commented Sep 20, 2018

Actual Ionic Native issues live here: https://github.com/ionic-team/ionic-native/issues/

@brianmak3
Copy link

try changing the {} to []
{} is not a known datatype

@brandyscarney brandyscarney added the ionitron: v3 moves the issue to the ionic-v3 repository label Nov 28, 2018
@ionitron-bot
Copy link

ionitron-bot bot commented Nov 28, 2018

Thanks for the issue! We have moved the source code and issues for Ionic 3 into a separate repository. I am moving this issue to the repository for Ionic 3. Please track this issue over there.

Thank you for using Ionic!

@ionitron-bot
Copy link

ionitron-bot bot commented Nov 28, 2018

Issue moved to: ionic-team/ionic-v3#116

@ionitron-bot ionitron-bot bot closed this as completed Nov 28, 2018
@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Nov 28, 2018
@ionitron-bot ionitron-bot bot removed the triage label Nov 28, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
ionitron: v3 moves the issue to the ionic-v3 repository
Projects
None yet
Development

No branches or pull requests

5 participants