[libpostgresql-jdbc-java] 01/09: 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:47 UTC 2017
This is an automated email from the git hooks/post-receive script.
ebourg-guest pushed a commit to tag REL8_3_606
in repository libpostgresql-jdbc-java.
commit ea835a4b1d1e0d7ecddd7809f8bb34d203bb3243
Author: Kris Jurka <books at ejurka.com>
Date: Sat Sep 26 15:21:34 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 c0e021a..3f153e5 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.107.2.1 2008/04/02 17:06:04 jurka Exp $
+* $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java,v 1.107.2.2 2009/05/27 23:55:27 jurka Exp $
*
*-------------------------------------------------------------------------
*/
@@ -279,9 +279,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();
}
@@ -301,9 +311,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..3f3b306 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.27.2.1 2008/11/16 12:14:17 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