SQLite Forum

Need If column exist option in SQLite
Login
This kind of thing I have usually seen handled in the application (logic) instead of via SQL statements.

The basic idea was to have a fixed table `appschema` or the like which has a single row listing the version of the application's schema found in the database.

When the application starts and accesses the database it compares the version from that table with the version it itself supports. Then

  - If the database is ahead of the application you can only abort.

  - If, on the other hand, the application is ahead of the database then it is expected to have code to update the old database schema to the new schema. This kind of code is usually written as a series of functions, each of which will incrementally update the schema from one version to the next. The application then simply invokes the functions for the "(database schema).next" up to "latest", in order, stepping the schema forward in easy increments. After that completes successfully it can then use the database as normal.