diff options
author | Barry Lind <barry@xythos.com> | 2003-05-29 03:21:32 +0000 |
---|---|---|
committer | Barry Lind <barry@xythos.com> | 2003-05-29 03:21:32 +0000 |
commit | a9983ab4149991ac03506cc7985ee0a4bf6aba34 (patch) | |
tree | 5d80262bbe148731b5fb2833b62f53aa69667d0e /src/interfaces/jdbc/org/postgresql/fastpath | |
parent | d998fac95304a63899fcda7b591f04349f1bfb0d (diff) |
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
Diffstat (limited to 'src/interfaces/jdbc/org/postgresql/fastpath')
-rw-r--r-- | src/interfaces/jdbc/org/postgresql/fastpath/Fastpath.java | 125 | ||||
-rw-r--r-- | src/interfaces/jdbc/org/postgresql/fastpath/FastpathArg.java | 14 |
2 files changed, 137 insertions, 2 deletions
diff --git a/src/interfaces/jdbc/org/postgresql/fastpath/Fastpath.java b/src/interfaces/jdbc/org/postgresql/fastpath/Fastpath.java index 1e094e15cf7..b9abb6eacce 100644 --- a/src/interfaces/jdbc/org/postgresql/fastpath/Fastpath.java +++ b/src/interfaces/jdbc/org/postgresql/fastpath/Fastpath.java @@ -6,7 +6,7 @@ * Copyright (c) 2003, PostgreSQL Global Development Group * * 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 $ * *------------------------------------------------------------------------- */ @@ -62,6 +62,129 @@ public class Fastpath */ 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 synchronized (stream) { diff --git a/src/interfaces/jdbc/org/postgresql/fastpath/FastpathArg.java b/src/interfaces/jdbc/org/postgresql/fastpath/FastpathArg.java index 7e59ce2387d..0cc8ff67573 100644 --- a/src/interfaces/jdbc/org/postgresql/fastpath/FastpathArg.java +++ b/src/interfaces/jdbc/org/postgresql/fastpath/FastpathArg.java @@ -7,7 +7,7 @@ * Copyright (c) 2003, PostgreSQL Global Development Group * * 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 s.Send(bytes); } } + + protected int sendSize() + { + if (type) + { + return 8; + } + else + { + return 4+bytes.length; + } + } } |