Skip to content

Commit

Permalink
396:JsonHelper 修正Json嵌套问题。(2016-10-18)
Browse files Browse the repository at this point in the history
397:MDataTable 优化批量更新问题。(2016-10-18)
  • Loading branch information
cyq1162 committed Oct 18, 2016
1 parent f407e61 commit ae6aaba
Show file tree
Hide file tree
Showing 5 changed files with 484 additions and 358 deletions.
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-10-17)")]
[assembly: AssemblyCompany("秋式软件 (2016-10-18)")]
[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.6.7")]
[assembly: AssemblyFileVersion("5.6.6.7")]
[assembly: AssemblyVersion("5.6.6.8")]
[assembly: AssemblyFileVersion("5.6.6.8")]
18 changes: 16 additions & 2 deletions SQL/SqlCreate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,15 @@ internal static string GetWhereIn(MCellStruct ms, List<string> items, DalType da
}

internal static string MySqlBulkCopySql = "LOAD DATA LOCAL INFILE '{0}' INTO TABLE {1} CHARACTER SET utf8 FIELDS TERMINATED BY '{2}' LINES TERMINATED BY '\r\n' {3}";

internal static string OracleBulkCopySql = "LOAD DATA INFILE '{0}' APPEND INTO TABLE {1} FIELDS TERMINATED BY '{2}' OPTIONALLY ENCLOSED BY '\"' {3}";
internal static string OracleSqlIDR = " userid={0} control='{1}' log='{2}'";//sqlldr
/// <summary>
/// 获得批量导入的列名。
/// </summary>
/// <param name="mdc"></param>
/// <param name="keepID"></param>
/// <param name="dalType"></param>
/// <returns></returns>
internal static string GetColumnName(MDataColumn mdc, bool keepID, DalType dalType)
{
StringBuilder sb = new StringBuilder();
Expand All @@ -814,7 +822,13 @@ internal static string GetColumnName(MDataColumn mdc, bool keepID, DalType dalTy
{
continue;
}
sb.Append(SqlFormat.Keyword(ms.ColumnName, dalType) + ",");
sb.Append(SqlFormat.Keyword(ms.ColumnName, dalType));
if (dalType == DalType.Oracle && DataType.GetGroup(ms.SqlType) == 2)
{
//日期
sb.Append(" DATE \"YYYY-MM-DD HH24:MI:SS\" NULLIF (" + ms.ColumnName + "=\"NULL\")");
}
sb.Append(",");
}
return sb.ToString().TrimEnd(',') + ")";
}
Expand Down
62 changes: 45 additions & 17 deletions Table/MDataRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1176,35 +1176,63 @@ internal void SetToEntity(ref object obj, MDataRow row)
int len = StaticTool.GetArgumentLength(ref propType, out argTypes);
if (len == 1) // Table
{
List<string> items = JsonSplit.SplitEscapeArray(cell.strValue);//内部去掉转义符号
objValue = Activator.CreateInstance(propType, items.Count);//创建实例
Type objListType = objValue.GetType();
bool isArray = sysType == SysType.Array;
for (int i = 0; i < items.Count; i++)

if (JsonSplit.IsJson(cell.strValue) && cell.strValue.Contains(":") && cell.strValue.Contains("{"))
{
MethodInfo method;
if (isArray)
#region Json嵌套处理。
MDataTable dt = MDataTable.CreateFrom(cell.strValue);//, SchemaCreate.GetColumns(argTypes[0])
objValue = Activator.CreateInstance(propType, dt.Rows.Count);//创建实例
Type objListType = objValue.GetType();
foreach (MDataRow rowItem in dt.Rows)
{
Object item = StaticTool.ChangeType(items[i], Type.GetType(propType.FullName.Replace("[]", "")));
method = objListType.GetMethod("Set");
object o = GetValue(rowItem, argTypes[0]);
MethodInfo method = objListType.GetMethod("Add");
if (method == null)
{
method = objListType.GetMethod("Push");
}
if (method != null)
{
method.Invoke(objValue, new object[] { i, item });
method.Invoke(objValue, new object[] { o });
}
}
else
dt = null;
#endregion
}
else
{
#region 数组处理
List<string> items = JsonSplit.SplitEscapeArray(cell.strValue);//内部去掉转义符号
objValue = Activator.CreateInstance(propType, items.Count);//创建实例
Type objListType = objValue.GetType();
bool isArray = sysType == SysType.Array;
for (int i = 0; i < items.Count; i++)
{
Object item = StaticTool.ChangeType(items[i], argTypes[0]);
method = objListType.GetMethod("Add");
if (method == null)
MethodInfo method;
if (isArray)
{
method = objListType.GetMethod("Push");
Object item = StaticTool.ChangeType(items[i], Type.GetType(propType.FullName.Replace("[]", "")));
method = objListType.GetMethod("Set");
if (method != null)
{
method.Invoke(objValue, new object[] { i, item });
}
}
if (method != null)
else
{
method.Invoke(objValue, new object[] { item });
Object item = StaticTool.ChangeType(items[i], argTypes[0]);
method = objListType.GetMethod("Add");
if (method == null)
{
method = objListType.GetMethod("Push");
}
if (method != null)
{
method.Invoke(objValue, new object[] { item });
}
}
}
#endregion
}
}
else if (len == 2) // row
Expand Down
Loading

0 comments on commit ae6aaba

Please sign in to comment.