Different directory for different SQL Databases
-
Hello all!
I've got an issue to manage few databases under SQlite in one Qt Application. Is there any way to store this databases in separate directory and by demand connect that DB that I need? I've been reading https://doc.qt.io/qt-5/qsqldatabase.html but I've not found anything. I need one active db at one time but from different location on device. -
@bogong There is not problem to do this
// Define 1st SQLite DB connection auto db1 = QSqlDatabase::addDatabase("QSQLITE", "FirstDB"); db1.setDatabaseName(<path_to _SQLite_DB_file>); // Define 2nd SQLite DB connection auto db2 = QSqlDatabase::addDatabase("QSQLITE", "SecondDB"); db2.setDatabaseName(<path_to _SQLite_DB_file>); ... // open connection to 1st DB auto db = QSqlDatabase::database("FirstDB");
-
-
I've not used SQLite, but I assume you can arrange for databases to be stored in particular directories by specifying the necessary path to https://doc.qt.io/qt-5/qsqldatabase.html#setDatabaseName.
-
To change which of multiple opened database you want to use for an operation:
If you create multiple database connections, specify a unique connection name for each one, when you call addDatabase(). Use database() with a connection name to get that connection.
-
-
Hi,
@bogong said in Different directory for different SQL Databases:
I need one active db at one time but from different location on device.
Can you clarify that statement ? How are you expecting to use these databases ?