Implement UpdateCount
authorPeter Mount
Sun, 11 Apr 1999 18:03:00 +0000 (18:03 +0000)
committerPeter Mount
Sun, 11 Apr 1999 18:03:00 +0000 (18:03 +0000)
src/interfaces/jdbc/CHANGELOG
src/interfaces/jdbc/example/basic.java
src/interfaces/jdbc/postgresql/Connection.java
src/interfaces/jdbc/postgresql/Statement.java

index 103c1bf6ff05f2be66d7a557a7cc0c038fb9c8fd..b6104df13aa695b6fd1d5754a042b8a080797141 100644 (file)
@@ -1,3 +1,10 @@
+Sun Apr 11 17:00:00 BST 1999
+   - getUpdateCount() now returns the actual update count (before it
+     simply returned 1 for everything).
+   - added some updates to example.basic so it would test the new update
+     count code.
+   - corrected typo in a comment in Statement.java
+
 Mon Jan 25 19:45:00 GMT 1999
    - created subfolders example/corba and example/corba/idl to hold the
      new example showing how to hook CORBA and PostgreSQL via JDBC
index 1ea20d1d932ff5a5911b6279ba45c40b81ed8893..939d460e240c60d7fc3768dc6196b929e083283f 100644 (file)
@@ -77,6 +77,10 @@ public class basic
     st.executeUpdate("insert into basic values (2,1)");
     st.executeUpdate("insert into basic values (3,1)");
     
+    // Now change the value of b from 1 to 8
+    st.executeUpdate("update basic set b=8");
+    System.out.println("Updated "+st.getUpdateCount()+" rows");
+    
     // For large inserts, a PreparedStatement is more efficient, because it
     // supports the idea of precompiling the SQL statement, and to store
     // directly, a Java object into any column. PostgreSQL doesnt support
index df354776f7fc51f7645e8230b82af331e0a2c336..4ec6fdb177c0e6984eba1c1d557c5ce407151f7b 100644 (file)
@@ -10,7 +10,7 @@ import postgresql.largeobject.*;
 import postgresql.util.*;
 
 /**
- * $Id: Connection.java,v 1.14 1999/01/17 04:51:50 momjian Exp $
+ * $Id: Connection.java,v 1.15 1999/04/11 18:03:00 peter Exp $
  *
  * This abstract class is used by postgresql.Driver to open either the JDBC1 or
  * JDBC2 versions of the Connection class.
@@ -321,6 +321,7 @@ public abstract class Connection
        int fqp = 0;
        boolean hfr = false;
        String recv_status = null, msg;
+       int update_count = 1;
        SQLException final_error = null;
        
        if (sql.length() > 8192)
@@ -358,6 +359,15 @@ public abstract class Connection
                break;
            case 'C':   // Command Status
                recv_status = pg_stream.ReceiveString(8192);
+               
+               // Now handle the update count correctly.
+               if(recv_status.startsWith("INSERT") || recv_status.startsWith("UPDATE")) {
+                   try {
+                       update_count = Integer.parseInt(recv_status.substring(1+recv_status.lastIndexOf(' ')));
+                   } catch(NumberFormatException nfe) {
+                       throw new SQLException("Unable to fathom update count \""+recv_status+"\"");
+                   }
+               }
                if (fields != null)
                hfr = true;
                else
@@ -414,8 +424,8 @@ public abstract class Connection
        }
        if (final_error != null)
        throw final_error;
-       return getResultSet(this, fields, tuples, recv_status, 1);
-       //return new ResultSet(this, fields, tuples, recv_status, 1);
+       
+       return getResultSet(this, fields, tuples, recv_status, update_count);
    }
     }
 
index 8a3332da0110eef9a7db0d5fc8757a6934de63cb..3b6c20c9a4fd1a132cfaee304237233b8cbd6014 100644 (file)
@@ -35,7 +35,7 @@ public class Statement implements java.sql.Statement
    }
 
    /**
-    * Execute a SQL statement that retruns a single ResultSet
+    * Execute a SQL statement that returns a single ResultSet
     *
     * @param sql typically a static SQL SELECT statement
     * @return a ResulSet that contains the data produced by the query