fixed problem connecting to server with client_min_messages set to debug. The code was not expecting to receive notice messages during the connection handshake.

This commit is contained in:
Barry Lind 2002-05-14 03:00:35 +00:00
parent ef9db25a7e
commit e25c93c7eb
1 changed files with 1077 additions and 1072 deletions

View File

@ -4,6 +4,7 @@ import java.io.*;
import java.net.*;
import java.sql.*;
import java.util.*;
import org.postgresql.Driver;
import org.postgresql.Field;
import org.postgresql.fastpath.*;
import org.postgresql.largeobject.*;
@ -11,7 +12,7 @@ import org.postgresql.util.*;
import org.postgresql.core.*;
/*
* $Id: Connection.java,v 1.45 2002/03/26 05:52:48 barry Exp $
* $Id: Connection.java,v 1.46 2002/05/14 03:00:35 barry Exp $
*
* This abstract class is used by org.postgresql.Driver to open either the JDBC1 or
* JDBC2 versions of the Connection class.
@ -30,7 +31,7 @@ public abstract class Connection
private String compatible;
/*
* The encoding to use for this connection.
The encoding to use for this connection.
*/
private Encoding encoding = Encoding.defaultEncoding();
@ -209,7 +210,6 @@ public abstract class Connection
case 'R':
// Get the type of request
areq = pg_stream.ReceiveIntegerR(4);
// Get the crypt password salt if there is one
if (areq == AUTH_REQ_CRYPT)
{
@ -217,7 +217,7 @@ public abstract class Connection
rst[0] = (byte)pg_stream.ReceiveChar();
rst[1] = (byte)pg_stream.ReceiveChar();
salt = new String(rst, 0, 2);
DriverManager.println("Crypt salt=" + salt);
Driver.debug("Crypt salt=" + salt);
}
// Or get the md5 password salt if there is one
@ -229,7 +229,7 @@ public abstract class Connection
rst[2] = (byte)pg_stream.ReceiveChar();
rst[3] = (byte)pg_stream.ReceiveChar();
salt = new String(rst, 0, 4);
DriverManager.println("MD5 salt=" + salt);
Driver.debug("MD5 salt=" + salt);
}
// now send the auth packet
@ -239,15 +239,15 @@ public abstract class Connection
break;
case AUTH_REQ_KRB4:
DriverManager.println("postgresql: KRB4");
Driver.debug("postgresql: KRB4");
throw new PSQLException("postgresql.con.kerb4");
case AUTH_REQ_KRB5:
DriverManager.println("postgresql: KRB5");
Driver.debug("postgresql: KRB5");
throw new PSQLException("postgresql.con.kerb5");
case AUTH_REQ_PASSWORD:
DriverManager.println("postgresql: PASSWORD");
Driver.debug("postgresql: PASSWORD");
pg_stream.SendInteger(5 + password.length(), 4);
pg_stream.Send(password.getBytes());
pg_stream.SendInteger(0, 1);
@ -255,7 +255,7 @@ public abstract class Connection
break;
case AUTH_REQ_CRYPT:
DriverManager.println("postgresql: CRYPT");
Driver.debug("postgresql: CRYPT");
String crypted = UnixCrypt.crypt(salt, password);
pg_stream.SendInteger(5 + crypted.length(), 4);
pg_stream.Send(crypted.getBytes());
@ -264,7 +264,7 @@ public abstract class Connection
break;
case AUTH_REQ_MD5:
DriverManager.println("postgresql: MD5");
Driver.debug("postgresql: MD5");
byte[] digest = MD5Digest.encode(PG_USER, password, salt);
pg_stream.SendInteger(5 + digest.length, 4);
pg_stream.Send(digest);
@ -291,7 +291,9 @@ public abstract class Connection
// As of protocol version 2.0, we should now receive the cancellation key and the pid
int beresp = pg_stream.ReceiveChar();
int beresp;
do {
beresp = pg_stream.ReceiveChar();
switch (beresp)
{
case 'K':
@ -306,19 +308,24 @@ public abstract class Connection
default:
throw new PSQLException("postgresql.con.setup");
}
} while (beresp == 'N');
// Expect ReadyForQuery packet
do {
beresp = pg_stream.ReceiveChar();
switch (beresp)
{
case 'Z':
break;
case 'N':
addWarning(pg_stream.ReceiveString(encoding));
break;
case 'E':
throw new PSQLException("postgresql.con.backend", pg_stream.ReceiveString(encoding));
default:
throw new PSQLException("postgresql.con.setup");
}
} while (beresp == 'N');
// "pg_encoding_to_char(1)" will return 'EUC_JP' for a backend compiled with multibyte,
// otherwise it's hardcoded to 'SQL_ASCII'.
// If the backend doesn't know about multibyte we can't assume anything about the encoding
@ -368,8 +375,6 @@ public abstract class Connection
*/
public void addWarning(String msg)
{
DriverManager.println(msg);
// Add the warning to the chain
if (firstWarning != null)
firstWarning.setNextWarning(new SQLWarning(msg));