Skip to content

Commit

Permalink
361:MDataTable增加Description属性。(2016-09-03)
Browse files Browse the repository at this point in the history
362:DBTool的GetColumns增加对表映射的支持(2016-09-05)
363:修正文本数据库的ResetTable方法(原表没有清空)(2016-09-06)
  • Loading branch information
cyq1162 committed Sep 6, 2016
1 parent e7f524a commit 6f00d15
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 136 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-09-02)")]
[assembly: AssemblyCompany("秋式软件 (2016-09-06)")]
[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.1")]
[assembly: AssemblyFileVersion("5.6.5.1")]
[assembly: AssemblyVersion("5.6.5.2")]
[assembly: AssemblyFileVersion("5.6.5.2")]
4 changes: 4 additions & 0 deletions SQL/SqlCreateForSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ internal static string CreateTableDescriptionSql(string tableName, MDataColumn c
}
}
}
if (dalType == DalType.MsSql)//增加表的描述
{
sb.AppendFormat("exec sp_addextendedproperty N'MS_Description', N'{0}', N'user', N'dbo', N'table', N'{1}';\r\n", columns.Description, tableName);
}
result = sb.ToString().TrimEnd(';');
break;
}
Expand Down
20 changes: 20 additions & 0 deletions Table/MDataColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,26 @@ public MDataTable Table
return _Table;
}
}
private string _Description = string.Empty;
/// <summary>
/// 表名描述
/// </summary>
public string Description
{
get
{
if (string.IsNullOrEmpty(_Description) && _Table != null)
{
return _Table.Description;
}
return _Description;
}
set
{
_Description = value;
}
}

internal MDataTable _Table;
public MDataColumn()
: base()
Expand Down
152 changes: 20 additions & 132 deletions Table/MDataTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,137 +23,7 @@ namespace CYQ.Data.Table
public partial class MDataTable
{
#region 隐式转换
/*
internal void ReadFromDbDataReader(DbDataReader sdr)
{
if (sdr != null)
{
if (Columns.Count > 0 && sdr.FieldCount > 0)
{
this.Rows.Clear();//如果直接从Row中加载架构,会多出一行,因此需要清除
#region 表架构处理(对于SetSelectColumns指定列查询时,需要去除一些列)

List<string> columns = new List<string>();//记录DataReader的列。
string name = string.Empty;
string hiddenFields = "," + AppConfig.DB.HiddenFields.ToLower() + ",";
bool isHiddenField = false;
for (int i = 0; i < sdr.FieldCount; i++)
{
name = sdr.GetName(i);
if (string.IsNullOrEmpty(name))
{
name = "Empty_" + i;
}
name = name.Trim('"');//sqlite的双引号问题。
isHiddenField = hiddenFields.IndexOf("," + name + ",", StringComparison.OrdinalIgnoreCase) > -1;
MCellStruct ms = Columns[name];
//isContain = Columns.Contains(name);
if (isHiddenField)
{
if (ms != null)
{
Columns.Remove(name);
}
else
{
continue;
}
}
else
{
if (ms != null)
{
ms.ReaderIndex = i;//设置和SDR对应的索引
Columns.SetOrdinal(name, i);
}
else
{
MCellStruct ms2 = new MCellStruct(name, DataType.GetSqlType(sdr.GetFieldType(i)));
ms2.ReaderIndex = i;
MDataCell mdc = new MDataCell(ref ms2);
Columns.Add(ms2);
}
}
columns.Add(name.ToLower());
}
for (int i = 0; i < Columns.Count; i++)//移除列。
{
if (!columns.Contains(Columns[i].ColumnName.ToLower()))
{
Columns.RemoveAt(i);
i--;
}
}
#endregion
#region 加载行数据
if (sdr.HasRows)
{
MDataRow mRecord = null;
object value = null;
List<int> errIndex = new List<int>();
while (sdr.Read())
{
mRecord = this.NewRow();
object[] values=new object[sdr.FieldCount];
for (int i = 0; i < Columns.Count; i++)
{
#region 读取数据
MCellStruct ms = Columns[i];
try
{
if (!errIndex.Contains(i))
{
value = ms.ReaderIndex > -1 ? sdr[ms.ReaderIndex] : sdr[ms.ColumnName];
}
else
{
value = sdr.GetString(ms.ReaderIndex > -1 ? ms.ReaderIndex : i);
}
}
catch
{
if (!errIndex.Contains(i))
{
errIndex.Add(i);
}
try
{
value = sdr.GetString(ms.ReaderIndex > -1 ? ms.ReaderIndex : i);
}
catch { }
}
if (value == null || value == DBNull.Value)
{
mRecord[i].cellValue.Value = DBNull.Value;
}
else if (Convert.ToString(value) == string.Empty)
{
mRecord[i].cellValue.Value = string.Empty;
mRecord[i].cellValue.IsNull = false;
}
else
{
mRecord[i].Value = value;
}
#endregion
}
Rows.Add(mRecord);
}
errIndex = null;
}
#endregion
}
sdr.Close();
sdr.Dispose();
sdr = null;
}
}
*/
/// <summary>
/// 从DataReader隐式转换成MDataTable
/// </summary>
Expand Down Expand Up @@ -290,7 +160,25 @@ public string TableName
_TableName = value;
}
}

private string _Description = string.Empty;
/// <summary>
/// 表名描述
/// </summary>
public string Description
{
get
{
if (string.IsNullOrEmpty(_Description))
{
return _TableName;
}
return _Description;
}
set
{
_Description = value;
}
}
private MDataColumn _Columns;
/// <summary>
/// 表格的架构列
Expand Down Expand Up @@ -598,7 +486,7 @@ public void Merge(MDataTable newTable)
{
for (int i = 0; i < newTable.Rows.Count; i++)
{
// _Rows.Add(newTable.Rows[i]);
// _Rows.Add(newTable.Rows[i]);
NewRow(true).LoadFrom(newTable.Rows[i]);
}
}
Expand Down
2 changes: 2 additions & 0 deletions Table/MDataTableJoin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ internal static MDataTable Join(MDataTable dtA, MDataTable dtB, params string[]
if (!isFind)
{
noFind.Add(v1);
joinRow = joinTable.NewRow(true);//找不到时,只加载A表。
joinRow.LoadFrom(row);//后载加A表(同名则复盖)
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions Tool/DBTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,10 @@ public static MDataColumn GetColumns(string tableName, string conn, out string e
Error.Throw(errInfo);
return null;
}
if (!tableName.Contains(" "))
{
tableName = GetMapTableName(conn, tableName);
}
MDataColumn mdc = TableSchema.GetColumns(tableName, ref helper);
helper.Dispose();
return mdc;
Expand Down
5 changes: 4 additions & 1 deletion 更新记录.txt
Original file line number Diff line number Diff line change
Expand Up @@ -573,4 +573,7 @@
357���ı����ݿ⣨NoSqlCommand������select a as b ������֧�֣�2016-09-02)
358��MAction�������Fillʱδ������ֵ�����⣨2016-09-02)
359��ORM��OrmBase��SimpleOrmBase������SetAopState������2016-09-02)
360��AutoCache������MAction��Fill������ʱ�Ļ������ã��ijɿ�¡��������Fillָ��ͬһ���棩��2016-09-02)
360��AutoCache������MAction��Fill������ʱ�Ļ������ã��ijɿ�¡��������Fillָ��ͬһ���棩��2016-09-02)
361��MDataTable����Description���ԡ���2016-09-03)
362��DBTool��GetColumns���ӶԱ�ӳ���֧�֣�2016-09-05)
363�������ı����ݿ��ResetTable������ԭ��û����գ���2016-09-06)

0 comments on commit 6f00d15

Please sign in to comment.