using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Data; using System.Data.Common; using System.Data.SqlClient; using System.Linq; using System.Text; namespace MJTop.Data.SPI { public interface IDB { //void BeginTran(); //void BeginTran(IsolationLevel isolationLevel); //void Commit(); //void Rollback(); #region AOP拦截 Action OnExecuting { get; set; } Action OnExecuted { get; set; } Action OnError { get; set; } #endregion TableTrigger DataChangeTriggers { get; } NameValueCollection GetInsertExcludeColumns(); ExcludeColumn InsertExcludeColumns { get; } NameValueCollection GetUpdateExcludeColumns(); ExcludeColumn UpdateExcludeColumns { get; } #region Bool查询 bool TryConnect(); bool ValidateSql(string strSql, out Exception ex); void CheckTabStuct(string tableName, params string[] columnNames); #endregion int RunStoreProc(string storeProcName, object parms = null); DataTable RunStoreProcGetDT(string storeProcName, object parms = null); DataSet RunStoreProcGetDS(string storeProcName, object parms = null); #region 基础查询 TRet Scalar(string strSql, TRet defRet, object parms = null); NameValueCollection GetFirstRow(string strSql, object parms = null); DataTable GetDataTable(string strSql, object parms = null); List GetListTable(string strSql, object parms = null); DataSet GetDataSet(string strSql, object parms = null); DbDataReader ExecReader(string commandText, object parms = null, CommandType commandType = CommandType.Text); TRet Single(string strSql, TRet defRet, object parms = null); List> GetListDictionary(string strSql, object parms = null); DataTable ReadTable(string strSql, object parms = null); List ReadList(string strSql, object parms = null); NameValueCollection ReadNameValues(string strSql, object parms = null); Dictionary ReadDictionary(string strSql, object parms = null, IEqualityComparer comparer = null); #endregion #region 执行 int ExecSql(string strSql, object parms = null); int ExecSqlTran(string strSql, object parms = null); int ExecSqlTran(params string[] sqlCmds); int ExecSqlTran(List>> strSqlList); #endregion int BulkInsert(string tableName, DataTable data, int batchSize = 200000, int timeout = 60); int BulkInsert(string tableName, DbDataReader reader, int batchSize = 200000, int timeout = 60); #region 根据表名,列名,列相关操作 bool Exist(string tableName, string columnName, object columnValue, params object[] excludeValues); bool Insert
(DT data, string tableName, params string[] excludeColNames); int InsertGetInt
(DT data, string tableName, params string[] excludeColNames); long InsertGetLong
(DT data, string tableName, params string[] excludeColNames); bool Update
(DT data, string tableName, string pkOrUniqueColName = "Id", params string[] excludeColNames); KeyValuePair Save
(DT data, string tableName, string pkOrUniqueColName = "Id", params string[] excludeColNames); bool UpSingle(string tableName, string columnName, object columnValue, object pkOrUniqueValue, string pkOrUniqueColName = "Id"); bool DeleteAll(string tableName); int Delete(string tableName, object pkOrUniqueColName); int Delete(string tableName, string columnName, params object[] columnValues); #endregion T Get(string tableName, object parms) where T : class, new(); T GetById(string tableName, object pkValue) where T : class, new(); List GetByIds(string tableName, object[] pkValues) where T : class, new(); List GetList(string tableName, object parms) where T : class, new(); List GetList(string strSql) where T : class, new(); DataTable SelectAll(string tableName, string orderbyStr = null); DataTable SelectTop(string tableName, int top, string orderbyStr = null); long SelectCount(string tableName, string whereAndStr = null); DataTable SelectTable(string joinTableName, string whereStr, string orderbyStr); KeyValuePair GetDataTableByPager(int currentPage, int pageSize, string selColumns, string joinTableName, string whereStr, string orderbyStr); } }