Esempio n. 1
0
 public static void AddToCache(string commandText, ResultSet resultSet)
 {
     cache.AddToCache(commandText, resultSet);
 }
Esempio n. 2
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);

            // this will clear out any unread data
            if (resultSet != null)
                resultSet.Close();

            // single result means we only return a single resultset.  If we have already
            // returned one, then we return false;
            if (resultSet != null && (commandBehavior & CommandBehavior.SingleResult) != 0)
                return false;

            // next load up the next resultset if any
            try
            {
                do
                {
                    resultSet = null;
                    resultSet = driver.NextResult(Statement.StatementId);
                    if (resultSet == null) return false;
                    if (resultSet.IsOutputParameters) return false;

                    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;
            }
		}
Esempio n. 3
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;
      }
    }
    private bool AllFieldsAccessed(ResultSet rs)
    {
      if (rs.Fields == null || rs.Fields.Length == 0) return true;

      for (int i = 0; i < rs.Fields.Length; i++)
        if (!rs.FieldRead(i)) return false;
      return true;
    }
    private void ReportUsageAdvisorWarnings(int statementId, ResultSet rs)
    {
      if (!Settings.UseUsageAdvisor) return;

      if (HasStatus(ServerStatusFlags.NoIndex))
        MySqlTrace.TraceEvent(TraceEventType.Warning, MySqlTraceEventType.UsageAdvisorWarning,
            Resources.TraceUAWarningNoIndex, driverId, UsageAdvisorWarningFlags.NoIndex);
      else if (HasStatus(ServerStatusFlags.BadIndex))
        MySqlTrace.TraceEvent(TraceEventType.Warning, MySqlTraceEventType.UsageAdvisorWarning,
            Resources.TraceUAWarningBadIndex, driverId, UsageAdvisorWarningFlags.BadIndex);

      // report abandoned rows
      if (rs.SkippedRows > 0)
        MySqlTrace.TraceEvent(TraceEventType.Warning, MySqlTraceEventType.UsageAdvisorWarning,
            Resources.TraceUAWarningSkippedRows, driverId, UsageAdvisorWarningFlags.SkippedRows, rs.SkippedRows);

      // report not all fields accessed
      if (!AllFieldsAccessed(rs))
      {
        StringBuilder notAccessed = new StringBuilder("");
        string delimiter = "";
        for (int i = 0; i < rs.Size; i++)
          if (!rs.FieldRead(i))
          {
            notAccessed.AppendFormat("{0}{1}", delimiter, rs.Fields[i].ColumnName);
            delimiter = ",";
          }
        MySqlTrace.TraceEvent(TraceEventType.Warning, MySqlTraceEventType.UsageAdvisorWarning,
            Resources.TraceUAWarningSkippedColumns, driverId, UsageAdvisorWarningFlags.SkippedColumns,
                notAccessed.ToString());
      }

      // report type conversions if any
      if (rs.Fields != null)
      {
        foreach (MySqlField f in rs.Fields)
        {
          StringBuilder s = new StringBuilder();
          string delimiter = "";
          foreach (Type t in f.TypeConversions)
          {
            s.AppendFormat("{0}{1}", delimiter, t.Name);
            delimiter = ",";
          }
          if (s.Length > 0)
            MySqlTrace.TraceEvent(TraceEventType.Warning, MySqlTraceEventType.UsageAdvisorWarning,
                Resources.TraceUAWarningFieldConversion, driverId, UsageAdvisorWarningFlags.FieldConversion,
                f.ColumnName, s.ToString());
        }
      }
    }
Esempio n. 6
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;
            }
        }
    public override ResultSet NextResult(int statementId, bool force)
    {
      // first let's see if we already have a resultset on this statementId
      if (activeResult != null)
      {
        //oldRS = activeResults[statementId];
        if (Settings.UseUsageAdvisor)
          ReportUsageAdvisorWarnings(statementId, activeResult);
        MySqlTrace.TraceEvent(TraceEventType.Information, MySqlTraceEventType.ResultClosed,
            Resources.TraceResultClosed, driverId, activeResult.TotalRows, activeResult.SkippedRows,
            rowSizeInBytes);
        rowSizeInBytes = 0;
        activeResult = null;
      }

      activeResult = base.NextResult(statementId, force);
      return activeResult;
    }
        private async Task <ResultSet> ScanResultSetAsyncAwaited(IOBehavior ioBehavior, ResultSet resultSet, CancellationToken cancellationToken)
        {
            m_resultSetBuffered = await resultSet.ReadResultSetHeaderAsync(ioBehavior, cancellationToken);

            return(m_resultSetBuffered);
        }
 private void ActivateResultSet(ResultSet resultSet)
 {
     Command.LastInsertedId = resultSet.LastInsertId;
     m_recordsAffected     += resultSet.RecordsAffected;
 }
Esempio n. 10
0
 public static void AddToCache(string commandText, ResultSet resultSet)
 {
     cache.AddToCache(commandText, resultSet);
 }
Esempio n. 11
0
 private ValueTask <int> ScanResultSetAsync(IOBehavior ioBehavior, ResultSet resultSet, CancellationToken cancellationToken)
 {
     if (!m_hasMoreResults)
     {
         return(default);
Esempio n. 12
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);
            }

            // this will clear out any unread data
            if (resultSet != null)
            {
                resultSet.Close();
            }

            // single result means we only return a single resultset.  If we have already
            // returned one, then we return false;
            if (resultSet != null && (commandBehavior & CommandBehavior.SingleResult) != 0)
            {
                return(false);
            }

            // next load up the next resultset if any
            try
            {
                do
                {
                    resultSet = null;
                    resultSet = driver.NextResult(Statement.StatementId);
                    if (resultSet == null)
                    {
                        return(false);
                    }
                    if (resultSet.IsOutputParameters)
                    {
                        return(false);
                    }

                    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;
            }
        }
Esempio n. 13
0
        private async Task <ResultSet> ScanResultSetAsyncAwaited(IOBehavior ioBehavior, ResultSet resultSet, CancellationToken cancellationToken)
        {
            using (Command.RegisterCancel(cancellationToken))
            {
                try
                {
                    m_resultSetBuffered = await resultSet.ReadResultSetHeaderAsync(ioBehavior).ConfigureAwait(false);

                    return(m_resultSetBuffered);
                }
                catch (MySqlException ex) when(ex.Number == (int)MySqlErrorCode.QueryInterrupted)
                {
                    m_resultSetBuffered = null;
                    cancellationToken.ThrowIfCancellationRequested();
                    throw;
                }
            }
        }
Esempio n. 14
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);

            // this will clear out any unread data
            if (resultSet != null)
                resultSet.Close();

            // single result means we only return a single resultset.  If we have already
            // returned one, then we return false;
            if (resultSet != null && (commandBehavior & CommandBehavior.SingleResult) != 0)
                return false;

            // next load up the next resultset if any
            try
            {
                do
                {
                    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);
                    }

                    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;
            }
		}