Commit a9983ab4 authored by Barry Lind's avatar Barry Lind

Initial attempt to integrate in V3 protocol support. This is still a work in

progress, although all RTs pass using the V3 protocol on a 7.4 database and also pass using the V2 protocol on a 7.3 database.
SSL support is known not to work.

 Modified Files:
 	jdbc/org/postgresql/PGConnection.java
 	jdbc/org/postgresql/errors.properties
 	jdbc/org/postgresql/core/BaseConnection.java
 	jdbc/org/postgresql/core/Encoding.java
 	jdbc/org/postgresql/core/Field.java
 	jdbc/org/postgresql/core/PGStream.java
 	jdbc/org/postgresql/core/QueryExecutor.java
 	jdbc/org/postgresql/core/StartupPacket.java
 	jdbc/org/postgresql/fastpath/Fastpath.java
 	jdbc/org/postgresql/fastpath/FastpathArg.java
 	jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java
 	jdbc/org/postgresql/test/jdbc2/BlobTest.java
 	jdbc/org/postgresql/test/jdbc2/CallableStmtTest.java
 	jdbc/org/postgresql/test/jdbc2/MiscTest.java
 	jdbc/org/postgresql/test/jdbc3/Jdbc3TestSuite.java
parent d998fac9
...@@ -9,15 +9,13 @@ ...@@ -9,15 +9,13 @@
* Copyright (c) 2003, PostgreSQL Global Development Group * Copyright (c) 2003, PostgreSQL Global Development Group
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/Attic/PGConnection.java,v 1.5 2003/04/14 10:39:51 davec Exp $ * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/Attic/PGConnection.java,v 1.6 2003/05/29 03:21:32 barry Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
package org.postgresql; package org.postgresql;
import java.sql.*; import java.sql.*;
import java.util.Properties;
import java.util.Vector;
import org.postgresql.core.Encoding; import org.postgresql.core.Encoding;
import org.postgresql.fastpath.Fastpath; import org.postgresql.fastpath.Fastpath;
import org.postgresql.largeobject.LargeObjectManager; import org.postgresql.largeobject.LargeObjectManager;
......
...@@ -6,14 +6,13 @@ ...@@ -6,14 +6,13 @@
* Copyright (c) 2003, PostgreSQL Global Development Group * Copyright (c) 2003, PostgreSQL Global Development Group
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/core/Attic/BaseConnection.java,v 1.2 2003/04/13 04:10:07 barry Exp $ * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/core/Attic/BaseConnection.java,v 1.3 2003/05/29 03:21:32 barry Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
package org.postgresql.core; package org.postgresql.core;
import java.sql.DatabaseMetaData; import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.Statement; import java.sql.Statement;
import java.sql.SQLException; import java.sql.SQLException;
import org.postgresql.PGConnection; import org.postgresql.PGConnection;
...@@ -32,6 +31,8 @@ public interface BaseConnection extends PGConnection ...@@ -32,6 +31,8 @@ public interface BaseConnection extends PGConnection
public Encoding getEncoding() throws SQLException; public Encoding getEncoding() throws SQLException;
public DatabaseMetaData getMetaData() throws SQLException; public DatabaseMetaData getMetaData() throws SQLException;
public Object getObject(String type, String value) throws SQLException; public Object getObject(String type, String value) throws SQLException;
public int getPGProtocolVersionMajor();
public int getPGProtocolVersionMinor();
public PGStream getPGStream(); public PGStream getPGStream();
public String getPGType(int oid) throws SQLException; public String getPGType(int oid) throws SQLException;
public int getPGType(String pgTypeName) throws SQLException; public int getPGType(String pgTypeName) throws SQLException;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Copyright (c) 2003, PostgreSQL Global Development Group * Copyright (c) 2003, PostgreSQL Global Development Group
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/core/Attic/Encoding.java,v 1.10 2003/03/07 18:39:41 barry Exp $ * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/core/Attic/Encoding.java,v 1.11 2003/05/29 03:21:32 barry Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -140,15 +140,22 @@ public class Encoding ...@@ -140,15 +140,22 @@ public class Encoding
*/ */
public byte[] encode(String s) throws SQLException public byte[] encode(String s) throws SQLException
{ {
byte[] l_return;
try try
{ {
if (encoding == null) if (encoding == null)
{ {
return s.getBytes(); l_return = s.getBytes();
} }
else else
{ {
return s.getBytes(encoding); l_return = s.getBytes(encoding);
}
//Don't return null, return an empty byte[] instead
if (l_return == null) {
return new byte[0];
} else {
return l_return;
} }
} }
catch (UnsupportedEncodingException e) catch (UnsupportedEncodingException e)
......
...@@ -6,17 +6,14 @@ ...@@ -6,17 +6,14 @@
* Copyright (c) 2003, PostgreSQL Global Development Group * Copyright (c) 2003, PostgreSQL Global Development Group
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/core/Attic/Field.java,v 1.1 2003/03/07 18:39:41 barry Exp $ * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/core/Attic/Field.java,v 1.2 2003/05/29 03:21:32 barry Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
package org.postgresql.core; package org.postgresql.core;
import java.lang.*;
import java.sql.*; import java.sql.*;
import java.util.*;
import org.postgresql.core.BaseConnection; import org.postgresql.core.BaseConnection;
import org.postgresql.util.PSQLException;
/* /*
*/ */
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Copyright (c) 2003, PostgreSQL Global Development Group * Copyright (c) 2003, PostgreSQL Global Development Group
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/core/Attic/PGStream.java,v 1.1 2003/03/07 18:39:41 barry Exp $ * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/core/Attic/PGStream.java,v 1.2 2003/05/29 03:21:32 barry Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -84,6 +84,25 @@ public class PGStream ...@@ -84,6 +84,25 @@ public class PGStream
Send(buf); Send(buf);
} }
/*
* Sends an integer to the back end
*
* @param val the integer to be sent
* @param siz the length of the integer in bytes (size of structure)
* @exception IOException if an I/O error occurs
*/
public void SendIntegerR(int val, int siz) throws IOException
{
byte[] buf = new byte[siz];
for (int i = 0; i < siz; i++)
{
buf[i] = (byte)(val & 0xff);
val >>= 8;
}
Send(buf);
}
/* /*
* Send an array of bytes to the backend * Send an array of bytes to the backend
* *
...@@ -273,7 +292,39 @@ public class PGStream ...@@ -273,7 +292,39 @@ public class PGStream
* an array of strings * an array of strings
* @exception SQLException if a data I/O error occurs * @exception SQLException if a data I/O error occurs
*/ */
public byte[][] ReceiveTuple(int nf, boolean bin) throws SQLException public byte[][] ReceiveTupleV3(int nf, boolean bin) throws SQLException
{
//TODO: use l_msgSize
int l_msgSize = ReceiveIntegerR(4);
int i;
int l_nf = ReceiveIntegerR(2);
byte[][] answer = new byte[l_nf][0];
for (i = 0 ; i < l_nf ; ++i)
{
int l_size = ReceiveIntegerR(4);
boolean isNull = l_size == -1;
if (isNull)
answer[i] = null;
else
{
answer[i] = Receive(l_size);
}
}
return answer;
}
/*
* Read a tuple from the back end. A tuple is a two dimensional
* array of bytes
*
* @param nf the number of fields expected
* @param bin true if the tuple is a binary tuple
* @return null if the current response has no more tuples, otherwise
* an array of strings
* @exception SQLException if a data I/O error occurs
*/
public byte[][] ReceiveTupleV2(int nf, boolean bin) throws SQLException
{ {
int i, bim = (nf + 7) / 8; int i, bim = (nf + 7) / 8;
byte[] bitmask = Receive(bim); byte[] bitmask = Receive(bim);
...@@ -313,7 +364,7 @@ public class PGStream ...@@ -313,7 +364,7 @@ public class PGStream
* @return array of bytes received * @return array of bytes received
* @exception SQLException if a data I/O error occurs * @exception SQLException if a data I/O error occurs
*/ */
private byte[] Receive(int siz) throws SQLException public byte[] Receive(int siz) throws SQLException
{ {
byte[] answer = new byte[siz]; byte[] answer = new byte[siz];
Receive(answer, 0, siz); Receive(answer, 0, siz);
......
...@@ -5,7 +5,7 @@ import java.io.IOException; ...@@ -5,7 +5,7 @@ import java.io.IOException;
/** /**
* Sent to the backend to initialize a newly created connection. * Sent to the backend to initialize a newly created connection.
* *
* $Id: StartupPacket.java,v 1.3 2003/03/07 18:39:42 barry Exp $ * $Id: StartupPacket.java,v 1.4 2003/05/29 03:21:32 barry Exp $
*/ */
public class StartupPacket public class StartupPacket
...@@ -30,6 +30,31 @@ public class StartupPacket ...@@ -30,6 +30,31 @@ public class StartupPacket
} }
public void writeTo(PGStream stream) throws IOException public void writeTo(PGStream stream) throws IOException
{
if (protocolMajor == 3) {
v3WriteTo(stream);
} else {
v2WriteTo(stream);
}
}
public void v3WriteTo(PGStream stream) throws IOException
{
stream.SendInteger(4 + 4 + "user".length() + 1 + user.length() + 1 + "database".length() +1 + database.length() + 1 + 1, 4);
stream.SendInteger(protocolMajor, 2);
stream.SendInteger(protocolMinor, 2);
stream.Send("user".getBytes());
stream.SendChar(0);
stream.Send(user.getBytes());
stream.SendChar(0);
stream.Send("database".getBytes());
stream.SendChar(0);
stream.Send(database.getBytes());
stream.SendChar(0);
stream.SendChar(0);
}
public void v2WriteTo(PGStream stream) throws IOException
{ {
stream.SendInteger(4 + 4 + SM_DATABASE + SM_USER + SM_OPTIONS + SM_UNUSED + SM_TTY, 4); stream.SendInteger(4 + 4 + SM_DATABASE + SM_USER + SM_OPTIONS + SM_UNUSED + SM_TTY, 4);
stream.SendInteger(protocolMajor, 2); stream.SendInteger(protocolMajor, 2);
......
...@@ -18,6 +18,7 @@ postgresql.con.misc:A connection error has occurred: {0} ...@@ -18,6 +18,7 @@ postgresql.con.misc:A connection error has occurred: {0}
postgresql.con.multres:Cannot handle multiple result groups. postgresql.con.multres:Cannot handle multiple result groups.
postgresql.con.pass:The password property is missing. It is mandatory. postgresql.con.pass:The password property is missing. It is mandatory.
postgresql.con.refused:Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections. postgresql.con.refused:Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
postgresql.con.scm:SCM credentials authentication is not supported by this driver.
postgresql.con.setup:Protocol error. Session setup failed. postgresql.con.setup:Protocol error. Session setup failed.
postgresql.con.sslfail:An error occured while getting setting up the SSL connection. postgresql.con.sslfail:An error occured while getting setting up the SSL connection.
postgresql.con.sslnotsupported:The server does not support SSL postgresql.con.sslnotsupported:The server does not support SSL
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Copyright (c) 2003, PostgreSQL Global Development Group * Copyright (c) 2003, PostgreSQL Global Development Group
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/fastpath/Attic/Fastpath.java,v 1.12 2003/03/07 18:39:42 barry Exp $ * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/fastpath/Attic/Fastpath.java,v 1.13 2003/05/29 03:21:32 barry Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -61,6 +61,129 @@ public class Fastpath ...@@ -61,6 +61,129 @@ public class Fastpath
* @exception SQLException if a database-access error occurs. * @exception SQLException if a database-access error occurs.
*/ */
public Object fastpath(int fnid, boolean resulttype, FastpathArg[] args) throws SQLException public Object fastpath(int fnid, boolean resulttype, FastpathArg[] args) throws SQLException
{
if (conn.haveMinimumServerVersion("7.4")) {
return fastpathV3(fnid, resulttype, args);
} else {
return fastpathV2(fnid, resulttype, args);
}
}
private Object fastpathV3(int fnid, boolean resulttype, FastpathArg[] args) throws SQLException
{
// added Oct 7 1998 to give us thread safety
synchronized (stream)
{
// send the function call
try
{
int l_msgLen = 0;
l_msgLen += 16;
for (int i=0;i < args.length;i++)
l_msgLen += args[i].sendSize();
stream.SendChar('F');
stream.SendInteger(l_msgLen,4);
stream.SendInteger(fnid, 4);
stream.SendInteger(1,2);
stream.SendInteger(1,2);
stream.SendInteger(args.length,2);
for (int i = 0;i < args.length;i++)
args[i].send(stream);
stream.SendInteger(1,2);
// This is needed, otherwise data can be lost
stream.flush();
}
catch (IOException ioe)
{
throw new PSQLException("postgresql.fp.send", new Integer(fnid), ioe);
}
// Now handle the result
// Now loop, reading the results
Object result = null; // our result
StringBuffer errorMessage = null;
int c;
boolean l_endQuery = false;
while (!l_endQuery)
{
c = stream.ReceiveChar();
switch (c)
{
case 'A': // Asynchronous Notify
int pid = stream.ReceiveInteger(4);
String msg = stream.ReceiveString(conn.getEncoding());
conn.addNotification(new org.postgresql.core.Notification(msg, pid));
break;
//------------------------------
// Error message returned
case 'E':
if ( errorMessage == null )
errorMessage = new StringBuffer();
int l_elen = stream.ReceiveIntegerR(4);
errorMessage.append(conn.getEncoding().decode(stream.Receive(l_elen-4)));
break;
//------------------------------
// Notice from backend
case 'N':
int l_nlen = stream.ReceiveIntegerR(4);
conn.addWarning(conn.getEncoding().decode(stream.Receive(l_nlen-4)));
break;
case 'V':
int l_msgLen = stream.ReceiveIntegerR(4);
int l_valueLen = stream.ReceiveIntegerR(4);
if (l_valueLen == -1)
{
//null value
}
else if (l_valueLen == 0)
{
result = new byte[0];
}
else
{
// Return an Integer if
if (resulttype)
result = new Integer(stream.ReceiveIntegerR(l_valueLen));
else
{
byte buf[] = new byte[l_valueLen];
stream.Receive(buf, 0, l_valueLen);
result = buf;
}
}
break;
case 'Z':
//TODO: use size better
if (stream.ReceiveIntegerR(4) != 5) throw new PSQLException("postgresql.con.setup");
//TODO: handle transaction status
char l_tStatus = (char)stream.ReceiveChar();
l_endQuery = true;
break;
default:
throw new PSQLException("postgresql.fp.protocol", new Character((char)c));
}
}
if ( errorMessage != null )
throw new PSQLException("postgresql.fp.error", errorMessage.toString());
return result;
}
}
private Object fastpathV2(int fnid, boolean resulttype, FastpathArg[] args) throws SQLException
{ {
// added Oct 7 1998 to give us thread safety // added Oct 7 1998 to give us thread safety
synchronized (stream) synchronized (stream)
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Copyright (c) 2003, PostgreSQL Global Development Group * Copyright (c) 2003, PostgreSQL Global Development Group
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/fastpath/Attic/FastpathArg.java,v 1.4 2003/03/07 18:39:42 barry Exp $ * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/fastpath/Attic/FastpathArg.java,v 1.5 2003/05/29 03:21:32 barry Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -100,5 +100,17 @@ public class FastpathArg ...@@ -100,5 +100,17 @@ public class FastpathArg
s.Send(bytes); s.Send(bytes);
} }
} }
protected int sendSize()
{
if (type)
{
return 8;
}
else
{
return 4+bytes.length;
}
}
} }
...@@ -8,7 +8,7 @@ import java.sql.*; ...@@ -8,7 +8,7 @@ import java.sql.*;
import org.postgresql.largeobject.*; import org.postgresql.largeobject.*;
/* /*
* $Id: BlobTest.java,v 1.7 2002/08/14 20:35:40 barry Exp $ * $Id: BlobTest.java,v 1.8 2003/05/29 03:21:32 barry Exp $
* *
* Some simple tests based on problems reported by users. Hopefully these will * Some simple tests based on problems reported by users. Hopefully these will
* help prevent previous problems from re-occuring ;-) * help prevent previous problems from re-occuring ;-)
...@@ -188,7 +188,7 @@ public class BlobTest extends TestCase ...@@ -188,7 +188,7 @@ public class BlobTest extends TestCase
result = result && f == -1 && b == -1; result = result && f == -1 && b == -1;
if (!result) if (!result)
System.out.println("\nBlob compare failed at " + c + " of " + blob.size()); assertTrue("Blob compare failed at " + c + " of " + blob.size(), false);
blob.close(); blob.close();
fis.close(); fis.close();
......
...@@ -56,7 +56,6 @@ public class CallableStmtTest extends TestCase ...@@ -56,7 +56,6 @@ public class CallableStmtTest extends TestCase
public void testGetDouble () throws Throwable public void testGetDouble () throws Throwable
{ {
// System.out.println ("Testing CallableStmt Types.DOUBLE");
CallableStatement call = con.prepareCall (func + pkgName + "getDouble (?) }"); CallableStatement call = con.prepareCall (func + pkgName + "getDouble (?) }");
call.setDouble (2, (double)3.04); call.setDouble (2, (double)3.04);
call.registerOutParameter (1, Types.DOUBLE); call.registerOutParameter (1, Types.DOUBLE);
...@@ -67,7 +66,6 @@ public class CallableStmtTest extends TestCase ...@@ -67,7 +66,6 @@ public class CallableStmtTest extends TestCase
public void testGetInt () throws Throwable public void testGetInt () throws Throwable
{ {
// System.out.println ("Testing CallableStmt Types.INTEGER");
CallableStatement call = con.prepareCall (func + pkgName + "getInt (?) }"); CallableStatement call = con.prepareCall (func + pkgName + "getInt (?) }");
call.setInt (2, 4); call.setInt (2, 4);
call.registerOutParameter (1, Types.INTEGER); call.registerOutParameter (1, Types.INTEGER);
...@@ -78,7 +76,6 @@ public class CallableStmtTest extends TestCase ...@@ -78,7 +76,6 @@ public class CallableStmtTest extends TestCase
public void testGetNumeric () throws Throwable public void testGetNumeric () throws Throwable
{ {
// System.out.println ("Testing CallableStmt Types.NUMERIC");
CallableStatement call = con.prepareCall (func + pkgName + "getNumeric (?) }"); CallableStatement call = con.prepareCall (func + pkgName + "getNumeric (?) }");
call.setBigDecimal (2, new java.math.BigDecimal(4)); call.setBigDecimal (2, new java.math.BigDecimal(4));
call.registerOutParameter (1, Types.NUMERIC); call.registerOutParameter (1, Types.NUMERIC);
...@@ -90,7 +87,6 @@ public class CallableStmtTest extends TestCase ...@@ -90,7 +87,6 @@ public class CallableStmtTest extends TestCase
public void testGetString () throws Throwable public void testGetString () throws Throwable
{ {
// System.out.println ("Testing CallableStmt Types.VARCHAR");
CallableStatement call = con.prepareCall (func + pkgName + "getString (?) }"); CallableStatement call = con.prepareCall (func + pkgName + "getString (?) }");
call.setString (2, "foo"); call.setString (2, "foo");
call.registerOutParameter (1, Types.VARCHAR); call.registerOutParameter (1, Types.VARCHAR);
......
...@@ -5,7 +5,7 @@ import junit.framework.TestCase; ...@@ -5,7 +5,7 @@ import junit.framework.TestCase;
import java.sql.*; import java.sql.*;
/* /*
* $Id: MiscTest.java,v 1.8 2002/09/06 21:23:06 momjian Exp $ * $Id: MiscTest.java,v 1.9 2003/05/29 03:21:32 barry Exp $
* *
* Some simple tests based on problems reported by users. Hopefully these will * Some simple tests based on problems reported by users. Hopefully these will
* help prevent previous problems from re-occuring ;-) * help prevent previous problems from re-occuring ;-)
...@@ -79,7 +79,6 @@ public class MiscTest extends TestCase ...@@ -79,7 +79,6 @@ public class MiscTest extends TestCase
public void xtestLocking() public void xtestLocking()
{ {
System.out.println("testing lock");
try try
{ {
Connection con = TestUtil.openDB(); Connection con = TestUtil.openDB();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment