internal OdbcDataReader(OdbcCommand command, CMDWrapper cmdWrapper, CommandBehavior commandbehavior)
 {
     this.command = command;
     this._commandBehavior = commandbehavior;
     this._cmdText = command.CommandText;
     this._cmdWrapper = cmdWrapper;
 }
        internal void DisconnectFromDataReaderAndConnection()
        {
            OdbcDataReader reader = null;

            if (this.weakDataReaderReference != null)
            {
                OdbcDataReader target = (OdbcDataReader)this.weakDataReaderReference.Target;
                if (this.weakDataReaderReference.IsAlive)
                {
                    reader = target;
                }
            }
            if (reader != null)
            {
                reader.Command = null;
            }
            this._transaction = null;
            if (this._connection != null)
            {
                this._connection.RemoveWeakReference(this);
                this._connection = null;
            }
            if (reader == null)
            {
                this.CloseCommandWrapper();
            }
            this._cmdWrapper = null;
        }
Beispiel #3
0
        // GetStatementHandle
        // ------------------
        // Try to return a cached statement handle.
        //
        // Creates a CmdWrapper object if necessary
        // If no handle is available a handle will be allocated.
        // Bindings will be unbound if a handle is cached and the bindings are invalid.
        //
        internal CMDWrapper GetStatementHandle()
        {
            // update the command wrapper object, allocate buffer
            // create reader object
            //
            if (_cmdWrapper == null)
            {
                _cmdWrapper = new CMDWrapper(_connection);

                Debug.Assert(null != _connection, "GetStatementHandle without connection?");
                _connection.AddWeakReference(this, OdbcReferenceCollection.CommandTag);
            }

            if (_cmdWrapper._dataReaderBuf == null)
            {
                _cmdWrapper._dataReaderBuf = new CNativeBuffer(4096);
            }

            // if there is already a statement handle we need to do some cleanup
            //
            if (null == _cmdWrapper.StatementHandle)
            {
                _isPrepared = false;
                _cmdWrapper.CreateStatementHandle();
            }
            else if ((null != _parameterCollection) && _parameterCollection.RebindCollection)
            {
                _cmdWrapper.FreeStatementHandle(ODBC32.STMT.RESET_PARAMS);
            }
            return(_cmdWrapper);
        }
Beispiel #4
0
        // OdbcCommand.Cancel()
        //
        // In ODBC3.0 ... a call to SQLCancel when no processing is done has no effect at all
        // (ODBC Programmer's Reference ...)
        //

        public override void Cancel()
        {
            CMDWrapper wrapper = _cmdWrapper;

            if (null != wrapper)
            {
                wrapper.Canceling = true;
                OdbcStatementHandle stmt = wrapper.StatementHandle;
                if (null != stmt)
                {
                    lock (stmt)
                    {
                        // Cancel the statement
                        ODBC32.RetCode retcode = stmt.Cancel();

                        // copy of StatementErrorHandler, because stmt may become null
                        switch (retcode)
                        {
                        case ODBC32.RetCode.SUCCESS:
                        case ODBC32.RetCode.SUCCESS_WITH_INFO:
                            // don't fire info message events on cancel
                            break;

                        default:
                            throw wrapper.Connection.HandleErrorNoThrow(stmt, retcode);
                        }
                    }
                }
            }
        }
        private static OdbcParameter[] DeriveParametersFromStoredProcedure(OdbcConnection connection, OdbcCommand command)
        {
            List <OdbcParameter> list            = new List <OdbcParameter>();
            CMDWrapper           statementHandle = command.GetStatementHandle();
            OdbcStatementHandle  hrHandle        = statementHandle.StatementHandle;
            string leftQuote = connection.QuoteChar("DeriveParameters");

            string[] strArray = MultipartIdentifier.ParseMultipartIdentifier(command.CommandText, leftQuote, leftQuote, '.', 4, true, "ODBC_ODBCCommandText", false);
            if (strArray[3] == null)
            {
                strArray[3] = command.CommandText;
            }
            ODBC32.RetCode retcode = hrHandle.ProcedureColumns(strArray[1], strArray[2], strArray[3], null);
            if (retcode != ODBC32.RetCode.SUCCESS)
            {
                connection.HandleError(hrHandle, retcode);
            }
            using (OdbcDataReader reader = new OdbcDataReader(command, statementHandle, CommandBehavior.Default))
            {
                reader.FirstResult();
                int fieldCount = reader.FieldCount;
                while (reader.Read())
                {
                    OdbcParameter item = new OdbcParameter {
                        ParameterName = reader.GetString(3)
                    };
                    switch (reader.GetInt16(4))
                    {
                    case 1:
                        item.Direction = ParameterDirection.Input;
                        break;

                    case 2:
                        item.Direction = ParameterDirection.InputOutput;
                        break;

                    case 4:
                        item.Direction = ParameterDirection.Output;
                        break;

                    case 5:
                        item.Direction = ParameterDirection.ReturnValue;
                        break;
                    }
                    item.OdbcType = TypeMap.FromSqlType((ODBC32.SQL_TYPE)reader.GetInt16(5))._odbcType;
                    item.Size     = reader.GetInt32(7);
                    switch (item.OdbcType)
                    {
                    case OdbcType.Decimal:
                    case OdbcType.Numeric:
                        item.ScaleInternal     = (byte)reader.GetInt16(9);
                        item.PrecisionInternal = (byte)reader.GetInt16(10);
                        break;
                    }
                    list.Add(item);
                }
            }
            retcode = hrHandle.CloseCursor();
            return(list.ToArray());
        }
Beispiel #6
0
 // Walks through the collection and binds each parameter
 //
 internal void Bind(OdbcCommand command, CMDWrapper cmdWrapper, CNativeBuffer parameterBuffer)
 {
     for (int i = 0; i < Count; ++i)
     {
         this[i].Bind(cmdWrapper.StatementHandle, command, checked ((short)(i + 1)), parameterBuffer, true);
     }
     _rebindCollection = false;
 }
Beispiel #7
0
        internal OdbcDataReader(OdbcCommand command, CMDWrapper cmdWrapper, CommandBehavior commandbehavior) {
            OdbcConnection.VerifyExecutePermission();

            Debug.Assert(command != null, "Command null on OdbcDataReader ctor");
            this.command = command;
            _commandBehavior = commandbehavior;
            _cmdText = command.CommandText;    // get a copy in case the command text on the command is changed ...
            _cmdWrapper = cmdWrapper;
        }
Beispiel #8
0
 internal void GetOutputValues(CMDWrapper cmdWrapper)
 {
     if (!this._rebindCollection)
     {
         CNativeBuffer parameterBuffer = cmdWrapper._nativeParameterBuffer;
         for (int i = 0; i < this.Count; i++)
         {
             this[i].GetOutputValue(parameterBuffer);
         }
     }
 }
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         this.DisconnectFromDataReaderAndConnection();
         this._parameterCollection = null;
         this.CommandText          = null;
     }
     this._cmdWrapper = null;
     this._isPrepared = false;
     base.Dispose(disposing);
 }
Beispiel #10
0
 internal void GetOutputValues(CMDWrapper cmdWrapper)
 {
     // mdac 88542 - we will not read out the parameters if the collection has changed
     if (!_rebindCollection)
     {
         CNativeBuffer parameterBuffer = cmdWrapper._nativeParameterBuffer;
         for (int i = 0; i < Count; ++i)
         {
             this[i].GetOutputValue(parameterBuffer);
         }
     }
 }
Beispiel #11
0
        // GetStatementHandle
        // ------------------
        // Try to return a cached statement handle.
        //
        // Creates a CmdWrapper object if necessary
        // If no handle is available a handle will be allocated.
        // Bindings will be unbound if a handle is cached and the bindings are invalid.
        //
        internal HandleRef GetStatementHandle()
        {
            ODBC32.RETCODE retcode;

            // update the command wrapper object, allocate buffer
            // create reader object
            //
            if (_cmdWrapper == null)
            {
                _cmdWrapper = new CMDWrapper();
            }
            _cmdWrapper._connection   = _connection;
            _cmdWrapper._connectionId = _connection._dbcWrapper._instanceId;
            _cmdWrapper._cmdText      = _cmdText;

            if (_cmdWrapper._dataReaderBuf == null)
            {
                _cmdWrapper._dataReaderBuf = new CNativeBuffer(4096);
            }

            // if there is already a statement handle we need to do some cleanup
            //
            if (_cmdWrapper._stmt != IntPtr.Zero)
            {
                if ((null != _parameterCollection) && (0 < _parameterCollection.Count))
                {
                    if (_parameterCollection.CollectionIsBound && _parameterCollection.BindingIsValid)
                    {
                        retcode = (ODBC32.RETCODE)UnsafeNativeMethods.Odbc32.SQLFreeStmt(
                            _cmdWrapper,
                            (short)ODBC32.STMT.UNBIND
                            );
                        // UNBIND should never fail so we assert only
                        if (retcode != ODBC32.RETCODE.SUCCESS)
                        {
                            Debug.Assert(false, "SQLFreeStmt(hstmt, (short)ODBC32.STMT.UNBIND) failed");
                        }
                        _parameterCollection.CollectionIsBound = false;
                    }
                }
            }
            else
            {
                _isPrepared = false;    // a new statement can't be prepare
                if (null != _parameterCollection)
                {
                    _parameterCollection.CollectionIsBound = false;
                }
                _cmdWrapper.AllocateStatementHandle(ref _cmdWrapper._stmt);
            }
            return(_cmdWrapper);
        }
Beispiel #12
0
        /// <include file='doc\OdbcCommand.uex' path='docs/doc[@for="OdbcCommand.Dispose"]/*' />
        override protected void Dispose(bool disposing)   // MDAC 65459
        {
            if (disposing)
            {
                // release mananged objects
                this.DisconnectFromDataReaderAndConnection();
                _parameterCollection = null;
            }
            _cmdWrapper = null;                         // let go of the CommandWrapper
            _hdesc      = IntPtr.Zero;
            _isPrepared = false;

            base.Dispose(disposing);    // notify base classes
        }
Beispiel #13
0
        protected override void Dispose(bool disposing)
        { // MDAC 65459
            if (disposing)
            {
                // release mananged objects
                // in V1.0, V1.1 the Connection,Parameters,CommandText,Transaction where reset
                this.DisconnectFromDataReaderAndConnection();
                _parameterCollection = null;
                CommandText          = null;
            }
            _cmdWrapper = null;                         // let go of the CommandWrapper
            _isPrepared = false;

            base.Dispose(disposing);    // notify base classes
        }
Beispiel #14
0
        private void CloseCommandWrapper()
        {
            CMDWrapper wrapper = _cmdWrapper;

            if (null != wrapper)
            {
                try {
                    wrapper.Dispose();

                    if (null != _connection)
                    {
                        _connection.RemoveWeakReference(this);
                    }
                }
                finally {
                    _cmdWrapper = null;
                }
            }
        }
        private void CloseCommandWrapper()
        {
            CMDWrapper wrapper = this._cmdWrapper;

            if (wrapper != null)
            {
                try
                {
                    wrapper.Dispose();
                    if (this._connection != null)
                    {
                        this._connection.RemoveWeakReference(this);
                    }
                }
                finally
                {
                    this._cmdWrapper = null;
                }
            }
        }
 internal CMDWrapper GetStatementHandle()
 {
     if (this._cmdWrapper == null)
     {
         this._cmdWrapper = new CMDWrapper(this._connection);
         this._connection.AddWeakReference(this, 1);
     }
     if (this._cmdWrapper._dataReaderBuf == null)
     {
         this._cmdWrapper._dataReaderBuf = new CNativeBuffer(0x1000);
     }
     if (this._cmdWrapper.StatementHandle == null)
     {
         this._isPrepared = false;
         this._cmdWrapper.CreateStatementHandle();
     }
     else if ((this._parameterCollection != null) && this._parameterCollection.RebindCollection)
     {
         this._cmdWrapper.FreeStatementHandle(ODBC32.STMT.RESET_PARAMS);
     }
     return(this._cmdWrapper);
 }
Beispiel #17
0
        internal void DisconnectFromDataReaderAndConnection()
        {
            // get a reference to the datareader if it is alive
            OdbcDataReader liveReader = null;

            if (_weakDataReaderReference != null)
            {
                OdbcDataReader reader;
                reader = (OdbcDataReader)_weakDataReaderReference.Target;
                if (_weakDataReaderReference.IsAlive)
                {
                    liveReader = reader;
                }
            }

            // remove reference to this from the live datareader
            if (liveReader != null)
            {
                liveReader.Command = null;
            }

            _transaction = null;

            if (null != _connection)
            {
                _connection.RemoveWeakReference(this);
                _connection = null;
            }

            // if the reader is dead we have to dismiss the statement
            if (liveReader == null)
            {
                CloseCommandWrapper();
            }
            // else DataReader now has exclusive ownership
            _cmdWrapper = null;
        }
        public override void Cancel()
        {
            CMDWrapper wrapper = this._cmdWrapper;

            if (wrapper != null)
            {
                wrapper.Canceling = true;
                OdbcStatementHandle statementHandle = wrapper.StatementHandle;
                if (statementHandle != null)
                {
                    lock (statementHandle)
                    {
                        ODBC32.RetCode retcode = statementHandle.Cancel();
                        switch (retcode)
                        {
                        case ODBC32.RetCode.SUCCESS:
                        case ODBC32.RetCode.SUCCESS_WITH_INFO:
                            return;
                        }
                        throw wrapper.Connection.HandleErrorNoThrow(statementHandle, retcode);
                    }
                }
            }
        }
        // GetStatementHandle
        // ------------------
        // Try to return a cached statement handle.
        //
        // Creates a CmdWrapper object if necessary
        // If no handle is available a handle will be allocated.
        // Bindings will be unbound if a handle is cached and the bindings are invalid.
        //
        internal CMDWrapper GetStatementHandle () {
            // update the command wrapper object, allocate buffer
            // create reader object
            //
            if (_cmdWrapper==null) {
                _cmdWrapper = new CMDWrapper(_connection);

                Debug.Assert(null != _connection, "GetStatementHandle without connection?");
                _connection.AddWeakReference(this, OdbcReferenceCollection.CommandTag);
            }

            if (_cmdWrapper._dataReaderBuf == null) {
                _cmdWrapper._dataReaderBuf = new CNativeBuffer(4096);
            }

            // if there is already a statement handle we need to do some cleanup
            //
            if (null == _cmdWrapper.StatementHandle) {
                _isPrepared = false;
                _cmdWrapper.CreateStatementHandle();
            }
            else if ((null != _parameterCollection) && _parameterCollection.RebindCollection) {
                _cmdWrapper.FreeStatementHandle(ODBC32.STMT.RESET_PARAMS);
            }
            return _cmdWrapper;
        }
 internal void DisconnectFromDataReaderAndConnection()
 {
     OdbcDataReader reader = null;
     if (this.weakDataReaderReference != null)
     {
         OdbcDataReader target = (OdbcDataReader) this.weakDataReaderReference.Target;
         if (this.weakDataReaderReference.IsAlive)
         {
             reader = target;
         }
     }
     if (reader != null)
     {
         reader.Command = null;
     }
     this._transaction = null;
     if (this._connection != null)
     {
         this._connection.RemoveWeakReference(this);
         this._connection = null;
     }
     if (reader == null)
     {
         this.CloseCommandWrapper();
     }
     this._cmdWrapper = null;
 }
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         this.DisconnectFromDataReaderAndConnection();
         this._parameterCollection = null;
         this.CommandText = null;
     }
     this._cmdWrapper = null;
     this._isPrepared = false;
     base.Dispose(disposing);
 }
 internal CMDWrapper GetStatementHandle()
 {
     if (this._cmdWrapper == null)
     {
         this._cmdWrapper = new CMDWrapper(this._connection);
         this._connection.AddWeakReference(this, 1);
     }
     if (this._cmdWrapper._dataReaderBuf == null)
     {
         this._cmdWrapper._dataReaderBuf = new CNativeBuffer(0x1000);
     }
     if (this._cmdWrapper.StatementHandle == null)
     {
         this._isPrepared = false;
         this._cmdWrapper.CreateStatementHandle();
     }
     else if ((this._parameterCollection != null) && this._parameterCollection.RebindCollection)
     {
         this._cmdWrapper.FreeStatementHandle(ODBC32.STMT.RESET_PARAMS);
     }
     return this._cmdWrapper;
 }
 private void CloseCommandWrapper()
 {
     CMDWrapper wrapper = this._cmdWrapper;
     if (wrapper != null)
     {
         try
         {
             wrapper.Dispose();
             if (this._connection != null)
             {
                 this._connection.RemoveWeakReference(this);
             }
         }
         finally
         {
             this._cmdWrapper = null;
         }
     }
 }
        internal void DisconnectFromDataReaderAndConnection () {
            // get a reference to the datareader if it is alive
            OdbcDataReader liveReader = null;
            if (this.weakDataReaderReference != null){
                OdbcDataReader reader;
                reader = (OdbcDataReader)this.weakDataReaderReference.Target;
                if (this.weakDataReaderReference.IsAlive) {
                    liveReader = reader;
                }
            }

            // remove reference to this from the live datareader
            if (liveReader != null) {
                liveReader.Command = null;
            }

            _transaction = null;

            if (null != _connection) {
                _connection.RemoveWeakReference(this);
                _connection = null;
            }

            // if the reader is dead we have to dismiss the statement
            if (liveReader == null){
                CloseCommandWrapper();
            }
            // else DataReader now has exclusive ownership
            _cmdWrapper = null;
        }
        override protected void Dispose(bool disposing) { // MDAC 65459
            if (disposing) {
                // release mananged objects
                // in V1.0, V1.1 the Connection,Parameters,CommandText,Transaction where reset
                this.DisconnectFromDataReaderAndConnection ();
                _parameterCollection = null;
                CommandText = null;
            }
            _cmdWrapper = null;                         // let go of the CommandWrapper
            _isPrepared = false;

            base.Dispose(disposing);    // notify base classes
        }
        private void CloseCommandWrapper() {
            CMDWrapper wrapper = _cmdWrapper;
            if (null != wrapper) {
                try {
                    wrapper.Dispose();

                    if (null != _connection) {
                        _connection.RemoveWeakReference(this);
                    }
                }
                finally {
                    _cmdWrapper = null;
                }
            }
        }
 internal void GetOutputValues (CMDWrapper cmdWrapper) {
     // mdac 88542 - we will not read out the parameters if the collection has changed
     if (!_rebindCollection) {
         CNativeBuffer parameterBuffer = cmdWrapper._nativeParameterBuffer;
         for(int i = 0; i < Count; ++i) {
             this[i].GetOutputValue(parameterBuffer);
         }
     }
 }
Beispiel #28
0
        // DeriveParametersFromStoredProcedure (
        //  OdbcConnection connection,
        //  OdbcCommand command);
        //
        // Uses SQLProcedureColumns to create an array of OdbcParameters
        //

        static private OdbcParameter[] DeriveParametersFromStoredProcedure(OdbcConnection connection, OdbcCommand command)
        {
            List <OdbcParameter> rParams = new List <OdbcParameter>();

            // following call ensures that the command has a statement handle allocated
            CMDWrapper          cmdWrapper = command.GetStatementHandle();
            OdbcStatementHandle hstmt      = cmdWrapper.StatementHandle;
            int cColsAffected;

            // maps an enforced 4-part qualified string as follows
            // parts[0] = null  - ignored but removal would be a run-time breaking change from V1.0
            // parts[1] = CatalogName (optional, may be null)
            // parts[2] = SchemaName (optional, may be null)
            // parts[3] = ProcedureName
            //
            string quote = connection.QuoteChar(ADP.DeriveParameters);

            string[] parts = MultipartIdentifier.ParseMultipartIdentifier(command.CommandText, quote, quote, '.', 4, true, Res.ODBC_ODBCCommandText, false);
            if (null == parts[3])
            { // match Everett behavior, if the commandtext is nothing but whitespace set the command text to the whitespace
                parts[3] = command.CommandText;
            }
            // note: native odbc appears to ignore all but the procedure name
            ODBC32.RetCode retcode = hstmt.ProcedureColumns(parts[1], parts[2], parts[3], null);

            // Note: the driver does not return an error if the given stored procedure does not exist
            // therefore we cannot handle that case and just return not parameters.

            if (ODBC32.RetCode.SUCCESS != retcode)
            {
                connection.HandleError(hstmt, retcode);
            }

            using (OdbcDataReader reader = new OdbcDataReader(command, cmdWrapper, CommandBehavior.Default))
            {
                reader.FirstResult();
                cColsAffected = reader.FieldCount;

                // go through the returned rows and filter out relevant parameter data
                //
                while (reader.Read())
                {
                    // devnote: column types are specified in the ODBC Programmer's Reference
                    // COLUMN_TYPE      Smallint    16bit
                    // COLUMN_SIZE      Integer     32bit
                    // DECIMAL_DIGITS   Smallint    16bit
                    // NUM_PREC_RADIX   Smallint    16bit

                    OdbcParameter parameter = new OdbcParameter();

                    parameter.ParameterName = reader.GetString(ODBC32.COLUMN_NAME - 1);
                    switch ((ODBC32.SQL_PARAM)reader.GetInt16(ODBC32.COLUMN_TYPE - 1))
                    {
                    case ODBC32.SQL_PARAM.INPUT:
                        parameter.Direction = ParameterDirection.Input;
                        break;

                    case ODBC32.SQL_PARAM.OUTPUT:
                        parameter.Direction = ParameterDirection.Output;
                        break;

                    case ODBC32.SQL_PARAM.INPUT_OUTPUT:
                        parameter.Direction = ParameterDirection.InputOutput;
                        break;

                    case ODBC32.SQL_PARAM.RETURN_VALUE:
                        parameter.Direction = ParameterDirection.ReturnValue;
                        break;

                    default:
                        Debug.Assert(false, "Unexpected Parametertype while DeriveParamters");
                        break;
                    }
                    parameter.OdbcType = TypeMap.FromSqlType((ODBC32.SQL_TYPE)reader.GetInt16(ODBC32.DATA_TYPE - 1))._odbcType;
                    parameter.Size     = (int)reader.GetInt32(ODBC32.COLUMN_SIZE - 1);
                    switch (parameter.OdbcType)
                    {
                    case OdbcType.Decimal:
                    case OdbcType.Numeric:
                        parameter.ScaleInternal     = (Byte)reader.GetInt16(ODBC32.DECIMAL_DIGITS - 1);
                        parameter.PrecisionInternal = (Byte)reader.GetInt16(ODBC32.NUM_PREC_RADIX - 1);
                        break;
                    }
                    rParams.Add(parameter);
                }
            }
            retcode = hstmt.CloseCursor();
            return(rParams.ToArray());;
        }
 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;
 }
 internal void GetOutputValues(CMDWrapper cmdWrapper)
 {
     if (!this._rebindCollection)
     {
         CNativeBuffer parameterBuffer = cmdWrapper._nativeParameterBuffer;
         for (int i = 0; i < this.Count; i++)
         {
             this[i].GetOutputValue(parameterBuffer);
         }
     }
 }
 internal void Bind(OdbcCommand command, CMDWrapper cmdWrapper, CNativeBuffer parameterBuffer)
 {
     for (int i = 0; i < this.Count; i++)
     {
         this[i].Bind(cmdWrapper.StatementHandle, command, (short) (i + 1), parameterBuffer, true);
     }
     this._rebindCollection = false;
 }
Beispiel #32
-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;
        }