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) => {
            console.log(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 ?

Thanks,

kinkaz

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