PDA

View Full Version : sqlite database creation



dimantoku
17th February 2015, 12:54
i wrote following code....

QSqlDatabase db=QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("new.db");

but i couldn't find the database in that folder.....is it not creating the database or the code is wrong????please help..........

jefftee
17th February 2015, 15:38
but i couldn't find the database in that folder.....is it not creating the database or the code is wrong????
Have you opened the database yet? If so, the database will be created in the current working directory for the running application since you have not specified a path. If you have not yet opened the database, it will not be created until it's opened.

Hope that helps.

ChrisW67
17th February 2015, 20:32
If memory serves, Sqlite file will not create the actual file until after you create tables in it.

jefftee
17th February 2015, 21:36
Perhaps the QSqlDatabase driver for SQLITE has this behavior, but the sqlite3 command line program will create an empty database as long as you do something that opens the database:



sqlite3 test.sqlite "select * from sqlite_master"


The above on a non-existent database will result in zero byte file being created.