2017-08-23 13:27:23 +02:00
|
|
|
|
#include "ConnectionConfig.h"
|
2017-03-05 21:23:36 +01:00
|
|
|
|
#include "util.h"
|
2017-01-14 20:07:12 +01:00
|
|
|
|
#include <QCoreApplication>
|
2017-03-05 21:23:36 +01:00
|
|
|
|
#include <QProcessEnvironment>
|
2019-09-16 19:24:39 +02:00
|
|
|
|
#include <QStringBuilder>
|
|
|
|
|
|
#include <QUrl>
|
2017-01-14 20:07:12 +01:00
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
|
|
struct {
|
|
|
|
|
|
SslMode mode;
|
|
|
|
|
|
const char* string;
|
|
|
|
|
|
} SslModeStringTable[] = {
|
|
|
|
|
|
{ SslMode::disable, "disable" },
|
|
|
|
|
|
{ SslMode::allow, "allow" },
|
|
|
|
|
|
{ SslMode::prefer, "prefer" },
|
|
|
|
|
|
{ SslMode::require, "require" },
|
|
|
|
|
|
{ SslMode::verify_ca, "verify-ca" },
|
|
|
|
|
|
{ SslMode::verify_full, "verify-full" }
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
inline const char *valuePtr(const std::string &v)
|
|
|
|
|
|
{
|
|
|
|
|
|
return v.empty() ? nullptr : v.c_str();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-17 18:09:19 +01:00
|
|
|
|
struct {
|
|
|
|
|
|
const char * host = "host";
|
|
|
|
|
|
const char * hostaddr = "hostaddr";
|
|
|
|
|
|
const char * port = "port";
|
|
|
|
|
|
const char * dbname = "dbname";
|
|
|
|
|
|
const char * user = "user";
|
|
|
|
|
|
const char * password = "password";
|
|
|
|
|
|
const char * sslmode = "sslmode";
|
|
|
|
|
|
const char * sslcert = "sslcert";
|
|
|
|
|
|
const char * sslkey = "sslkey";
|
|
|
|
|
|
const char * sslrootcert = "sslrootcert";
|
|
|
|
|
|
const char * sslcrl = "sslcrl";
|
|
|
|
|
|
} keywords;
|
|
|
|
|
|
|
2017-01-14 20:07:12 +01:00
|
|
|
|
} // end unnamed namespace
|
|
|
|
|
|
|
2019-09-16 19:24:39 +02:00
|
|
|
|
QString SslModeToString(SslMode sm)
|
|
|
|
|
|
{
|
2022-05-26 08:25:31 +02:00
|
|
|
|
for (auto e : SslModeStringTable)
|
|
|
|
|
|
if (e.mode == sm)
|
2019-09-16 19:24:39 +02:00
|
|
|
|
return QString::fromUtf8(e.string);
|
2022-05-26 08:25:31 +02:00
|
|
|
|
|
2019-09-16 19:24:39 +02:00
|
|
|
|
return {};
|
2017-01-14 20:07:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-09-16 19:24:39 +02:00
|
|
|
|
SslMode StringToSslMode(QString s)
|
2017-01-14 20:07:12 +01:00
|
|
|
|
{
|
|
|
|
|
|
SslMode result = SslMode::allow;
|
2022-05-26 08:25:31 +02:00
|
|
|
|
for (auto e : SslModeStringTable)
|
|
|
|
|
|
if (e.string == s)
|
2017-01-14 20:07:12 +01:00
|
|
|
|
result = e.mode;
|
2022-05-26 08:25:31 +02:00
|
|
|
|
|
|
|
|
|
|
return {};
|
2017-01-14 20:07:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ConnectionConfig::ConnectionConfig()
|
2025-02-17 18:09:19 +01:00
|
|
|
|
: m_parameters{{"application_name", QCoreApplication::applicationName()}}
|
2017-01-14 20:07:12 +01:00
|
|
|
|
{}
|
|
|
|
|
|
|
2019-08-27 20:12:00 +02:00
|
|
|
|
const ConnectionGroup *ConnectionConfig::parent() const
|
2019-08-25 15:33:51 +02:00
|
|
|
|
{
|
|
|
|
|
|
return m_group;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ConnectionConfig::setParent(ConnectionGroup *grp)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_group = grp;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-11-04 11:26:20 +01:00
|
|
|
|
|
|
|
|
|
|
void ConnectionConfig::setUuid(const QUuid &uuid)
|
|
|
|
|
|
{
|
2022-05-26 08:25:31 +02:00
|
|
|
|
if (uuid != m_uuid)
|
|
|
|
|
|
{
|
2018-11-04 11:26:20 +01:00
|
|
|
|
m_dirty = true;
|
|
|
|
|
|
m_uuid = uuid;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const QUuid &ConnectionConfig::uuid() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_uuid;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-09-16 19:24:39 +02:00
|
|
|
|
void ConnectionConfig::setName(const QString& desc)
|
2017-01-14 20:07:12 +01:00
|
|
|
|
{
|
2022-05-26 08:25:31 +02:00
|
|
|
|
if (m_name != desc)
|
|
|
|
|
|
{
|
2017-02-26 19:29:50 +01:00
|
|
|
|
m_dirty = true;
|
|
|
|
|
|
m_name = std::move(desc);
|
|
|
|
|
|
}
|
2017-01-14 20:07:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-09-16 19:24:39 +02:00
|
|
|
|
const QString& ConnectionConfig::name() const
|
2017-01-14 20:07:12 +01:00
|
|
|
|
{
|
2017-01-15 12:27:36 +01:00
|
|
|
|
return m_name;
|
2017-01-14 20:07:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-09-16 19:24:39 +02:00
|
|
|
|
void ConnectionConfig::setHost(const QString& host)
|
2017-01-14 20:07:12 +01:00
|
|
|
|
{
|
2025-02-17 18:09:19 +01:00
|
|
|
|
setParameter(keywords.host, host);
|
2017-01-14 20:07:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-17 18:09:19 +01:00
|
|
|
|
QString ConnectionConfig::host() const
|
2017-01-14 20:07:12 +01:00
|
|
|
|
{
|
2025-02-17 18:09:19 +01:00
|
|
|
|
return getParameter(keywords.host);
|
2017-01-14 20:07:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-09-16 19:24:39 +02:00
|
|
|
|
void ConnectionConfig::setHostAddr(const QString &v)
|
2017-01-14 20:07:12 +01:00
|
|
|
|
{
|
2025-02-17 18:09:19 +01:00
|
|
|
|
setParameter(keywords.hostaddr, v);
|
2017-01-14 20:07:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-17 18:09:19 +01:00
|
|
|
|
QString ConnectionConfig::hostAddr() const
|
2017-01-14 20:07:12 +01:00
|
|
|
|
{
|
2025-02-17 18:09:19 +01:00
|
|
|
|
return getParameter(keywords.hostaddr);
|
2017-01-14 20:07:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ConnectionConfig::setPort(unsigned short port)
|
|
|
|
|
|
{
|
2025-02-17 18:09:19 +01:00
|
|
|
|
setParameter(keywords.port, QString::number(port));
|
2017-01-14 20:07:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unsigned short ConnectionConfig::port() const
|
|
|
|
|
|
{
|
2025-02-17 18:09:19 +01:00
|
|
|
|
QString s = getParameter(keywords.port);
|
|
|
|
|
|
if (s.isEmpty())
|
|
|
|
|
|
return 5432;
|
|
|
|
|
|
|
|
|
|
|
|
unsigned short port = static_cast<unsigned short>(s.toInt());
|
|
|
|
|
|
return port;
|
2017-01-14 20:07:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-09-16 19:24:39 +02:00
|
|
|
|
void ConnectionConfig::setUser(const QString& v)
|
2017-01-14 20:07:12 +01:00
|
|
|
|
{
|
2025-02-17 18:09:19 +01:00
|
|
|
|
setParameter(keywords.user, v);
|
2017-01-14 20:07:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-17 18:09:19 +01:00
|
|
|
|
QString ConnectionConfig::user() const
|
2017-01-14 20:07:12 +01:00
|
|
|
|
{
|
2025-02-17 18:09:19 +01:00
|
|
|
|
return getParameter(keywords.user);
|
2017-01-14 20:07:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-09-16 19:24:39 +02:00
|
|
|
|
void ConnectionConfig::setPassword(const QString& v)
|
2017-01-14 20:07:12 +01:00
|
|
|
|
{
|
2025-02-17 18:09:19 +01:00
|
|
|
|
setParameter(keywords.password, v);
|
2017-01-14 20:07:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-17 18:09:19 +01:00
|
|
|
|
QString ConnectionConfig::password() const
|
2017-01-14 20:07:12 +01:00
|
|
|
|
{
|
2025-02-17 18:09:19 +01:00
|
|
|
|
return getParameter(keywords.password);
|
2017-01-14 20:07:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-09-16 19:24:39 +02:00
|
|
|
|
void ConnectionConfig::setDbname(const QString& v)
|
2017-01-14 20:07:12 +01:00
|
|
|
|
{
|
2025-02-17 18:09:19 +01:00
|
|
|
|
setParameter(keywords.dbname, v);
|
2017-01-14 20:07:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-17 18:09:19 +01:00
|
|
|
|
QString ConnectionConfig::dbname() const
|
2017-01-14 20:07:12 +01:00
|
|
|
|
{
|
2025-02-17 18:09:19 +01:00
|
|
|
|
return getParameter(keywords.dbname);
|
2017-01-14 20:07:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ConnectionConfig::setSslMode(SslMode m)
|
|
|
|
|
|
{
|
2025-02-17 18:09:19 +01:00
|
|
|
|
setParameter(keywords.sslmode, SslModeToString(m));
|
2017-01-14 20:07:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SslMode ConnectionConfig::sslMode() const
|
|
|
|
|
|
{
|
2025-02-17 18:09:19 +01:00
|
|
|
|
QString s = getParameter(keywords.sslmode);
|
|
|
|
|
|
return StringToSslMode(s);
|
2017-01-14 20:07:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-09-16 19:24:39 +02:00
|
|
|
|
void ConnectionConfig::setSslCert(const QString& v)
|
2017-01-14 20:07:12 +01:00
|
|
|
|
{
|
2025-02-17 18:09:19 +01:00
|
|
|
|
setParameter(keywords.sslcert, v);
|
2017-01-14 20:07:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-17 18:09:19 +01:00
|
|
|
|
QString ConnectionConfig::sslCert() const
|
2017-01-14 20:07:12 +01:00
|
|
|
|
{
|
2025-02-17 18:09:19 +01:00
|
|
|
|
return getParameter(keywords.sslcert);
|
2017-01-14 20:07:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-09-16 19:24:39 +02:00
|
|
|
|
void ConnectionConfig::setSslKey(const QString& v)
|
2017-01-14 20:07:12 +01:00
|
|
|
|
{
|
2025-02-17 18:09:19 +01:00
|
|
|
|
setParameter(keywords.sslkey, v);
|
2017-01-14 20:07:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-17 18:09:19 +01:00
|
|
|
|
QString ConnectionConfig::sslKey() const
|
2017-01-14 20:07:12 +01:00
|
|
|
|
{
|
2025-02-17 18:09:19 +01:00
|
|
|
|
return getParameter(keywords.sslkey);
|
2017-01-14 20:07:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-09-16 19:24:39 +02:00
|
|
|
|
void ConnectionConfig::setSslRootCert(const QString& v)
|
2017-01-14 20:07:12 +01:00
|
|
|
|
{
|
2025-02-17 18:09:19 +01:00
|
|
|
|
setParameter(keywords.sslrootcert, v);
|
2017-01-14 20:07:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-17 18:09:19 +01:00
|
|
|
|
QString ConnectionConfig::sslRootCert() const
|
2017-01-14 20:07:12 +01:00
|
|
|
|
{
|
2025-02-17 18:09:19 +01:00
|
|
|
|
return getParameter(keywords.sslrootcert);
|
2017-01-14 20:07:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-09-16 19:24:39 +02:00
|
|
|
|
void ConnectionConfig::setSslCrl(const QString& v)
|
2017-01-14 20:07:12 +01:00
|
|
|
|
{
|
2025-02-17 18:09:19 +01:00
|
|
|
|
setParameter(keywords.sslcrl, v);
|
2017-01-14 20:07:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-17 18:09:19 +01:00
|
|
|
|
QString ConnectionConfig::sslCrl() const
|
2017-01-14 20:07:12 +01:00
|
|
|
|
{
|
2025-02-17 18:09:19 +01:00
|
|
|
|
return getParameter(keywords.sslcrl);
|
2017-01-14 20:07:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-17 18:09:19 +01:00
|
|
|
|
// bool ConnectionConfig::isSameDatabase(const ConnectionConfig &rhs) const
|
|
|
|
|
|
// {
|
|
|
|
|
|
// return host() == rhs.host()
|
|
|
|
|
|
// // && m_hostaddr == rhs.m_hostaddr
|
|
|
|
|
|
// // && m_port == rhs.m_port
|
|
|
|
|
|
// // && m_user == rhs.m_user
|
|
|
|
|
|
// // && m_password == rhs.m_password
|
|
|
|
|
|
// // && m_dbname == rhs.m_dbname
|
|
|
|
|
|
// ;
|
|
|
|
|
|
|
|
|
|
|
|
// }
|
2017-02-26 19:29:50 +01:00
|
|
|
|
|
|
|
|
|
|
bool ConnectionConfig::dirty() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_dirty;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ConnectionConfig::clean()
|
|
|
|
|
|
{
|
|
|
|
|
|
m_dirty = false;
|
|
|
|
|
|
}
|
2017-03-05 21:23:36 +01:00
|
|
|
|
|
2019-08-27 20:12:00 +02:00
|
|
|
|
QString ConnectionConfig::makeLongDescription() const
|
|
|
|
|
|
{
|
2019-09-16 19:24:39 +02:00
|
|
|
|
QString result;
|
|
|
|
|
|
result = name() % " (" % user() % "@" % host() % ":" % QString::number(port()) % "/" % dbname() % ")";
|
|
|
|
|
|
return result;
|
2019-08-27 20:12:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-05 14:33:51 +02:00
|
|
|
|
const QByteArray& ConnectionConfig::encodedPassword() const
|
2019-09-01 14:07:58 +02:00
|
|
|
|
{
|
|
|
|
|
|
return m_encodedPassword;
|
|
|
|
|
|
}
|
2017-03-05 21:23:36 +01:00
|
|
|
|
|
2019-09-16 19:24:39 +02:00
|
|
|
|
void ConnectionConfig::setEncodedPassword(const QByteArray &encodedPassword)
|
2019-09-01 14:07:58 +02:00
|
|
|
|
{
|
|
|
|
|
|
m_dirty = true;
|
2019-09-16 19:24:39 +02:00
|
|
|
|
m_encodedPassword = encodedPassword;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString ConnectionConfig::escapeConnectionStringValue(const QString &value)
|
|
|
|
|
|
{
|
|
|
|
|
|
bool contains_spaces = false;
|
|
|
|
|
|
int escapes = 0;
|
|
|
|
|
|
for (auto&& c : value)
|
2022-05-26 08:25:31 +02:00
|
|
|
|
if (c == ' ')
|
|
|
|
|
|
contains_spaces = true;
|
|
|
|
|
|
else if (c == '\'' || c == '\\')
|
|
|
|
|
|
++escapes;
|
2019-09-16 19:24:39 +02:00
|
|
|
|
|
2022-05-26 08:25:31 +02:00
|
|
|
|
if (contains_spaces || escapes > 0 || value.length() == 0)
|
|
|
|
|
|
{
|
2019-09-16 19:24:39 +02:00
|
|
|
|
QString result;
|
|
|
|
|
|
result.reserve(2 + value.length() + escapes);
|
|
|
|
|
|
result += '\'';
|
2022-05-26 08:25:31 +02:00
|
|
|
|
for (auto&& c : value)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (c == '\'' || c == '\\')
|
2019-09-16 19:24:39 +02:00
|
|
|
|
result += '\\';
|
|
|
|
|
|
result += c;
|
|
|
|
|
|
}
|
|
|
|
|
|
result += '\'';
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
2022-05-26 08:25:31 +02:00
|
|
|
|
else
|
2019-09-16 19:24:39 +02:00
|
|
|
|
return value;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString ConnectionConfig::connectionString() const
|
|
|
|
|
|
{
|
|
|
|
|
|
QString s;
|
2025-02-17 18:09:19 +01:00
|
|
|
|
|
|
|
|
|
|
for (auto && param : m_parameters)
|
2022-05-26 08:25:31 +02:00
|
|
|
|
{
|
2025-02-17 18:09:19 +01:00
|
|
|
|
// maybe we should prevent empty parameters from staying in the map?
|
|
|
|
|
|
if (!param.second.isEmpty())
|
|
|
|
|
|
{
|
|
|
|
|
|
s += param.first % "=" % escapeConnectionStringValue(param.second);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// s += "host="
|
|
|
|
|
|
// % escapeConnectionStringValue(m_host)
|
|
|
|
|
|
// % " port="
|
|
|
|
|
|
// % QString::number(m_port)
|
|
|
|
|
|
// % " user="
|
|
|
|
|
|
// % escapeConnectionStringValue(m_user);
|
|
|
|
|
|
// s += " password=";
|
|
|
|
|
|
// s += escapeConnectionStringValue(m_password);
|
|
|
|
|
|
// s += " dbname=";
|
|
|
|
|
|
// s += escapeConnectionStringValue(m_dbname);
|
|
|
|
|
|
// s += " sslmode=";
|
|
|
|
|
|
// s += SslModeToString(m_sslMode);
|
|
|
|
|
|
// if (!m_sslCert.isEmpty())
|
|
|
|
|
|
// {
|
|
|
|
|
|
// s += " sslcert=";
|
|
|
|
|
|
// s += escapeConnectionStringValue(m_sslCert);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// if (!m_sslKey.isEmpty())
|
|
|
|
|
|
// {
|
|
|
|
|
|
// s += " sslkey=";
|
|
|
|
|
|
// s += escapeConnectionStringValue(m_sslKey);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// if (!m_sslRootCert.isEmpty())
|
|
|
|
|
|
// {
|
|
|
|
|
|
// s += " sslrootcrt=";
|
|
|
|
|
|
// s += escapeConnectionStringValue(m_sslRootCert);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// if (!m_sslCrl.isEmpty())
|
|
|
|
|
|
// {
|
|
|
|
|
|
// s += " sslCrl=";
|
|
|
|
|
|
// s += escapeConnectionStringValue(m_sslCrl);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// s += " client_encoding=utf8";
|
|
|
|
|
|
// s += " application_name=";
|
|
|
|
|
|
// s += escapeConnectionStringValue(m_applicationName);
|
|
|
|
|
|
|
|
|
|
|
|
return s;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ConnectionConfig::setParameter(const QString &name, const QString &value)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (value.isEmpty())
|
2022-05-26 08:25:31 +02:00
|
|
|
|
{
|
2025-02-17 18:09:19 +01:00
|
|
|
|
if (m_parameters.erase(name) > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_dirty = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
2022-05-26 08:25:31 +02:00
|
|
|
|
{
|
2025-02-17 18:09:19 +01:00
|
|
|
|
auto findResult = m_parameters.find(name);
|
|
|
|
|
|
if (findResult == m_parameters.end())
|
|
|
|
|
|
{
|
|
|
|
|
|
m_parameters.insert({name, value});
|
|
|
|
|
|
m_dirty = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (findResult->second != value)
|
|
|
|
|
|
{
|
|
|
|
|
|
findResult->second = value;
|
|
|
|
|
|
m_dirty = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//if (name == "sslMode")
|
|
|
|
|
|
// m_sslMode = StringToSslMode(value);
|
2019-09-16 19:24:39 +02:00
|
|
|
|
|
2025-02-17 18:09:19 +01:00
|
|
|
|
// Would it better to store everything in the map or keep the specific
|
|
|
|
|
|
// fields for common keywords?
|
|
|
|
|
|
// Map over fields
|
|
|
|
|
|
// + can use foreach
|
|
|
|
|
|
// - not strongly typed, but we should be carefull not to restrict ourselves
|
|
|
|
|
|
// the specific fields are more something that helps in the UI
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString ConnectionConfig::getParameter(const QString &name) const
|
|
|
|
|
|
{
|
|
|
|
|
|
auto findResult = m_parameters.find(name);
|
|
|
|
|
|
if (findResult == m_parameters.end())
|
|
|
|
|
|
return {};
|
|
|
|
|
|
return findResult->second;
|
2019-09-01 14:07:58 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-03-05 21:23:36 +01:00
|
|
|
|
void ConnectionConfig::writeToEnvironment(QProcessEnvironment &env) const
|
|
|
|
|
|
{
|
2025-02-17 18:09:19 +01:00
|
|
|
|
strToEnv(env, "PGHOST", getParameter(keywords.host));
|
|
|
|
|
|
strToEnv(env, "PGHOSTADDR", getParameter(keywords.hostaddr));
|
|
|
|
|
|
strToEnv(env, "PGPORT", getParameter(keywords.port));
|
|
|
|
|
|
strToEnv(env, "PGDATABASE", getParameter(keywords.dbname));
|
|
|
|
|
|
strToEnv(env, "PGUSER", getParameter(keywords.user));
|
|
|
|
|
|
strToEnv(env, "PGPASSWORD", getParameter(keywords.password));
|
|
|
|
|
|
strToEnv(env, "PGSSLMODE", getParameter(keywords.sslmode));
|
|
|
|
|
|
// strToEnv(env, "PGSSLCERT", m_sslCert);
|
|
|
|
|
|
// strToEnv(env, "PGSSLKEY", m_sslKey);
|
|
|
|
|
|
// strToEnv(env, "PGSSLROOTCERT", m_sslRootCert);
|
|
|
|
|
|
// strToEnv(env, "PGSSLCRL", m_sslCrl);
|
2017-03-05 21:23:36 +01:00
|
|
|
|
strToEnv(env, "PGSSLCOMPRESSION", "0");
|
|
|
|
|
|
strToEnv(env, "PGCONNECT_TIMEOUT", "10");
|
|
|
|
|
|
env.insert("PGCLIENTENCODING", "utf8");
|
|
|
|
|
|
|
|
|
|
|
|
env.remove("PGREQUIRESSL");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-09-16 19:24:39 +02:00
|
|
|
|
void ConnectionConfig::strToEnv(QProcessEnvironment &env, const QString &var, const QString &val)
|
2017-03-05 21:23:36 +01:00
|
|
|
|
{
|
2019-09-16 19:24:39 +02:00
|
|
|
|
if (val.isEmpty())
|
2017-03-05 21:23:36 +01:00
|
|
|
|
env.remove(var);
|
|
|
|
|
|
else
|
2019-09-16 19:24:39 +02:00
|
|
|
|
env.insert(var, val);
|
2017-03-05 21:23:36 +01:00
|
|
|
|
}
|
2019-08-25 15:33:51 +02:00
|
|
|
|
|
2019-08-27 20:12:00 +02:00
|
|
|
|
void ConnectionGroup::erase(int idx, int count)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_connections.remove(idx, count);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ConnectionGroup::add(std::shared_ptr<ConnectionConfig> cc)
|
2019-08-25 15:33:51 +02:00
|
|
|
|
{
|
|
|
|
|
|
cc->setParent(this);
|
|
|
|
|
|
m_connections.push_back(cc);
|
2019-08-27 20:12:00 +02:00
|
|
|
|
return m_connections.size() - 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ConnectionGroup::update(int idx, const ConnectionConfig &cc)
|
|
|
|
|
|
{
|
|
|
|
|
|
auto node = m_connections[idx];
|
|
|
|
|
|
*node = cc;
|
|
|
|
|
|
node->setParent(this);
|
2019-08-25 15:33:51 +02:00
|
|
|
|
}
|