/* * 作者:吴隆健 * 日期: 2019-04-23 * 时间: 13:17 * */ using System; using System.Data; using System.Collections.Generic; using System.Data.SqlClient; using System.Threading.Tasks; namespace MrWu.DB { /// /// sql链接 T是sql的链接类型 K是指令类型 M是参数类型 /// public interface ISqlEx { /// /// 链接池 /// IConnectionPool connPool { get; } /// /// 获取一个连接 /// /// /// T GetConnection(string dbbase); /// /// 开始执行存储过程 /// /// 数据库名称 /// 存储过程名称 /// IProdureParameter BeginProcedure(string dbbase,string procedure); /// /// 给存储过程添加参数 /// /// 存储过程命令 /// 参数名 /// 参数值 /// 参数类型 /// 参数种类 void AddParam(IProdureParameter spp,string paramName,object value,M type,ParameterDirection pd = ParameterDirection.Input); /// /// 提交存储过程 /// /// 存储过程命令 /// 查询的结果集 /// 重试次数 小于0表示使用配置值 大于等于0表示自定义 /// 执行存储过程所有参数 Dictionary SubProcedure(IProdureParameter spp, DataSet ds = null,int againCount = -1); /// /// 执行sql语句 /// /// 数据库名称 /// sql语句 /// sql的额外参数 /// 查询的结果集 /// 重试次数 小于0表示使用配置值 大于等于0表示自定义 /// 受影响的行数 int ExecuteSql(string dbbase,string sql,IEnumerable sqlparams = null,DataSet ds = null,int againCount = -1); /// /// 执行一个普通的查询 /// /// 数据库名称 /// 数据库表名 /// 查询的列 /// 查询条件 /// 查询的行数 /// 重试次数 小于0表示使用配置值 大于等于0表示自定义 /// sql参数 /// 查询的结果集 DataTable Select(string dbbase, string table, string[] column = null, string where = null, int count = 0,int againCount = -1, IEnumerable sqlparams = null); /// /// 执行cmd /// /// 数据库指令 /// 数据库名称 /// 结果集 /// 重试次数 小于0表示使用配置值 大于等于0表示自定义 /// 受影响的行数 int Execute(K cmd,string dbname, DataSet ds = null,int againCount = -1); /// /// 执行一个事务 /// /// 数据库名称 /// 存储过程指令 IProdureParameter BeginTransaction(string dbbase); /// /// 为事务添加sql语句 /// /// 存储过程指令 /// sql语句 /// 额外参数 int TransactionAddSql(IProdureParameter spp, string sql, List> sqlparams = null); /// /// 提交一个事务 /// /// 存储过程指令 /// bool SubTransaction(IProdureParameter spp); /// /// 回滚事务 /// /// void RollbackTransaction(IProdureParameter spp); #region 异步方法 /// /// 异步提交存储过程 /// /// 存储过程命令 /// 查询的结果集 /// 重试次数 小于0表示使用配置值 大于等于0表示自定义 /// 执行存储过程所有参数 Task> SubProcedureAsync(IProdureParameter spp, DataSet ds = null, int againCount = -1); /// /// 异步执行sql语句 /// /// 数据库名称 /// sql语句 /// sql的额外参数 /// 查询的结果集 /// 重试次数 小于0表示使用配置值 大于等于0表示自定义 /// 受影响的行数 Task ExecuteSqlAsync(string dbbase, string sql, IEnumerable sqlparams = null, DataSet ds = null, int againCount = -1); /// /// 异步执行一个普通的查询 /// /// 数据库名称 /// 数据库表名 /// 查询的列 /// 查询条件 /// 查询的行数 /// 重试次数 小于0表示使用配置值 大于等于0表示自定义 /// sql参数 /// 查询的结果集 Task SelectAsync(string dbbase, string table, string[] column = null, string where = null, int count = 0, int againCount = -1, IEnumerable sqlparams = null); /// /// 异步执行cmd /// /// 数据库指令 /// 数据库名称 /// 结果集 /// 重试次数 小于0表示使用配置值 大于等于0表示自定义 /// 受影响的行数 Task ExecuteAsync(K cmd, string dbname, DataSet ds = null, int againCount = -1); #endregion } }