예제 #1
0
    /// <summary>
    /// Test CUBRIDTransaction class
    /// </summary>
    private static void Test_Transaction()
    {
      using (CUBRIDConnection conn = new CUBRIDConnection())
      {
        conn.ConnectionString = TestCases.connString;
        conn.Open();

        TestCases.ExecuteSQL("drop table if exists t", conn);

        conn.BeginTransaction();

        string sql = "create table t(idx integer)";
        using (CUBRIDCommand command = new CUBRIDCommand(sql, conn))
        {
          command.ExecuteNonQuery();
        }

        int tablesCount = GetTablesCount("t", conn);
        Debug.Assert(tablesCount == 1);

        conn.Rollback();

        //Verify the table does not exist
        tablesCount = GetTablesCount("t", conn);
        Debug.Assert(tablesCount == 0);

        conn.BeginTransaction();

        sql = "create table t(idx integer)";
        using (CUBRIDCommand command = new CUBRIDCommand(sql, conn))
        {
          command.ExecuteNonQuery();
        }

        tablesCount = GetTablesCount("t", conn);
        Debug.Assert(tablesCount == 1);

        conn.Commit();

        tablesCount = GetTablesCount("t", conn);
        Debug.Assert(tablesCount == 1);

        conn.BeginTransaction();

        TestCases.ExecuteSQL("drop table t", conn);

        conn.Commit();

        tablesCount = GetTablesCount("t", conn);
        Debug.Assert(tablesCount == 0);
      }
    }
예제 #2
0
        public void Transaction_Test()
        {
            using (CUBRIDConnection conn = new CUBRIDConnection())
            {
                conn.ConnectionString = DBHelper.connString;
                conn.Open();

                DBHelper.ExecuteSQL("drop table if exists t", conn);

                LogTestStep("Begin a transaction, then rollback");
                conn.BeginTransaction();
                DBHelper.ExecuteSQL("create table t(idx integer)", conn);
                int tablesCount = DBHelper.GetTablesCount("t", conn);
                Assert.AreEqual(1, tablesCount);

                conn.Rollback();
                //Verify the table does not exist
                tablesCount = DBHelper.GetTablesCount("t", conn);
                Assert.AreEqual(0, tablesCount);
                LogStepPass();

                LogTestStep("Begin a transaction, then commit, then rollback");
                conn.BeginTransaction();
                DBHelper.ExecuteSQL("create table t(idx integer)", conn);
                tablesCount = DBHelper.GetTablesCount("t", conn);
                Assert.AreEqual(1, tablesCount);

                conn.Commit();
                tablesCount = DBHelper.GetTablesCount("t", conn);
                Assert.AreEqual(1, tablesCount);

                conn.Rollback();
                tablesCount = DBHelper.GetTablesCount("t", conn);
                Assert.AreEqual(1, tablesCount);

                LogStepPass();
                Console.WriteLine();
                //revert the test db                
                DBHelper.ExecuteSQL("drop table t", conn);
                conn.Commit();

                LogTestResult();
            }
        }
예제 #3
0
    public static void Test_BeginDbTransaction()
    {
        try
        {
            conn.SetConnectionTimeout(30);
        }
        catch (Exception e)
        {
            Debug.Assert(e.ToString() == "Not allowed to change the 'ConnectionTimeout'");
        }
        using (CUBRIDConnection conn = new CUBRIDConnection())
        {
            conn.ConnectionString = TestCases.connString;
            conn.Open();

            string source = conn.DataSource;
            TestCases.ExecuteSQL("drop table if exists t", conn);

            conn.BeginTransaction();

            string sql = "create table t(idx integer)";
            using (CUBRIDCommand command = new CUBRIDCommand(sql, conn))
            {
                command.ExecuteNonQuery();
            }

            int tablesCount = GetTablesCount("t", conn);
            Debug.Assert(tablesCount == 1);

            conn.Rollback();

            //Verify the table does not exist
            tablesCount = GetTablesCount("t", conn);
            Debug.Assert(tablesCount == 0);

            conn.BeginTransaction();

            sql = "create table t(idx integer)";
            using (CUBRIDCommand command = new CUBRIDCommand(sql, conn))
            {
                command.ExecuteNonQuery();
            }

            tablesCount = GetTablesCount("t", conn);
            Debug.Assert(tablesCount == 1);

            conn.Commit();

            tablesCount = GetTablesCount("t", conn);
            Debug.Assert(tablesCount == 1);

            conn.BeginTransaction();

            TestCases.ExecuteSQL("drop table t", conn);

            conn.Commit();

            tablesCount = GetTablesCount("t", conn);
            Debug.Assert(tablesCount == 0);


            //IsolationLevel.Chaos
            try
            {
                conn.BeginTransaction(IsolationLevel.Chaos);
            }
            catch (Exception e)
            {
                Debug.Assert(e.Message == "Not supported in CUBRID!");
            }


            //IsolationLevel.ReadCommitted
            conn.BeginTransaction(IsolationLevel.ReadCommitted);
            sql = "create table t(idx integer)";
            using (CUBRIDCommand command = new CUBRIDCommand(sql, conn))
            {
                command.ExecuteNonQuery();
            }

            tablesCount = GetTablesCount("t", conn);
            Debug.Assert(tablesCount == 1);

            conn.Commit();

            tablesCount = GetTablesCount("t", conn);
            Debug.Assert(tablesCount == 1);

            conn.BeginTransaction();

            TestCases.ExecuteSQL("drop table t", conn);

            conn.Commit();

            tablesCount = GetTablesCount("t", conn);
            Debug.Assert(tablesCount == 0);


            //IsolationLevel.RepeatableRead
            conn.BeginTransaction(IsolationLevel.RepeatableRead);
            sql = "create table t(idx integer)";
            using (CUBRIDCommand command = new CUBRIDCommand(sql, conn))
            {
                command.ExecuteNonQuery();
            }

            tablesCount = GetTablesCount("t", conn);
            Debug.Assert(tablesCount == 1);

            conn.Commit();

            tablesCount = GetTablesCount("t", conn);
            Debug.Assert(tablesCount == 1);

            conn.BeginTransaction();

            TestCases.ExecuteSQL("drop table t", conn);

            conn.Commit();

            tablesCount = GetTablesCount("t", conn);
            Debug.Assert(tablesCount == 0);

            //IsolationLevel.Serializable
            conn.BeginTransaction(IsolationLevel.Serializable);
            sql = "create table t(idx integer)";
            using (CUBRIDCommand command = new CUBRIDCommand(sql, conn))
            {
                command.ExecuteNonQuery();
            }

            tablesCount = GetTablesCount("t", conn);
            Debug.Assert(tablesCount == 1);

            conn.Commit();

            tablesCount = GetTablesCount("t", conn);
            Debug.Assert(tablesCount == 1);

            conn.BeginTransaction();

            TestCases.ExecuteSQL("drop table t", conn);

            conn.Commit();

            tablesCount = GetTablesCount("t", conn);
            Debug.Assert(tablesCount == 0);

            //IsolationLevel.Snapshot
            try
            {
                conn.BeginTransaction(IsolationLevel.Snapshot);
            }
            catch (Exception e)
            {
                Debug.Assert(e.Message == "Not supported in CUBRID!");
            }

            //IsolationLevel.Snapshot
            try
            {
                conn.BeginTransaction(IsolationLevel.Unspecified);
            }
            catch (Exception e)
            {
                Debug.Assert(e.Message == "Unknown isolation level is not supported!");
            }
            try
            {
                conn.BeginTransaction(0);
            }
            catch (Exception e)
            {
                Debug.Assert(e.Message == "Unknown isolation level is not supported!");
            }
        }
    }