This is an automated email from the git hooks/post-receive script. ebourg-guest pushed a commit to tag REL8_0_316 in repository libpostgresql-jdbc-java.
commit 2e3fe1ffb9461bc25edd621a212a18cee023b2b8 Author: Kris Jurka <[email protected]> Date: Sat Apr 29 00:07:10 2006 +0000 When performing replace processing we must continue processing until we hit the end of a user supplied query, not just once we've detected the end of a valid query. Consider the example: SELECT a FROM t WHERE (1>0)) ORDER BY a; We must send the whole query to the backend, not just the section before the last closing parenthesis. Reported by Senden Kris --- org/postgresql/core/PGStream.java | 45 +++++++++++++++++++++------ org/postgresql/core/v2/QueryExecutorImpl.java | 20 ++++++++++-- org/postgresql/core/v3/QueryExecutorImpl.java | 13 ++++++-- org/postgresql/util/PSQLState.java | 3 +- 4 files changed, 65 insertions(+), 16 deletions(-) diff --git a/org/postgresql/core/PGStream.java b/org/postgresql/core/PGStream.java index cf6500e..c1117f5 100644 --- a/org/postgresql/core/PGStream.java +++ b/org/postgresql/core/PGStream.java @@ -3,7 +3,7 @@ * Copyright (c) 2003-2005, PostgreSQL Global Development Group * * IDENTIFICATION -* $PostgreSQL: pgjdbc/org/postgresql/core/PGStream.java,v 1.13 2005/01/11 08:25:43 jurka Exp $ +* $PostgreSQL: pgjdbc/org/postgresql/core/PGStream.java,v 1.13.2.1 2005/12/02 03:06:55 jurka Exp $ * *------------------------------------------------------------------------- */ @@ -343,7 +343,7 @@ public class PGStream * an array of bytearrays * @exception IOException if a data I/O error occurs */ - public byte[][] ReceiveTupleV3() throws IOException + public byte[][] ReceiveTupleV3() throws IOException, OutOfMemoryError { //TODO: use l_msgSize int l_msgSize = ReceiveIntegerR(4); @@ -351,17 +351,23 @@ public class PGStream int l_nf = ReceiveIntegerR(2); byte[][] answer = new byte[l_nf][0]; + OutOfMemoryError oom = null; 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); + if (l_size != -1) { + try { + answer[i] = new byte[l_size]; + Receive(answer[i], 0, l_size); + } catch(OutOfMemoryError oome) { + oom = oome; + Skip(l_size); + } } } + + if (oom != null) + throw oom; return answer; } @@ -377,7 +383,7 @@ public class PGStream * an array of bytearrays * @exception IOException if a data I/O error occurs */ - public byte[][] ReceiveTupleV2(int nf, boolean bin) throws IOException + public byte[][] ReceiveTupleV2(int nf, boolean bin) throws IOException, OutOfMemoryError { int i, bim = (nf + 7) / 8; byte[] bitmask = Receive(bim); @@ -386,6 +392,7 @@ public class PGStream int whichbit = 0x80; int whichbyte = 0; + OutOfMemoryError oom = null; for (i = 0 ; i < nf ; ++i) { boolean isNull = ((bitmask[whichbyte] & whichbit) == 0); @@ -404,9 +411,19 @@ public class PGStream len -= 4; if (len < 0) len = 0; - answer[i] = Receive(len); + try { + answer[i] = new byte[len]; + Receive(answer[i], 0, len); + } catch(OutOfMemoryError oome) { + oom = oome; + Skip(len); + } } } + + if (oom != null) + throw oom; + return answer; } @@ -445,6 +462,14 @@ public class PGStream } } + public void Skip(int size) throws IOException { + long s = 0; + while (s < size) { + s += pg_input.skip(size - s); + } + } + + /** * Copy data from an input stream to the connection. * diff --git a/org/postgresql/core/v2/QueryExecutorImpl.java b/org/postgresql/core/v2/QueryExecutorImpl.java index 3f59793..4e004a3 100644 --- a/org/postgresql/core/v2/QueryExecutorImpl.java +++ b/org/postgresql/core/v2/QueryExecutorImpl.java @@ -4,7 +4,7 @@ * Copyright (c) 2004, Open Cloud Limited. * * IDENTIFICATION -* $PostgreSQL: pgjdbc/org/postgresql/core/v2/QueryExecutorImpl.java,v 1.10.2.2 2005/02/15 08:55:50 jurka Exp $ +* $PostgreSQL: pgjdbc/org/postgresql/core/v2/QueryExecutorImpl.java,v 1.10.2.3 2005/12/15 23:29:29 jurka Exp $ * *------------------------------------------------------------------------- */ @@ -394,7 +394,15 @@ public class QueryExecutorImpl implements QueryExecutor { if (Driver.logDebug) Driver.debug(" <=BE BinaryRow"); - Object tuple = pgStream.ReceiveTupleV2(fields.length, true); + Object tuple = null; + try { + tuple = pgStream.ReceiveTupleV2(fields.length, true); + } catch(OutOfMemoryError oome) { + if (maxRows == 0 || tuples.size() < maxRows) { + handler.handleError(new PSQLException(GT.tr("Ran out of memory retrieving query results."), PSQLState.OUT_OF_MEMORY, oome)); + } + } + for (int i = 0; i < fields.length; i++) fields[i].setFormat(Field.BINARY_FORMAT); //Set the field to binary format if (maxRows == 0 || tuples.size() < maxRows) @@ -428,7 +436,13 @@ public class QueryExecutorImpl implements QueryExecutor { if (Driver.logDebug) Driver.debug(" <=BE DataRow"); - Object tuple = pgStream.ReceiveTupleV2(fields.length, false); + Object tuple = null; + try { + tuple = pgStream.ReceiveTupleV2(fields.length, false); + } catch(OutOfMemoryError oome) { + if (maxRows == 0 || tuples.size() < maxRows) + handler.handleError(new PSQLException(GT.tr("Ran out of memory retrieving query results."), PSQLState.OUT_OF_MEMORY, oome)); + } if (maxRows == 0 || tuples.size() < maxRows) tuples.addElement(tuple); } diff --git a/org/postgresql/core/v3/QueryExecutorImpl.java b/org/postgresql/core/v3/QueryExecutorImpl.java index 4b2b5c0..dc1a42b 100644 --- a/org/postgresql/core/v3/QueryExecutorImpl.java +++ b/org/postgresql/core/v3/QueryExecutorImpl.java @@ -4,7 +4,7 @@ * Copyright (c) 2004, Open Cloud Limited. * * IDENTIFICATION -* $PostgreSQL: pgjdbc/org/postgresql/core/v3/QueryExecutorImpl.java,v 1.21.2.1 2005/11/05 09:27:56 jurka Exp $ +* $PostgreSQL: pgjdbc/org/postgresql/core/v3/QueryExecutorImpl.java,v 1.21.2.2 2006/04/26 20:07:51 jurka Exp $ * *------------------------------------------------------------------------- */ @@ -1253,7 +1253,16 @@ public class QueryExecutorImpl implements QueryExecutor { break; case 'D': // Data Transfer (ongoing Execute response) - Object tuple = pgStream.ReceiveTupleV3(); + Object tuple = null; + try { + tuple = pgStream.ReceiveTupleV3(); + } catch(OutOfMemoryError oome) { + if (!noResults) { + handler.handleError(new PSQLException(GT.tr("Ran out of memory retrieving query results."), PSQLState.OUT_OF_MEMORY, oome)); + } + } + + if (!noResults) { if (tuples == null) diff --git a/org/postgresql/util/PSQLState.java b/org/postgresql/util/PSQLState.java index 3ef5c7b..2aadcea 100644 --- a/org/postgresql/util/PSQLState.java +++ b/org/postgresql/util/PSQLState.java @@ -3,7 +3,7 @@ * Copyright (c) 2003-2005, PostgreSQL Global Development Group * * IDENTIFICATION -* $PostgreSQL: pgjdbc/org/postgresql/util/PSQLState.java,v 1.8 2005/01/14 01:20:25 oliver Exp $ +* $PostgreSQL: pgjdbc/org/postgresql/util/PSQLState.java,v 1.9 2005/01/15 07:53:03 oliver Exp $ * *------------------------------------------------------------------------- */ @@ -71,6 +71,7 @@ public class PSQLState implements java.io.Serializable public final static PSQLState DATA_TYPE_MISMATCH = new PSQLState("42821"); public final static PSQLState UNDEFINED_FUNCTION = new PSQLState("42883"); + public final static PSQLState OUT_OF_MEMORY = new PSQLState("53200"); public final static PSQLState OBJECT_NOT_IN_STATE = new PSQLState("55000"); public final static PSQLState SYSTEM_ERROR = new PSQLState("60000"); -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/libpostgresql-jdbc-java.git _______________________________________________ pkg-java-commits mailing list [email protected] http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-java-commits

