Пример #1
0
        /// <summary>
        /// Advances the data reader to the next result, when reading the results of batch SQL statements.
        /// </summary>
        /// <returns></returns>
        public bool NextResult()
        {
            if (!isOpen)
            {
                throw new MySqlException("Invalid attempt to NextResult when reader is closed.");
            }

            // clear any rows that have not been read from the last rowset
            if (currentResult != null)
            {
                currentResult.Consume();
            }

            // tell our command to continue execution of the SQL batch until it its
            // another resultset
            try
            {
                CommandResult nextResult = command.GetNextResultSet(this);
                if (nextResult != null)
                {
                    currentResult = nextResult;
                }
                else
                {
                    // if there was no more resultsets, then signal done
                    canRead = false;
                    return(false);
                }
                readCount = 0;

                schemaTable = null;

                // When executing query statements, the result byte that is returned
                // from MySql is the column count.  That is why we reference the LastResult
                // property here to dimension our field array
                connection.SetState(ConnectionState.Fetching);

                // load in our field defs and set our internal variables so we know
                // what we can do (canRead, hasRows)
                canRead = hasRows = currentResult.Load();
                fields  = currentResult.Fields;
                return(true);
            }
            catch (Exception ex)
            {
                if (ex is MySqlException && !(ex as MySqlException).IsFatal)
                {
                    connection.SetState(ConnectionState.Open);
                }
                else
                {
                    connection.Terminate();
                }
                throw;
            }
            finally
            {
                if (connection.State != ConnectionState.Closed && connection.State != ConnectionState.Open)
                {
                    connection.SetState(ConnectionState.Open);
                }
            }
        }