MySql.Data.MySqlClient.MySqlDataReader.NextResult C# (CSharp) Method

NextResult() public method

Advances the data reader to the next result, when reading the results of batch SQL statements.
public NextResult ( ) : bool
return bool
    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;
      }
    }

Usage Example

Ejemplo n.º 1
0
 public MySqlDataReader ExecuteReader(CommandBehavior behavior)
 {
     this.lastResult = null;
     this.CheckState();
     if (this.cmdText != null && this.cmdText.Trim().Length != 0)
     {
         string sql = this.TrimSemicolons(this.cmdText);
         this.updateCount = -1L;
         MySqlDataReader mySqlDataReader = new MySqlDataReader(this, behavior);
         if (this.preparedStatement == null)
         {
             this.sqlBuffers = this.PrepareSqlBuffers(sql);
         }
         else
         {
             this.preparedStatement.ExecutionCount = 0;
         }
         this.HandleCommandBehaviors(behavior);
         mySqlDataReader.NextResult();
         this.connection.Reader = mySqlDataReader;
         return(mySqlDataReader);
     }
     throw new InvalidOperationException(Resources.CommandTextNotInitialized);
 }
All Usage Examples Of MySql.Data.MySqlClient.MySqlDataReader::NextResult