Is it possible to attach an SQLITE database and still use the Qt database classes?
Printable View
Is it possible to attach an SQLITE database and still use the Qt database classes?
Well, you could use the sql statementthen it is pure SQL and has nothing to do with Qt. => You can still use Qt's classes.Code:
ATTACH DATABASE filename AS databasename
Or you can simply useCode:
//...
Thanks. I was not sure if that method would work.
Now that I expected to work.Quote:
Or you can simply useCode:
//...
Now the question is mainly can I use 2 databases in the same QSqlQuery? I assume with the ATTACH database sql statement I can do this.
Hello all!
Regarding the same subject.
It is possible to attach a database that resides into a QTemporaryFile?
Thank you!
Have you tried? Why shouldn't it working? It's a "normal" file. Just use QTemporaryFile::fileName() to work with the file.
with Qt classes you need add two databases using QSqlDatabase::addDatabase, but you need specify different connectionName:
Code:
db1.setDatabaseName("path/to/db1"); db2.setDatabaseName("path/to/db2"); //opening databases and etc.
then you can get data from these databases like this:
Code:
... //preparing query and execution ... //preparing query and execution ...
are you sure that your code will work?
the first parameter of QSqlDatabase::addDatabase should be a name of a driver? i.e. should be:
Code:
db.setDatabaseName("path/to/file"); //...