Пример #1
0
        public void conn_setIsolationLevel()
        {
            string conn_string = "server=test-db-server;database=demodb;port=33000;user=dba;password="******"drop table if exists test_isolation";
            cmd.ExecuteNonQuery();

            // open another session
            CUBRIDConnection conn2 = new CUBRIDConnection();
            conn2.ConnectionString = conn_string;
            conn2.Open();

            CUBRIDCommand cmd2 = new CUBRIDCommand();
            cmd2.Connection = conn2;


            // set up the isolation level to 
            conn.SetAutoCommit(false);
            conn.SetIsolationLevel(CUBRIDIsolationLevel.TRAN_REP_CLASS_COMMIT_INSTANCE);
            cmd.CommandText = "create table test_isolation(a int)";
            cmd.ExecuteNonQuery();

            conn.Commit();

            conn.Close();
        }
Пример #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
        public void APIS_485()
        {
            LogTestStep("Test the lockTimeout is set successfully");
            CUBRIDConnection conn = new CUBRIDConnection();
            conn.ConnectionString = DBHelper.connString;
            Assert.AreEqual(-1, conn.LockTimeout);
            
            conn.Open();
            int timeout = 20;
            conn.SetLockTimeout(timeout);
            Assert.AreEqual(timeout, conn.LockTimeout);

            DBHelper.ExecuteSQL("drop table if exists t", conn);
            DBHelper.ExecuteSQL("create table t(id integer)", conn);
            DBHelper.ExecuteSQL("insert into t values (1)", conn);

            conn.SetAutoCommit(false);
            CUBRIDConnection conn2 = null;
            double elapseTime = 0;
            var stopwatch = new Stopwatch();
            try
            {
                Thread thread2 = new Thread(delegate()
                {
                    conn2 = new CUBRIDConnection();
                    conn2.ConnectionString = DBHelper.connString;
                    conn2.Open();
                    conn2.SetAutoCommit(false);

                    conn2.BeginTransaction();
                    DBHelper.ExecuteSQL("update t set id=2", conn2);
                });
                conn.BeginTransaction();
                thread2.Start();
                Thread.Sleep(5000);

                stopwatch.Start();
                DBHelper.ExecuteSQL("update t set id=3", conn);
                thread2.Join();
            }
            catch (Exception ex)
            {
                stopwatch.Stop();
                elapseTime = (double)stopwatch.ElapsedMilliseconds / 1000;
                double diffTime = elapseTime - (double)(timeout / 1000);
                Console.WriteLine("different time = " + stopwatch.ElapsedMilliseconds);
                Console.WriteLine("different time = " + diffTime);
                Log(ex.Message);
                Assert.AreEqual(timeout, conn.LockTimeout);

                if (diffTime >= 0 && diffTime < 10)
                {
                    LogStepPass();
                }
                else
                {
                    LogStepFail();
                }
            }
            finally
            {
                LogTestResult();
                //DBHelper.ExecuteSQL("drop table t", conn);
                conn.Close();
                conn2.Close();
            }
        }
Пример #4
0
        public void SetIsolationLevel_Test()
        {
            string sqlTablesCount = "select count(*) from db_class";
            int tablesCount, newTableCount;

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

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

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

                conn.Commit();
                newTableCount = (int)DBHelper.GetSingleValue(sqlTablesCount, conn);
                Assert.AreEqual(tablesCount + 1, newTableCount);

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

                LogTestResult();
            }
        }
Пример #5
0
        public void AutoCommit_SetAfterOpen_Test()
        {
            int tablesCount;

            Log("Test SetAutoCommit, GetAutoCommit, AutoCommit");

            LogTestStep("Set AutoCommit as false");
            using (CUBRIDConnection conn = new CUBRIDConnection())
            {
                conn.ConnectionString = DBHelper.connString;
                conn.Open();

                conn.SetAutoCommit(false);

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

                //Create table
                DBHelper.ExecuteSQL("create table xyz(id int)", conn);

                //Verify the current AutoCimmit value
                Assert.AreEqual(false, conn.GetAutoCommit());

            }

            using (CUBRIDConnection conn2 = new CUBRIDConnection())
            {
                conn2.ConnectionString = DBHelper.connString;
                conn2.Open();

                //Verify table was not created
                Assert.AreEqual(tablesCount, (int)DBHelper.GetSingleValue("select count(*) from db_class", conn2));

                LogStepPass();

                LogTestStep("Set AutoCommit as true");
                conn2.SetAutoCommit(true);
                //Create table
                DBHelper.ExecuteSQL("create table xyz(id int)", conn2);

                //Verify the current AutoCimmit value
                Assert.AreEqual(true, conn2.GetAutoCommit());
            }

            using (CUBRIDConnection conn3 = new CUBRIDConnection())
            {
                conn3.ConnectionString = DBHelper.connString;
                conn3.Open();

                //Verify table was created
                Assert.AreEqual(tablesCount + 1, (int)DBHelper.GetSingleValue("select count(*) from db_class", conn3));

                LogStepPass();

                LogTestStep("Set AutoCommit as default");
                //Leave the AutoCommit as default
                DBHelper.ExecuteSQL("drop table if exists xyz", conn3);
                Assert.AreEqual(true, conn3.GetAutoCommit());
            }

            using (CUBRIDConnection conn4 = new CUBRIDConnection())
            {
                conn4.ConnectionString = DBHelper.connString;
                conn4.Open();

                //Verify table was deleted
                Assert.AreEqual(tablesCount, (int)DBHelper.GetSingleValue("select count(*) from db_class", conn4));

                LogStepPass();
            }

            LogTestResult();
        }
Пример #6
0
        public void CUBRIDCommand_Constructor_SQLAndConnAndTran_Test()
        {
            CUBRIDConnection conn = new CUBRIDConnection();
            conn.ConnectionString = DBHelper.connString;
            conn.Open();
            conn.SetAutoCommit(false);

            string sql = "drop table if exists t";
            CUBRIDTransaction transaction = new CUBRIDTransaction(conn, CUBRIDIsolationLevel.TRAN_DEFAULT_ISOLATION);
            CUBRIDCommand cmd = new CUBRIDCommand(sql, conn, transaction);

            conn.BeginTransaction();
            cmd.ExecuteNonQuery();
            cmd.CommandText = "create table t (id int, name varchar(50))";
            cmd.ExecuteNonQuery();
            cmd.CommandText = "insert into t values(1, 'Nancy')";
            cmd.ExecuteNonQuery();
            conn.Commit();

            cmd.CommandText = "select * from t";
            CUBRIDDataReader reader = (CUBRIDDataReader)cmd.ExecuteReader();
            reader.Read();
            Assert.AreEqual(2, reader.FieldCount);
            Assert.AreEqual("1", reader.GetString(0));
            Assert.AreEqual("Nancy", reader.GetString(1));

            cmd.Close();
            reader.Close();
            conn.Close();
        }