Skip to content

Commit

Permalink
380:MAction Update的where条件Error时,RecordsAffected值从原来的0变更为-2;(2016-09-30)
Browse files Browse the repository at this point in the history
381:MDataTable 修正批量更新的返回值问题(2016-09-30)
382:MAction 内部增加IsIgnoreDeleteField 内部属性(2016-09-30)
  • Loading branch information
cyq1162 committed Sep 30, 2016
1 parent e300045 commit 3420cbc
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 22 deletions.
15 changes: 8 additions & 7 deletions Action/MAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,8 @@ public partial class MAction : IDisposable
#region 全局变量

internal DbBase dalHelper;//数据操作

private SqlCreate _sqlCreate;



private InsertOp _option = InsertOp.ID;

private NoSqlAction _noSqlAction = null;
private MDataRow _Data;//表示一行
/// <summary>
Expand Down Expand Up @@ -248,6 +243,10 @@ internal void SetIdentityInsertOff()
}
_AllowInsertID = false;
}
/// <summary>
/// 当DeleteField被设置后(删除转更新操作),如果仍想删除操作(可将些属性置为true)
/// </summary>
internal bool IsIgnoreDeleteField = false;
#endregion

#region 构造函数
Expand Down Expand Up @@ -512,6 +511,7 @@ private bool InsertOrUpdate(string sqlCommandText)
}
break;
default:
#region MyRegion
bool isTrans = dalHelper.isOpenTrans;
int groupID = DataType.GetGroup(_Data.PrimaryCell.Struct.SqlType);
bool isNum = groupID == 1 && _Data.PrimaryCell.Struct.Scale <= 0;
Expand Down Expand Up @@ -539,6 +539,7 @@ private bool InsertOrUpdate(string sqlCommandText)
{
dalHelper.EndTransaction();
}
#endregion
break;
}
if ((ID != null && Convert.ToString(ID) != "-2") || (dalHelper.recordsAffected > -2 && _option == InsertOp.None))
Expand All @@ -555,7 +556,7 @@ private bool InsertOrUpdate(string sqlCommandText)
returnResult = dalHelper.ExeNonQuery(sqlCommandText, false) > 0;
}
}
else if (!_isInsertCommand && _Data.GetState() == 1) // 更新操作。
else if (!_isInsertCommand && _Data.GetState() == 1 && dalHelper.recordsAffected != -2) // 更新操作。
{
//输出警告信息
return true;
Expand Down Expand Up @@ -794,7 +795,7 @@ public bool Delete(object where)
if (aopResult == AopResult.Default || aopResult == AopResult.Continue)
{
string deleteField = AppConfig.DB.DeleteField;
bool isToUpdate = !string.IsNullOrEmpty(deleteField) && _Data.Columns.Contains(deleteField);
bool isToUpdate =!IsIgnoreDeleteField && !string.IsNullOrEmpty(deleteField) && _Data.Columns.Contains(deleteField);
switch (dalHelper.dalType)
{
case DalType.Txt:
Expand Down
6 changes: 3 additions & 3 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[assembly: AssemblyTitle("CYQ.Data 数据层(ORM)框架 V5 版本")]
[assembly: AssemblyDescription("论坛:http://www.cyqdata.com/cyqdata")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("秋式软件 (2016-09-29)")]
[assembly: AssemblyCompany("秋式软件 (2016-09-30)")]
[assembly: AssemblyProduct("CYQ.Data 数据层(ORM)框架 V5 版本")]
[assembly: AssemblyCopyright("版权所有 (C) 秋式软件 2010-2020")]
[assembly: AssemblyTrademark("CYQ.Data")]
Expand All @@ -31,5 +31,5 @@
//
// 可以指定所有这些值,也可以使用“修订号”和“内部版本号”的默认值,
// 方法是按如下所示使用“*”:
[assembly: AssemblyVersion("5.6.5.8")]
[assembly: AssemblyFileVersion("5.6.5.8")]
[assembly: AssemblyVersion("5.6.5.9")]
[assembly: AssemblyFileVersion("5.6.5.9")]
10 changes: 4 additions & 6 deletions SQL/SqlCreate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,13 @@ internal string GetInsertSql()
if (cell.IsNull && !cell.Struct.IsCanNull && cell.Struct.DefaultValue == null)
{
_action.dalHelper.debugInfo.Append(AppConst.HR + "error : " + cell.ColumnName + " can't be null" + AppConst.BR);
_action.dalHelper.recordsAffected = -2;
isCanDo = false;
break;
}
if (cell.cellValue.State > 0)
{
_TempSql.Append("[" + cell.ColumnName + "],");
_TempSql.Append(SqlFormat.Keyword(cell.ColumnName, _action.DalType) + ",");
_TempSql2.Append(_action.dalHelper.Pre + cell.ColumnName + ",");
object value = cell.Value;
DbType dbType = DataType.GetDbType(cell.Struct.SqlType.ToString(), _action.DalType);
Expand All @@ -139,16 +140,12 @@ internal string GetInsertSql()
switch (_action.dalHelper.dalType)
{
case DalType.Oracle:
_TempSql = _TempSql.Replace("[", "").Replace("]", "");
if (!_action.AllowInsertID && DataType.GetGroup(primaryCell.Struct.SqlType) == 1)
{
_TempSql.Append(primaryCell.ColumnName + ",");
_TempSql2.Append(AutoID + ".nextval,");
}
break;
case DalType.MySql:
_TempSql = _TempSql.Replace("[", "`").Replace("]", "`");
break;
}

string sql = _TempSql.ToString().TrimEnd(',') + _TempSql2.ToString().TrimEnd(',') + ")";
Expand Down Expand Up @@ -371,7 +368,7 @@ internal string GetColumnsSql()
}
else
{
_action.dalHelper.debugInfo.Append(AppConst.HR + "error : " + TableName + " no contains column " + columnName + AppConst.BR);
_action.dalHelper.debugInfo.Append(AppConst.HR + "warn : " + TableName + " no contains column " + columnName + AppConst.BR);
}
}
}
Expand Down Expand Up @@ -518,6 +515,7 @@ private string GetWhereFromObj(object whereObj)
if (cell.IsNullOrEmpty)
{
isCanDo = false;
_action.dalHelper.recordsAffected = -2;
_action.dalHelper.debugInfo.Append(AppConst.HR + "error : " + cell.ColumnName + " can't be null" + AppConst.BR);
return "1=2 and " + cell.ColumnName + " is null";
}
Expand Down
11 changes: 6 additions & 5 deletions Table/MDataTableBatchAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@ bool IsAllowMySqlBulkCopy()

return false;
}
return true;
}
internal bool MySqlBulkCopyInsert(bool keepID)
{
Expand Down Expand Up @@ -632,6 +631,7 @@ internal bool BulkCopyUpdate()
{
int count = 0, pageSize = 5000;
MDataTable dt = null;
bool result = false;
using (MAction action = new MAction(mdt.TableName, _Conn))
{
action.SetAopState(Aop.AopOp.CloseAll);
Expand All @@ -650,7 +650,6 @@ internal bool BulkCopyUpdate()
action.BeginTransation();
}

bool result = false;
MCellStruct keyColumn = jointPrimaryIndex != null ? mdt.Columns[jointPrimaryIndex[0]] : mdt.Columns.FirstPrimary;
string columnName = keyColumn.ColumnName;
for (int i = 0; i < count; i++)
Expand All @@ -662,7 +661,9 @@ internal bool BulkCopyUpdate()
string whereIn = SqlCreate.GetWhereIn(keyColumn, dt.GetColumnItems<string>(columnName, BreakOp.NullOrEmpty, true), action.DalType);
MDataTable dtData = action.Select(whereIn);//获取远程数据。
dtData.Load(dt);//重新加载赋值。
result = action.Delete(whereIn);//如果存在IsDeleted,会被转Update(导致后续无法Insert)
action.IsIgnoreDeleteField = true;//处理如果存在IsDeleted,会被转Update(导致后续无法Insert)、外层也有判断,不会进来。
result = action.Delete(whereIn);
action.IsIgnoreDeleteField = false;
if (result)
{
dtData.DynamicData = action;
Expand All @@ -677,14 +678,14 @@ internal bool BulkCopyUpdate()
}
if (_dalHelper == null)
{
action.BeginTransation();
action.EndTransation();
}
else
{
action.dalHelper = sourceHelper;//还原。
}
}
return true;
return result;
}
internal bool Auto()
{
Expand Down
5 changes: 4 additions & 1 deletion 更新记录.txt
Original file line number Diff line number Diff line change
Expand Up @@ -592,4 +592,7 @@
376��SqlCompatible���Ӷԣ�+ ||����Left��Right�����Ĵ�����2016-09-24)
377��Oracle��ODP.NET������BindByName��Ϊtrue��2016-09-24)
378��MDataRowCollection AddNew����������Winform��DataGrid��ʱ���ڿհ��к����������ص��ʱ�������ӿհ����ݵ����⡣��2016-09-29)
379��MAction SetPara�������ط�����2016-09-29)
379��MAction SetPara�������ط�����2016-09-29)
380��MAction Update��where����Errorʱ��RecordsAffectedֵ��ԭ����0���Ϊ-2����2016-09-30)
381��MDataTable �����������µķ���ֵ���⣨2016-09-30)
382��MAction �ڲ�����IsIgnoreDeleteField �ڲ����ԣ�2016-09-30)

0 comments on commit 3420cbc

Please sign in to comment.