This is an automated email from the git hooks/post-receive script. ebourg-guest pushed a commit to tag REL8_2_511 in repository libpostgresql-jdbc-java.
commit e032415ab3753dae1b196403b85a5a0dc5547fb6 Author: Kris Jurka <[email protected]> Date: Sat Sep 26 15:21:40 2009 +0000 After running the statement passed to executeUpdate, we check to see if it was a SELECT and complain because it is not a query method. The code was not checking all of the results if it was passed a multi- statement query string. This resulted in the surprising and silent partial execution of SELECT statements. As reported by Joseph Shraibman. --- org/postgresql/jdbc2/AbstractJdbc2Statement.java | 31 +++++++++++++++++++----- org/postgresql/test/jdbc2/StatementTest.java | 20 ++++++++++++++- 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/org/postgresql/jdbc2/AbstractJdbc2Statement.java b/org/postgresql/jdbc2/AbstractJdbc2Statement.java index 50c38f4..31113d6 100644 --- a/org/postgresql/jdbc2/AbstractJdbc2Statement.java +++ b/org/postgresql/jdbc2/AbstractJdbc2Statement.java @@ -3,7 +3,7 @@ * Copyright (c) 2004-2005, PostgreSQL Global Development Group * * IDENTIFICATION -* $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java,v 1.96.2.7 2008/04/02 17:06:13 jurka Exp $ +* $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java,v 1.96.2.8 2009/05/27 23:55:35 jurka Exp $ * *------------------------------------------------------------------------- */ @@ -280,9 +280,19 @@ public abstract class AbstractJdbc2Statement implements BaseStatement executeWithFlags(p_sql, 0); return 0; } - if (executeWithFlags(p_sql, QueryExecutor.QUERY_NO_RESULTS)) - throw new PSQLException(GT.tr("A result was returned when none was expected."), + + executeWithFlags(p_sql, QueryExecutor.QUERY_NO_RESULTS); + + ResultWrapper iter = result; + while (iter != null) { + if (iter.getResultSet() != null) { + throw new PSQLException(GT.tr("A result was returned when none was expected."), PSQLState.TOO_MANY_RESULTS); + + } + iter = iter.getNext(); + } + return getUpdateCount(); } @@ -302,9 +312,18 @@ public abstract class AbstractJdbc2Statement implements BaseStatement executeWithFlags(0); return 0; } - if (executeWithFlags(QueryExecutor.QUERY_NO_RESULTS)) - throw new PSQLException(GT.tr("A result was returned when none was expected."), - PSQLState.TOO_MANY_RESULTS); + + executeWithFlags(QueryExecutor.QUERY_NO_RESULTS); + + ResultWrapper iter = result; + while (iter != null) { + if (iter.getResultSet() != null) { + throw new PSQLException(GT.tr("A result was returned when none was expected."), + PSQLState.TOO_MANY_RESULTS); + + } + iter = iter.getNext(); + } return getUpdateCount(); } diff --git a/org/postgresql/test/jdbc2/StatementTest.java b/org/postgresql/test/jdbc2/StatementTest.java index 205ebc0..d77d620 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.24 2006/12/01 08:53:46 jurka Exp $ +* $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/StatementTest.java,v 1.24.2.1 2008/11/16 12:14:28 jurka Exp $ * *------------------------------------------------------------------------- */ @@ -462,4 +462,22 @@ public class StatementTest extends TestCase } catch (SQLException sqle) { } } + public void testExecuteUpdateFailsOnSelect() throws SQLException + { + Statement stmt = con.createStatement(); + try { + stmt.executeUpdate("SELECT 1"); + fail("Should have thrown an error."); + } catch (SQLException sqle) { } + } + + public void testExecuteUpdateFailsOnMultiStatementSelect() throws SQLException + { + Statement stmt = con.createStatement(); + try { + stmt.executeUpdate("/* */; SELECT 1"); + fail("Should have thrown an error."); + } catch (SQLException sqle) { } + } + } -- 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

