Ionic-native: Ionic 2 SQLite documentation error

Created on 13 Jul 2016  Â·  19Comments  Â·  Source: ionic-team/ionic-native

_From @Natanael1234 on July 8, 2016 18:40_

Cannot use SQLite plugin in my Angular 2/Ionic 2 project.

The way SQLite is instantiated accordint to the Ionic 2 documentation is not working.

Sublime gives me an error message:

Supplied parameters do not match nay signature of the call target.

It means that the constructor shoud receive parameters. But what parameters?

Ionic 2 SQLite plugin documentation:
http://ionicframework.com/docs/v2/native/sqlite/

import { SQLite } from 'ionic-native';

let db = new SQLite();
db.openDatabse({
  name: 'data.db',
  location: 'default' // the location field is required
}).then(() => {
  db.executeSql('create table danceMoves(name VARCHAR(32))', {}).then(() => {

  }, (err) => {
    console.error('Unable to execute sql', err);
  })
}, (err) => {
  console.error('Unable to open database', err);
});

It also says Property 'openDatabse' does not exist on type 'SQLite'

_Copied from original issue: driftyco/ionic#7242_

All 19 comments

Hello, thanks for opening an issue with us! Since this issue seems to be an ionic native issue and not an ionic framework issue i will be moving this issue to that repo. Thanks for using Ionic!

Hey there,

Are you using the latest version of Ionic Native?

Run the following command to update to latest version: npm i --save ionic-native@latest

This SQLite plugin syntax was only introduced after ionic-native v1.3.1.

Please verify that you're using the latest version, and get back to me if you're still having issues.

I'm using v1.3.2 and the 'openDatabse' does not exist on type 'SQLite' error still shows.

I think it's because ionic-native doesn't take care of the web version case where it should use websql instead.

Oh yes I don't think this plugin falls back to websql or something when
you're on the web. You have to be on your phone for it to work.

On Jul 14, 2016 10:24 AM, "Carlos Esteban Lopez Jaramillo" <
[email protected]> wrote:

I think it's because ionic-native doesn't take care of the web server
case.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/driftyco/ionic-native/issues/288#issuecomment-232680652,
or mute the thread
https://github.com/notifications/unsubscribe/ANJ8dHJ36ouHbXaoBScDMxTuAzc6DaBjks5qVkapgaJpZM4JLfQc
.

Just though about it, you shouldn't be getting that error even if you're running on a browser.

The openDatabase method is part of ionic-native, and to be able to reach it without having the plugin installed.

Can you share steps to reproduce that error? @Luchillo

Solved by recreating the project from scratch.

Just copied my root configs, app folder, ect and reinstalled node_modules and plugins.

Note that the example says

db.openDatabse({

not

db.openDatabase({

Thanks @Natanael1234 I fixed the docs now.

I'm such a derp, how did i miss such a typo? still i think the ionic-native version of the SqLite plugin isn't for me, i need to have that WebSql fallback for my project.

There is other typos in Ionic 2 documentation.

Ionic Native SQLite is ok but it's not the most intuitive and easy to use tool in my opinion. I feel the lack of an ORM tool.

Perhaps you whould like to experiment SQLStorage. SQLStorage runs on top of SQLite but its operation is far more simple, in many cases, since it uses key value pairs to store data.

I do use SqlStorage and in it i have made a versioning system for Ionic 2 app, however i'm about to make a tutorial on DB management and versioning, and was trying all the options to see what is better.

I'm trying to use SQLite in my project, but it's returning the following error:

"Unable to execute sql", source: file:///android_asset/www/build/main.js"

Here's the implementation inside the constructor:

this.database = new SQLite(); 
this.database.openDatabase({ 
  name: "data.db", 
  location: "default" 
})
.then(() => { 
  this.database.executeSql("create table if not exists people(id INTEGER PRIMARY KEY AUTOINCREMENT, firstname TEXT, lastname TEXT)", [])
  .then(() => { 
    console.log("TABLE CREATED: "); 
  }, 
  (error) => { 
    console.error("Unable to execute sql", error); 
  })
}, 
(error) => { 
  console.error("Unable to open database", error); 
});

@saademou to help us, we're going to need to see what error returns, otherwise all I can guess is that you have an error in your SQL statement.

the error is :

"Unable to execute sql", source: file:///android_asset/www/build/main.js"

these errors also :

Storage: SQLite plugin not installed, falling back to WebSQL. Make sure to install cordova-sqlite-storage in production!
main.js:65010Native: tried calling StatusBar.styleDefault, but Cordova is not available. Make sure to include cordova.js or run in a device/simulator

ERROR: TypeError: Cannot read property 'executeSql' of undefined

as @Natanael1234 :

Solved by recreating the project from scratch.
Just copied my root configs, app folder, ect and reinstalled node_modules and plugins.

No it doesn't works. How to fix this.Has anybody experience this like before.Please provide solution for me.

Was this page helpful?
0 / 5 - 0 ratings