Handling protocol not supported error message when working with protocol 2 and 3
Hi all,
I'm finishing the implementation of the protocol 3.0 and now I'm working
in how to connect to server using protocol 3.0 when the server doesn't
support it 7.3- .
As suggested in a previous mail about how to handle with both protocol
versions, I'm trying first to connect using version 3.0. The problem is
if the server is a 7.3 or earlier, it would answer with a non supported
protocol error message, but as I'm in the protocol 3.0 version mode, I
would expect a error message in the new format and not in the 2.0 format.
How I could handle it?
I know this error happens early in the connection establishment, when I
send the StartupPacket and I could use this info to do some choices
about when to use the version 2 or 3. The problem is that I also could
get a lot of errors when sending the startup packet, as password
incorrect, database and others.
I was thinking about examining the first 4 bytes ( as this is where the
message length is located) and try if these bytes could be translated to
"FATA" which would mean the "FATAL: unsupported frontend protocol\n"
error. But I think this would be a big hack. Is there a more elegant
solution?
I know this question was alread raised some time ago, but I couldn't
find it.
Thanks in advance.
--
Regards,
Francisco Figueiredo Jr.
------
"My grandfather once told me that there are two
kinds of people: those
who work and those who take the credit. He told me
to try to be in the
first group; there was less competition there."
- Indira Gandhi
"Francisco Figueiredo Jr." <fxjrlists@yahoo.com.br> writes:
I'm finishing the implementation of the protocol 3.0 and now I'm working
in how to connect to server using protocol 3.0 when the server doesn't
support it 7.3- .
I'd suggest using the same methods libpq does. You do have to be
prepared to accept an old-format error message.
regards, tom lane
Tom Lane wrote:
"Francisco Figueiredo Jr." <fxjrlists@yahoo.com.br> writes:
I'm finishing the implementation of the protocol 3.0 and now I'm working
in how to connect to server using protocol 3.0 when the server doesn't
support it 7.3- .I'd suggest using the same methods libpq does. You do have to be
prepared to accept an old-format error message.
Yes, I'm prepared, but the problem is how can I in advance know which
format the message is, as I'm expecing a 3 version and comes a 2 version
error message?
Uhmmmm, I could see in the following line in libpq how it does it:
if (beresp == 'E' && (msgLength < 8 || msgLength > 30000))
So this is how it checks ahead, if the value is very large, the
msgLength would be bigger than 30000 and this would mean a string error
and so the 2.0 version error message. I think I will get this approach too.
Thanks Tom Lane.
regards, tom lane
--
Regards,
Francisco Figueiredo Jr.
------
"My grandfather once told me that there are two
kinds of people: those
who work and those who take the credit. He told me
to try to be in the
first group; there was less competition there."
- Indira Gandhi