コード例 #1
0
        public void Transaction_Commit_Transaction()
        {
            using var connection = new JetConnection(JetConnection.GetConnectionString(StoreName, Helpers.DataAccessProviderFactory));
            connection.Open();

            using var firstTransaction = connection.BeginTransaction();
            using (var command = connection.CreateCommand("select count(*) from SimpleTable"))
            {
                command.Transaction = firstTransaction;
                command.ExecuteScalar();
            }
            firstTransaction.Commit();

            using var secondTransaction = connection.BeginTransaction();
            using (var command = connection.CreateCommand("select count(*) from SimpleTable"))
            {
                command.Transaction = secondTransaction;
                command.ExecuteScalar();
            }
            connection.Close();

            connection.Open();
            using (var command = connection.CreateCommand("select count(*) from SimpleTable"))
            {
                command.ExecuteScalar();
            }
        }
コード例 #2
0
        public void Transaction_Rollback_Transaction()
        {
            DbCommand command;


            JetConnection connection = new JetConnection(ConnectionString);

            connection.Open();
            DbTransaction firstTransaction = connection.BeginTransaction();

            command             = connection.CreateCommand("Select count(*) from SimpleTable");
            command.Transaction = firstTransaction;
            command.ExecuteScalar();
            firstTransaction.Rollback();

            DbTransaction secondTransaction = connection.BeginTransaction();

            command             = connection.CreateCommand("Select count(*) from SimpleTable");
            command.Transaction = secondTransaction;
            command.ExecuteScalar();


            connection.Close();

            connection.Open();
            command = connection.CreateCommand("Select count(*) from SimpleTable");
            command.ExecuteScalar();
        }
コード例 #3
0
        public void Delete_rollback_implicit()
        {
            using (var transaction = _connection.BeginTransaction())
            {
                using var deleteCommand   = _connection.CreateCommand();
                deleteCommand.CommandText = @"delete * from `Cookies` where `Name` = 'Basic'";
                deleteCommand.Transaction = transaction;
                var affected = deleteCommand.ExecuteNonQuery();

                Assert.AreEqual(1, affected);
            }

            using var verifyCommand   = _connection.CreateCommand();
            verifyCommand.CommandText = @"select count(*) as `Count` from `Cookies`";
            var count = verifyCommand.ExecuteScalar();

            Assert.AreEqual(2, count);
        }
コード例 #4
0
        public void Transaction_Execute_Close_Open_Transaction()
        {
            DbCommand     command;
            DbTransaction transaction;

            JetConnection connection = new JetConnection(ConnectionString);

            connection.Open();
            transaction         = connection.BeginTransaction();
            command             = connection.CreateCommand("INSERT INTO SimpleTable(Col) VALUES ('aaa')");
            command.Transaction = transaction;
            command.ExecuteScalar();
            connection.Close();
            connection.Open();
            transaction         = connection.BeginTransaction();
            command             = connection.CreateCommand("Select count(*) from SimpleTable");
            command.Transaction = transaction;
            Assert.AreEqual(0, command.ExecuteScalar());
        }
コード例 #5
0
        public void Transaction_Transaction()
        {
            using var connection = new JetConnection(JetConnection.GetConnectionString(StoreName, Helpers.DataAccessProviderFactory));
            connection.Open();

            using var firstTransaction = connection.BeginTransaction();
            using var command          = connection.CreateCommand("select count(*) from SimpleTable");
            command.Transaction        = firstTransaction;
            command.ExecuteScalar();

            try
            {
                using var secondTransaction = connection.BeginTransaction();
            }
            catch (Exception e)
            {
                Assert.AreEqual("JetConnection does not support parallel transactions", e.Message);
                throw;
            }
        }
コード例 #6
0
        public void Transaction_Execute_Commit_Commit()
        {
            using var connection = new JetConnection(JetConnection.GetConnectionString(StoreName, Helpers.DataAccessProviderFactory));
            connection.Open();

            using var transaction = connection.BeginTransaction();
            using var command     = connection.CreateCommand("select count(*) from SimpleTable");
            command.Transaction   = transaction;
            command.ExecuteScalar();
            transaction.Commit();
            transaction.Commit();
        }
コード例 #7
0
        public void Transaction_Execute_Close_Open_Transaction()
        {
            using var connection = new JetConnection(JetConnection.GetConnectionString(StoreName, Helpers.DataAccessProviderFactory));
            connection.Open();

            using var transaction1 = connection.BeginTransaction();

            using (var command = connection.CreateCommand("INSERT INTO SimpleTable(Col) VALUES ('aaa')"))
            {
                command.Transaction = transaction1;
                command.ExecuteScalar();
            }

            connection.Close();
            connection.Open();
            using var transaction2 = connection.BeginTransaction();

            using (var command = connection.CreateCommand("select count(*) from SimpleTable"))
            {
                command.Transaction = transaction2;
                Assert.AreEqual(0, command.ExecuteScalar());
            }
        }
コード例 #8
0
        public void Transaction_Transaction()
        {
            DbCommand command;


            JetConnection connection = new JetConnection(ConnectionString);

            connection.Open();
            DbTransaction firstTransaction = connection.BeginTransaction();

            command             = connection.CreateCommand("Select count(*) from SimpleTable");
            command.Transaction = firstTransaction;
            command.ExecuteScalar();

            try
            {
                DbTransaction secondTransaction = connection.BeginTransaction();
            }
            catch (Exception e)
            {
                Assert.AreEqual("JetConnection does not support parallel transactions", e.Message);
                throw;
            }
        }
コード例 #9
0
        public void Transaction_Execute_Commit_Commit()
        {
            DbCommand command;

            JetConnection connection = new JetConnection(ConnectionString);

            connection.Open();
            DbTransaction transaction = connection.BeginTransaction();

            command             = connection.CreateCommand("Select count(*) from SimpleTable");
            command.Transaction = transaction;
            command.ExecuteScalar();
            transaction.Commit();
            transaction.Commit();

            connection.Close();
        }
コード例 #10
0
        public void Transaction_Execute_Close_Open_Execute()
        {
            DbCommand command;

            JetConnection connection = new JetConnection(ConnectionString);

            connection.Open();
            var transaction = connection.BeginTransaction();

            command             = connection.CreateCommand("Select count(*) from MSysAccessStorage");
            command.Transaction = transaction;
            command.ExecuteScalar();
            connection.Close();
            connection.Open();
            command = connection.CreateCommand("Select count(*) from MSysAccessStorage");
            command.ExecuteScalar();
        }
コード例 #11
0
        public void Transaction_Execute_Close_Open_Execute()
        {
            using var connection = new JetConnection(JetConnection.GetConnectionString(StoreName, Helpers.DataAccessProviderFactory));
            connection.Open();

            using var transaction = connection.BeginTransaction();

            using (var command = connection.CreateCommand("select count(*) from MSysAccessStorage"))
            {
                command.Transaction = transaction;
                command.ExecuteScalar();
            }

            connection.Close();
            connection.Open();

            using (var command = connection.CreateCommand("select count(*) from MSysAccessStorage"))
            {
                command.ExecuteScalar();
            }
        }
コード例 #12
0
        public void Transaction_Execute_Commit_Close_Open_Execute()
        {
            using var connection = new JetConnection(JetConnection.GetConnectionString(StoreName, Helpers.DataAccessProviderFactory));
            connection.Open();

            using var transaction = connection.BeginTransaction();

            using (var command = connection.CreateCommand($"select count(*) from `{JetConnection.DefaultDualTableName}`"))
            {
                command.Transaction = transaction;
                command.ExecuteScalar();
            }

            transaction.Commit();
            connection.Close();
            connection.Open();

            using (var command = connection.CreateCommand($"select count(*) from `{JetConnection.DefaultDualTableName}`"))
            {
                command.ExecuteScalar();
            }
        }
コード例 #13
0
        public void UpdateTestWithTransactionsRun()
        {
            var queries = Helpers.GetQueries(Properties.Resources.UpdateTestQueries);

            Assert.AreEqual(6, queries.Length);

            DbDataReader reader;

            for (var index = 0; index < queries.Length - 2; index++)
            {
                var transaction = _connection.BeginTransaction();
                var query       = queries[index];
                reader = Helpers.Execute(_connection, transaction, query);
                reader?.Dispose();
                transaction.Commit();
            }

            reader = Helpers.Execute(_connection, queries[4]);
            reader.Read();
            Assert.AreEqual(1, reader.GetInt32(0));
            reader.Dispose();

            Helpers.Execute(_connection, queries[5]);
        }
コード例 #14
0
 public void GetTransaction_From_Closed_Connection()
 {
     JetConnection connection  = new JetConnection(ConnectionString);
     var           transaction = connection.BeginTransaction();
 }
コード例 #15
0
 public void GetTransaction_From_Closed_Connection()
 {
     using var connection  = new JetConnection(JetConnection.GetConnectionString(StoreName, Helpers.DataAccessProviderFactory));
     using var transaction = connection.BeginTransaction();
 }