<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -93,12 +93,12 @@ public class Command extends RubyObject {
         PreparedStatement sqlStatement = null;
         java.sql.ResultSet keys = null;
         String sqlText = prepareSqlTextForPs(api.getInstanceVariable(recv, &quot;@text&quot;).asJavaString(), recv, args);
-        boolean supportsGeneratedKeys = driver.supportsJdbcGeneratedKeys();
 
         try {
-            if (supportsGeneratedKeys) {
+            if (driver.supportsConnectionPrepareStatementMethodWithGKFlag()) {
                 sqlStatement =
-                        conn.prepareStatement(sqlText, Statement.RETURN_GENERATED_KEYS);
+                        conn.prepareStatement(sqlText,
+                            driver.supportsJdbcGeneratedKeys() ? Statement.RETURN_GENERATED_KEYS : Statement.NO_GENERATED_KEYS);
             } else {
                 // If java.sql.PreparedStatement#getGeneratedKeys() is not supported,
                 // then it is important to call java.sql.Connection#prepareStatement(String)
@@ -135,7 +135,7 @@ public class Command extends RubyObject {
             debug(recv.getRuntime(), sqlStatement.toString(), Long.valueOf(endTime - startTime));
 
             if (keys == null) {
-                if (supportsGeneratedKeys) {
+                if (driver.supportsJdbcGeneratedKeys()) {
                     // Derby, H2, and MySQL all support getGeneratedKeys(), but only
                     // to varying extents.
                     //
@@ -155,7 +155,7 @@ public class Command extends RubyObject {
                     keys = sqlStatement.getGeneratedKeys();
 
                 } else {
-                    // If there is no support, then a custom method canb e defined
+                    // If there is no support, then a custom method can be defined
                     // to return a ResultSet with keys
                     keys = driver.getGeneratedKeys(conn);
                 }</diff>
      <filename>do_jdbc/src/java/data_objects/Command.java</filename>
    </modified>
    <modified>
      <diff>@@ -11,6 +11,10 @@ public abstract class AbstractDriverDefinition implements DriverDefinition {
 
     public abstract boolean supportsJdbcGeneratedKeys();
 
+    public boolean supportsConnectionPrepareStatementMethodWithGKFlag() {
+        return true;
+    }
+
     public ResultSet getGeneratedKeys(Connection connection) {
         return null;
     }</diff>
      <filename>do_jdbc/src/java/data_objects/drivers/AbstractDriverDefinition.java</filename>
    </modified>
    <modified>
      <diff>@@ -18,6 +18,14 @@ public interface DriverDefinition {
     public boolean supportsJdbcGeneratedKeys();
 
     /**
+     * A workaround for drivers that throw a SQLException if Connection#prepareStatement(String, int)
+     * is called.
+     *
+     * @return
+     */
+    public boolean supportsConnectionPrepareStatementMethodWithGKFlag();
+
+    /**
      * If the driver does not properly support JDBC 3.0's autogenerated keys,
      * then custom SQL can be provided to look up the autogenerated keys for
      * a connection.</diff>
      <filename>do_jdbc/src/java/data_objects/drivers/DriverDefinition.java</filename>
    </modified>
    <modified>
      <diff>@@ -6,6 +6,11 @@ public class Sqlite3DriverDefinition extends AbstractDriverDefinition {
 
     public boolean supportsJdbcGeneratedKeys()
     {
+        return true;
+    }
+
+    public boolean supportsConnectionPrepareStatementMethodWithGKFlag()
+    {
         return false;
     }
 </diff>
      <filename>do_sqlite3/ext-java/src/main/java/do_sqlite3/Sqlite3DriverDefinition.java</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>5acd09ed81966b838685f0c54383bddc620ac7f1</id>
    </parent>
  </parents>
  <author>
    <name>Alex Coles</name>
    <email>alex@alexcolesportfolio.com</email>
  </author>
  <url>http://github.com/sam/do/commit/308d051875fb35f4ac70e3e5b99b17bd4673bee5</url>
  <id>308d051875fb35f4ac70e3e5b99b17bd4673bee5</id>
  <committed-date>2009-01-08T02:28:40-08:00</committed-date>
  <authored-date>2009-01-08T02:28:40-08:00</authored-date>
  <message>[do_jdbc] Fix (try #2) for drivers not implementing all overloaded variants of
Connection#prepareStatement

* Introduce a ugly hack, in the form of
  DriverDefinition#supportsConnectionPrepareStatementMethodWithGKFlag
  to determine whether we can safely call
  java.sql.Connection#prepareStatement(String, int)
  without causing a SQLException.
* By default, most drivers will support this, so
  AbstractDriverDefinition#supportsConnectionPrepareStatementMethodWithGKFlag
  will return true. Sqlite3DriverDefinition overrides this.
* Sqlite3DriverDefinition#supportsJdbcGeneratedKeys now returns
  true: (similar to Derby) SQLiteJDBC driver does support
  PreparedStatement#getGeneratedKeys() - it just does so with
  some caveats -- in this case, possible race conditions according
  to the Driver's inline comments. For the moment, we'll employ this
  support, as experimental as it may be.

Signed-off-by: Alex Coles &lt;alex@alexcolesportfolio.com&gt;</message>
  <tree>510b9fe774df8efec8f6ca581115d492a2f946e1</tree>
  <committer>
    <name>Alex Coles</name>
    <email>alex@alexcolesportfolio.com</email>
  </committer>
</commit>
