Index: java/client/org/apache/derby/client/am/Statement.java =================================================================== --- java/client/org/apache/derby/client/am/Statement.java (revision 628487) +++ java/client/org/apache/derby/client/am/Statement.java (working copy) @@ -1941,21 +1941,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) { + + else { newSection = agent_.sectionManager_.getDynamicSection(resultSetHoldability_); - writePrepareDescribeOutput(constructSelectFromInsertSQL(sql), newSection); - writeOpenQuery(newSection, - fetchSize_, - resultSetType_); - } 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_, @@ -2023,16 +2015,7 @@ if (scrollableRS != null && !scrollableRS.isRowsetCursor_) { scrollableRS.readPositioningFetch_(); } - - if (sqlUpdateMode_ == isInsertSql__ && generatedKeysColumnNames_ != null) { - readPrepareDescribeOutput(); - readOpenQuery(); - if (resultSet_ != null) { - generatedKeysResultSet_ = resultSet_; - resultSet_ = null; - updateCount_ = 1; - } - } else { + else { readExecuteImmediate(); if (sqlUpdateMode_ == isInsertSql__ && autoGeneratedKeys_ == RETURN_GENERATED_KEYS) { @@ -2661,20 +2644,8 @@ : 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) { String s = "select IDENTITY_VAL_LOCAL() from SYSIBM.SYSDUMMY1"; Index: java/client/org/apache/derby/client/am/PreparedStatement.java =================================================================== --- java/client/org/apache/derby/client/am/PreparedStatement.java (revision 628487) +++ java/client/org/apache/derby/client/am/PreparedStatement.java (working copy) @@ -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; @@ -1925,14 +1919,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 @@ -2020,30 +2006,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 + 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 (chainOpenQueryForAutoGeneratedKeys) { + prepareAutoGeneratedKeysStatement(); + writeOpenQuery(preparedStatementForAutoGeneratedKeys_.section_, + preparedStatementForAutoGeneratedKeys_.fetchSize_, + preparedStatementForAutoGeneratedKeys_.resultSetType_); } + if (chainAutoCommit) { // we have encountered an error in writing the execute, so do not @@ -2105,14 +2083,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) {