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