[Qt-interest] SQLite and create new database file

Robert Hairgrove evorgriahr at hispeed.ch
Tue Jan 20 23:25:43 CET 2009


Thank you for your input!

Constantin Makshin wrote:
> Obviously, a file can't be considered a database until you create at 
> least one table.

Obvious maybe for SQLite, but not for other databases!

  So, IMHO, instead of storing an empty (but valid)
> database in resources and then extracting it when the file doesn't 
> exist, you can do one of these things immediately after successfully 
> opening/creating the database file:
> 1) check if required table exists with 
> QSqlDatabase::tables().contains(tableName) and, if it fails (the table 
> is not present in the database), create one;
> 2) execute "CREATE TABLE IF NOT EXISTS ..." query.
> 
> Since SQLite supports "IF NOT EXISTS" clause of "CREATE TABLE" 
> statement, the second variant should be OK.

Sounds good!



More information about the Qt-interest-old mailing list