This is an automated email from the git hooks/post-receive script. ebourg-guest pushed a commit to tag REL8_0_314 in repository libpostgresql-jdbc-java.
commit d993a601753d5c77ec0070c74fc27d94a1719962 Author: Kris Jurka <[email protected]> Date: Sat Nov 5 09:27:56 2005 +0000 The driver needs to break a statement into individual queries to use the V3 extended query protocol. The parsing code did not recognize multiple rule actions separated by semi-colons as one query. Jolly Chen --- org/postgresql/core/v3/QueryExecutorImpl.java | 15 +++++++++++++-- org/postgresql/test/jdbc2/StatementTest.java | 21 ++++++++++++++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/org/postgresql/core/v3/QueryExecutorImpl.java b/org/postgresql/core/v3/QueryExecutorImpl.java index 945a9b8..4731627 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.20 2005/01/27 22:50:13 oliver Exp $ +* $PostgreSQL: pgjdbc/org/postgresql/core/v3/QueryExecutorImpl.java,v 1.21 2005/02/01 07:27:54 jurka Exp $ * *------------------------------------------------------------------------- */ @@ -66,6 +66,7 @@ public class QueryExecutorImpl implements QueryExecutor { boolean inSingleQuotes = false; boolean inDoubleQuotes = false; + int inParen = 0; for (int i = 0; i < query.length(); ++i) { @@ -94,8 +95,18 @@ public class QueryExecutorImpl implements QueryExecutor { } break; - case ';': + case '(': + if (!inSingleQuotes && !inDoubleQuotes) + inParen++; + break; + + case ')': if (!inSingleQuotes && !inDoubleQuotes) + inParen--; + break; + + case ';': + if (!inSingleQuotes && !inDoubleQuotes && inParen == 0) { fragmentList.add(query.substring(fragmentStart, i)); fragmentStart = i + 1; diff --git a/org/postgresql/test/jdbc2/StatementTest.java b/org/postgresql/test/jdbc2/StatementTest.java index 781dc26..d033462 100644 --- a/org/postgresql/test/jdbc2/StatementTest.java +++ b/org/postgresql/test/jdbc2/StatementTest.java @@ -3,7 +3,7 @@ * Copyright (c) 2004-2005, PostgreSQL Global Development Group * * IDENTIFICATION -* $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/StatementTest.java,v 1.15 2005/01/27 11:30:48 jurka Exp $ +* $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/StatementTest.java,v 1.15.2.1 2005/08/12 18:22:31 jurka Exp $ * *------------------------------------------------------------------------- */ @@ -318,4 +318,23 @@ public class StatementTest extends TestCase stmt.close(); } + /** + * The parser tries to break multiple statements into individual + * queries as required by the V3 extended query protocol. It can + * be a little overzealous sometimes and this test ensures we + * keep multiple rule actions together in one statement. + */ + public void testParsingSemiColons() throws SQLException + { + Statement stmt = con.createStatement(); + stmt.execute("CREATE RULE r1 AS ON INSERT TO escapetest DO (DELETE FROM test_statement ; INSERT INTO test_statement VALUES (1); INSERT INTO test_statement VALUES (2); );"); + stmt.executeUpdate("INSERT INTO escapetest(ts) VALUES (NULL)"); + ResultSet rs = stmt.executeQuery("SELECT i from test_statement ORDER BY i"); + assertTrue(rs.next()); + assertEquals(1, rs.getInt(1)); + assertTrue(rs.next()); + assertEquals(2, rs.getInt(1)); + assertTrue(!rs.next()); + } + } -- 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

