I'm using the Lua sqlite3 interface, I was wondering if there is an easy way to check if there is already an existing database, and if not create it and create required tables/columns.
Check for existing database?
Posted by Renny on Tue 30 Sep 2014 07:40 PM — 2 posts, 11,422 views.
What I usually do is:
That way it automatically gets created if necessary. Also the database is automatically created anyway if it isn't there.
If there is other initialization you want to do (eg. populate a table) you can check if a specific table exists:
If you get a row back, then the table exists.
CREATE TABLE IF NOT EXISTS ...
That way it automatically gets created if necessary. Also the database is automatically created anyway if it isn't there.
If there is other initialization you want to do (eg. populate a table) you can check if a specific table exists:
SELECT name FROM sqlite_master WHERE type='table' AND name='table_name';
If you get a row back, then the table exists.