You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by km...@apache.org on 2008/02/20 23:21:15 UTC

svn commit: r629637 - in /db/derby/code/branches/10.3/java/client/org/apache/derby/client/am: PreparedStatement.java Statement.java

Author: kmarsden
Date: Wed Feb 20 14:21:14 2008
New Revision: 629637

URL: http://svn.apache.org/viewvc?rev=629637&view=rev
Log:
DERBY-3426 Remove unused code for autogenerated keys columnNames
merge from trunk revision 628780

Modified:
    db/derby/code/branches/10.3/java/client/org/apache/derby/client/am/PreparedStatement.java
    db/derby/code/branches/10.3/java/client/org/apache/derby/client/am/Statement.java

Modified: db/derby/code/branches/10.3/java/client/org/apache/derby/client/am/PreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/client/org/apache/derby/client/am/PreparedStatement.java?rev=629637&r1=629636&r2=629637&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/client/org/apache/derby/client/am/PreparedStatement.java (original)
+++ db/derby/code/branches/10.3/java/client/org/apache/derby/client/am/PreparedStatement.java Wed Feb 20 14:21:14 2008
@@ -301,13 +301,7 @@
     void prepare() throws SqlException {
         try {
             // flow prepare, no static initialization is needed
-            // already checked if columnNames is not null and server supports select from insert
-            // in prepareStatementX()
-            if (sqlUpdateMode_ == isInsertSql__ && generatedKeysColumnNames_ != null) {
-                flowPrepareForSelectFromInsert();
-            } else {
-                flowPrepareDescribeInputOutput();
-            }
+            flowPrepareDescribeInputOutput();
         } catch (SqlException e) {
             this.markClosed();
             throw e;
@@ -1924,14 +1918,6 @@
         return array;
     }
 
-    void flowPrepareForSelectFromInsert() throws SqlException {
-        agent_.beginWriteChain(this);
-        writePrepareDescribeInputOutput(constructSelectFromInsertSQL(sql_), section_);
-        agent_.flow(this);
-        readPrepareDescribeInputOutput();
-        agent_.endReadChain();
-    }
-
     void writePrepareDescribeInputOutput(String sql,
                                          Section section) throws SqlException {
         // Notice that sql_ is passed in since in general ad hoc sql must be passed in for unprepared statements
@@ -2019,30 +2005,22 @@
 
                 chainAutoCommit = connection_.willAutoCommitGenerateFlow() && isAutoCommittableStatement_;
 
-                if (sqlUpdateMode_ == isInsertSql__ && generatedKeysColumnNames_ != null) {
-                    writeOpenQuery(section_,
-                            fetchSize_,
-                            resultSetType_,
-                            numInputColumns,
-                            parameterMetaData_,
-                            parameters_);
-                } else {
-                    boolean chainOpenQueryForAutoGeneratedKeys = (sqlUpdateMode_ == isInsertSql__ && autoGeneratedKeys_ == RETURN_GENERATED_KEYS);
-                    writeExecute(section_,
-                            parameterMetaData_,
-                            parameters_,
-                            numInputColumns,
-                            outputExpected,
-                            (chainAutoCommit || chainOpenQueryForAutoGeneratedKeys)// chain flag
-                    ); // chain flag
-
-                    if (chainOpenQueryForAutoGeneratedKeys) {
-                        prepareAutoGeneratedKeysStatement();
-                        writeOpenQuery(preparedStatementForAutoGeneratedKeys_.section_,
-                                preparedStatementForAutoGeneratedKeys_.fetchSize_,
-                                preparedStatementForAutoGeneratedKeys_.resultSetType_);
-                    }
+                boolean chainOpenQueryForAutoGeneratedKeys = (sqlUpdateMode_ == isInsertSql__ && autoGeneratedKeys_ == RETURN_GENERATED_KEYS);
+                writeExecute(section_,
+                        parameterMetaData_,
+                        parameters_,
+                        numInputColumns,
+                        outputExpected,
+                        (chainAutoCommit || chainOpenQueryForAutoGeneratedKeys)// chain flag
+                ); // chain flag
+
+                if (chainOpenQueryForAutoGeneratedKeys) {
+                    prepareAutoGeneratedKeysStatement();
+                    writeOpenQuery(preparedStatementForAutoGeneratedKeys_.section_,
+                            preparedStatementForAutoGeneratedKeys_.fetchSize_,
+                            preparedStatementForAutoGeneratedKeys_.resultSetType_);
                 }
+                
 
                 if (chainAutoCommit) {
                     // we have encountered an error in writing the execute, so do not
@@ -2104,14 +2082,7 @@
                     scrollableRS.readPositioningFetch_();
                 }
 
-                if (sqlUpdateMode_ == isInsertSql__ && generatedKeysColumnNames_ != null) {
-                    readOpenQuery();
-                    if (resultSet_ != null) {
-                        generatedKeysResultSet_ = resultSet_;
-                        resultSet_ = null;
-                        updateCount_ = 1;
-                    }
-                } else {
+                else {
                     readExecute();
 
                     if (sqlUpdateMode_ == isInsertSql__ && autoGeneratedKeys_ == RETURN_GENERATED_KEYS) {

Modified: db/derby/code/branches/10.3/java/client/org/apache/derby/client/am/Statement.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/client/org/apache/derby/client/am/Statement.java?rev=629637&r1=629636&r2=629637&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/client/org/apache/derby/client/am/Statement.java (original)
+++ db/derby/code/branches/10.3/java/client/org/apache/derby/client/am/Statement.java Wed Feb 20 14:21:14 2008
@@ -1919,21 +1919,13 @@
                     }
                     writeExecuteImmediate(sql, newSection);
                 }
-                // if sql is an insert and columnNames is not null, and
-                // then transform the insert statement into an
-                // select from insert statement.
-                // else chain an "select from identity_val_local()" to the insert statement
-                else if (sqlUpdateMode_ == isInsertSql__ && generatedKeysColumnNames_ != null) {
-                    newSection = agent_.sectionManager_.getDynamicSection(resultSetHoldability_);
-                    writePrepareDescribeOutput(constructSelectFromInsertSQL(sql), newSection);
-                    writeOpenQuery(newSection,
-                            fetchSize_,
-                            resultSetType_);
-                } else {
+            
+               else {
                     newSection = agent_.sectionManager_.getDynamicSection(resultSetHoldability_);
 
                     writeExecuteImmediate(sql, newSection);
                     if (sqlUpdateMode_ == isInsertSql__ && autoGeneratedKeys_ == RETURN_GENERATED_KEYS) {
+                        // chain a "select from identity_val_local()" to the insert statement
                         prepareAutoGeneratedKeysStatement();
                         writeOpenQuery(preparedStatementForAutoGeneratedKeys_.section_,
                                 preparedStatementForAutoGeneratedKeys_.fetchSize_,
@@ -2001,24 +1993,13 @@
                 if (scrollableRS != null && !scrollableRS.isRowsetCursor_) {
                     scrollableRS.readPositioningFetch_();
                 }
+                readExecuteImmediate();
 
-                if (sqlUpdateMode_ == isInsertSql__ && generatedKeysColumnNames_ != null) {
-                    readPrepareDescribeOutput();
-                    readOpenQuery();
-                    if (resultSet_ != null) {
-                        generatedKeysResultSet_ = resultSet_;
-                        resultSet_ = null;
-                        updateCount_ = 1;
-                    }
-                } else {
-                    readExecuteImmediate();
-
-                    if (sqlUpdateMode_ == isInsertSql__ && autoGeneratedKeys_ == RETURN_GENERATED_KEYS) {
-                        readPrepareAutoGeneratedKeysStatement();
-                        preparedStatementForAutoGeneratedKeys_.readOpenQuery();
-                        generatedKeysResultSet_ = preparedStatementForAutoGeneratedKeys_.resultSet_;
-                        preparedStatementForAutoGeneratedKeys_.resultSet_ = null;
-                    }
+                if (sqlUpdateMode_ == isInsertSql__ && autoGeneratedKeys_ == RETURN_GENERATED_KEYS) {
+                    readPrepareAutoGeneratedKeysStatement();
+                    preparedStatementForAutoGeneratedKeys_.readOpenQuery();
+                    generatedKeysResultSet_ = preparedStatementForAutoGeneratedKeys_.resultSet_;
+                    preparedStatementForAutoGeneratedKeys_.resultSet_ = null;
                 }
 
                 if (connection_.autoCommit_) {
@@ -2639,19 +2620,7 @@
                 : cursorAttributes.toString();
     }
 
-    protected String constructSelectFromInsertSQL(String sql) {
-        String temp = "select ";
-        int numOfColumns = generatedKeysColumnNames_.length;
-
-        for (int i = 0; i < numOfColumns; i++) {
-            temp += generatedKeysColumnNames_[i];
-            if ((i + 1) < numOfColumns) {
-                temp += ",";
-            }
-        }
-        temp += (" from final table (" + sql + ")");
-        return temp;
-    }
+  
 
     void getPreparedStatementForAutoGeneratedKeys() throws SqlException {
         if (preparedStatementForAutoGeneratedKeys_ == null) {