Thread: SVN Commit by andreas: r4795 - in branches/REL-1_4_0_PATCHES/pgadmin3/src: base include/base schema
SVN Commit by andreas: r4795 - in branches/REL-1_4_0_PATCHES/pgadmin3/src: base include/base schema
From
svn@pgadmin.org
Date:
Author: andreas Date: 2005-12-06 13:09:22 +0000 (Tue, 06 Dec 2005) New Revision: 4795 Modified: branches/REL-1_4_0_PATCHES/pgadmin3/src/base/pgConnBase.cpp branches/REL-1_4_0_PATCHES/pgadmin3/src/include/base/pgConnBase.h branches/REL-1_4_0_PATCHES/pgadmin3/src/schema/pgServer.cpp Log: store UTF8 connect info in pgpass.conf if necessary Modified: branches/REL-1_4_0_PATCHES/pgadmin3/src/base/pgConnBase.cpp =================================================================== --- branches/REL-1_4_0_PATCHES/pgadmin3/src/base/pgConnBase.cpp 2005-12-06 13:00:46 UTC (rev 4794) +++ branches/REL-1_4_0_PATCHES/pgadmin3/src/base/pgConnBase.cpp 2005-12-06 13:09:22 UTC (rev 4795) @@ -74,6 +74,7 @@ conv = &wxConvLibc; needColQuoting = false; + utfConnectString = false; // Check the hostname/ipaddress struct hostent *host; @@ -172,7 +173,9 @@ #if wxUSE_UNICODE wxCharBuffer cstrUTF=connstr.mb_str(wxConvUTF8); conn = PQconnectdb(cstrUTF); - if (PQstatus(conn) != CONNECTION_OK) + if (PQstatus(conn) == CONNECTION_OK) + utfConnectString = true; + else { wxCharBuffer cstrLibc=connstr.mb_str(wxConvLibc); if (strcmp(cstrUTF, cstrLibc)) Modified: branches/REL-1_4_0_PATCHES/pgadmin3/src/include/base/pgConnBase.h =================================================================== --- branches/REL-1_4_0_PATCHES/pgadmin3/src/include/base/pgConnBase.h 2005-12-06 13:00:46 UTC (rev 4794) +++ branches/REL-1_4_0_PATCHES/pgadmin3/src/include/base/pgConnBase.h 2005-12-06 13:09:22 UTC (rev 4795) @@ -71,6 +71,7 @@ wxString GetHost() const { return dbHost; } wxString GetDbname() const { return dbname; } wxString GetName() const; + bool GetNeedUtfConnectString() { return utfConnectString; } int GetPort() const { return atoi(PQport(conn)); }; wxString GetTTY() const { return wxString(PQtty(conn), *conv); } wxString GetOptions() const { return wxString(PQoptions(conn), *conv); } @@ -97,7 +98,7 @@ int connStatus; wxMBConv *conv; - bool needColQuoting; + bool needColQuoting, utfConnectString; wxString dbHost, dbname; OID lastSystemOID; OID dbOid; Modified: branches/REL-1_4_0_PATCHES/pgadmin3/src/schema/pgServer.cpp =================================================================== --- branches/REL-1_4_0_PATCHES/pgadmin3/src/schema/pgServer.cpp 2005-12-06 13:00:46 UTC (rev 4794) +++ branches/REL-1_4_0_PATCHES/pgadmin3/src/schema/pgServer.cpp 2005-12-06 13:09:22 UTC (rev 4795) @@ -471,15 +471,31 @@ if (file.IsOpened()) { wxString before; + wxString after; + + wxString passwd; + wxString seekStr; + +#if wxUSE_UNICODE + if (GetConnection()->GetNeedUtfConnectString()) + { + passwd = wxString(password.mb_str(wxConvUTF8), wxConvLibc); + seekStr = wxString(GetName().mb_str(wxConvUTF8), wxConvLibc) + wxT(":") + + NumToStr((long)GetPort()) + wxT(":*:") + + wxString(username.mb_str(wxConvUTF8), wxConvLibc) + wxT(":") ; + } + else +#endif + { + passwd = password; + seekStr = GetName() + wxT(":") + + NumToStr((long)GetPort()) + wxT(":*:") + + username + wxT(":") ; + } + file.Read(before); - wxStringTokenizer lines(before, wxT("\n\r")); - wxString seekStr= GetName() + wxT(":") - + NumToStr((long)GetPort()) + wxT(":*:") - + username + wxT(":") ; - wxString after; - file.Seek(0); bool found=false; while (lines.HasMoreTokens()) @@ -490,13 +506,13 @@ // entry found found=true; if (storePwd) - file.Write(seekStr + password + END_OF_LINE); + file.Write(seekStr + passwd + END_OF_LINE); } else file.Write(str + END_OF_LINE); } if (!found && storePwd) - file.Write(seekStr + password + END_OF_LINE); + file.Write(seekStr + passwd + END_OF_LINE); file.Close(); } @@ -506,6 +522,8 @@ int pgServer::Connect(frmMain *form, bool askPassword, const wxString &pwd) { wxLogInfo(wxT("Attempting to create a connection object...")); + + bool storePassword = false; if (!conn || conn->GetStatus() != PGCONN_OK) { @@ -539,7 +557,7 @@ iSetStorePwd(dlg.GetStorePwd()); password = dlg.GetPassword(); - StorePassword(); + storePassword = true; } } else @@ -619,6 +637,8 @@ settings->Write(wxT("Updates/UseSSL"), true); UpdateIcon(form->GetBrowser()); + if (storePassword) + StorePassword(); } else {