Skip to content

Commit fee6235

Browse files
committed
Close chris2511#306 chris2511#537 Allow Database-driver options in config file
XCA tries to read Database-driver specific options from configurartion files in the getUserSettingsDir() named after the driver and the host.
1 parent b2869e0 commit fee6235

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
lines changed

doc/rst/database.rst

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,44 @@ Apple macos
4545
- **ODBC**: It requires the /usr/local/opt/libiodbc/lib/libiodbc.2.dylib.
4646
When installing unixodbc via brew the library must be symlinked from
4747
/opt/homebrew/Cellar/libiodbc/3.52.16/lib/libiodbc.2.dylib
48-
- **MariaDB**: Probably via ODBC ?
48+
- **MariaDB**: Since XCA-2.8.0 the MariaDB plugin is included in the
49+
xca.app bundle. No additional installation is required.
4950

5051
Windows
5152
.......
5253

5354
- **PostgreSQL**: https://www.enterprisedb.com/downloads/postgres-postgresql-downloads
54-
(Commandline tools are sufficient). Add the bin directory of the Postgres
55+
(Commandline tools are sufficient). Add the *bin* directory of the Postgres
5556
installation directory to your PATH (C:\\Program Files\\PostgreSQL\\16)
56-
- **ODBC**: Use the *ODBC Datasources 64bit* app to configure the SQL Server
57-
If the data source is configured completel, only the matching DSN
57+
- **ODBC**: Use the *ODBC Datasources 64bit* app to configure the SQL Server.
58+
If the data source is configured completel, only the matching DSN is required
59+
in the XCA connection settings.
5860
- **MariaDB (MySQL)**: Install the Plugin from here:
5961
https://github.com/thecodemonkey86/qt_mysql_driver. Select the MinGW variant
6062
and install it as documented.
6163

64+
Driver specific configurations
65+
..............................
66+
67+
Additional options for the database connection can be set in configuration files.
68+
They must be put in the XCA configuration directory, which is displayed in the about dialog.
69+
If there is already a file called *dbhistory* then you know you are in the right place.
70+
The options-file must be named after the database driver, e.g. *QPSQL*, *QMYSQL* or *QODBC*
71+
optionally followed by a dash and the database-hostname (exactly as used in the connection settings
72+
including an optional port number) and a *.options* extension.
73+
74+
Examples:
75+
76+
- QMYSQL-192.168.12.13.options
77+
- QPSQL.options
78+
79+
Also the environment variable XCA_<driver-name>_OPTIONS may be used to set the options.
80+
81+
The file must contain the options as ; separated key=value pairs. The recognized options depend
82+
on the database driver. See:
83+
https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PARAMKEYWORDS for PostgreSQL and
84+
https://doc.qt.io/qt-6/sql-driver.html#connection-options for MySQL and
85+
https://doc.qt.io/qt-6/sql-driver.html#odbc-unicode-support for ODBC.
6286

6387
.. _extracting-items:
6488

lib/database_model.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,22 @@ void database_model::openRemoteDatabase(const QString &connName,
409409
db.setUserName(params["user"]);
410410
db.setPassword(pass);
411411

412+
const QStringList sql_opt_files = {
413+
QString("%1-%2.options").arg(db.driverName()).arg(params["host"]),
414+
QString("%1.options").arg(db.driverName())
415+
};
416+
for (const QString &file : sql_opt_files) {
417+
QString path = getUserSettingsDir() + "/" + file;
418+
qDebug() << "TRYING" << path;
419+
XFile f(getUserSettingsDir() + "/" + file);
420+
if (f.exists() && f.open_read()) {
421+
qDebug() << "READING" << file;
422+
QString opts = f.readAll();
423+
db.setConnectOptions(opts);
424+
break;
425+
}
426+
f.close();
427+
}
412428
QString envvar(QString("XCA_%1_OPTIONS").arg(db.driverName()));
413429
const char *opts = getenv(envvar.toLatin1());
414430
if (opts)

release/build-mac.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ do_openssl
133133
# aqt install-src mac 6.6.3 --archives qtbase
134134
# qtbase/src/plugins/sqldrivers/mysql/CMakeLists.txt:
135135
# -qt_internal_force_macos_intel_arch(QMYSQLDriverPlugin)
136-
# do_qsqlmysql
136+
do_qsqlmysql
137137

138138

139139
cmake -B "$BUILDDIR" "$XCA_DIR" \

0 commit comments

Comments
 (0)