Example #1
0
 private static MySqlDataReader ExecuteReader(MySqlConnection connection, MySqlTransaction transaction, CommandType commandType, string commandText, MySqlParameter[] commandParameters, MySqlConnectionOwnership connectionOwnership)
 {
     MySqlDataReader reader2;
     if (connection == null)
     {
         throw new ArgumentNullException("connection");
     }
     bool mustCloseConnection = false;
     MySqlCommand command = new MySqlCommand();
     try
     {
         MySqlDataReader reader;
         PrepareCommand(command, connection, transaction, commandType, commandText, commandParameters, out mustCloseConnection);
         if (connectionOwnership == MySqlConnectionOwnership.External)
         {
             reader = command.ExecuteReader();
         }
         else
         {
             reader = command.ExecuteReader(CommandBehavior.CloseConnection);
         }
         bool flag2 = true;
         foreach (MySqlParameter parameter in command.Parameters)
         {
             if (parameter.Direction != ParameterDirection.Input)
             {
                 flag2 = false;
             }
         }
         if (flag2)
         {
             command.Parameters.Clear();
         }
         reader2 = reader;
     }
     catch
     {
         if (mustCloseConnection)
         {
             connection.Close();
         }
         throw;
     }
     return reader2;
 }
Example #2
0
 /// <summary>
 /// Create and prepare a MySqlCommand, and call ExecuteReader with the appropriate CommandBehavior.
 /// </summary>
 /// <remarks>
 /// If we created and opened the connection, we want the connection to be closed when the DataReader is closed.
 /// 
 /// If the caller provided the connection, we want to leave it to them to manage.
 /// </remarks>
 /// <param name="connection">A valid MySqlConnection, on which to execute this command</param>
 /// <param name="transaction">A valid MySqlTransaction, or 'null'</param>
 /// <param name="commandType">The CommandType (stored procedure, text, etc.)</param>
 /// <param name="commandText">The stored procedure name or T-MySql command</param>
 /// <param name="commandParameters">An array of MySqlParameters to be associated with the command or 'null' if no parameters are required</param>
 /// <param name="connectionOwnership">Indicates whether the connection parameter was provided by the caller, or created by MySqlHelper</param>
 /// <returns>MySqlDataReader containing the results of the command</returns>
 private static MySqlDataReader ExecuteReader(MySqlConnection connection, MySqlTransaction transaction, CommandType commandType, string commandText, MySqlParameter[] commandParameters, MySqlConnectionOwnership connectionOwnership)
 {
     if (connection == null) throw new ArgumentNullException("connection");
     bool mustCloseConnection = false;
     // Create a command and prepare it for execution
     MySqlCommand cmd = new MySqlCommand();
     try
     {
         PrepareCommand(cmd, connection, transaction, commandType, commandText, commandParameters, out mustCloseConnection);
         // Create a reader
         MySqlDataReader dataReader;
         // Call ExecuteReader with the appropriate CommandBehavior
         if (connectionOwnership == MySqlConnectionOwnership.External)
         {
             dataReader = cmd.ExecuteReader();
         }
         else
         {
             dataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
         }
         // Detach the MySqlParameters from the command object, so they can be used again.
         // HACK: There is a problem here, the output parameter values are fletched
         // when the reader is closed, so if the parameters are detached from the command
         // then the MySqlReader can磘 set its values.
         // When this happen, the parameters can磘 be used again in other command.
         bool canClear = true;
         foreach (MySqlParameter commandParameter in cmd.Parameters)
         {
             if (commandParameter.Direction != ParameterDirection.Input)
                 canClear = false;
         }
         if (canClear)
         {
             cmd.Parameters.Clear();
         }
         return dataReader;
     }
     catch
     {
         if (mustCloseConnection)
             connection.Close();
         throw;
     }
 }