[Qt-interest] SQLite and create new database file

Israel Brewster israel at frontierflying.com
Mon Jan 19 18:07:27 CET 2009


On Jan 18, 2009, at 10:09 PM, Christoph Duelli wrote:

>>>> QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
>>>> db.setDatabaseName(fileName);
>>>> db.open();
>
> note that addDatabase and setDatabaseName both *do not* create  
> tables in the
> (or a) database.
> QDatabase is a database *connection* (and said calls just establish  
> and name
> a connection to a database).
>
> Creating a table in a database is done with SQL (see QSqlQuery):
> QSqlQuery q; // pass your QSqlDatabase if more than one connection
> q.exec("your sql command");
> ...
>
> There are other possibilites, too. See the Qt docs.
>
> HTH

>

For what it is worth, I have been working on a SQLite QT application  
for the last month or so now, and in my code the above referenced code  
block DOES create a new database file. Granted, it is empty, has no  
tables, and is not a valid database in any way (until I run a  
QSqlQuery to create some), but the file itself is created. Actually,  
this behavior caused me some problems in initial testing, as a file  
was created but not populated, and then when my application tried to  
open it again it got an error because it wasn't a valid database  
file :) Keep in mind, of course, the pathing issue- unless "fileName"  
is the full path to the file, it will be created in the current  
directory, which may not be what you are expecting.

-----------------------------------------------
Israel Brewster
Computer Support Technician
Frontier Flying Service Inc.
5245 Airport Industrial Rd
Fairbanks, AK 99709
(907) 450-7250 x293
-----------------------------------------------
> Christoph
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest




More information about the Qt-interest-old mailing list