当前位置: 首页>>代码示例>>C#>>正文


C# CUBRIDConnection.SetAutoCommit方法代码示例

本文整理汇总了C#中CUBRID.Data.CUBRIDClient.CUBRIDConnection.SetAutoCommit方法的典型用法代码示例。如果您正苦于以下问题:C# CUBRIDConnection.SetAutoCommit方法的具体用法?C# CUBRIDConnection.SetAutoCommit怎么用?C# CUBRIDConnection.SetAutoCommit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CUBRID.Data.CUBRIDClient.CUBRIDConnection的用法示例。


在下文中一共展示了CUBRIDConnection.SetAutoCommit方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: conn_setIsolationLevel

        public void conn_setIsolationLevel()
        {
            string conn_string = "server=test-db-server;database=demodb;port=33000;user=dba;password=";
            CUBRIDConnection conn = new CUBRIDConnection();
            conn.ConnectionString = conn_string;
            conn.Open();

            CUBRIDCommand cmd = new CUBRIDCommand();
            cmd.Connection = conn;
            cmd.CommandText = "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();
        }
开发者ID:CUBRID,项目名称:cubrid-adonet,代码行数:31,代码来源:BTSIssue.cs

示例2: Test_AutoCommit

    /// <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);
      }
    }
开发者ID:CUBRID,项目名称:cubrid-adonet,代码行数:45,代码来源:TestTransaction.cs

示例3: APIS_485

        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();
            }
        }
开发者ID:CUBRID,项目名称:cubrid-adonet,代码行数:67,代码来源:BTSIssue.cs

示例4: SetIsolationLevel_Test

        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();
            }
        }
开发者ID:CUBRID,项目名称:cubrid-adonet,代码行数:28,代码来源:CUBRIDConnectionTest.cs

示例5: AutoCommit_SetAfterOpen_Test

        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();
        }
开发者ID:CUBRID,项目名称:cubrid-adonet,代码行数:72,代码来源:CUBRIDConnectionTest.cs

示例6: CUBRIDCommand_Constructor_SQLAndConnAndTran_Test

        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();
        }
开发者ID:CUBRID,项目名称:cubrid-adonet,代码行数:30,代码来源:CUBRIDCommandTest.cs


注:本文中的CUBRID.Data.CUBRIDClient.CUBRIDConnection.SetAutoCommit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。