Пример #1
0
        private bool NextResult(bool disposing, bool allresults) {
            // if disposing, loop through all the remaining results and ignore error messages
            // if allresults, loop through all results and collect all error messages for a single exception
            // callers are via Close(false, true), Dispose(true, false), NextResult(false,false)
            Debug.Assert(!disposing || !allresults, "both disposing & allresults are true");
            const int MaxConsecutiveFailure = 2000; // see WebData 72126 for why more than 1000

            SQLLEN cRowsAffected;
            Int16 cColsAffected;
            ODBC32.RetCode retcode, firstRetCode = ODBC32.RetCode.SUCCESS;
            bool hasMoreResults;
            bool hasColumns = false;
            bool singleResult = IsCommandBehavior(CommandBehavior.SingleResult);

            if (IsClosed) {
                throw ADP.DataReaderClosed("NextResult");
            }
            _fieldNameLookup = null;

            if (IsCancelingCommand || _noMoreResults) {
                return false;
            }

            //Blow away the previous cache (since the next result set will have a different shape,
            //different schema data, and different data.
            _isRead = false;
            _hasRows = HasRowsStatus.DontKnow;
            _fieldNameLookup = null;
            this.metadata = null;
            this.schemaTable = null;

            int loop = 0; // infinite loop protection, max out after 2000 consecutive failed results
            OdbcErrorCollection errors = null; // SQLBU 342112
            do {
                _isValidResult = false;
                retcode = StatementHandle.MoreResults();
                hasMoreResults = ((retcode == ODBC32.RetCode.SUCCESS)
                                ||(retcode == ODBC32.RetCode.SUCCESS_WITH_INFO));

                if (retcode == ODBC32.RetCode.SUCCESS_WITH_INFO) {
                    Connection.HandleErrorNoThrow(StatementHandle, retcode);
                }
                else if (!disposing && (retcode != ODBC32.RetCode.NO_DATA) && (ODBC32.RetCode.SUCCESS != retcode)) {
                    // allow for building comulative error messages.
                    if (null == errors) {
                        firstRetCode = retcode;
                        errors = new OdbcErrorCollection();
                    }
                    ODBC32.GetDiagErrors(errors, null, StatementHandle, retcode);
                    ++loop;
                }

                if (!disposing && hasMoreResults) {
                    loop = 0;
                    cRowsAffected = GetRowCount();              // get rowcount of the current resultset (if any)
                    CalculateRecordsAffected(cRowsAffected);    // update recordsaffected
                    if (!singleResult) {
                        // update row- and columncount
                        FieldCountNoThrow(out cColsAffected);
                        hasColumns = (0 != cColsAffected);
                        _isValidResult = hasColumns;
                    }
                }
            } while ((!singleResult && hasMoreResults && !hasColumns)  // repeat for results with no columns
                     || ((ODBC32.RetCode.NO_DATA != retcode) && allresults && (loop < MaxConsecutiveFailure)) // or process all results until done
                     || (singleResult && hasMoreResults));           // or for any result in singelResult mode
            if (MaxConsecutiveFailure <= loop) {
                Bid.Trace("<odbc.OdbcDataReader.NextResult|INFO> 2000 consecutive failed results");
            }

            if(retcode == ODBC32.RetCode.NO_DATA) {
                this.dataCache = null;
                _noMoreResults = true;
            }
            if (null != errors) {
                Debug.Assert(!disposing, "errors while disposing");
                errors.SetSource(Connection.Driver);
                OdbcException exception = OdbcException.CreateException(errors, firstRetCode);
                Connection.ConnectionIsAlive(exception);
                throw exception;
            }
            return (hasMoreResults);
        }
 internal ODBC32.RetCode FieldCountNoThrow(out short cColsAffected)
 {
     if (this.IsCancelingCommand)
     {
         cColsAffected = 0;
         return ODBC32.RetCode.ERROR;
     }
     ODBC32.RetCode code = this.StatementHandle.NumberOfResultColumns(out cColsAffected);
     if (code != ODBC32.RetCode.SUCCESS)
     {
         cColsAffected = 0;
         return code;
     }
     this._hiddenColumns = 0;
     if ((this.IsCommandBehavior(CommandBehavior.KeyInfo) && !this.Connection.ProviderInfo.NoSqlSoptSSNoBrowseTable) && !this.Connection.ProviderInfo.NoSqlSoptSSHiddenColumns)
     {
         for (int i = 0; i < cColsAffected; i++)
         {
             if (this.GetColAttribute(i, (ODBC32.SQL_DESC) 0x4bb, ~ODBC32.SQL_COLUMN.COUNT, ODBC32.HANDLER.IGNORE).ToInt64() == 1L)
             {
                 this._hiddenColumns = cColsAffected - i;
                 cColsAffected = (short) i;
                 break;
             }
         }
     }
     this.dataCache = new DbCache(this, cColsAffected);
     return code;
 }
 private void Close(bool disposing)
 {
     Exception exception = null;
     CMDWrapper wrapper = this._cmdWrapper;
     if ((wrapper != null) && (wrapper.StatementHandle != null))
     {
         if (this.IsNonCancelingCommand)
         {
             this.NextResult(disposing, !disposing);
             if (this.command != null)
             {
                 if (this.command.HasParameters)
                 {
                     this.command.Parameters.GetOutputValues(this._cmdWrapper);
                 }
                 wrapper.FreeStatementHandle(ODBC32.STMT.CLOSE);
                 this.command.CloseFromDataReader();
             }
         }
         wrapper.FreeKeyInfoStatementHandle(ODBC32.STMT.CLOSE);
     }
     if (this.command != null)
     {
         this.command.CloseFromDataReader();
         if (this.IsCommandBehavior(CommandBehavior.CloseConnection))
         {
             this.command.Parameters.RebindCollection = true;
             this.Connection.Close();
         }
     }
     else if (wrapper != null)
     {
         wrapper.Dispose();
     }
     this.command = null;
     this._isClosed = true;
     this.dataCache = null;
     this.metadata = null;
     this.schemaTable = null;
     this._isRead = false;
     this._hasRows = HasRowsStatus.DontKnow;
     this._isValidResult = false;
     this._noMoreResults = true;
     this._noMoreRows = true;
     this._fieldNameLookup = null;
     this.SetCurrentRowColumnInfo(-1, 0);
     if ((exception != null) && !disposing)
     {
         throw exception;
     }
     this._cmdWrapper = null;
 }
 private bool NextResult(bool disposing, bool allresults)
 {
     ODBC32.RetCode code;
     bool flag;
     ODBC32.RetCode sUCCESS = ODBC32.RetCode.SUCCESS;
     bool flag3 = false;
     bool flag2 = this.IsCommandBehavior(CommandBehavior.SingleResult);
     if (this.IsClosed)
     {
         throw ADP.DataReaderClosed("NextResult");
     }
     this._fieldNameLookup = null;
     if (this.IsCancelingCommand || this._noMoreResults)
     {
         return false;
     }
     this._isRead = false;
     this._hasRows = HasRowsStatus.DontKnow;
     this._fieldNameLookup = null;
     this.metadata = null;
     this.schemaTable = null;
     int num = 0;
     OdbcErrorCollection errors = null;
     do
     {
         this._isValidResult = false;
         code = this.StatementHandle.MoreResults();
         flag = (code == ODBC32.RetCode.SUCCESS) || (code == ODBC32.RetCode.SUCCESS_WITH_INFO);
         if (code == ODBC32.RetCode.SUCCESS_WITH_INFO)
         {
             this.Connection.HandleErrorNoThrow(this.StatementHandle, code);
         }
         else if ((!disposing && (code != ODBC32.RetCode.NO_DATA)) && (code != ODBC32.RetCode.SUCCESS))
         {
             if (errors == null)
             {
                 sUCCESS = code;
                 errors = new OdbcErrorCollection();
             }
             ODBC32.GetDiagErrors(errors, null, this.StatementHandle, code);
             num++;
         }
         if (!disposing && flag)
         {
             num = 0;
             SQLLEN rowCount = this.GetRowCount();
             this.CalculateRecordsAffected((int) rowCount);
             if (!flag2)
             {
                 short num2;
                 this.FieldCountNoThrow(out num2);
                 flag3 = 0 != num2;
                 this._isValidResult = flag3;
             }
         }
     }
     while ((((!flag2 && flag) && !flag3) || (((ODBC32.RetCode.NO_DATA != code) && allresults) && (num < 0x7d0))) || (flag2 && flag));
     if (0x7d0 <= num)
     {
         Bid.Trace("<odbc.OdbcDataReader.NextResult|INFO> 2000 consecutive failed results");
     }
     if (code == ODBC32.RetCode.NO_DATA)
     {
         this.dataCache = null;
         this._noMoreResults = true;
     }
     if (errors != null)
     {
         errors.SetSource(this.Connection.Driver);
         OdbcException innerException = OdbcException.CreateException(errors, sUCCESS);
         this.Connection.ConnectionIsAlive(innerException);
         throw innerException;
     }
     return flag;
 }
Пример #5
-1
        private void Close(bool disposing) {
            Exception error = null;

            CMDWrapper wrapper = _cmdWrapper;
            if (null != wrapper && wrapper.StatementHandle != null) {
                        // disposing
                        // true to release both managed and unmanaged resources; false to release only unmanaged resources.
                        //
                if (IsNonCancelingCommand) {
                            //Read any remaining results off the wire
                    // some batch statements may not be executed until SQLMoreResults is called.
                    // We want the user to be able to do ExecuteNonQuery or ExecuteReader
                    // and close without having iterate to get params or batch.
                    //
                    NextResult(disposing, !disposing); // false,true or true,false
                            if (null != command) {
                        if (command.HasParameters) {
                            // Output Parameters are not guareenteed to be returned until all the data
                            // from any restssets are read, so we do this after the above NextResult call(s)
                            command.Parameters.GetOutputValues(_cmdWrapper);
                        }
                        wrapper.FreeStatementHandle(ODBC32.STMT.CLOSE);
                                command.CloseFromDataReader();
                            }
                        }
                wrapper.FreeKeyInfoStatementHandle(ODBC32.STMT.CLOSE);
                }

                // if the command is still around we call CloseFromDataReader,
                // otherwise we need to dismiss the statement handle ourselves
                //
                if (null != command) {
                    command.CloseFromDataReader();

                if(IsCommandBehavior(CommandBehavior.CloseConnection)) {
                        Debug.Assert(null != Connection, "null cmd connection");
                    command.Parameters.RebindCollection = true;
                        Connection.Close();
                    }
                }
            else if (null != wrapper) {
                wrapper.Dispose();
            }

            this.command = null;
            _isClosed=true;
            this.dataCache = null;
            this.metadata = null;
            this.schemaTable = null;
            _isRead = false;
            _hasRows = HasRowsStatus.DontKnow;
            _isValidResult = false;
            _noMoreResults = true;
            _noMoreRows = true;
            _fieldNameLookup = null;

            SetCurrentRowColumnInfo(-1, 0);

            if ((null != error) && !disposing) {
                throw error;
            }
            _cmdWrapper = null;
        }
Пример #6
-1
        internal ODBC32.RetCode FieldCountNoThrow(out Int16 cColsAffected) {
            if (IsCancelingCommand) {
                cColsAffected = 0;
                return ODBC32.RetCode.ERROR;
            }

            ODBC32.RetCode retcode = StatementHandle.NumberOfResultColumns(out cColsAffected);
            if (retcode == ODBC32.RetCode.SUCCESS) {
                _hiddenColumns = 0;
                if (IsCommandBehavior(CommandBehavior.KeyInfo)) {
                    // we need to search for the first hidden column
                    //
                    if (!Connection.ProviderInfo.NoSqlSoptSSNoBrowseTable && !Connection.ProviderInfo.NoSqlSoptSSHiddenColumns) {
                        for (int i=0; i<cColsAffected; i++)
                        {
                            SQLLEN isHidden = GetColAttribute(i, (ODBC32.SQL_DESC)ODBC32.SQL_CA_SS.COLUMN_HIDDEN, (ODBC32.SQL_COLUMN)(-1), ODBC32.HANDLER.IGNORE);
                            if (isHidden.ToInt64() == 1) {
                                _hiddenColumns = (int)cColsAffected-i;
                                cColsAffected = (Int16)i;
                                break;
                            }
                        }
                    }
                }
                this.dataCache = new DbCache(this, cColsAffected);
            }
            else {
                cColsAffected = 0;
            }
            return retcode;
        }