Пример #1
0
        /// <summary>
        /// Test basic SQL statements execution, using parameters
        /// </summary>
        private static void Test_Command_Multiple_CommandText()
        {
            string sqlTablesCount = "select count(*) from db_class";
            int    tablesCount, newTableCount;

            using (CUBRIDConnection conn = new CUBRIDConnection())
            {
                conn.ConnectionString = TestCases.connString;
                conn.Open();
                using (CUBRIDCommand cmd = conn.CreateCommand())
                {
                    tablesCount     = (int)TestCases.GetSingleValue(sqlTablesCount, conn);
                    cmd.CommandText = "create table test(id int)";
                    cmd.CommandType = CommandType.Text;
                    cmd.ExecuteNonQuery();
                    newTableCount = (int)TestCases.GetSingleValue(sqlTablesCount, conn);
                    Debug.Assert(newTableCount == tablesCount + 1);
                    cmd.CommandText = "drop table test";
                    cmd.CommandType = CommandType.Text;
                    cmd.ExecuteNonQuery();
                    newTableCount = (int)TestCases.GetSingleValue(sqlTablesCount, conn);
                    Debug.Assert(newTableCount == tablesCount);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Test CUBRIDConnection Auto-Commit property
        /// </summary>
        private static void Test_AutoCommit()
        {
            int tablesCount;

            using (CUBRIDConnection conn = new CUBRIDConnection())
            {
                conn.ConnectionString = TestCases.connString;
                conn.Open();

                conn.SetAutoCommit(false);

                tablesCount = (int)TestCases.GetSingleValue("select count(*) from db_class", conn);

                //Create table
                TestCases.ExecuteSQL("drop table if exists xyz", conn);
                TestCases.ExecuteSQL("create table xyz(id int)", conn);
            }

            using (CUBRIDConnection conn = new CUBRIDConnection())
            {
                conn.ConnectionString = TestCases.connString;
                conn.Open();

                //Verify table was not created
                Debug.Assert(tablesCount == (int)TestCases.GetSingleValue("select count(*) from db_class", conn));

                //Create table
                TestCases.ExecuteSQL("drop table if exists xyz", conn);
                TestCases.ExecuteSQL("create table xyz(id int)", conn);
            }

            using (CUBRIDConnection conn = new CUBRIDConnection())
            {
                conn.ConnectionString = TestCases.connString;
                conn.Open();

                //Verify table was created
                Debug.Assert(tablesCount == ((int)TestCases.GetSingleValue("select count(*) from db_class", conn) - 1));

                TestCases.ExecuteSQL("drop table if exists xyz", conn);
            }
        }
Пример #3
0
        /// <summary>
        /// Test CUBRID Isolation Levels
        /// </summary>
        private static void Test_IsolationLevel()
        {
            string sqlTablesCount = "select count(*) from db_class";
            int    tablesCount, newTableCount;

            using (CUBRIDConnection conn = new CUBRIDConnection())
            {
                conn.ConnectionString = TestCases.connString;
                conn.Open();

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

                conn.SetIsolationLevel(CUBRIDIsolationLevel.TRAN_REP_READ);
                Debug.Assert(conn.GetIsolationLevel() == CUBRIDIsolationLevel.TRAN_REP_READ);

                tablesCount = (int)TestCases.GetSingleValue(sqlTablesCount, conn);
                TestCases.ExecuteSQL("create table isol(id int)", conn);
                newTableCount = (int)TestCases.GetSingleValue(sqlTablesCount, conn);
                //Verify table was created
                Debug.Assert(newTableCount == tablesCount + 1);

                using (CUBRIDConnection connOut = new CUBRIDConnection())
                {
                    connOut.ConnectionString = TestCases.connString;
                    connOut.Open();

                    newTableCount = (int)TestCases.GetSingleValue(sqlTablesCount, connOut);
                    //CREATE TABLE is visible from another connection
                    Debug.Assert(newTableCount == tablesCount + 1);
                }

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

            using (CUBRIDConnection conn = new CUBRIDConnection())
            {
                conn.ConnectionString = TestCases.connString;
                conn.Open();

                conn.SetIsolationLevel(CUBRIDIsolationLevel.TRAN_REP_CLASS_COMMIT_INSTANCE);
                Debug.Assert(conn.GetIsolationLevel() == CUBRIDIsolationLevel.TRAN_REP_CLASS_COMMIT_INSTANCE);

                tablesCount = (int)TestCases.GetSingleValue(sqlTablesCount, conn);
                conn.BeginTransaction();
                TestCases.ExecuteSQL("create table isol(id int)", conn);
                newTableCount = (int)TestCases.GetSingleValue(sqlTablesCount, conn);
                //Verify table was created
                Debug.Assert(newTableCount == tablesCount + 1);

                using (CUBRIDConnection connOut = new CUBRIDConnection())
                {
                    connOut.ConnectionString = TestCases.connString;
                    connOut.Open();
                    newTableCount = (int)TestCases.GetSingleValue(sqlTablesCount, connOut);
                    Debug.Assert(newTableCount == tablesCount);
                }

                conn.Commit();

                newTableCount = (int)TestCases.GetSingleValue(sqlTablesCount, conn);
                //Verify table was created
                Debug.Assert(newTableCount == tablesCount + 1);

                TestCases.ExecuteSQL("drop table if exists isol", conn);
                newTableCount = (int)TestCases.GetSingleValue(sqlTablesCount, conn);
                Debug.Assert(newTableCount == tablesCount);
            }
        }