/// <summary> /// 失败表示存在更新影响条数为0的update /// </summary> public override bool UpdateAll <T>(DbQueryBuilder queryBuilder) { bool result = true; DbCommand command = Session.CreateCommand(); foreach (var updateBuilder in queryBuilder.UpdateBuilders) { command.CommandText = updateBuilder.ToQueryString(Session, new T().TableName); updateBuilder.AddParameter(command, Session); WriteQueryLog(command, Session); result = result && Session.ExecuteNonQuery(command) > 0; } return(result); }
/// <summary> /// 提供对应数据库的数据库语句构建类 /// </summary> /// <param name="session"></param> /// <returns></returns> public static DbQueryBuilder GetDbQueryBuilder(this DbSession session) { DbQueryBuilder result; switch (session.DatabaseType) { case EDatabaseType.MSSQL: case EDatabaseType.MySQL: //TODO MySQL暂时启用MSSQL方案 case EDatabaseType.SQLite: // TODO SQLite暂时启用MSSQL方案 result = new DbQueryBuilder(); break; case EDatabaseType.Oracle: //TODO 未支持多数据库 default: throw new NotImplementedException("未实现该类别的QueryBuilder" + session.DatabaseType); } return(result); }
/// <summary> /// 失败表示影响数据为0 /// </summary> public override bool Delete <T>(DbQueryBuilder queryBuilder) { var deleteBuilder = queryBuilder.DeleteBuilder; return(Delete <T>(deleteBuilder)); }
/// 组合查询 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="Session"></param> /// <param name="queryBuilder"></param> /// <returns></returns> public override List <T> SelectUnion <T>(DbQueryBuilder queryBuilder) { throw new NotImplementedException(); }
/// <summary> /// 失败返回 new List<T>() /// </summary> public override List <T> SelectAll <T>(DbQueryBuilder queryBuilder) { SelectBuilder selectBuilder = queryBuilder.SelectBuilders.First(); return(SelectAll <T>(selectBuilder)); }
/// <summary> /// 返回 是否成功新增 /// </summary> public override bool Insert <T>(DbQueryBuilder queryBuilder) { var insertBuilder = queryBuilder.InsertBuilders.First(); return(Insert <T>(insertBuilder)); }
/// <summary> /// 失败返回null /// </summary> public override T Select <T>(DbQueryBuilder queryBuilder) { SelectBuilder selectBuilder = queryBuilder.SelectBuilders.FirstOrDefault(); return(Select <T>(selectBuilder)); }
/// <summary> /// 失败表示存在更新影响条数为0的update /// </summary> public override bool Update <T>(DbQueryBuilder queryBuilder) { var updateBuilder = queryBuilder.UpdateBuilders.First(); return(Update <T>(updateBuilder)); }
/// <summary> /// 返回 是否有数据受操作影响 /// </summary> public abstract bool Insert <T>(DbQueryBuilder queryBuilder) where T : VLModel_DB, new();
public abstract List <T> SelectAll <T>() where T : VLModel_DB, new();//IDbSession session /// <summary> /// 未查询到数据时返回 New List() /// 多个SelectBuilder组合查询 /// </summary> public abstract List <T> SelectUnion <T>(DbQueryBuilder queryBuilder) where T : VLModel_DB, new();
/// <summary> /// 未查询到数据时返回 null /// </summary> public abstract T Select <T>(DbQueryBuilder queryBuilder) where T : VLModel_DB, new();
/// <summary> /// 返回 是否有数据受操作影响 /// </summary> public abstract bool UpdateAll <T>(DbQueryBuilder queryBuilder) where T : VLModel_DB, new();
/// <summary> /// 返回 是否有数据受操作影响 /// </summary> public abstract bool Delete <T>(DbQueryBuilder queryBuilder) where T : VLModel_DB, new();