PDA

View Full Version : How do I execute an .schema command using Qt's SQLITE driver?



danielperaza
3rd April 2010, 22:39
Greetings everybody.

I'm developing a database application using SQLITE. I would like to check at start up if my database has been correctly initialized and its structure is O.K. So I wonder first, if it's possible to compare the SqLite .schema command's output with my start up SQL script, and second, how could I do that using Qt's SqLite driver?

ChrisW67
4th April 2010, 07:07
The ".schema" command is a part of the Sqlite command line client, and not part of Sqlite SQL. You can access schema information with standard SQL queries against the sqlite_master table. See http://www.sqlite.org/faq.html#q7

danielperaza
4th April 2010, 15:31
Thanks ! ;)

ChrisW67
5th April 2010, 06:33
You could also look at QSqlDatabase::tables() for a list of table names and QSqlDatabase::record() for column names.

danielperaza
5th April 2010, 20:21
You could also look at QSqlDatabase::tables() for a list of table names and QSqlDatabase::record() for column names.

Yes, but that will not provide me the exact SQL CREATE statement used to create the structure of each table. Querying sqlite_master, instead, will do it.