--- src/db/pgConn.cpp.orig Tue Oct 7 06:42:53 2003 +++ src/db/pgConn.cpp Fri Oct 10 04:31:09 2003 @@ -40,7 +40,7 @@ pgConn::pgConn(const wxString& server, const wxString& database, const wxString& username, const wxString& password, int port, int sslmode) -: conv(wxConvLibc) +// : conv(wxConvLibc) { wxLogInfo(wxT("Creating pgConn object")); wxString msg, hostip; @@ -54,6 +54,8 @@ majorVersion=0; noticeArg=0; + needConvUTF8 = false; + #ifdef __WXMSW__ struct in_addr ipaddr; #else @@ -153,9 +155,12 @@ { wxLogInfo(wxT("Setting client_encoding to 'UNICODE'")); if (PQsetClientEncoding(conn, "UNICODE")) - wxLogError(wxT("%s"), wxString(PQerrorMessage(conn), conv).c_str()); + wxLogError(wxT("%s"), wxString(PQerrorMessage(conn), wxConvUTF8).c_str()); else - conv = wxConvUTF8; + /* conv = wxConvUTF8; + It is inserted temporarily because the relations of the multiplex succession + aren't clear though it is the work of constructor. */ + needConvUTF8 = true; } #else @@ -202,8 +207,17 @@ void pgConn::Notice(const char *msg) { - wxString str(msg, conv); + if (needConvUTF8) + { + wxString str(msg, wxConvUTF8); + wxLogNotice(wxT("%s"), str.c_str()); + } + else + { + wxString str(msg, wxConvLibc); wxLogNotice(wxT("%s"), str.c_str()); + } + if (noticeArg && noticeProc) (*noticeProc)(noticeArg, msg); @@ -220,14 +234,20 @@ PGresult *qryRes; wxLogSql(wxT("Void query (%s:%d): %s"), this->GetHost().c_str(), this->GetPort(), sql.c_str()); - qryRes = PQexec(conn, sql.mb_str(conv)); + if (needConvUTF8) + qryRes = PQexec(conn, sql.mb_str(wxConvUTF8)); + else + qryRes = PQexec(conn, sql.mb_str(wxConvLibc)); int res = PQresultStatus(qryRes); // Check for errors if (res != PGRES_TUPLES_OK && res != PGRES_COMMAND_OK) { - wxLogError(wxT("%s"), wxString(PQerrorMessage(conn), conv).c_str()); + if (needConvUTF8) + wxLogError(wxT("%s"), wxString(PQerrorMessage(conn), wxConvUTF8).c_str()); + else + wxLogError(wxT("%s"), wxString(PQerrorMessage(conn), wxConvLibc).c_str()); } // Cleanup & exit @@ -252,12 +272,18 @@ // Execute the query and get the status. PGresult *qryRes; wxLogSql(wxT("Scalar query (%s:%d): %s"), this->GetHost().c_str(), this->GetPort(), sql.c_str()); - qryRes = PQexec(conn, sql.mb_str(conv)); + if (needConvUTF8) + qryRes = PQexec(conn, sql.mb_str(wxConvUTF8)); + else + qryRes = PQexec(conn, sql.mb_str(wxConvLibc)); // Check for errors if (PQresultStatus(qryRes) != PGRES_TUPLES_OK) { - wxLogError(wxT("%s"), wxString(PQerrorMessage(conn), conv).c_str()); + if (needConvUTF8) + wxLogError(wxT("%s"), wxString(PQerrorMessage(conn), wxConvUTF8).c_str()); + else + wxLogError(wxT("%s"), wxString(PQerrorMessage(conn), wxConvLibc).c_str()); PQclear(qryRes); return wxEmptyString; } @@ -272,7 +298,10 @@ // Retrieve the query result and return it. wxString result; - result=wxString(PQgetvalue(qryRes, 0, 0), conv); + if (needConvUTF8) + result=wxString(PQgetvalue(qryRes, 0, 0), wxConvUTF8); + else + result=wxString(PQgetvalue(qryRes, 0, 0), wxConvLibc); wxLogSql(wxT("Query result: %s"), result.c_str()); @@ -286,13 +315,17 @@ // Execute the query and get the status. PGresult *qryRes; wxLogSql(wxT("Set query (%s:%d): %s"), this->GetHost().c_str(), this->GetPort(), sql.c_str()); - qryRes = PQexec(conn, sql.mb_str(conv)); + + if (needConvUTF8) + qryRes = PQexec(conn, sql.mb_str(wxConvUTF8)); + else + qryRes = PQexec(conn, sql.mb_str(wxConvLibc)); int status= PQresultStatus(qryRes); if (status == PGRES_TUPLES_OK || status == PGRES_COMMAND_OK) { - pgSet *set = new pgSet(qryRes, conn, conv, needColQuoting); + pgSet *set = new pgSet(qryRes, conn, needConvUTF8, needColQuoting); if (!set) { wxLogError(__("Couldn't create a pgSet object!")); @@ -302,7 +335,10 @@ } else { - wxLogError(wxT("%s"), wxString(PQerrorMessage(conn), conv).c_str()); + if (needConvUTF8) + wxLogError(wxT("%s"), wxString(PQerrorMessage(conn), wxConvUTF8).c_str()); + else + wxLogError(wxT("%s"), wxString(PQerrorMessage(conn), wxConvLibc).c_str()); PQclear(qryRes); } --- src/db/pgSet.cpp.orig Tue Oct 7 06:42:53 2003 +++ src/db/pgSet.cpp Fri Oct 10 04:31:19 2003 @@ -22,11 +22,13 @@ #include "sysLogger.h" #include "pgDefs.h" -pgSet::pgSet(PGresult *newRes, PGconn *newConn, wxMBConv &cnv, bool needColQt) -: conv(cnv) +pgSet::pgSet(PGresult *newRes, PGconn *newConn, bool ConedConvUTF8, bool needColQt) +//: conv(cnv) { needColQuoting = needColQt; + needConvUTF8 = ConedConvUTF8; + wxLogInfo(wxT("Creating pgSet object")); conn = newConn; res = newRes; @@ -125,9 +127,15 @@ int col; if (needColQuoting) - col = PQfnumber(res, qtIdent(colname).mb_str(conv)); + if (needConvUTF8) + col = PQfnumber(res, qtIdent(colname).mb_str(wxConvUTF8)); + else + col = PQfnumber(res, qtIdent(colname).mb_str(wxConvLibc)); + else + if (needConvUTF8) + col = PQfnumber(res, colname.mb_str(wxConvUTF8)); else - col = PQfnumber(res, colname.mb_str(conv)); + col = PQfnumber(res, colname.mb_str(wxConvLibc)); if (col < 0) wxLogError(__("Column not found in pgSet: ") + colname); @@ -381,7 +389,7 @@ if (rc == PGRES_TUPLES_OK) { - dataSet = new pgSet(result, conn->conn, conn->conv, conn->needColQuoting); + dataSet = new pgSet(result, conn->conn, conn->needConvUTF8, conn->needColQuoting); dataSet->MoveFirst(); dataSet->GetVal(0); } --- src/include/pgConn.h.orig Tue Oct 7 06:42:53 2003 +++ src/include/pgConn.h Fri Oct 10 04:29:59 2003 @@ -67,6 +67,7 @@ OID GetLastSystemOID() const { return lastSystemOID; } bool BackendMinimumVersion(int major, int minor); void RegisterNoticeProcessor(PQnoticeProcessor proc, void *arg); + #ifdef SSL bool IsSSLconnected(); #endif @@ -76,7 +77,9 @@ private: PGconn *conn; int minorVersion, majorVersion; - wxMBConv &conv; + + bool needConvUTF8; /* wxMBConv &conv; */ + bool resolvedIP, needColQuoting; wxString dbHost; OID lastSystemOID; --- src/include/pgSet.h.orig Tue Oct 7 06:42:53 2003 +++ src/include/pgSet.h Fri Oct 10 04:30:12 2003 @@ -38,7 +38,7 @@ class pgSet { public: - pgSet(PGresult *newRes, PGconn *newConn, wxMBConv &cnv, bool needColQt); + pgSet(PGresult *newRes, PGconn *newConn, bool needConvUTF8, bool needColQt); ~pgSet(); long NumRows() const { return nRows; } long NumCols() const { return PQnfields(res); } @@ -84,7 +84,9 @@ PGresult *res; long pos, nRows; wxString ExecuteScalar(const wxString& sql) const; - wxMBConv &conv; + + bool needConvUTF8; /* wxMBConv &conv; */ + bool needColQuoting; };