storesafe / cordova-sqlite-storage-help

Help forum for Cordova sqlite plugin projects
2 stars 1 forks source link

Dropping Null value columns while inserting in SQlite DB? #4

Open Priya-Ahuja opened 7 years ago

Priya-Ahuja commented 7 years ago

Hi.. I am working on a Cordova SQLite application.Following is the list the plugins i am using for inserting data into SQLite DB

  1. Cordova-plugin-dbcopy 2.cordova-plugin-sqlite2 3.cordova-plugin-storage but on every insert query i need to pass all the column values even if there is a null value to that column because I face an error saying 10 values expected and 8 are passed.But I don't face this issue on SQLite browser..Any idea? New to SQLite and cordova..Please guide.
brodycj commented 7 years ago

I think you mean cordova-plugin-dbcopy, cordova-plugin-sqlite-2, and cordova-sqlite-storage. Using both cordova-plugin-sqlite-2 (not supported here) and cordova-sqlite-storage leads to undefined results because both plugins define the same JavaScript functions.

According to the Web SQL spec you have to specify all column values.

In case of cordova-sqlite-storage it will only complain if you specify too many column values.

Also please be sure that you use sqlitePlugin.openDatabase. If you use window.openDatabase you get Web SQL and miss the benefits of the sqlite plugin.

Priya-Ahuja commented 7 years ago

Thanks for the help @brodybits ..I deleted the cordova-plugin-sqlite2.. My code to copy the db window.plugins.sqlDB.copy("mydb.db", 0, function () { db = $cordovaSQLite.openDB({ name: "mydb.db", location: 0 }); and still while inserting i am getting the following error :

Failed to import SQL; message=sqlite3_prepare_v2 failure: table Details has 15 columns but 12 values were supplied

brodycj commented 7 years ago

Marking this as "community help" since I generally do not support Ionic or other Angular derivatives for free. I also do not support the dbcopy plugin.

I suggest you post the CREATE TABLE statement along with the actual inserting code.

Priya-Ahuja commented 7 years ago

Since i am using dbcopy plugin to first copy the db with blank schema in the phone , I am not making CREATE TABLE statements , i am only doing insert statements.

brodycj commented 7 years ago

Understood. Here is what I suggest to get help:

Get a dump of the sqlite database file (open with the sqlite3 command tool and do .dump).

Make a new test app based on https://github.com/brodybits/cordova-sqlite-storage-starter-app that creates the table and attempts to populate the data. Note that this app already includes cordova-sqlite-storage in config.xml so there is no need to add the sqlite plugin, just add one or more desired platforms.

Then see if you can reproduce the problem in the test app. If not, then try one thing at a time until you see what does and does not work.