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