Skip to content

Commit

Permalink
376:SqlCompatible增加对(+ ||)、Left和Right函数的处理(2016-09-24)
Browse files Browse the repository at this point in the history
377:Oracle的ODP.NET参数添BindByName置为true(2016-09-24)
378:MDataRowCollection AddNew方法,处理Winform(DataGrid绑定时)在空白行和数据行来回点击时不断添加空白数据的问题。(2016-09-29)
379:MAction SetPara增加重载方法(2016-09-29)
  • Loading branch information
cyq1162 committed Sep 29, 2016
1 parent 035fba0 commit e300045
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 9 deletions.
7 changes: 7 additions & 0 deletions Action/MAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,13 @@ public MAction SetExpression(string updateExpression)
_sqlCreate.updateExpression = updateExpression;
return this;
}
/// <summary>
/// 参数化传参[当Where条件为参数化(如:name=@name)语句时使用]
/// </summary>
public MAction SetPara(object paraName, object value)
{
return SetPara(paraName, value, DbType.String);
}
List<AopCustomDbPara> customParaNames = new List<AopCustomDbPara>();
/// <summary>
/// 参数化传参[当Where条件为参数化(如:name=@name)语句时使用]
Expand Down
9 changes: 9 additions & 0 deletions DAL/DbBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,15 @@ public void ClearParameters()

private void SetCommandText(string commandText, bool isProc)
{
if (OracleDal.clientType > 0)
{
Type t = _com.GetType();
System.Reflection.PropertyInfo pi = t.GetProperty("BindByName");
if (pi != null)
{
pi.SetValue(_com, true, null);
}
}
_com.CommandText = isProc ? commandText : SqlFormat.Compatible(commandText, dalType, false);
if (!isProc && dalType == DalType.SQLite && _com.CommandText.Contains("charindex"))
{
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-22)")]
[assembly: AssemblyCompany("秋式软件 (2016-09-29)")]
[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.7")]
[assembly: AssemblyFileVersion("5.6.5.7")]
[assembly: AssemblyVersion("5.6.5.8")]
[assembly: AssemblyFileVersion("5.6.5.8")]
68 changes: 67 additions & 1 deletion SQL/SqlCompatible.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,80 @@ internal static string Format(string text, DalType dalType)
text = FormatLen(text, dalType);
text = FormatGUID(text, dalType);
text = FormatIsNull(text, dalType);
text = FormatContact(text, dalType);
text = FormatLeft(text, dalType);
text = FormatRight(text, dalType);
text = FormatDate(text, dalType, SqlValue.Year, "Year");
text = FormatDate(text, dalType, SqlValue.Month, "Month");
text = FormatDate(text, dalType, SqlValue.Day, "Day");
}
return text;
}
#region 过滤与多数据库标签解析

internal static string FormatLeft(string text, DalType dalType)
{
switch (dalType)
{
//substr(MAX(SheetId),1,4)) IS NULL THEN 0 ELSE substr(MAX(SheetId)length(MAX(SheetId))-4,4)
case DalType.Oracle:
int index = text.IndexOf(SqlValue.Left);//left(a,4) =>to_char(substr(a,1,4))
if (index > -1)
{
do
{
index = text.IndexOf('(', index);
int end = text.IndexOf(',', index);
int end2 = text.IndexOf(')', end + 1);
text = text.Insert(end2, ")");
text = text.Insert(end + 1, "1,");
index = text.IndexOf(SqlValue.Left, end);//寻找还有没有第二次出现的函数字段
}
while (index > -1);
return text.Replace(SqlValue.Left, "to_char(substr");
}
return text;
default:
return text.Replace(SqlValue.Left, "Left");
}
}
internal static string FormatRight(string text, DalType dalType)
{
switch (dalType)
{
case DalType.Oracle:
int index = text.IndexOf(SqlValue.Right);//right(a,4) => to_char(substr(a,length(a)-4,4))
if (index > -1)
{
do
{
////substr(MAX(SheetId),1,4)) IS NULL THEN 0 ELSE substr(MAX(SheetId)length(MAX(SheetId))-4,4)
index = text.IndexOf('(', index);
int end = text.IndexOf(',', index);
string key = text.Substring(index + 1, end - index - 1);//找到 a
int end2 = text.IndexOf(')', end + 1);
string key2 = text.Substring(end + 1, end2 - end - 1);//找到b
text = text.Insert(end2, ")");
text = text.Insert(end + 1, "length(" + key + ")+1-" + key2 + ",");//
index = text.IndexOf(SqlValue.Right, end);//寻找还有没有第二次出现的函数字段
}
while (index > -1);
return text.Replace(SqlValue.Right, "to_char(substr");
}
return text;
default:
return text.Replace(SqlValue.Right, "Right");
}
}
internal static string FormatContact(string text, DalType dalType)
{
switch (dalType)
{
case DalType.Oracle:
return text.Replace(SqlValue.Contact, "||");
default:
return text.Replace(SqlValue.Contact, "+");
}
}
internal static string FormatIsNull(string text, DalType dalType)
{
switch (dalType)
Expand Down
14 changes: 14 additions & 0 deletions SQL/SqlValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,19 @@ public class SqlValue
/// </example>
/// </summary>
public const string CaseWhen = "[#CASE#WHEN]";//多条件分支
/// <summary>
/// 数据库链接符号 + Oracle下为:||
/// </summary>
public const string Contact = "[#+]";//多条件分支

/// <summary>
/// 数据库Left函数
/// </summary>
public const string Left = "[#LEFT]";//多条件分支

/// <summary>
/// 数据库Right函数
/// </summary>
public const string Right = "[#RIGHT]";//多条件分支
}
}
19 changes: 15 additions & 4 deletions Table/MDataRowCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ private void CheckError(MDataRow item, IEnumerable<MDataRow> collection)
/// </summary>
public partial class MDataRowCollection : IBindingList
{


void IBindingList.AddIndex(PropertyDescriptor property)
{
Expand All @@ -254,7 +254,18 @@ void IBindingList.AddIndex(PropertyDescriptor property)

object IBindingList.AddNew()
{
return this.Table.NewRow(true);
if (Count > 0)
{
MDataRow row = this[Count - 1];
foreach (MDataCell cell in row)
{
if (!cell.IsNull) // 避免重复新增加空行。
{
return this.Table.NewRow(true);
}
}
}
return null;
}

bool IBindingList.AllowEdit
Expand Down Expand Up @@ -303,7 +314,7 @@ event ListChangedEventHandler IBindingList.ListChanged

void IBindingList.RemoveIndex(PropertyDescriptor property)
{

}

void IBindingList.RemoveSort()
Expand Down Expand Up @@ -380,7 +391,7 @@ void System.Collections.IList.Remove(object value)
void System.Collections.IList.RemoveAt(int index)
{
this.RemoveAt(index);
this.onListChanged(this,ResetEventArgs);
this.onListChanged(this, ResetEventArgs);

}

Expand Down
6 changes: 5 additions & 1 deletion 更新记录.txt
Original file line number Diff line number Diff line change
Expand Up @@ -588,4 +588,8 @@
372��JsonHelper.ToJson���Ӷ�List<MDataTable>��List<DataTable>��֧�֣�2016-09-20)
373��DBBase����Oracle�·��ص�DataBase�������⡣��2016-09-21)
374��Oracle�ļ��ط�ʽ����Сϸ���Ż���2016-09-22)
375��StaticTool����ChangeType�ж���Guid��ת����2016-09-22)
375��StaticTool����ChangeType�ж���Guid��ת����2016-09-22)
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)

0 comments on commit e300045

Please sign in to comment.