Пример #1
0
        /// <summary>
        /// Executes a query that returns the number of rows affected.
        /// This runs in blocking mode.
        /// </summary>
        /// <param name="cmd">The <see cref="DbCommand"/> to execute.</param>
        /// <param name="queryBase">The <see cref="DbQueryBase"/> that is executing this command.</param>
        /// <param name="lastInsertedId">Contains the ID for the row that was inserted into the database. Only valid when the
        /// query contains an auto-increment column and the operation being performed is an insert.</param>
        /// <returns>The number of rows affected.</returns>
        public int ExecuteNonReaderWithResult(DbCommand cmd, DbQueryBase queryBase, out long lastInsertedId)
        {
            try
            {
                int ret;

                // Grab the execution lock since we are going to be executing queries
                lock (_executeQuerySync)
                {
                    // Empty out the queue
                    FlushQueue();

                    // Execute our job
                    ret = cmd.ExecuteNonQuery();

                    // Get the lastInsertedId
                    lastInsertedId = _dbConnectionPool.GetLastInsertedId(cmd);
                }

                return(ret);
            }
            finally
            {
                queryBase.ReleaseCommand(cmd);
            }
        }
        protected override void Dispose(bool disposeManaged)
        {
            try
            {
                if (DataReader != null)
                {
                    DataReader.Dispose();
                }
            }
            finally
            {
                try
                {
                    _dbQueryBase.ConnectionPool.QueryRunner.EndExecuteReader();
                }
                catch (SynchronizationLockException ex)
                {
                    const string errmsg = "Failed to release reader on `{0}` for query `{1}`. Exception: {2}";
                    if (log.IsErrorEnabled)
                    {
                        log.ErrorFormat(errmsg, this, _command, ex);
                    }
                    Debug.Fail(string.Format(errmsg, this, _command, ex));
                }
                finally
                {
                    try
                    {
                        _dbQueryBase.ReleaseCommand(_command);
                    }
                    finally
                    {
                        // Release the object references
                        _command     = null;
                        _dbQueryBase = null;
                        DataReader   = null;

                        // Throw back into the pool
                        lock (_poolSync)
                        {
                            Debug.Assert(!_pool.Contains(this));
                            _pool.Push(this);
                        }
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Executes a query that returns the number of rows affected.
        /// This runs in blocking mode.
        /// </summary>
        /// <param name="cmd">The <see cref="DbCommand"/> to execute.</param>
        /// <param name="queryBase">The <see cref="DbQueryBase"/> that is executing this command.</param>
        /// <returns>The number of rows affected.</returns>
        public int ExecuteNonReaderWithResult(DbCommand cmd, DbQueryBase queryBase)
        {
            try
            {
                int ret;

                // Grab the execution lock since we are going to be executing queries
                lock (_executeQuerySync)
                {
                    // Empty out the queue
                    FlushQueue();

                    // Execute our job
                    ret = cmd.ExecuteNonQuery();
                }

                return(ret);
            }
            finally
            {
                queryBase.ReleaseCommand(cmd);
            }
        }
Пример #4
0
        /// <summary>
        /// Executes a query that returns the number of rows affected.
        /// This runs in blocking mode.
        /// </summary>
        /// <param name="cmd">The <see cref="DbCommand"/> to execute.</param>
        /// <param name="queryBase">The <see cref="DbQueryBase"/> that is executing this command.</param>
        /// <param name="lastInsertedId">Contains the ID for the row that was inserted into the database. Only valid when the
        /// query contains an auto-increment column and the operation being performed is an insert.</param>
        /// <returns>The number of rows affected.</returns>
        public int ExecuteNonReaderWithResult(DbCommand cmd, DbQueryBase queryBase, out long lastInsertedId)
        {
            try
            {
                int ret;

                // Grab the execution lock since we are going to be executing queries
                lock (_executeQuerySync)
                {
                    // Empty out the queue
                    FlushQueue();

                    // Execute our job
                    ret = cmd.ExecuteNonQuery();

                    // Get the lastInsertedId
                    lastInsertedId = _dbConnectionPool.GetLastInsertedId(cmd);
                }

                return ret;
            }
            finally
            {
                queryBase.ReleaseCommand(cmd);
            }
        }
Пример #5
0
        /// <summary>
        /// Executes a query that returns the number of rows affected.
        /// This runs in blocking mode.
        /// </summary>
        /// <param name="cmd">The <see cref="DbCommand"/> to execute.</param>
        /// <param name="queryBase">The <see cref="DbQueryBase"/> that is executing this command.</param>
        /// <returns>The number of rows affected.</returns>
        public int ExecuteNonReaderWithResult(DbCommand cmd, DbQueryBase queryBase)
        {
            try
            {
                int ret;

                // Grab the execution lock since we are going to be executing queries
                lock (_executeQuerySync)
                {
                    // Empty out the queue
                    FlushQueue();

                    // Execute our job
                    ret = cmd.ExecuteNonQuery();
                }

                return ret;
            }
            finally
            {
                queryBase.ReleaseCommand(cmd);
            }
        }