public MySqlTransactionScope(MySqlConnection con, Transaction trans,
     MySqlTransaction simpleTransaction)
 {
   connection = con;
   baseTransaction = trans;
   this.simpleTransaction = simpleTransaction;
 }
Beispiel #2
0
 private void initTransaction()
 {
     base.command = base.client.getNewCommand();
     this.transaction = base.client.getTransaction();
     base.command.Transaction = this.transaction;
     base.command.Connection = this.transaction.Connection;
     this.finishedTransaction = false;
 }
Beispiel #3
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;
    }
Beispiel #4
0
 public MySqlCommand(string cmdText, MySqlConnection connection,
     MySqlTransaction transaction)
     : this(cmdText, connection)
 {
     curTransaction = transaction;
 }
Beispiel #5
0
		internal void CloseFully()
		{
			if (settings.Pooling && driver.IsOpen)
			{
				// if we are in a transaction, roll it back
				if (driver.HasStatus(ServerStatusFlags.InTransaction))
				{
					MySqlTransaction t = new MySqlTransaction(this, IsolationLevel.Unspecified);
					t.Rollback();
				}

				MySqlPoolManager.ReleaseConnection(driver);
			}
			else
				driver.Close();
			driver = null;
		}
Beispiel #6
0
		public new MySqlTransaction BeginTransaction(IsolationLevel iso)
		{
			//TODO: check note in help
			if (State != ConnectionState.Open)
				Throw(new InvalidOperationException(Resources.ConnectionNotOpen));

			// First check to see if we are in a current transaction
			if (driver.HasStatus(ServerStatusFlags.InTransaction))
				Throw(new InvalidOperationException(Resources.NoNestedTransactions));

			MySqlTransaction t = new MySqlTransaction(this, iso);

			MySqlCommand cmd = new MySqlCommand("", this);

			cmd.CommandText = "SET SESSION TRANSACTION ISOLATION LEVEL ";
			switch (iso)
			{
				case IsolationLevel.ReadCommitted:
					cmd.CommandText += "READ COMMITTED";
					break;
				case IsolationLevel.ReadUncommitted:
					cmd.CommandText += "READ UNCOMMITTED";
					break;
				case IsolationLevel.RepeatableRead:
					cmd.CommandText += "REPEATABLE READ";
					break;
				case IsolationLevel.Serializable:
					cmd.CommandText += "SERIALIZABLE";
					break;
				case IsolationLevel.Chaos:
					Throw(new NotSupportedException(Resources.ChaosNotSupported));
					break;
				case IsolationLevel.Snapshot:
					Throw(new NotSupportedException(Resources.SnapshotNotSupported));
					break;
			}

			cmd.ExecuteNonQuery();

			cmd.CommandText = "BEGIN";
			cmd.ExecuteNonQuery();

			return t;
		}