conn.BeginTransaction();

string sql = "create table t(idx integer)";
using (CUBRIDCommand command = new CUBRIDCommand(sql, conn))
{
command.ExecuteNonQuery();
} conn.Rollback(); conn.BeginTransaction(); sql = "create table t(idx integer, a varchar(20))";
using (CUBRIDCommand command = new CUBRIDCommand(sql, conn))
{
command.ExecuteNonQuery();
} conn.Commit(); //Here is a complete example:
using CUBRID.Data.CUBRIDClient;
using System.Diagnostics; namespace TransactionExample
{
class Program
{
private static void ExecuteSQL(string sql, CUBRIDConnection conn)
{
using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
{
cmd.ExecuteNonQuery();
}
} private static int GetTablesCount(string tableName, CUBRIDConnection conn)
{
int count = 0;
string sql = "select count(*) from db_class where class_name = '" + tableName + "'"; using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
{
count = (int)cmd.ExecuteScalar();
} return count;
} static void Main(string[] args)
{
CUBRIDConnectionStringBuilder sb = new CUBRIDConnectionStringBuilder("localhost", "demodb", "public", "", "33000");
using (CUBRIDConnection conn = new CUBRIDConnection(sb.GetConnectionString()))
{
conn.Open();
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(); ExecuteSQL("drop table t", conn); conn.Commit(); tablesCount = GetTablesCount("t", conn);
Debug.Assert(tablesCount == 0);
conn.Close();
}
}
}
}

  

最新文章

  1. Mac系统下Android生成keystore
  2. h5移动端-1
  3. Replication的犄角旮旯(二)--寻找订阅端丢失的记录
  4. WCF会话(Session)与实例(Instance)管理
  5. [NOIP2012] 普及组
  6. Selenium IDE验证点
  7. javascript中的一些偏门知识
  8. 运行 Docker 容器时的安全风险:别丢了你的套接字
  9. c#基础语言编程-Path和Directory
  10. java学习之break 和 continue
  11. php 对象的一些特性
  12. [C++程序设计]字符数组的赋值与引用
  13. 如何迅速成为Java高手
  14. Dubbo分布式服务子系统的划分
  15. POJ 2533 - Longest Ordered Subsequence - [最长递增子序列长度][LIS问题]
  16. c#等程序中的关于时间的最大值【DateTime.MaxValue】和最小值【DateTime.MinValue】
  17. Decimal integer conversion
  18. dede的cfg_keywords和cfg_description无法显示
  19. dxg:TreeListView.RowDecorationTemplate
  20. POSIX 线程 – pthread_sigmask

热门文章

  1. phaser运用中,dota战术板
  2. 如何在WPF应用程序中使用视频处理控件TVideoGrabber
  3. python PIL安装
  4. js 中的call()函数
  5. 【python cookbook】【数据结构与算法】13.通过公共键对字典列表排序
  6. flex 调用gp服务
  7. Spring使用p名称空间配置属性
  8. Hive与数据库的异同
  9. 在centos6.5-64bit上安装wxHexEditor,以查看编译二进制文件
  10. ectouch第八讲 之模板内容修改