SQLite Forum

Need If column exist option in SQLite
Login
Nor, of course, do you need the "LIMIT 1".

If you prepare the statement `select newcol from newtable` then the return code from the prepare will be SQLITE_OK if BOTH the table newtable exists AND the column newcol exists in that table.  

If the column newcol does not exist in the table newtable (which exists), OR, the table newtable does not exist, you will get an SQLITE_ERROR result, and you can examine the error message text to see what the problem was.

In the event that SQLITE_OK was returned because the table existed and it contained the desired column, then you still have to execute the statement if you want to execute it.  However, since you do not need to execute the statement, you could simply dispose of it right then and there by calling sqlite3_finalize on the statement handle.

There is no need to execute the statement.

It would be much easier to just put the schema type indicator and version number in the database somewhere and if when you check they are nonsense use that to "fire the customer" (that is, put in your warranty that there are no "user serviceable parts inside" and that if the customer attempts "user servicing" which busts the database, then they will have to pay to have it fixed at your "fix user bustage" hourly rate (I used to claim this was $10,000.00 per hour, which was extremely effective at stopping end-user fiddling)).