本文整理汇总了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();
}
示例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);
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
示例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();
}