empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r747144 - /incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java
Date Mon, 23 Feb 2009 21:32:57 GMT
Author: doebele
Date: Mon Feb 23 21:32:52 2009
New Revision: 747144

URL: http://svn.apache.org/viewvc?rev=747144&view=rev
Log:
EMPIREDB-34

Modified:
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java?rev=747144&r1=747143&r2=747144&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java
(original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDatabaseDriver.java
Mon Feb 23 21:32:52 2009
@@ -420,21 +420,23 @@
         try
         {
             int count = 0;
-            int retGenKeys = (genKeys!=null) ? Statement.RETURN_GENERATED_KEYS 
-                                             : Statement.NO_GENERATED_KEYS;
             if (sqlParams!=null)
             {   // Use a prepared statement
-                PreparedStatement pstmt = conn.prepareStatement(sqlCmd, retGenKeys);
+                PreparedStatement pstmt = (genKeys!=null) 
+                    ? conn.prepareStatement(sqlCmd, Statement.RETURN_GENERATED_KEYS)
+                    : conn.prepareStatement(sqlCmd);
 	            prepareStatement(pstmt, sqlParams);
 	            count = pstmt.executeUpdate(); 
             }
             else
             {   // Execute a simple statement
                 stmt = conn.createStatement();
-                count = stmt.executeUpdate(sqlCmd, retGenKeys);
+                count = (genKeys!=null)
+                    ? stmt.executeUpdate(sqlCmd, Statement.RETURN_GENERATED_KEYS)
+                    : stmt.executeUpdate(sqlCmd);
             }
             // Retrieve any auto-generated keys
-            if (genKeys!=null)
+            if (genKeys!=null && count>0)
             {   // Return Keys
                 ResultSet rs = stmt.getGeneratedKeys();
                 try {
@@ -444,6 +446,7 @@
                     rs.close();
                 }
             }
+            // done
             return count;
         } finally
         { // Close



Mime
View raw message