Beispiel #1
0
        ///////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Disposes of the command and clears all member variables
        /// </summary>
        /// <param name="disposing">Whether or not the class is being explicitly or implicitly disposed</param>
        protected override void Dispose(bool disposing)
        {
            SQLiteConnection.OnChanged(_cnn, new ConnectionEventArgs(
                                           SQLiteConnectionEventType.DisposingCommand, null, _transaction, this,
                                           null, null, null, new object[] { disposing, disposed }));

            bool skippedDispose = false;

            try
            {
                if (!disposed)
                {
                    if (disposing)
                    {
                        ////////////////////////////////////
                        // dispose managed resources here...
                        ////////////////////////////////////

                        // If a reader is active on this command, don't destroy the command, instead let the reader do it
                        SQLiteDataReader reader = null;
                        if (_activeReader != null)
                        {
                            try
                            {
                                reader = _activeReader.Target as SQLiteDataReader;
                            }
                            catch (InvalidOperationException)
                            {
                            }
                        }

                        if (reader != null)
                        {
                            reader._disposeCommand = true;
                            _activeReader          = null;
                            skippedDispose         = true;
                            return;
                        }

                        Connection = null;
                        _parameterCollection.Clear();
                        _commandText = null;
                    }

                    //////////////////////////////////////
                    // release unmanaged resources here...
                    //////////////////////////////////////
                }
            }
            finally
            {
                if (!skippedDispose)
                {
                    base.Dispose(disposing);

                    //
                    // NOTE: Everything should be fully disposed at this point.
                    //
                    disposed = true;
                }
            }
        }