コード例 #1
0
        public void Transaction_Rollback_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.Rollback();

            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 RenameColumnQuery()
        {
            try
            {
                JetConnection.ClearAllPools();
                File.Delete("AdoxTest.accdb");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            AdoxWrapper.CreateEmptyDatabase(JetConnection.GetConnectionString("AdoxTest.accdb"));

            using (JetConnection connection = new JetConnection(JetConnection.GetConnectionString("AdoxTest.accdb")))
            {
                connection.Open();
                CreateTable(connection);

                CheckColumnExists(connection, "tableName", "columnName");

                connection.CreateCommand("rename column tableName.columnName to newColumnName").ExecuteNonQuery();

                connection.Close();
                JetConnection.ClearAllPools();
                connection.Open();
                CheckColumnExists(connection, "tableName", "newColumnName");
            }

            JetConnection.ClearAllPools();
            File.Delete("AdoxTest.accdb");
        }
コード例 #3
0
        public void OpenSeveralTimes()
        {
            JetConnection connection = new JetConnection(ConnectionString);

            connection.Open();
            connection.Open();
        }
コード例 #4
0
        //[TestMethod]
        public void RenameIndexAdox()
        {
            try
            {
                JetConnection.ClearAllPools();
                File.Delete("AdoxTest.accdb");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            AdoxWrapper.CreateEmptyDatabase(JetConnection.GetConnectionString("AdoxTest.accdb"));

            using (JetConnection connection = new JetConnection(JetConnection.GetConnectionString("AdoxTest.accdb")))
            {
                connection.Open();
                CreateTable(connection);

                CheckIndexExists(connection, "indexName");

                AdoxWrapper.RenameIndex(JetConnection.GetConnectionString("AdoxTest.accdb"), "tableName", "indexName", "newIndexName");

                connection.Close();
                connection.Open();
                CheckIndexExists(connection, "newIndexName");
            }

            JetConnection.ClearAllPools();
            File.Delete("AdoxTest.accdb");
        }
コード例 #5
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();
        }
コード例 #6
0
        public void Raise_Events()
        {
            var stateChangeCount = 0;

            using var connection    = new JetConnection(JetConnection.GetConnectionString(StoreName, Helpers.DataAccessProviderFactory));
            connection.StateChange += (sender, args) =>
            {
                Console.WriteLine($"{args.OriginalState} => {args.CurrentState}");
                stateChangeCount++;
            };

            connection.Open();
            using var command = connection.CreateCommand("select * from MSysAccessStorage");
            var dataReader = command.ExecuteReader();

            while (dataReader.Read())
            {
            }

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

            Assert.AreEqual(4, stateChangeCount);
        }
コード例 #7
0
 public void GetSchema_From_Open_Connection()
 {
     using var connection = new JetConnection(JetConnection.GetConnectionString(StoreName, Helpers.DataAccessProviderFactory));
     connection.Open();
     connection.GetSchema();
     connection.Close();
 }
コード例 #8
0
        public void Read_Database_From_Open_Connection()
        {
            JetConnection connection = new JetConnection(ConnectionString);

            connection.Open();
            Assert.IsTrue(connection.Database == string.Empty);
        }
コード例 #9
0
        public static JetConnection CreateAndOpenJetDatabase(string storeName = null)
        {
            var connection = new JetConnection(CreateJetDatabase(storeName));

            connection.Open();
            return(connection);
        }
コード例 #10
0
        public void ShowWhere()
        {
            int exists    = 0;
            int notExists = 0;

            using (new Timer("ShowWhere"))
                using (JetConnection connection = JetDatabaseFixture.GetConnection())
                {
                    connection.Open();
                    for (int i = 0; i < 1000; i++)
                    {
                        if (TableExistsShowWhere(connection, $"Employees_{i % 500}"))
                        {
                            exists++;
                        }
                        else
                        {
                            notExists++;
                        }
                    }
                }

            Assert.AreEqual(600, exists);
            Assert.AreEqual(400, notExists);
        }
コード例 #11
0
        public void CreateDatabaseWithWrongPassword()
        {
            using var connection = new JetConnection(Helpers.DataAccessProviderFactory);

            var command = connection.CreateCommand();

            command.CommandText = $"CREATE DATABASE '{StoreName}' PASSWORD 'wrong password'";
            command.ExecuteNonQuery();
            Assert.IsTrue(File.Exists(StoreName));

            var csb = Helpers.DataAccessProviderFactory.CreateConnectionStringBuilder();

            csb.SetDataSource(StoreName);
            csb.SetDatabasePassword("right password");

            connection.ConnectionString = csb.ConnectionString;

            try
            {
                connection.Open();
            }
            catch (Exception e)
            {
                Assert.IsInstanceOfType(e, typeof(DbException));
            }
        }
コード例 #12
0
        public void Read_DataSource_From_Open_Connection()
        {
            JetConnection connection = new JetConnection(ConnectionString);

            connection.Open();
            Assert.AreEqual(FileName, connection.DataSource);
        }
コード例 #13
0
        public void Read_ConnectionString_From_Open_Connection()
        {
            JetConnection connection = new JetConnection(ConnectionString);

            connection.Open();
            Assert.AreEqual(ConnectionString, connection.ConnectionString);
        }
コード例 #14
0
        public void Change_ConnectionString_From_Open_Connection()
        {
            JetConnection connection = new JetConnection(ConnectionString);

            connection.Open();
            connection.ConnectionString = ConnectionStringDummy;
        }
コード例 #15
0
        public void Run()
        {
            try
            {
                for (var i = 0; i < 100; i++)
                {
                    using var connection = new JetConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Northwind.accdb");
                    connection.Open();

                    for (var j = 0; j < 2000; j++)
                    {
                        Console.WriteLine($"{i:00}: {j:000}");

                        //
                        // Select_Union:
                        //

                        using (var command1 = connection.CreateCommand())
                        {
                            command1.CommandText = @"SELECT `c`.`Address`
FROM `Customers` AS `c`
WHERE `c`.`City` = 'Berlin'
UNION
SELECT `c0`.`Address`
FROM `Customers` AS `c0`
WHERE `c0`.`City` = 'London'";

                            using (var dataReader1 = command1.ExecuteReader())
                            {
                                while (dataReader1.Read())
                                {
                                }
                            }
                        }

                        //
                        // Select_bool_closure:
                        //

                        using (var command2 = connection.CreateCommand())
                        {
                            command2.CommandText = @"SELECT 1
FROM `Customers` AS `c`";

                            using (var dataReader2 = command2.ExecuteReader())
                            {
                                while (dataReader2.Read())
                                {
                                }
                            }
                        }
                    }
                }
            }
            catch (AccessViolationException e)
            {
                Console.WriteLine(e);
                Console.ReadKey(true);
            }
        }
コード例 #16
0
        public void Change_Database_From_Open_Connection()
        {
            JetConnection connection = new JetConnection(ConnectionString);

            connection.Open();
            connection.ChangeDatabase("abcd");
        }
コード例 #17
0
        public void Read_ServerVersion_From_Open_Connection()
        {
            JetConnection connection = new JetConnection(ConnectionString);

            connection.Open();
            Console.WriteLine(connection.ServerVersion);
        }
コード例 #18
0
        public static JetConnection CreateAndOpenDatabase(string storeName)
        {
            CreateDatabase(storeName);
            var connection = new JetConnection(storeName);

            connection.Open();
            return(connection);
        }
コード例 #19
0
        public void Read_ConnectionString_From_Open_Connection()
        {
            var connectionString = JetConnection.GetConnectionString(StoreName, Helpers.DataAccessProviderFactory);

            using var connection = new JetConnection(connectionString);
            connection.Open();
            Assert.AreEqual(connectionString, connection.ConnectionString);
        }
コード例 #20
0
        public void Transaction_Execute_Close_Open()
        {
            DbCommand command;

            JetConnection connection = new JetConnection(ConnectionString);

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

            command             = connection.CreateCommand("INSERT INTO SimpleTable(Col) VALUES ('aaa')");
            command.Transaction = transaction;
            command.ExecuteScalar();
            connection.Close();
            connection.Open();
            command = connection.CreateCommand("Select count(*) from SimpleTable");
            Assert.AreEqual(0, command.ExecuteScalar());
        }
コード例 #21
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();
        }
コード例 #22
0
        public void GetSchema_From_Open_Connection()
        {
            JetConnection connection = new JetConnection(ConnectionString);

            connection.Open();
            connection.GetSchema();
            connection.Close();
        }
コード例 #23
0
        public void GetDataReader_From_Open_Connection()
        {
            JetConnection connection = new JetConnection(ConnectionString);

            connection.Open();
            var dataReader = connection.CreateCommand("Select * from MSysAccessStorage").ExecuteReader();

            while (dataReader.Read())
            {
            }
        }
コード例 #24
0
        public void Transaction_Execute_Close_Open()
        {
            using var connection = new JetConnection(JetConnection.GetConnectionString(StoreName, Helpers.DataAccessProviderFactory));
            connection.Open();

            using var transaction = connection.BeginTransaction();

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

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

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

            var dataReader = connection.CreateCommand("select * from MSysAccessStorage")
                             .ExecuteReader();

            while (dataReader.Read())
            {
            }
        }
コード例 #26
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();
            }
        }
コード例 #27
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();
        }
コード例 #28
0
        public void GetDataReader_From_Open_Connection()
        {
            using var connection = new JetConnection(JetConnection.GetConnectionString(StoreName, Helpers.DataAccessProviderFactory), Helpers.DataAccessProviderFactory);
            connection.Open();

            var dataReader = connection.CreateCommand($"select * from `{JetConnection.DefaultDualTableName}`")
                             .ExecuteReader();

            while (dataReader.Read())
            {
            }
        }
コード例 #29
0
        public void Cleanup()
        {
            using (JetConnection connection = JetDatabaseFixture.GetConnection())
            {
                connection.Open();

                for (int i = 0; i < 300; i++)
                {
                    string sql = $@"DROP TABLE [Employees_{i}]";
                    connection.CreateCommand(sql).ExecuteNonQuery();
                }
            }
        }
コード例 #30
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();
            }
        }