| 396 | } |
| 397 | |
| 398 | void database_model::openRemoteDatabase(const QString &connName, |
| 399 | const DbMap ¶ms, const Passwd &pass) |
| 400 | { |
| 401 | QSqlDatabase db = QSqlDatabase::database(connName, false); |
| 402 | |
| 403 | db.setDatabaseName(params["dbname"]); |
| 404 | QStringList hostport = params["host"].split(":"); |
| 405 | if (hostport.size() > 0) |
| 406 | db.setHostName(hostport[0]); |
| 407 | if (hostport.size() > 1) |
| 408 | db.setPort(hostport[1].toInt()); |
| 409 | db.setUserName(params["user"]); |
| 410 | db.setPassword(pass); |
| 411 | |
| 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 | } |
| 428 | QString envvar(QString("XCA_%1_OPTIONS").arg(db.driverName())); |
| 429 | const char *opts = getenv(envvar.toLatin1()); |
| 430 | if (opts) |
| 431 | db.setConnectOptions(opts); |
| 432 | |
| 433 | XSqlQuery::setTablePrefix(params["prefix"]); |
| 434 | db.open(); |
| 435 | QSqlError e = db.lastError(); |
| 436 | |
| 437 | if (e.isValid() || !db.isOpen()) { |
| 438 | XSqlQuery::clearTablePrefix(); |
| 439 | db.close(); |
| 440 | throw errorEx(e); |
| 441 | } |
| 442 | /* This is MySQL specific. Execute it always, because |
| 443 | * dbType() could return "ODBC" but connect to MariaDB |
| 444 | */ |
| 445 | XSqlQuery q("SET SESSION SQL_MODE='ANSI'"); |
| 446 | q.exec("PRAGMA secure_delete = 'true'"); |
| 447 | } |
| 448 | |
| 449 | void database_model::openLocalDatabase(const QString &connName, |
| 450 | const QString &descriptor) |
nothing calls this directly
no test coverage detected