[libpostgresql-jdbc-java] 09/11: 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.
Emmanuel Bourg
ebourg-guest at moszumanska.debian.org
Mon Jan 9 10:19:19 UTC 2017
This is an automated email from the git hooks/post-receive script.
ebourg-guest pushed a commit to tag REL8_0_315
in repository libpostgresql-jdbc-java.
commit 79bb5edf8ec22fbbc67c56e08ea549f87c604108
Author: Kris Jurka <books at ejurka.com>
Date: Wed Feb 1 18:52:41 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/jdbc2/AbstractJdbc2Statement.java | 20 ++++++++++++++++----
org/postgresql/test/jdbc2/StatementTest.java | 11 ++++++++++-
2 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/org/postgresql/jdbc2/AbstractJdbc2Statement.java b/org/postgresql/jdbc2/AbstractJdbc2Statement.java
index 03c1de2..04c523e 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.68.2.10 2005/10/03 17:26:36 jurka Exp $
+* $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java,v 1.68.2.11 2005/12/04 21:41:36 jurka Exp $
*
*-------------------------------------------------------------------------
*/
@@ -701,8 +701,21 @@ public abstract class AbstractJdbc2Statement implements BaseStatement
{
// Since escape codes can only appear in SQL CODE, we keep track
// of if we enter a string or not.
- StringBuffer newsql = new StringBuffer(p_sql.length());
- parseSql(p_sql,0,newsql,false);
+ int len = p_sql.length();
+ StringBuffer newsql = new StringBuffer(len);
+ int i=0;
+ while (i<len){
+ i=parseSql(p_sql,i,newsql,false);
+ // We need to loop here in case we encounter invalid
+ // SQL, consider: SELECT a FROM t WHERE (1 > 0)) ORDER BY a
+ // We can't ending replacing after the extra closing paren
+ // because that changes a syntax error to a valid query
+ // that isn't what the user specified.
+ if (i < len) {
+ newsql.append(p_sql.charAt(i));
+ i++;
+ }
+ }
return newsql.toString();
}
else
@@ -868,7 +881,6 @@ public abstract class AbstractJdbc2Statement implements BaseStatement
StringBuffer arg = new StringBuffer();
int lastPos=i;
i=parseSql(args,i,arg,true);
- int nestedCount=0;
if (lastPos!=i){
parsedArgs.add(arg);
}
diff --git a/org/postgresql/test/jdbc2/StatementTest.java b/org/postgresql/test/jdbc2/StatementTest.java
index 79c0f87..20a18fe 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.2.2 2005/11/05 09:27:56 jurka Exp $
+* $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/StatementTest.java,v 1.15.2.3 2005/12/15 23:29:39 jurka Exp $
*
*-------------------------------------------------------------------------
*/
@@ -345,4 +345,13 @@ public class StatementTest extends TestCase
assertTrue(!rs.next());
}
+ public void testUnbalancedParensParseError() throws SQLException
+ {
+ Statement stmt = con.createStatement();
+ try {
+ stmt.executeQuery("SELECT i FROM test_statement WHERE (1 > 0)) ORDER BY i");
+ fail("Should have thrown a parse 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