Ejemplo n.º 1
0
        internal static async Task <MyCatDataReader> CreateAsync(MyCatCommand command, CommandBehavior behavior, IOBehavior ioBehavior, CancellationToken cancellationToken)
        {
            var dataReader = new MyCatDataReader(command, behavior);
            await dataReader.ReadFirstResultSetAsync(ioBehavior, cancellationToken).ConfigureAwait(false);

            return(dataReader);
        }
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
 protected override void Dispose(bool disposing)
 {
     try
     {
         if (disposing)
         {
             if (!m_isFinished && m_connection != null && m_connection.CurrentTransaction == this)
             {
                 using (var cmd = new MyCatCommand("rollback", m_connection, this))
                     cmd.ExecuteNonQuery();
                 m_connection.CurrentTransaction = null;
             }
             m_connection = null;
         }
     }
     finally
     {
         base.Dispose(disposing);
     }
 }
Ejemplo n.º 4
0
        private void DoClose()
        {
            if (Command != null)
            {
                while (NextResult())
                {
                }
                m_resultSet         = null;
                m_resultSetBuffered = null;
                m_nextResultSetBuffer.Clear();

                var connection = Command.Connection;
                connection.HasActiveReader = false;
                Command.ReaderClosed();
                if ((m_behavior & CommandBehavior.CloseConnection) != 0)
                {
                    Command.Dispose();
                    connection.Close();
                }
                Command = null;
            }
        }
Ejemplo n.º 5
0
        internal async Task RollbackAsync(IOBehavior ioBehavior, CancellationToken cancellationToken)
        {
            VerifyNotDisposed();
            if (m_isFinished)
            {
                throw new InvalidOperationException("Already committed or rolled back.");
            }

            if (m_connection.CurrentTransaction == this)
            {
                using (var cmd = new MyCatCommand("rollback", m_connection, this))
                    await cmd.ExecuteNonQueryAsync(ioBehavior, cancellationToken).ConfigureAwait(false);
                m_connection.CurrentTransaction = null;
                m_isFinished = true;
            }
            else if (m_connection.CurrentTransaction != null)
            {
                throw new InvalidOperationException("This is not the active transaction.");
            }
            else if (m_connection.CurrentTransaction == null)
            {
                throw new InvalidOperationException("There is no active transaction.");
            }
        }
Ejemplo n.º 6
0
 private MyCatDataReader(MyCatCommand command, CommandBehavior behavior)
 {
     Command    = command;
     m_behavior = behavior;
 }