Ejemplo n.º 1
0
 public MyCatCommand(string commandText, MyCatConnection connection, MyCatTransaction transaction)
 {
     CommandText           = commandText;
     DbConnection          = connection;
     DbTransaction         = transaction;
     m_parameterCollection = new MyCatParameterCollection();
     CommandType           = CommandType.Text;
 }
Ejemplo n.º 2
0
        private async Task <MyCatTransaction> BeginDbTransactionAsync(IsolationLevel isolationLevel, IOBehavior ioBehavior, CancellationToken cancellationToken)
        {
            if (State != ConnectionState.Open)
            {
                throw new InvalidOperationException("Connection is not open.");
            }
            if (CurrentTransaction != null)
            {
                throw new InvalidOperationException("Transactions may not be nested.");
            }

            string isolationLevelValue;

            switch (isolationLevel)
            {
            case IsolationLevel.ReadUncommitted:
                isolationLevelValue = "read uncommitted";
                break;

            case IsolationLevel.ReadCommitted:
                isolationLevelValue = "read committed";
                break;

            case IsolationLevel.Unspecified:
            // "In terms of the SQL:1992 transaction isolation levels, the default InnoDB level is REPEATABLE READ." - http://dev.mysql.com/doc/refman/5.7/en/innodb-transaction-model.html
            case IsolationLevel.RepeatableRead:
                isolationLevelValue = "repeatable read";
                break;

            case IsolationLevel.Serializable:
                isolationLevelValue = "serializable";
                break;

            case IsolationLevel.Chaos:
            case IsolationLevel.Snapshot:
            default:
                throw new NotSupportedException("IsolationLevel.{0} is not supported.".FormatInvariant(isolationLevel));
            }

            using (var cmd = new MyCatCommand("set session transaction isolation level " + isolationLevelValue + "; start transaction;", this))
                await cmd.ExecuteNonQueryAsync(ioBehavior, cancellationToken).ConfigureAwait(false);

            var transaction = new MyCatTransaction(this, isolationLevel);

            CurrentTransaction = transaction;
            return(transaction);
        }
Ejemplo n.º 3
0
 public MyCatCommand(MyCatConnection connection, MyCatTransaction transaction)
     : this(null, connection, transaction)
 {
 }