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

      

  • 相关阅读:
    mentohust 使用
    查找 GPU 计算能力
    在写代码过程中遇到的问题,以及当时的解决方法(如实记录)
    ubuntu14.04 解决屏幕亮度无法调节的问题
    Ubuntu14.04下安装 boost (boost_1.54 最简单的方法)
    在 Ubuntu下安装 labelImg (标数据用)
    在树莓派上配置MariaDB
    使用Telegraf + Influxdb + Grafana 监控SQLserver服务器的运行状况
    如何读懂SQL Server的事务日志
    ActiveMQ安装使用与spring整合配置教程
  • 原文地址:https://www.cnblogs.com/wang2650/p/5287945.html
Copyright © 2011-2022 走看看