mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-18 20:08:15 +08:00
- 兼容 SqlServer varchar/nvarchar 表达式解析,分别解析为:N'' 和 '';
This commit is contained in:
@ -1,9 +1,11 @@
|
||||
using FreeSql.Internal;
|
||||
using FreeSql.Internal.Model;
|
||||
using SafeObjectPool;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Data.Common;
|
||||
using System.Data.Odbc;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
@ -26,8 +28,10 @@ namespace FreeSql.Odbc.SqlServer
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static DateTime dt1970 = new DateTime(1970, 1, 1);
|
||||
public override object AddslashesProcessParam(object param, Type mapType)
|
||||
string[] ncharDbTypes = new[] { "NVARCHAR", "NCHAR", "NTEXT" };
|
||||
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
|
||||
{
|
||||
if (param == null) return "NULL";
|
||||
if (mapType != null && mapType != param.GetType() && (param is IEnumerable == false || mapType.IsArrayOrList()))
|
||||
@ -35,7 +39,11 @@ namespace FreeSql.Odbc.SqlServer
|
||||
if (param is bool || param is bool?)
|
||||
return (bool)param ? 1 : 0;
|
||||
else if (param is string)
|
||||
{
|
||||
if (mapColumn != null && mapColumn.CsType.NullableTypeOrThis() == typeof(string) && ncharDbTypes.Any(a => mapColumn.Attribute.DbType.Contains(a)) == false)
|
||||
return string.Concat("'", param.ToString().Replace("'", "''"), "'");
|
||||
return string.Concat("N'", param.ToString().Replace("'", "''"), "'");
|
||||
}
|
||||
else if (param is char)
|
||||
return string.Concat("'", param.ToString().Replace("'", "''"), "'");
|
||||
else if (param is Enum)
|
||||
@ -58,7 +66,7 @@ namespace FreeSql.Odbc.SqlServer
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
var ie = param as IEnumerable;
|
||||
foreach (var z in ie) sb.Append(",").Append(AddslashesProcessParam(z, mapType));
|
||||
foreach (var z in ie) sb.Append(",").Append(AddslashesProcessParam(z, mapType, mapColumn));
|
||||
return sb.Length == 0 ? "(NULL)" : sb.Remove(0, 1).Insert(0, "(").Append(")").ToString();
|
||||
}
|
||||
return string.Concat("'", param.ToString().Replace("'", "''"), "'");
|
||||
|
@ -105,11 +105,11 @@ namespace FreeSql.Odbc.SqlServer
|
||||
if (objType == null) objType = callExp.Method.DeclaringType;
|
||||
if (objType != null || objType.IsArrayOrList())
|
||||
{
|
||||
tsc?.SetMapTypeTmp(null);
|
||||
tsc.SetMapColumnTmp(null);
|
||||
var args1 = getExp(callExp.Arguments[argIndex]);
|
||||
var oldMapType = tsc?.SetMapTypeReturnOld(tsc?.mapTypeTmp);
|
||||
var oldMapType = tsc.SetMapTypeReturnOld(tsc.mapTypeTmp);
|
||||
var left = objExp == null ? null : getExp(objExp);
|
||||
tsc.SetMapTypeReturnOld(oldMapType);
|
||||
tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType);
|
||||
switch (callExp.Method.Name)
|
||||
{
|
||||
case "Contains":
|
||||
|
Reference in New Issue
Block a user