[libpostgresql-jdbc-java] 10/12: 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:20:28 UTC 2017


This is an automated email from the git hooks/post-receive script.

ebourg-guest pushed a commit to tag REL8_2_507
in repository libpostgresql-jdbc-java.

commit 5bf77d5d9aad4fde7054ebe496d374070e1f5dd6
Author: Kris Jurka <books at ejurka.com>
Date:   Tue Nov 27 19:33:13 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 761960c..554ad34 100644
--- a/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java
+++ b/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java
@@ -44,6 +44,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;
@@ -730,7 +731,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++ )
             {
@@ -1168,7 +1169,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();
 
@@ -1232,7 +1233,7 @@ public abstract class AbstractJdbc2ResultSet implements BaseResultSet, org.postg
         if (!doingUpdates)
             return; // No work pending.
 
-        StringBuffer updateSQL = new StringBuffer("UPDATE " + tableName + " SET  ");
+        StringBuffer updateSQL = new StringBuffer("UPDATE " + onlyTable + tableName + " SET  ");
         
         int numColumns = updateValues.size();
         Iterator columns = updateValues.keySet().iterator();
@@ -1629,6 +1630,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 86b56f7..8bbf977 100644
--- a/org/postgresql/test/jdbc2/UpdateableResultTest.java
+++ b/org/postgresql/test/jdbc2/UpdateableResultTest.java
@@ -428,7 +428,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