Example #1
0
        /// <summary>
        /// Advances the data reader to the next result, when reading the results of batch SQL statements.
        /// </summary>
        /// <returns></returns>
        public override bool NextResult()
        {
            if (!isOpen)
            {
                throw new MySqlException(Resources.NextResultIsClosed);
            }

            bool isCaching = command.CommandType == CommandType.TableDirect && command.EnableCaching &&
                             (commandBehavior & CommandBehavior.SequentialAccess) == 0;

            // this will clear out any unread data
            if (resultSet != null)
            {
                resultSet.Close();
                if (isCaching)
                {
                    TableCache.AddToCache(command.CommandText, resultSet);
                }
            }

            // single result means we only return a single resultset.  If we have already
            // returned one, then we return false
            // TableDirect is basically a select * from a single table so it will generate
            // a single result also
            if (resultSet != null &&
                ((commandBehavior & CommandBehavior.SingleResult) != 0 || isCaching))
            {
                return(false);
            }

            // next load up the next resultset if any
            try
            {
                do
                {
                    resultSet = null;
                    // if we are table caching, then try to retrieve the resultSet from the cache
                    if (isCaching)
                    {
                        resultSet = TableCache.RetrieveFromCache(command.CommandText,
                                                                 command.CacheAge);
                    }

                    if (resultSet == null)
                    {
                        resultSet = driver.NextResult(Statement.StatementId, false);
                        if (resultSet == null)
                        {
                            return(false);
                        }
                        if (resultSet.IsOutputParameters && command.CommandType == CommandType.StoredProcedure)
                        {
                            StoredProcedure sp = statement as StoredProcedure;
                            sp.ProcessOutputParameters(this);
                            resultSet.Close();
                            if (!sp.ServerProvidingOutputParameters)
                            {
                                return(false);
                            }
                            // if we are using server side output parameters then we will get our ok packet
                            // *after* the output parameters resultset
                            resultSet = driver.NextResult(Statement.StatementId, true);
                        }
                        resultSet.Cached = isCaching;
                    }

                    if (resultSet.Size == 0)
                    {
                        Command.lastInsertedId = resultSet.InsertedId;
                        if (affectedRows == -1)
                        {
                            affectedRows = resultSet.AffectedRows;
                        }
                        else
                        {
                            affectedRows += resultSet.AffectedRows;
                        }
                    }
                } while (resultSet.Size == 0);

                return(true);
            }
            catch (MySqlException ex)
            {
                if (ex.IsFatal)
                {
                    connection.Abort();
                }
                if (ex.Number == 0)
                {
                    throw new MySqlException(Resources.FatalErrorReadingResult, ex);
                }
                if ((commandBehavior & CommandBehavior.CloseConnection) != 0)
                {
                    Close();
                }
                throw;
            }
        }
Example #2
0
        public override bool NextResult()
        {
            if (!this.isOpen)
            {
                this.Throw(new MySqlException(Resources.NextResultIsClosed));
            }
            bool flag = this.command.CommandType == CommandType.TableDirect && this.command.EnableCaching && (this.commandBehavior & CommandBehavior.SequentialAccess) == CommandBehavior.Default;

            if (this.resultSet != null)
            {
                this.resultSet.Close();
                if (flag)
                {
                    TableCache.AddToCache(this.command.CommandText, this.resultSet);
                }
            }
            if (this.resultSet != null && ((this.commandBehavior & CommandBehavior.SingleResult) != CommandBehavior.Default || flag))
            {
                return(false);
            }
            goto IL_8A;
            bool result;

            try
            {
                while (true)
                {
IL_8A:
                    this.resultSet = null;
                    if (flag)
                    {
                        this.resultSet = TableCache.RetrieveFromCache(this.command.CommandText, this.command.CacheAge);
                    }
                    if (this.resultSet == null)
                    {
                        this.resultSet = this.driver.NextResult(this.Statement.StatementId, false);
                        if (this.resultSet == null)
                        {
                            break;
                        }
                        if (this.resultSet.IsOutputParameters && this.command.CommandType == CommandType.StoredProcedure)
                        {
                            StoredProcedure storedProcedure = this.statement as StoredProcedure;
                            storedProcedure.ProcessOutputParameters(this);
                            this.resultSet.Close();
                            if (!storedProcedure.ServerProvidingOutputParameters)
                            {
                                goto Block_14;
                            }
                            this.resultSet = this.driver.NextResult(this.Statement.StatementId, true);
                        }
                        this.resultSet.Cached = flag;
                    }
                    if (this.resultSet.Size == 0)
                    {
                        this.Command.lastInsertedId = this.resultSet.InsertedId;
                        if (this.affectedRows == -1L)
                        {
                            this.affectedRows = (long)this.resultSet.AffectedRows;
                        }
                        else
                        {
                            this.affectedRows += (long)this.resultSet.AffectedRows;
                        }
                    }
                    if (this.resultSet.Size != 0)
                    {
                        goto Block_17;
                    }
                }
                result = false;
                return(result);

Block_14:
                result = false;
                return(result);

Block_17:
                result = true;
            }
            catch (MySqlException ex)
            {
                if (ex.IsFatal)
                {
                    this.connection.Abort();
                }
                if (ex.Number == 0)
                {
                    throw new MySqlException(Resources.FatalErrorReadingResult, ex);
                }
                if ((this.commandBehavior & CommandBehavior.CloseConnection) != CommandBehavior.Default)
                {
                    this.Close();
                }
                throw;
            }
            return(result);
        }