本文整理汇总了C#中CUBRID.Data.CUBRIDClient.CUBRIDConnection.Rollback方法的典型用法代码示例。如果您正苦于以下问题:C# CUBRIDConnection.Rollback方法的具体用法?C# CUBRIDConnection.Rollback怎么用?C# CUBRIDConnection.Rollback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CUBRID.Data.CUBRIDClient.CUBRIDConnection
的用法示例。
在下文中一共展示了CUBRIDConnection.Rollback方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test_Transaction
/// <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: Transaction_Test
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: Test_BeginDbTransaction
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);
//.........这里部分代码省略.........