zoukankan      html  css  js  c++  java
  • CUBRID学习笔记 33 net事务 cubrid教程示例

    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(); } } } }

      

  • 相关阅读:
    linux学习之centos(四):git的安装
    MongoDB学习
    linux学习之centos(三):mysql数据库的安装和配置
    面经中高频知识点归纳(三)
    各编程语言的内存分配方式
    carson常用linux命令整理
    在 Linux 虚拟机中手动安装或升级 VMware Tools
    Fidder 网络抓包调试工具
    面经中高频知识点归纳(二)
    java集合类
  • 原文地址:https://www.cnblogs.com/wang2650/p/5287945.html
Copyright © 2011-2022 走看看