[libpostgresql-jdbc-java] 02/22: 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.
Emmanuel Bourg
ebourg-guest at moszumanska.debian.org
Mon Jan 9 10:20:52 UTC 2017
This is an automated email from the git hooks/post-receive script.
ebourg-guest pushed a commit to tag REL8_4_702
in repository libpostgresql-jdbc-java.
commit 5b72e98cca066428bbd251d66198bfb4d00ba103
Author: Kris Jurka <books at ejurka.com>
Date: Sat Sep 26 15:21:27 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 212b709..40cad0a 100644
--- a/org/postgresql/jdbc2/AbstractJdbc2Statement.java
+++ b/org/postgresql/jdbc2/AbstractJdbc2Statement.java
@@ -3,7 +3,7 @@
* Copyright (c) 2004-2008, PostgreSQL Global Development Group
*
* IDENTIFICATION
-* $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java,v 1.113 2009/01/28 09:50:21 jurka Exp $
+* $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java,v 1.114 2009/05/27 23:55:19 jurka Exp $
*
*-------------------------------------------------------------------------
*/
@@ -296,9 +296,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();
}
@@ -318,9 +328,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 bb12ef7..1f83ddb 100644
--- a/org/postgresql/test/jdbc2/StatementTest.java
+++ b/org/postgresql/test/jdbc2/StatementTest.java
@@ -3,7 +3,7 @@
* Copyright (c) 2004-2008, PostgreSQL Global Development Group
*
* IDENTIFICATION
-* $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/StatementTest.java,v 1.27 2008/01/08 06:56:31 jurka Exp $
+* $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/StatementTest.java,v 1.28 2008/11/16 12:14:07 jurka Exp $
*
*-------------------------------------------------------------------------
*/
@@ -460,4 +460,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
More information about the pkg-java-commits
mailing list