Обсуждение: pgConn.cpp.patch

Поиск
Список
Период
Сортировка

pgConn.cpp.patch

От
Adam H.Pendleton
Дата:
This patch fixes a bug in the error reporting of the new connection
dialog when setting the database encoding.

ahp

Вложения

Re: pgConn.cpp.patch

От
"Dave Page"
Дата:

> -----Original Message-----
> From: Adam H.Pendleton [mailto:fmonkey@fmonkey.net]
> Sent: 25 June 2003 03:02
> To: pgadmin-hackers@postgresql.org
> Subject: [pgadmin-hackers] pgConn.cpp.patch
>
>
> This patch fixes a bug in the error reporting of the new connection
> dialog when setting the database encoding.

Hi Adam,

I don't believe this patch is correct. PQsetClientEncoding returns 0 on
success and -1 on failure [1], therefore !PQsetClientEncoding is true
upon success.

-       if (PQsetClientEncoding(conn, "UNICODE"))
+       if (!PQsetClientEncoding(conn, "UNICODE"))
            wxLogError(wxT("%s"), wxString(PQerrorMessage(conn),
wxConvUTF8).c_str());

Patch NOT applied.

Regards, Dave.

[1]
http://www.postgresql.org/docs/view.php?version=7.3&idoc=0&file=multibyt
e.html

Re: pgConn.cpp.patch

От
"Adam H. Pendleton"
Дата:
Dave Page wrote:
 
-----Original Message-----
From: Adam H.Pendleton [mailto:fmonkey@fmonkey.net] 
Sent: 25 June 2003 03:02
To: pgadmin-hackers@postgresql.org
Subject: [pgadmin-hackers] pgConn.cpp.patch


This patch fixes a bug in the error reporting of the new connection 
dialog when setting the database encoding.   
Hi Adam,

I don't believe this patch is correct. PQsetClientEncoding returns 0 on
success and -1 on failure [1], therefore !PQsetClientEncoding is true
upon success.
 
The docs may say that, but I can tell you that:

if (PQsetClientEncoding(conn, "SQL_ASCII"))
           wxLogError(wxT("%s"), PQerrorMessage(conn));

causes wxLogError to be run, if there was an error in the connection.  For example, try connecting to a postgres database with an incorrect password.  You will get *two* password incorrect dialogs.  The first is displayed by the above code.

ahp


Re: pgConn.cpp.patch

От
"Dave Page"
Дата:
 
-----Original Message-----
From: Adam H. Pendleton [mailto:fmonkey@fmonkey.net]
Sent: 25 June 2003 14:40
To: Dave Page
Cc: pgadmin-hackers@postgresql.org
Subject: Re: [pgadmin-hackers] pgConn.cpp.patch

Dave Page wrote: 
 
  The docs may say that, but I can tell you that:

if (PQsetClientEncoding(conn, "SQL_ASCII"))
           wxLogError(wxT("%s"), PQerrorMessage(conn));

causes wxLogError to be run, if there was an error in the connection.  For example, try connecting to a postgres database with an incorrect password.  You will get *two* password incorrect dialogs.  The first is displayed by the above code.

Yes, this is because the PQsetClientEncoding fails because the connection failed. I've changed the preceeding code to:
 
    // Set client encoding to Unicode/Ascii
    if (PQstatus(conn) == CONNECTION_OK)
    {
 
#if wxUSE_UNICODE
 
       wxLogInfo(wxT("Setting client_encoding to 'UNICODE'"));
 
...
...
 
which takes care of it.
 
Regards, Dave.

Re: pgConn.cpp.patch

От
"Adam H. Pendleton"
Дата:
Dave Page wrote:
 Yes, this is because the PQsetClientEncoding fails because the connection failed. I've changed the preceeding code to:
 
    // Set client encoding to Unicode/Ascii
    if (PQstatus(conn) == CONNECTION_OK)
    {
 
#if wxUSE_UNICODE
 
       wxLogInfo(wxT("Setting client_encoding to 'UNICODE'"));
 
...
...
 
which takes care of it.
 
Regards, Dave.
Doh!  Of course it fails.  Well, at least this saves me from having to figure out what I missed.  BTW, if PQsetClientEncoding fails, which it does, then why would the error come up as a password error?  Does that mean that PQsetClientEncoding doesn't change the Postgres errors like other PQ functions?

ahp

Re: pgConn.cpp.patch

От
"Dave Page"
Дата:
 
-----Original Message-----
From: Adam H. Pendleton [mailto:fmonkey@fmonkey.net]
Sent: 25 June 2003 15:51
To: Dave Page
Cc: pgadmin-hackers@postgresql.org
Subject: Re: [pgadmin-hackers] pgConn.cpp.patch

Dave Page wrote:
Doh!  Of course it fails.  Well, at least this saves me from having to figure out what I missed.  BTW, if PQsetClientEncoding fails, which it does, then why would the error come up as a password error?   
 
I think it's because libpq is clever enough to keep the 'real' error rather than just say that the encoding couldn't be set. This makes sense if you think about it, because normally the client encoding will fail to get set if an invaid encoding is chosen - this can only be discovered when the connection is present.
 
 Does that mean that PQsetClientEncoding doesn't change the Postgres errors like other PQ functions?

 
No. If it gets a real error, then you will see it. Try changing the 'UNICODE' to 'SOMETHINGELSE' and logging in. Note that in this case you may still see 2 sequential error messages - 1 as the master connection is established, then a second for whichever database auto-reopens (and of course, subsequent db opens). 
 
Regards, Dave.