storesafe / cordova-sqlite-storage

A Cordova/PhoneGap plugin to open and use sqlite databases on Android, iOS and Windows with HTML5/Web SQL API
Other
2.15k stars 715 forks source link

ADD COLUMN IF NOT EXISTS and AFTER #979

Open tiagocaus opened 3 years ago

tiagocaus commented 3 years ago

I need to add new columns to my app. How do I add a new column at a given position using AFTER?

Example:

db.transaction(function (tx) {
    tx.executeSql("ALTER TABLE checklist ADD COLUMN IF NOT EXISTS assinatura_chegada text AFTER assinatura");
});
MikeDimmickMnetics commented 3 years ago

SQLite does not support the IF NOT EXISTS or AFTER clauses. See https://www.sqlite.org/lang_altertable.html for the supported syntax.

To determine if the table already contains the column, use PRAGMA table_info(checklist).

SQLite does not support inserting columns. You can only append them to the end of the table definition.