/// <summary> /// 更新数据 /// </summary> /// <typeparam name="valueType">数据类型</typeparam> /// <typeparam name="modelType">模型类型</typeparam> /// <param name="sqlTool">SQL操作工具</param> /// <param name="connection">SQL连接</param> /// <param name="value">匹配成员值</param> /// <param name="memberMap">成员位图</param> /// <param name="query">查询信息</param> /// <returns>更新是否成功</returns> internal override bool Update <valueType, modelType> (Sql.Table <valueType, modelType> sqlTool, ref DbConnection connection, valueType value, MemberMap <modelType> memberMap, ref UpdateQuery <modelType> query) { if (query.NotQuery) { if (executeNonQuery(ref connection, query.UpdateSql) > 0) { sqlTool.CallOnUpdated(value, null, memberMap); return(true); } } else { GetQuery <modelType> getQuery = new GetQuery <modelType> { MemberMap = query.MemberMap, Sql = query.Sql }; valueType oldValue = AutoCSer.Emit.Constructor <valueType> .New(); if (Get(sqlTool, ref connection, oldValue, ref getQuery) && executeNonQuery(connection, query.UpdateSql) > 0 && Get(sqlTool, ref connection, value, ref getQuery)) { sqlTool.CallOnUpdated(value, oldValue, memberMap); return(true); } } return(false); }
/// <summary> /// 更新数据 /// </summary> /// <typeparam name="valueType">数据类型</typeparam> /// <typeparam name="modelType">模型类型</typeparam> /// <param name="sqlTool">SQL操作工具</param> /// <param name="connection">SQL连接</param> /// <param name="value">匹配成员值</param> /// <param name="memberMap">成员位图</param> /// <param name="query">查询信息</param> /// <returns>更新是否成功</returns> internal override ReturnType Update <valueType, modelType> (Sql.Table <valueType, modelType> sqlTool, ref DbConnection connection, valueType value, MemberMap <modelType> memberMap, ref UpdateQuery <modelType> query) { if (connection == null) { connection = GetConnection(); } if (connection != null) { sqlTool.Log.Error(query.Sql, LogLevel.Error | LogLevel.AutoCSer); if (query.NotQuery) { if (executeNonQuery(connection, query.Sql) > 0) { sqlTool.CallOnUpdated(value, null, memberMap); return(ReturnType.Success); } return(ReturnType.NotFoundData); } else { ReturnType returnType = ReturnType.Unknown; try { using (DbCommand command = getCommand(connection, query.Sql, CommandType.Text)) using (DbDataReader reader = command.ExecuteReader(CommandBehavior.SingleResult)) { if (reader.Read()) { valueType oldValue = AutoCSer.Metadata.DefaultConstructor <valueType> .Constructor(); DataModel.Model <modelType> .Setter.Set(reader, oldValue, query.MemberMap); if (reader.NextResult() && reader.Read()) { DataModel.Model <modelType> .Setter.Set(reader, value, query.MemberMap); sqlTool.CallOnUpdated(value, oldValue, memberMap); return(returnType = ReturnType.Success); } } } return(returnType = ReturnType.NotFoundData); } finally { if (returnType == ReturnType.Unknown) { sqlTool.Log.Error(query.Sql, LogLevel.Error | LogLevel.AutoCSer); } } } } return(ReturnType.ConnectionFailed); }
/// <summary> /// 更新数据 /// </summary> /// <typeparam name="valueType">数据类型</typeparam> /// <typeparam name="modelType">模型类型</typeparam> /// <param name="sqlTool">SQL操作工具</param> /// <param name="connection">SQL连接</param> /// <param name="value">匹配成员值</param> /// <param name="memberMap">成员位图</param> /// <param name="query">查询信息</param> /// <returns>更新是否成功</returns> internal override bool Update <valueType, modelType> (Sql.Table <valueType, modelType> sqlTool, ref DbConnection connection, valueType value, MemberMap <modelType> memberMap, ref UpdateQuery <modelType> query) { if (connection == null) { connection = GetConnection(); } if (connection != null) { sqlTool.Log.Add(AutoCSer.Log.LogType.Error, query.Sql); if (query.NotQuery) { if (executeNonQuery(connection, query.Sql) > 0) { sqlTool.CallOnUpdated(value, null, memberMap); return(true); } } else { bool isFinally = false; try { using (DbCommand command = getCommand(connection, query.Sql, CommandType.Text)) using (DbDataReader reader = command.ExecuteReader(CommandBehavior.SingleResult)) { if (reader.Read()) { valueType oldValue = AutoCSer.Emit.Constructor <valueType> .New(); DataModel.Model <modelType> .Setter.Set(reader, oldValue, query.MemberMap); if (reader.NextResult() && reader.Read()) { DataModel.Model <modelType> .Setter.Set(reader, value, query.MemberMap); sqlTool.CallOnUpdated(value, oldValue, memberMap); return(isFinally = true); } } } isFinally = true; } finally { if (!isFinally) { sqlTool.Log.Add(AutoCSer.Log.LogType.Error, query.Sql); } } } } return(false); }
/// <summary> /// 更新数据 /// </summary> /// <typeparam name="valueType">数据类型</typeparam> /// <typeparam name="modelType">模型类型</typeparam> /// <param name="sqlTool">SQL操作工具</param> /// <param name="transaction">事务操作</param> /// <param name="value">匹配成员值</param> /// <param name="memberMap">成员位图</param> /// <param name="query">查询信息</param> /// <returns>更新是否成功</returns> internal override bool Update <valueType, modelType> (Sql.Table <valueType, modelType> sqlTool, Transaction transaction, valueType value, MemberMap <modelType> memberMap, ref UpdateQuery <modelType> query) { if (sqlTool.CallOnUpdate(value, memberMap) && executeNonQuery(transaction, query.UpdateSql) > 0) { sqlTool.CallOnUpdated(transaction, value, memberMap); return(true); } return(false); }
/// <summary> /// 更新数据 /// </summary> /// <typeparam name="valueType">数据类型</typeparam> /// <typeparam name="modelType">模型类型</typeparam> /// <param name="sqlTool">SQL操作工具</param> /// <param name="transaction">事务操作</param> /// <param name="value">匹配成员值</param> /// <param name="memberMap">成员位图</param> /// <param name="query">查询信息</param> /// <returns>更新是否成功</returns> internal override ReturnType Update <valueType, modelType> (Sql.Table <valueType, modelType> sqlTool, Transaction transaction, valueType value, MemberMap <modelType> memberMap, ref UpdateQuery <modelType> query) { if (sqlTool.CallOnUpdate(value, memberMap)) { if (executeNonQuery(transaction, query.Sql) > 0) { sqlTool.CallOnUpdated(transaction, value, memberMap); return(ReturnType.Success); } return(ReturnType.NotFoundData); } return(ReturnType.EventCancel); }