Ejemplo n.º 1
0
 public MySqlTransactionScope(MySqlConnection con, Transaction trans,
     MySqlTransaction simpleTransaction)
 {
   connection = con;
   baseTransaction = trans;
   this.simpleTransaction = simpleTransaction;
 }
Ejemplo n.º 2
0
 public MySqlBulkLoader(MySqlConnection connection)
 {
   Connection = connection;
   Local = true;
   FieldTerminator = defaultFieldTerminator;
   LineTerminator = defaultLineTerminator;
   FieldQuotationCharacter = Char.MinValue;
   ConflictOption = MySqlBulkLoaderConflictOption.None;
   columns = new StringCollection();
   expressions = new StringCollection();
 }
Ejemplo n.º 3
0
        public PerformanceMonitor(MySqlConnection connection)
        {
            this.connection = connection;

              string categoryName = Resources.PerfMonCategoryName;

              if (connection.Settings.UsePerformanceMonitor && procedureHardQueries == null)
              {
              procedureHardQueries = new PerformanceCounter(categoryName,
                                                        "HardProcedureQueries", false);
              procedureSoftQueries = new PerformanceCounter(categoryName,
                                                        "SoftProcedureQueries", false);
              }
        }
Ejemplo n.º 4
0
        /*
         * Because the user should not be able to directly create a
         * DataReader object, the constructors are
         * marked as internal.
         */
        internal MySqlDataReader(MySqlCommand cmd, PreparableStatement statement, CommandBehavior behavior)
        {
            this.command = cmd;
              connection = (MySqlConnection)command.Connection;
              commandBehavior = behavior;
              driver = connection.driver;
              affectedRows = -1;
              this.statement = statement;

              if (cmd.CommandType == CommandType.StoredProcedure &&
              cmd.UpdatedRowSource == UpdateRowSource.FirstReturnedRecord)
              {
            disableZeroAffectedRows = true;
              }
        }
Ejemplo n.º 5
0
        public DataSet GetProcedure(MySqlConnection conn, string spName, string cacheKey)
        {
            DataSet ds = null;

              if (cacheKey != null)
              {
            int hash = cacheKey.GetHashCode();

            lock (procHash.SyncRoot)
            {
              ds = (DataSet)procHash[hash];
            }
              }
              if (ds == null)
            ds = AddNew(conn, spName);
              return ds;
        }
Ejemplo n.º 6
0
    /// <summary>
    /// Executes a single command against a MySQL database.  The <see cref="MySqlConnection"/> is assumed to be
    /// open when the method is called and remains open after the method completes.
    /// </summary>
    /// <param name="connection"><see cref="MySqlConnection"/> object to use</param>
    /// <param name="commandText">SQL command to be executed</param>
    /// <param name="commandParameters">Array of <see cref="MySqlParameter"/> objects to use with the command.</param>
    /// <returns></returns>
    public static int ExecuteNonQuery(MySqlConnection connection, string commandText, params MySqlParameter[] commandParameters)
    {
      //create a command and prepare it for execution
      MySqlCommand cmd = new MySqlCommand();
      cmd.Connection = connection;
      cmd.CommandText = commandText;
      cmd.CommandType = CommandType.Text;

      if (commandParameters != null)
        foreach (MySqlParameter p in commandParameters)
          cmd.Parameters.Add(p);

      int result = cmd.ExecuteNonQuery();
      cmd.Parameters.Clear();

      return result;
    }
Ejemplo n.º 7
0
 /// <summary>
 /// Executes a single command against a MySQL database.
 /// </summary>
 /// <param name="connection"><see cref="MySqlConnection"/> object to use for the command</param>
 /// <param name="commandText">Command text to use</param>
 /// <returns><see cref="MySqlDataReader"/> object ready to read the results of the command</returns>
 public static MySqlDataReader ExecuteReader(MySqlConnection connection, string commandText)
 {
   //pass through the call providing null for the set of SqlParameters
   return ExecuteReader(connection, null, commandText, (MySqlParameter[])null, true);
 }
Ejemplo n.º 8
0
    /// <summary>
    /// Executes a single command against a MySQL database, possibly inside an existing transaction.
    /// </summary>
    /// <param name="connection"><see cref="MySqlConnection"/> object to use for the command</param>
    /// <param name="transaction"><see cref="MySqlTransaction"/> object to use for the command</param>
    /// <param name="commandText">Command text to use</param>
    /// <param name="commandParameters">Array of <see cref="MySqlParameter"/> objects to use with the command</param>
    /// <param name="ExternalConn">True if the connection should be preserved, false if not</param>
    /// <returns><see cref="MySqlDataReader"/> object ready to read the results of the command</returns>
    private static MySqlDataReader ExecuteReader(MySqlConnection connection, MySqlTransaction transaction, string commandText, MySqlParameter[] commandParameters, bool ExternalConn)
    {
      //create a command and prepare it for execution
      MySqlCommand cmd = new MySqlCommand();
      cmd.Connection = connection;
      cmd.Transaction = transaction;
      cmd.CommandText = commandText;
      cmd.CommandType = CommandType.Text;

      if (commandParameters != null)
        foreach (MySqlParameter p in commandParameters)
          cmd.Parameters.Add(p);

      //create a reader
      MySqlDataReader dr;

      // call ExecuteReader with the appropriate CommandBehavior
      if (ExternalConn)
      {
        dr = cmd.ExecuteReader();
      }
      else
      {
        dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
      }

      // detach the SqlParameters from the command object, so they can be used again.
      cmd.Parameters.Clear();

      return dr;
    }
Ejemplo n.º 9
0
 public SchemaProvider(MySqlConnection connectionToUse)
 {
     connection = connectionToUse;
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Execute a single command against a MySQL database.
 /// </summary>
 /// <param name="connection"><see cref="MySqlConnection"/> object to use</param>
 /// <param name="commandText">Command text to use for the command</param>
 /// <returns>The first column of the first row in the result set, or a null reference if the result set is empty.</returns>
 public static object ExecuteScalar(MySqlConnection connection, string commandText)
 {
   //pass through the call providing null for the set of MySqlParameters
   return ExecuteScalar(connection, commandText, (MySqlParameter[])null);
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Initializes a new instance of the 
 /// <see cref="MySqlScript"/> class.
 /// </summary>
 /// <param name="connection">The connection.</param>
 /// <param name="query">The query.</param>
 public MySqlScript(MySqlConnection connection, string query)
   : this()
 {
   this.connection = connection;
   this.query = query;
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Initializes a new instance of the 
 /// <see cref="MySqlScript"/> class.
 /// </summary>
 /// <param name="connection">The connection.</param>
 public MySqlScript(MySqlConnection connection)
   : this()
 {
   this.connection = connection;
 }
Ejemplo n.º 13
0
 public MySqlDataAdapter(string selectCommandText, MySqlConnection connection)
     : this()
 {
     SelectCommand = new MySqlCommand(selectCommandText, connection);
 }
Ejemplo n.º 14
0
 public MySqlClient(DatabaseManager dbManager, int id)
 {
     this.dbManager = dbManager;
     this.connection = new MySqlConnection();
 }
Ejemplo n.º 15
0
        public static MySqlDbType NameToType(string typeName, bool unsigned,
       bool realAsFloat, MySqlConnection connection)
        {
            switch (typeName.ToUpper(CultureInfo.InvariantCulture))
              {
            case "CHAR": return MySqlDbType.String;
            case "VARCHAR": return MySqlDbType.VarChar;
            case "DATE": return MySqlDbType.Date;
            case "DATETIME": return MySqlDbType.DateTime;
            case "NUMERIC":
            case "DECIMAL":
            case "DEC":
            case "FIXED":
              if (connection.driver.Version.isAtLeast(5, 0, 3))
            return MySqlDbType.NewDecimal;
              else
            return MySqlDbType.Decimal;
            case "YEAR":
              return MySqlDbType.Year;
            case "TIME":
              return MySqlDbType.Time;
            case "TIMESTAMP":
              return MySqlDbType.Timestamp;
            case "SET": return MySqlDbType.Set;
            case "ENUM": return MySqlDbType.Enum;
            case "BIT": return MySqlDbType.Bit;

            case "TINYINT":
              return unsigned ? MySqlDbType.UByte : MySqlDbType.Byte;
            case "BOOL":
            case "BOOLEAN":
              return MySqlDbType.Byte;
            case "SMALLINT":
              return unsigned ? MySqlDbType.UInt16 : MySqlDbType.Int16;
            case "MEDIUMINT":
              return unsigned ? MySqlDbType.UInt24 : MySqlDbType.Int24;
            case "INT":
            case "INTEGER":
              return unsigned ? MySqlDbType.UInt32 : MySqlDbType.Int32;
            case "SERIAL":
              return MySqlDbType.UInt64;
            case "BIGINT":
              return unsigned ? MySqlDbType.UInt64 : MySqlDbType.Int64;
            case "FLOAT": return MySqlDbType.Float;
            case "DOUBLE": return MySqlDbType.Double;
            case "REAL": return
               realAsFloat ? MySqlDbType.Float : MySqlDbType.Double;
            case "TEXT":
              return MySqlDbType.Text;
            case "BLOB":
              return MySqlDbType.Blob;
            case "LONGBLOB":
              return MySqlDbType.LongBlob;
            case "LONGTEXT":
              return MySqlDbType.LongText;
            case "MEDIUMBLOB":
              return MySqlDbType.MediumBlob;
            case "MEDIUMTEXT":
              return MySqlDbType.MediumText;
            case "TINYBLOB":
              return MySqlDbType.TinyBlob;
            case "TINYTEXT":
              return MySqlDbType.TinyText;
            case "BINARY":
              return MySqlDbType.Binary;
            case "VARBINARY":
              return MySqlDbType.VarBinary;
              }
              throw new MySqlException("Unhandled type encountered");
        }
Ejemplo n.º 16
0
 public override void CloseQuery(MySqlConnection connection, int statementId)
 {
     base.CloseQuery(connection, statementId);
 }
Ejemplo n.º 17
0
 public override List<MySqlError> ReportWarnings(MySqlConnection connection)
 {
     return base.ReportWarnings(connection);
 }
Ejemplo n.º 18
0
    /// <summary>
    /// Executes a single command against a MySQL database.
    /// </summary>
    /// <param name="connectionString">Settings to use for this command</param>
    /// <param name="commandText">Command text to use</param>
    /// <param name="commandParameters">Array of <see cref="MySqlParameter"/> objects to use with the command</param>
    /// <returns><see cref="MySqlDataReader"/> object ready to read the results of the command</returns>
    public static MySqlDataReader ExecuteReader(string connectionString, string commandText, params MySqlParameter[] commandParameters)
    {
      //create & open a SqlConnection
      MySqlConnection cn = new MySqlConnection();
      cn.Open();

      //call the private overload that takes an internally owned connection in place of the connection string
      return ExecuteReader(cn, null, commandText, commandParameters, false);
    }
Ejemplo n.º 19
0
 /// <summary>
 /// Executes a single command against a MySQL database.
 /// </summary>
 /// <param name="connection">Connection to use for the command</param>
 /// <param name="commandText">Command text to use</param>
 /// <param name="commandParameters">Array of <see cref="MySqlParameter"/> objects to use with the command</param>
 /// <returns><see cref="MySqlDataReader"/> object ready to read the results of the command</returns>
 public static MySqlDataReader ExecuteReader(MySqlConnection connection, string commandText, params MySqlParameter[] commandParameters)
 {
   //call the private overload that takes an internally owned connection in place of the connection string
   return ExecuteReader(connection, null, commandText, commandParameters, true);
 }
Ejemplo n.º 20
0
 public MySqlCommand(string cmdText, MySqlConnection connection,
     MySqlTransaction transaction)
     : this(cmdText, connection)
 {
     curTransaction = transaction;
 }
Ejemplo n.º 21
0
    /// <summary>
    /// Execute a single command against a MySQL database.
    /// </summary>
    /// <param name="connection"><see cref="MySqlConnection"/> object to use</param>
    /// <param name="commandText">Command text to use for the command</param>
    /// <param name="commandParameters">Parameters to use for the command</param>
    /// <returns>The first column of the first row in the result set, or a null reference if the result set is empty.</returns>
    public static object ExecuteScalar(MySqlConnection connection, string commandText, params MySqlParameter[] commandParameters)
    {
      //create a command and prepare it for execution
      MySqlCommand cmd = new MySqlCommand();
      cmd.Connection = connection;
      cmd.CommandText = commandText;
      cmd.CommandType = CommandType.Text;

      if (commandParameters != null)
        foreach (MySqlParameter p in commandParameters)
          cmd.Parameters.Add(p);

      //execute the command & return the results
      object retval = cmd.ExecuteScalar();

      // detach the SqlParameters from the command object, so they can be used again.
      cmd.Parameters.Clear();
      return retval;

    }
Ejemplo n.º 22
0
 public MySqlCommand(string cmdText, MySqlConnection connection)
     : this(cmdText)
 {
     Connection = connection;
 }
Ejemplo n.º 23
0
    /// <summary>
    /// Executes a single command against a MySQL database.  A new <see cref="MySqlConnection"/> is created
    /// using the <see cref="MySqlConnection.ConnectionString"/> given.
    /// </summary>
    /// <param name="connectionString"><see cref="MySqlConnection.ConnectionString"/> to use</param>
    /// <param name="commandText">SQL command to be executed</param>
    /// <param name="parms">Array of <see cref="MySqlParameter"/> objects to use with the command.</param>
    /// <returns></returns>
    public static int ExecuteNonQuery(string connectionString, string commandText, params MySqlParameter[] parms)
    {
      //create & open a SqlConnection, and dispose of it after we are done.
      using (MySqlConnection cn = new MySqlConnection())
      {
        cn.Open();

        //call the overload that takes a connection in place of the connection string
        return ExecuteNonQuery(cn, commandText, parms);
      }
    }
Ejemplo n.º 24
0
 public MySqlPromotableTransaction(MySqlConnection connection, Transaction baseTransaction)
 {
   this.connection = connection;
   this.baseTransaction = baseTransaction;
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Executes a single SQL command and returns the resultset in a <see cref="DataSet"/>.  
 /// The state of the <see cref="MySqlConnection"/> object remains unchanged after execution
 /// of this method.
 /// </summary>
 /// <param name="connection"><see cref="MySqlConnection"/> object to use</param>
 /// <param name="commandText">Command to execute</param>
 /// <returns><see cref="DataSet"/> containing the resultset</returns>
 public static DataSet ExecuteDataset(MySqlConnection connection, string commandText)
 {
   //pass through the call providing null for the set of SqlParameters
   return ExecuteDataset(connection, commandText, (MySqlParameter[])null);
 }
Ejemplo n.º 26
0
 internal static string GetDefaultCollation(string charset, MySqlConnection connection)
 {
   lock (lockObject)
   {
     if (defaultCollations == null)
       InitCollections(connection);
   }
   if (!defaultCollations.ContainsKey(charset))
     return null;
   return defaultCollations[charset];
 }
Ejemplo n.º 27
0
    internal static void InitCollections(MySqlConnection connection)
    {
      defaultCollations = new Dictionary<string, string>();
      maxLengths = new Dictionary<string, int>();

      MySqlCommand cmd = new MySqlCommand("SHOW CHARSET", connection);
      using (MySqlDataReader reader = cmd.ExecuteReader())
      {
        while (reader.Read())
        {
          defaultCollations.Add(reader.GetString(0), reader.GetString(2));
          maxLengths.Add(reader.GetString(0), Convert.ToInt32(reader.GetValue(3)));
        }
      }
    }
Ejemplo n.º 28
0
    /// <summary>
    /// Executes a single SQL command and returns the resultset in a <see cref="DataSet"/>.  
    /// The state of the <see cref="MySqlConnection"/> object remains unchanged after execution
    /// of this method.
    /// </summary>
    /// <param name="connection"><see cref="MySqlConnection"/> object to use</param>
    /// <param name="commandText">Command to execute</param>
    /// <param name="commandParameters">Parameters to use for the command</param>
    /// <returns><see cref="DataSet"/> containing the resultset</returns>
    public static DataSet ExecuteDataset(MySqlConnection connection, string commandText, params MySqlParameter[] commandParameters)
    {
      //create a command and prepare it for execution
      MySqlCommand cmd = new MySqlCommand();
      cmd.Connection = connection;
      cmd.CommandText = commandText;
      cmd.CommandType = CommandType.Text;

      if (commandParameters != null)
        foreach (MySqlParameter p in commandParameters)
          cmd.Parameters.Add(p);

      //create the DataAdapter & DataSet
      MySqlDataAdapter da = new MySqlDataAdapter(cmd);
      DataSet ds = new DataSet();

      //fill the DataSet using default values for DataTable names, etc.
      da.Fill(ds);

      // detach the MySqlParameters from the command object, so they can be used again.			
      cmd.Parameters.Clear();

      //return the dataset
      return ds;
    }
Ejemplo n.º 29
0
    internal static int GetMaxLength(string charset, MySqlConnection connection)
    {
      lock (lockObject)
      {
        if (maxLengths == null)
          InitCollections(connection);
      }

      if (!maxLengths.ContainsKey(charset))
        return 1;
      return maxLengths[charset];
    }
Ejemplo n.º 30
0
 /// <summary>
 /// Updates the given table with data from the given <see cref="DataSet"/>
 /// </summary>
 /// <param name="connectionString">Settings to use for the update</param>
 /// <param name="commandText">Command text to use for the update</param>
 /// <param name="ds"><see cref="DataSet"/> containing the new data to use in the update</param>
 /// <param name="tablename">Tablename in the dataset to update</param>
 public static void UpdateDataSet(string connectionString, string commandText, DataSet ds, string tablename)
 {
   MySqlConnection cn = new MySqlConnection();
   cn.Open();
   MySqlDataAdapter da = new MySqlDataAdapter(commandText, cn);
   MySqlCommandBuilder cb = new MySqlCommandBuilder(da);
   cb.ToString();
   da.Update(ds, tablename);
   cn.Close();
 }