[libpostgresql-jdbc-java] 04/06: Make code that parses queries for updateable resultsets aware of the ONLY clause.
Emmanuel Bourg
ebourg-guest at moszumanska.debian.org
Mon Jan 9 10:19:35 UTC 2017
This is an automated email from the git hooks/post-receive script.
ebourg-guest pushed a commit to tag REL8_0_321
in repository libpostgresql-jdbc-java.
commit 7f1bae80133bfc558939211c414d1eda5f37feec
Author: Kris Jurka <books at ejurka.com>
Date: Tue Nov 27 19:33:31 2007 +0000
Make code that parses queries for updateable resultsets aware of the
ONLY clause.
Oleg Vasylenko + me
---
org/postgresql/jdbc2/AbstractJdbc2ResultSet.java | 11 ++++++++---
org/postgresql/test/jdbc2/UpdateableResultTest.java | 13 ++++++++++++-
2 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java b/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java
index aac6a2d..5f0f7ba 100644
--- a/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java
+++ b/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java
@@ -45,6 +45,7 @@ public abstract class AbstractJdbc2ResultSet implements BaseResultSet, org.postg
private boolean usingOID = false; // are we using the OID for the primary key?
private Vector primaryKeys; // list of primary keys
private boolean singleTable = false;
+ private String onlyTable = "";
private String tableName = null;
private PreparedStatement updateStatement = null;
private PreparedStatement insertStatement = null;
@@ -740,7 +741,7 @@ public abstract class AbstractJdbc2ResultSet implements BaseResultSet, org.postg
{
- StringBuffer deleteSQL = new StringBuffer("DELETE FROM " ).append(tableName).append(" where " );
+ StringBuffer deleteSQL = new StringBuffer("DELETE FROM " ).append(onlyTable).append(tableName).append(" where " );
for ( int i = 0; i < numKeys; i++ )
{
@@ -1178,7 +1179,7 @@ public abstract class AbstractJdbc2ResultSet implements BaseResultSet, org.postg
}
}
- selectSQL.append(" from " ).append(tableName).append(" where ");
+ selectSQL.append(" from " ).append(onlyTable).append(tableName).append(" where ");
int numKeys = primaryKeys.size();
@@ -1245,7 +1246,7 @@ public abstract class AbstractJdbc2ResultSet implements BaseResultSet, org.postg
try
{
- StringBuffer updateSQL = new StringBuffer("UPDATE " + tableName + " SET ");
+ StringBuffer updateSQL = new StringBuffer("UPDATE " + onlyTable + tableName + " SET ");
int numColumns = updateValues.size();
Iterator columns = updateValues.keySet().iterator();
@@ -1672,6 +1673,10 @@ public abstract class AbstractJdbc2ResultSet implements BaseResultSet, org.postg
if (name.toLowerCase().equals("from"))
{
tableName = st.nextToken();
+ if (tableName.toLowerCase().equals("only")) {
+ tableName = st.nextToken();
+ onlyTable = "ONLY ";
+ }
tableFound = true;
}
}
diff --git a/org/postgresql/test/jdbc2/UpdateableResultTest.java b/org/postgresql/test/jdbc2/UpdateableResultTest.java
index 5ea48d3..499d021 100644
--- a/org/postgresql/test/jdbc2/UpdateableResultTest.java
+++ b/org/postgresql/test/jdbc2/UpdateableResultTest.java
@@ -422,7 +422,18 @@ public class UpdateableResultTest extends TestCase
rs.moveToInsertRow();
rs.close();
st.close();
- }
+ }
+
+ public void testUpdateSelectOnly() throws Exception
+ {
+ Statement st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
+ ResultSet.CONCUR_UPDATABLE);
+
+ ResultSet rs = st.executeQuery( "select * from only second");
+ assertTrue(rs.next());
+ rs.updateInt(1, 2);
+ rs.updateRow();
+ }
public void testUpdateReadOnlyResultSet() throws Exception
{
--
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