MCPcopy Create free account
hub / github.com/chris2511/xca / openRemoteDatabase

Method openRemoteDatabase

lib/database_model.cpp:398–447  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

396}
397
398void database_model::openRemoteDatabase(const QString &connName,
399 const DbMap &params, 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
449void database_model::openLocalDatabase(const QString &connName,
450 const QString &descriptor)

Callers

nothing calls this directly

Calls 12

errorExClass · 0.85
splitMethod · 0.80
sizeMethod · 0.80
open_readMethod · 0.80
closeMethod · 0.80
openMethod · 0.80
lastErrorMethod · 0.80
isOpenMethod · 0.80
QStringClass · 0.70
getUserSettingsDirFunction · 0.70
isValidMethod · 0.45
execMethod · 0.45

Tested by

no test coverage detected