QSqlDatabase never fails
-
Hi
I am just starting to explore Qt support for databases and have this as a first attempt to open a data base
@
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setHostName("hostname");
db.setDatabaseName("databasename");
db.setUserName("username");
db.setPassword("password");
bool ok = db.open();
@
When I run this ok is always true, no matter what arguments are passed.I would be grateful if someone could explain this
Thanks
[edit: replaced inputs with something more generic SGaist]
-
Hi,
sqlite is a file based database so you essentially give it the name of your database file and that's all. No credentials required by default.
You can even have your database completely in memory if needed.
-
But if I supply a non existent filename the call to open still succeeds and I do not understand why
-
A new database is created with that filename
-
Ah ok
So I will have to see if the file exists before opening itthanks
-
Either that or have the database initialization code run using the "IF NOT EXIST" clause