internal OdbcDataReader(OdbcCommand command, CMDWrapper cmdWrapper, CommandBehavior commandbehavior)
 {
     this.command = command;
     this._commandBehavior = commandbehavior;
     this._cmdText = command.CommandText;
     this._cmdWrapper = cmdWrapper;
 }
Exemplo n.º 2
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;
        }
 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;
 }
 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 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);
         }
     }
 }
Exemplo n.º 6
0
        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;
        }
Exemplo n.º 7
0
        private void CloseCommandWrapper() {
            CMDWrapper wrapper = _cmdWrapper;
            if (null != wrapper) {
                try {
                    wrapper.Dispose();

                    if (null != _connection) {
                        _connection.RemoveWeakReference(this);
                    }
                }
                finally {
                    _cmdWrapper = null;
                }
            }
        }
Exemplo n.º 8
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;
        }
Exemplo n.º 9
0
        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 = 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;
 }
 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 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;
 }
 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;
 }
Exemplo n.º 15
-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;
        }