Sqlite integration query issue

Hey everyone,

I am trying to use the SQLite cordova plugin on my Ionic 2 app.

My code looks like this :

    this.platform.ready().then(() => {
        let options = { name : "my_db" };
        this.storage = new Storage(SqlStorage, options);
        this.storage.query("CREATE TABLE IF NOT EXISTS categories (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(50))", []).then((data) => {
            console.log("New table : " + JSON.stringify(data));
        }, (error) => {

And I’m getting an error I don’t really understand (at least in this case) : number of '?'s in statement string does not match argument count.

I installed cordova-sqlite-plugin, even though I’m pretty sure it’s only used on a real phone/emulator, so I don’t think this should be causing any problem.

What did I do wrong ?



I have the same code as yours and it is working.

I copied/pasted your code in mine and it is working.

I am not an expert, but do you have other code that “insert” or “update” or “delete” things from ‘categories’ tables? I think it is in that part of the code that you have an issue, no?

Thanks for your answer.

No, I don’t have any other code like “insert” at the moment, because the table I tried to create is never created, so I’m basically stuck at this point. As mentioned, I get the error : number of '?'s in statement string does not match argument count when I try to create the table. (The (error) callback is called).

I’m using Chrome, and when I inspect “WebSQL” under the “Resources” tab, I only have a table “kv” created (which I assume is used to store as data “key-value”, and not using the query method. No sign of my “categories” table.

Try this blog page from Nick.

Also, it is important to execute this ionic plugin add cordova-sqlite-storage

1 Like

I followed the article, but sadly it’s not working for me.

  1. I have android + ios platforms installed.
  2. The cordova-sqlite-storage is installed (even though this might not be necessary to test in dev).

I can create/open my database successfully but the query to create a table doesn’t work.

I tried to create a whole new project and it’s fine if I follow exactly the blog page you gave me.

I don’t know why, but it seems the architecture has changed from when I installed my Ionic app.

Previously (on my version), the “app” folder and its containing folders was inside the “www” folder.

It looks like now the “app” folder is on the root of any new ionic project.

I guess I’ll juste have to tweak around and copy/paste files and hopefully it’s gonna work eventually…

EDIT : updating to the newest version of Ionic finally solved the problem.

Is my tutorial already dated?

No, don’t worry, it’s fine :smile:

I just needed to update to the latest version of Ionic 2. It seems there was an issue with the older alpha version I was working on !

Thanks for your help :smile:

1 Like