Skip to content

Commit

Permalink
Add extend options in connstr.
Browse files Browse the repository at this point in the history
Для сервера можно добавить дополнительные параметры подключения.
В настройка сервера на закладке "Дополнительно" в поле "Connect str"
  • Loading branch information
lsv authored and levinsv committed Oct 13, 2023
1 parent e239035 commit 0093e36
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 30 deletions.
12 changes: 9 additions & 3 deletions db/pgConn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static void pgNoticeProcessor(void *arg, const char *message)
}

pgConn::pgConn(const wxString &server, const wxString &service, const wxString &hostaddr, const wxString &database, const wxString &username, const wxString &password,
int port, const wxString &rolename, int sslmode, OID oid, const wxString &applicationname,
int port, const wxString &rolename, const wxString& addconnstr, int sslmode, OID oid, const wxString &applicationname,
const wxString &sslcert, const wxString &sslkey, const wxString &sslrootcert, const wxString &sslcrl,
const bool sslcompression) : m_cancelConn(NULL)
{
Expand All @@ -64,6 +64,7 @@ pgConn::pgConn(const wxString &server, const wxString &service, const wxString &
save_password = password;
save_port = port;
save_rolename = rolename;
save_addconnstr = addconnstr;
save_sslmode = sslmode;
save_oid = oid;
save_applicationname = applicationname;
Expand Down Expand Up @@ -122,7 +123,12 @@ pgConn::pgConn(const wxString &server, const wxString &service, const wxString &
connstr.Append(wxT(" port="));
connstr.Append(NumToStr((long)port));
}

if (!addconnstr.IsEmpty())
{
connstr.Append(wxT(" "));
connstr.Append(addconnstr);
}

if (libpqVersion > 7.3)
{
switch (sslmode)
Expand Down Expand Up @@ -362,7 +368,7 @@ pgConn *pgConn::Duplicate(const wxString &_appName)
{
pgConn *res = new pgConn(wxString(save_server), wxString(save_service),
wxString(save_hostaddr), wxString(save_database), wxString(save_username),
wxString(save_password), save_port, save_rolename, save_sslmode, save_oid,
wxString(save_password), save_port, save_rolename, save_addconnstr, save_sslmode, save_oid,
_appName.IsEmpty() ? save_applicationname : _appName, save_sslcert, save_sslkey,
save_sslrootcert, save_sslcrl, save_sslcompression);

Expand Down
13 changes: 8 additions & 5 deletions dlg/dlgSelectConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,17 @@ pgConn *dlgSelectConnection::CreateConn(wxString &applicationname, bool &created


int sslmode = remoteServer ? remoteServer->GetSSL() : 0;

return CreateConn(serv, db, user, port, role, sslmode, applicationname, true);
wxString addconnstr;
if (remoteServer) {
addconnstr = remoteServer->GetConnStr();
}
return CreateConn(serv, db, user, port, role, addconnstr, sslmode, applicationname, true);
}

pgConn *dlgSelectConnection::CreateConn(wxString &server, wxString &dbname, wxString &username, int port, wxString &rolename, int sslmode, wxString &applicationname, bool writeMRU)
pgConn *dlgSelectConnection::CreateConn(wxString &server, wxString &dbname, wxString &username, int port, wxString &rolename, wxString &addconnstr, int sslmode, wxString &applicationname, bool writeMRU)
{
pgConn *newconn;
newconn = new pgConn(server, wxEmptyString, wxEmptyString, dbname, username, wxT(""), port, rolename, sslmode, 0, applicationname);
newconn = new pgConn(server, wxEmptyString, wxEmptyString, dbname, username, wxT(""), port, rolename, addconnstr, sslmode, 0, applicationname);
if (newconn->GetStatus() != PGCONN_OK &&
newconn->GetLastError().Cmp(wxString(PQnoPasswordSupplied, wxConvUTF8)) == 0)
{
Expand All @@ -290,7 +293,7 @@ pgConn *dlgSelectConnection::CreateConn(wxString &server, wxString &dbname, wxSt
if (dlg.Go() != wxID_OK)
return NULL;

newconn = new pgConn(server, wxEmptyString, wxEmptyString, dbname, username, dlg.GetPassword(), port, rolename, sslmode, 0, applicationname);
newconn = new pgConn(server, wxEmptyString, wxEmptyString, dbname, username, dlg.GetPassword(), port, rolename, addconnstr, sslmode, 0, applicationname);
}

if (newconn)
Expand Down
11 changes: 9 additions & 2 deletions dlg/dlgServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#define stStorePwd CTRL_STATIC("stStorePwd")
#define chkStorePwd CTRL_CHECKBOX("chkStorePwd")
#define txtRolename CTRL_TEXT("txtRolename")
#define txtConnStr CTRL_TEXT("txtConnStr")
#define stRestore CTRL_STATIC("stRestore")
#define chkRestore CTRL_CHECKBOX("chkRestore")
#define stPassword CTRL_STATIC("stPassword")
Expand Down Expand Up @@ -80,6 +81,7 @@ BEGIN_EVENT_TABLE(dlgServer, dlgProperty)
EVT_TEXT(XRCID("txtPort") , dlgProperty::OnChange)
EVT_TEXT(XRCID("txtUsername"), dlgProperty::OnChange)
EVT_TEXT(XRCID("txtRolename"), dlgProperty::OnChange)
EVT_TEXT(XRCID("txtConnStr"), dlgProperty::OnChange)
EVT_TEXT(XRCID("txtDbRestriction"), dlgServer::OnChangeRestr)
EVT_COMBOBOX(XRCID("cbSSL"), dlgProperty::OnChange)
EVT_CHECKBOX(XRCID("chkStorePwd"), dlgProperty::OnChange)
Expand Down Expand Up @@ -231,6 +233,7 @@ void dlgServer::OnOK(wxCommandEvent &ev)
server->iSetDatabase(cbDatabase->GetValue());
server->iSetUsername(txtUsername->GetValue());
server->iSetRolename(txtRolename->GetValue());
server->iSetConnStr(txtConnStr->GetValue());
server->iSetStorePwd(chkStorePwd->GetValue());
server->iSetRestore(chkRestore->GetValue());
server->iSetDbRestriction(txtDbRestriction->GetValue().Trim());
Expand Down Expand Up @@ -274,6 +277,7 @@ void dlgServer::OnOK(wxCommandEvent &ev)
server->GetPort(),
server->GetStorePwd(),
server->GetRolename(),
server->GetConnStr(),
server->GetRestore(),
server->GetSSL(),
server->GetColour(),
Expand Down Expand Up @@ -466,6 +470,7 @@ int dlgServer::Go(bool modal)
txtUsername->SetValue(server->GetUsername());
chkStorePwd->SetValue(server->GetStorePwd());
txtRolename->SetValue(server->GetRolename());
txtConnStr->SetValue(server->GetConnStr());
chkRestore->SetValue(server->GetRestore());
txtDbRestriction->SetValue(server->GetDbRestriction());
colourPicker->SetColour(server->GetColour());
Expand Down Expand Up @@ -517,6 +522,7 @@ int dlgServer::Go(bool modal)
txtUsername->Disable();
chkStorePwd->Disable();
txtRolename->Disable();
txtConnStr->Disable();
chkRestore->Disable();
txtDbRestriction->Disable();
colourPicker->Disable();
Expand Down Expand Up @@ -579,7 +585,7 @@ pgObject *dlgServer::CreateObject(pgCollection *collection)
txtService->GetValue(), cbDatabase->GetValue(),
txtUsername->GetValue(), StrToLong(txtPort->GetValue()),
chkTryConnect->GetValue() && chkStorePwd->GetValue(),
txtRolename->GetValue(), chkRestore->GetValue(), cbSSL->GetCurrentSelection(),
txtRolename->GetValue(), txtConnStr->GetValue(), chkRestore->GetValue(), cbSSL->GetCurrentSelection(),
colourPicker->GetColourString(), cbGroup->GetValue(),
chkSSHTunnel->GetValue(), txtTunnelHost->GetValue(), txtTunnelUsername->GetValue(),
radioBtnPassword->GetValue(),
Expand All @@ -593,7 +599,7 @@ pgObject *dlgServer::CreateObject(pgCollection *collection)
txtService->GetValue(), cbDatabase->GetValue(),
txtUsername->GetValue(), StrToLong(txtPort->GetValue()),
chkTryConnect->GetValue() && chkStorePwd->GetValue(),
txtRolename->GetValue(), chkRestore->GetValue(), cbSSL->GetCurrentSelection(),
txtRolename->GetValue(), txtConnStr->GetValue(), chkRestore->GetValue(), cbSSL->GetCurrentSelection(),
colourPicker->GetColourString(), cbGroup->GetValue());
}

Expand Down Expand Up @@ -645,6 +651,7 @@ void dlgServer::CheckChange()
|| cbSSL->GetCurrentSelection() != server->GetSSL()
|| chkStorePwd->GetValue() != server->GetStorePwd()
|| txtRolename->GetValue() != server->GetRolename()
|| txtConnStr->GetValue() != server->GetConnStr()
|| chkRestore->GetValue() != server->GetRestore()
|| txtDbRestriction->GetValue() != server->GetDbRestriction()
|| sColour != sColour2
Expand Down
1 change: 1 addition & 0 deletions frm/frmMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,7 @@ void frmMain::StoreServers()
settings->WriteInt(key + wxT("Port"), server->GetPort());
settings->WriteBool(key + wxT("StorePwd"), server->GetStorePwd());
settings->Write(key + wxT("Rolename"), server->GetRolename());
settings->Write(key + wxT("ConnStr"), server->GetConnStr());
settings->WriteBool(key + wxT("Restore"), server->GetRestore());
settings->Write(key + wxT("Database"), server->GetDatabaseName());
settings->Write(key + wxT("Username"), server->GetUsername());
Expand Down
6 changes: 4 additions & 2 deletions frm/frmStatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ void frmStatus::OnChangeDatabase(wxCommandEvent &ev)
}

locks_connection = new pgConn(connection->GetHostName(), connection->GetService(), connection->GetHostAddr(), cbDatabase->GetValue(),
connection->GetUser(), connection->GetPassword(), connection->GetPort(), connection->GetRole(), connection->GetSslMode(),
connection->GetUser(), connection->GetPassword(), connection->GetPort(), connection->GetRole(),"", connection->GetSslMode(),
0, connection->GetApplicationName(), connection->GetSSLCert(), connection->GetSSLKey(), connection->GetSSLRootCert(), connection->GetSSLCrl(),
connection->GetSSLCompression());

Expand Down Expand Up @@ -1253,7 +1253,7 @@ void frmStatus::OnCopyQuery(wxCommandEvent &ev)
{
pgConn *conn = new pgConn(connection->GetHostName(), connection->GetService(), connection->GetHostAddr(), dbname,
connection->GetUser(), connection->GetPassword(),
connection->GetPort(), connection->GetRole(), connection->GetSslMode(), connection->GetDbOid(),
connection->GetPort(), connection->GetRole(),"", connection->GetSslMode(), connection->GetDbOid(),
connection->GetApplicationName(),
connection->GetSSLCert(), connection->GetSSLKey(), connection->GetSSLRootCert(), connection->GetSSLCrl(),
connection->GetSSLCompression());
Expand Down Expand Up @@ -3437,6 +3437,7 @@ void frmStatus::OnCommit(wxCommandEvent &event)
connection->GetPassword(),
connection->GetPort(),
connection->GetRole(),
"",
connection->GetSslMode(),
0,
connection->GetApplicationName(),
Expand Down Expand Up @@ -3494,6 +3495,7 @@ void frmStatus::OnRollback(wxCommandEvent &event)
connection->GetPassword(),
connection->GetPort(),
connection->GetRole(),
"",
connection->GetSslMode(),
0,
connection->GetApplicationName(),
Expand Down
8 changes: 6 additions & 2 deletions include/db/pgConn.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class pgConn
public:
pgConn(const wxString &server = wxT(""), const wxString &service = wxT(""), const wxString &hostaddr = wxT(""),
const wxString &database = wxT(""), const wxString &username = wxT(""), const wxString &password = wxT(""),
int port = 5432, const wxString &rolename = wxT(""), int sslmode = 0, OID oid = 0,
int port = 5432, const wxString &rolename = wxT(""), const wxString& addconnstr = wxT(""), int sslmode = 0, OID oid = 0,
const wxString &applicationname = wxT("pgAdmin"),
const wxString &sslcert = wxT(""), const wxString &sslkey = wxT(""), const wxString &sslrootcert = wxT(""), const wxString &sslcrl = wxT(""),
const bool sslcompression = true);
Expand Down Expand Up @@ -178,6 +178,10 @@ class pgConn
{
return save_sslkey;
}
wxString GetAddConnStr() const
{
return save_addconnstr;
}
wxString GetSSLRootCert() const
{
return save_sslrootcert;
Expand Down Expand Up @@ -303,7 +307,7 @@ class pgConn
wxString reservedNamespaces;
wxString connstr;

wxString save_server, save_service, save_hostaddr, save_database, save_username, save_password, save_rolename, save_applicationname;
wxString save_server, save_service, save_hostaddr, save_database, save_username, save_password, save_rolename, save_addconnstr, save_applicationname;
wxString save_sslcert, save_sslkey, save_sslrootcert, save_sslcrl;
int save_port, save_sslmode;
bool save_sslcompression;
Expand Down
2 changes: 1 addition & 1 deletion include/dlg/dlgSelectConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class dlgSelectConnection : public DialogWithHelp
return remoteServer;
}
pgConn *CreateConn(wxString &applicationame, bool &createdNew);
pgConn *CreateConn(wxString &server, wxString &dbname, wxString &username, int port, wxString &rolename, int sslmode, wxString &applicationame, bool writeMRU = false);
pgConn *CreateConn(wxString &server, wxString &dbname, wxString &username, int port, wxString &rolename, wxString& addconnstr, int sslmode, wxString &applicationame, bool writeMRU = false);
wxString GetServerName();
wxString GetDatabase();

Expand Down
12 changes: 10 additions & 2 deletions include/schema/pgServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class pgServer : public pgObject
public:
pgServer(const wxString &newServer = wxT(""), const wxString &newHostAddr = wxT(""), const wxString &newDescription = wxT(""),
const wxString &newService = wxT(""), const wxString &newDatabase = wxT(""), const wxString &newUsername = wxT(""), int newPort = 5432,
bool storePwd = false, const wxString &newRolename = wxT(""), bool restore = true, int sslMode = 0,
bool storePwd = false, const wxString &newRolename = wxT(""), const wxString& newConnStr = wxT(""), bool restore = true, int sslMode = 0,
const wxString &colour = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW).GetAsString(wxC2S_HTML_SYNTAX), const wxString &group = wxEmptyString,
bool sshTunnel = false, const wxString &newTunnelHost = wxEmptyString, const wxString &newTunnelUserName = wxEmptyString, bool authModePwd = true,
const wxString &newTunnelPassword = wxEmptyString, const wxString &newPublicKey = wxEmptyString, const wxString &newIdentityFile = wxEmptyString,
Expand Down Expand Up @@ -112,6 +112,10 @@ class pgServer : public pgObject
{
return rolename;
}
wxString GetConnStr() const
{
return connstr;
}
bool GetRestore() const
{
return restore;
Expand Down Expand Up @@ -308,6 +312,10 @@ class pgServer : public pgObject
{
rolename = newVal;
}
void iSetConnStr(const wxString& newVal)
{
connstr = newVal;
}
void iSetRestore(const bool b)
{
restore = b;
Expand Down Expand Up @@ -534,7 +542,7 @@ class pgServer : public pgObject
pgConn *conn;
long serverIndex;
bool connected, passwordValid, autovacuumRunning;
wxString service, hostaddr, database, username, password, rolename, ver, error;
wxString service, hostaddr, database, username, password, rolename, connstr, ver, error;
wxString lastDatabase, lastSchema, description, serviceId, discoveryId;
wxDateTime upSince;
int port, ssl;
Expand Down
6 changes: 4 additions & 2 deletions pgAdmin3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,8 @@ bool pgAdmin3::OnInit()
winSplash->Show(false);
dlgSelectConnection dlg(NULL, NULL);
dlg.CenterOnParent();
conn = dlg.CreateConn(host, database, username, port, rolename, sslmode, applicationname);
wxString connstr = "";
conn = dlg.CreateConn(host, database, username, port, rolename,connstr, sslmode, applicationname);
}
else
{
Expand Down Expand Up @@ -822,7 +823,8 @@ bool pgAdmin3::OnInit()
winSplash->Show(false);
dlgSelectConnection dlg(NULL, NULL);
dlg.CenterOnParent();
conn = dlg.CreateConn(host, database, username, port, rolename, sslmode, applicationname);
wxString connstr = "";
conn = dlg.CreateConn(host, database, username, port, rolename, connstr, sslmode, applicationname);
}
else
{
Expand Down
1 change: 1 addition & 0 deletions schema/pgRole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ void pgRole::ReassignDropOwnedTo(frmMain *form)
GetConnection()->GetPassword(),
GetConnection()->GetPort(),
GetConnection()->GetRole(),
GetConnection()->GetAddConnStr(),
GetConnection()->GetSslMode(),
0,
GetConnection()->GetApplicationName(),
Expand Down

0 comments on commit 0093e36

Please sign in to comment.