- 禁止 Contains 表达式元素参数化

This commit is contained in:
28810 2019-11-22 23:14:32 +08:00
parent 6e6135e9e7
commit 26d1d961b8
13 changed files with 31 additions and 7 deletions

View File

@ -110,13 +110,6 @@
清空状态数据 清空状态数据
</summary> </summary>
</member> </member>
<member name="M:FreeSql.DbSet`1.RemoveAsync(System.Linq.Expressions.Expression{System.Func{`0,System.Boolean}})">
<summary>
根据 lambda 条件删除数据
</summary>
<param name="predicate"></param>
<returns></returns>
</member>
<member name="M:FreeSql.DbSet`1.Add(`0)"> <member name="M:FreeSql.DbSet`1.Add(`0)">
<summary> <summary>
添加 添加

View File

@ -348,6 +348,11 @@ namespace FreeSql.Tests
g.sqlserver.Select<TestMySqlStringIsNullable>().Where(a => a.varchar == name).ToList(); g.sqlserver.Select<TestMySqlStringIsNullable>().Where(a => a.varchar == name).ToList();
g.sqlserver.Select<TestMySqlStringIsNullable>().Where(a => a.varchar == name.SetDbParameter(10)).ToList(); g.sqlserver.Select<TestMySqlStringIsNullable>().Where(a => a.varchar == name.SetDbParameter(10)).ToList();
var testarr = new string[] { "1", "2" };
var sdfsdgselect3 = g.sqlserver.Select<TestMySqlStringIsNullable>().Where(a => testarr.Contains(a.varchar));
g.sqlserver.Select<TestMySqlStringIsNullable>().Where(a => testarr.Contains(a.varchar)).ToList();
} }
} }

View File

@ -1225,6 +1225,12 @@ namespace FreeSql.Internal
this.mapType = newValue; this.mapType = newValue;
return old; return old;
} }
public List<DbParameter> SetDbParamsReturnOld(List<DbParameter> newValue)
{
var old = this.dbParams;
this.dbParams = newValue;
return old;
}
public ExpTSC CloneSetgetSelectGroupingMapStringAndgetSelectGroupingMapStringAndtbtype(List<SelectColumnInfo> v1, Func<Expression[], string> v2, SelectTableInfoType v3) public ExpTSC CloneSetgetSelectGroupingMapStringAndgetSelectGroupingMapStringAndtbtype(List<SelectColumnInfo> v1, Func<Expression[], string> v2, SelectTableInfoType v3)
{ {

View File

@ -104,8 +104,10 @@ namespace FreeSql.MySql
tsc.SetMapColumnTmp(null); tsc.SetMapColumnTmp(null);
var args1 = getExp(callExp.Arguments[argIndex]); var args1 = getExp(callExp.Arguments[argIndex]);
var oldMapType = tsc.SetMapTypeReturnOld(tsc.mapTypeTmp); var oldMapType = tsc.SetMapTypeReturnOld(tsc.mapTypeTmp);
var oldDbParams = tsc.SetDbParamsReturnOld(null);
var left = objExp == null ? null : getExp(objExp); var left = objExp == null ? null : getExp(objExp);
tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType); tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType);
tsc.SetDbParamsReturnOld(oldDbParams);
switch (callExp.Method.Name) switch (callExp.Method.Name)
{ {
case "Contains": case "Contains":

View File

@ -111,8 +111,10 @@ namespace FreeSql.Odbc.Default
tsc.SetMapColumnTmp(null); tsc.SetMapColumnTmp(null);
var args1 = getExp(callExp.Arguments[argIndex]); var args1 = getExp(callExp.Arguments[argIndex]);
var oldMapType = tsc.SetMapTypeReturnOld(tsc.mapTypeTmp); var oldMapType = tsc.SetMapTypeReturnOld(tsc.mapTypeTmp);
var oldDbParams = tsc.SetDbParamsReturnOld(null);
var left = objExp == null ? null : getExp(objExp); var left = objExp == null ? null : getExp(objExp);
tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType); tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType);
tsc.SetDbParamsReturnOld(oldDbParams);
switch (callExp.Method.Name) switch (callExp.Method.Name)
{ {
case "Contains": case "Contains":

View File

@ -104,8 +104,10 @@ namespace FreeSql.Odbc.MySql
tsc.SetMapColumnTmp(null); tsc.SetMapColumnTmp(null);
var args1 = getExp(callExp.Arguments[argIndex]); var args1 = getExp(callExp.Arguments[argIndex]);
var oldMapType = tsc.SetMapTypeReturnOld(tsc.mapTypeTmp); var oldMapType = tsc.SetMapTypeReturnOld(tsc.mapTypeTmp);
var oldDbParams = tsc.SetDbParamsReturnOld(null);
var left = objExp == null ? null : getExp(objExp); var left = objExp == null ? null : getExp(objExp);
tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType); tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType);
tsc.SetDbParamsReturnOld(oldDbParams);
switch (callExp.Method.Name) switch (callExp.Method.Name)
{ {
case "Contains": case "Contains":

View File

@ -104,8 +104,10 @@ namespace FreeSql.Odbc.Oracle
tsc.SetMapColumnTmp(null); tsc.SetMapColumnTmp(null);
var args1 = getExp(callExp.Arguments[argIndex]); var args1 = getExp(callExp.Arguments[argIndex]);
var oldMapType = tsc.SetMapTypeReturnOld(tsc.mapTypeTmp); var oldMapType = tsc.SetMapTypeReturnOld(tsc.mapTypeTmp);
var oldDbParams = tsc.SetDbParamsReturnOld(null);
var left = objExp == null ? null : getExp(objExp); var left = objExp == null ? null : getExp(objExp);
tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType); tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType);
tsc.SetDbParamsReturnOld(oldDbParams);
switch (callExp.Method.Name) switch (callExp.Method.Name)
{ {
case "Contains": case "Contains":

View File

@ -133,8 +133,10 @@ namespace FreeSql.Odbc.PostgreSQL
tsc.SetMapColumnTmp(null); tsc.SetMapColumnTmp(null);
var args1 = getExp(callExp.Arguments[argIndex]); var args1 = getExp(callExp.Arguments[argIndex]);
var oldMapType = tsc.SetMapTypeReturnOld(tsc.mapTypeTmp); var oldMapType = tsc.SetMapTypeReturnOld(tsc.mapTypeTmp);
var oldDbParams = tsc.SetDbParamsReturnOld(null);
left = objExp == null ? null : getExp(objExp); left = objExp == null ? null : getExp(objExp);
tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType); tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType);
tsc.SetDbParamsReturnOld(oldDbParams);
//判断 in 或 array @> array //判断 in 或 array @> array
if (left.StartsWith("array[") || left.EndsWith("]")) if (left.StartsWith("array[") || left.EndsWith("]"))
return $"({args1}) in ({left.Substring(6, left.Length - 7)})"; return $"({args1}) in ({left.Substring(6, left.Length - 7)})";

View File

@ -108,8 +108,10 @@ namespace FreeSql.Odbc.SqlServer
tsc.SetMapColumnTmp(null); tsc.SetMapColumnTmp(null);
var args1 = getExp(callExp.Arguments[argIndex]); var args1 = getExp(callExp.Arguments[argIndex]);
var oldMapType = tsc.SetMapTypeReturnOld(tsc.mapTypeTmp); var oldMapType = tsc.SetMapTypeReturnOld(tsc.mapTypeTmp);
var oldDbParams = tsc.SetDbParamsReturnOld(null);
var left = objExp == null ? null : getExp(objExp); var left = objExp == null ? null : getExp(objExp);
tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType); tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType);
tsc.SetDbParamsReturnOld(oldDbParams);
switch (callExp.Method.Name) switch (callExp.Method.Name)
{ {
case "Contains": case "Contains":

View File

@ -104,8 +104,10 @@ namespace FreeSql.Oracle
tsc.SetMapColumnTmp(null); tsc.SetMapColumnTmp(null);
var args1 = getExp(callExp.Arguments[argIndex]); var args1 = getExp(callExp.Arguments[argIndex]);
var oldMapType = tsc.SetMapTypeReturnOld(tsc.mapTypeTmp); var oldMapType = tsc.SetMapTypeReturnOld(tsc.mapTypeTmp);
var oldDbParams = tsc.SetDbParamsReturnOld(null);
var left = objExp == null ? null : getExp(objExp); var left = objExp == null ? null : getExp(objExp);
tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType); tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType);
tsc.SetDbParamsReturnOld(oldDbParams);
switch (callExp.Method.Name) switch (callExp.Method.Name)
{ {
case "Contains": case "Contains":

View File

@ -163,8 +163,10 @@ namespace FreeSql.PostgreSQL
tsc.SetMapColumnTmp(null); tsc.SetMapColumnTmp(null);
var args1 = getExp(callExp.Arguments[argIndex]); var args1 = getExp(callExp.Arguments[argIndex]);
var oldMapType = tsc.SetMapTypeReturnOld(tsc.mapTypeTmp); var oldMapType = tsc.SetMapTypeReturnOld(tsc.mapTypeTmp);
var oldDbParams = tsc.SetDbParamsReturnOld(null);
left = objExp == null ? null : getExp(objExp); left = objExp == null ? null : getExp(objExp);
tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType); tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType);
tsc.SetDbParamsReturnOld(oldDbParams);
//判断 in 或 array @> array //判断 in 或 array @> array
if (left.StartsWith("array[") || left.EndsWith("]")) if (left.StartsWith("array[") || left.EndsWith("]"))
return $"({args1}) in ({left.Substring(6, left.Length - 7)})"; return $"({args1}) in ({left.Substring(6, left.Length - 7)})";

View File

@ -108,8 +108,10 @@ namespace FreeSql.SqlServer
tsc.SetMapColumnTmp(null); tsc.SetMapColumnTmp(null);
var args1 = getExp(callExp.Arguments[argIndex]); var args1 = getExp(callExp.Arguments[argIndex]);
var oldMapType = tsc.SetMapTypeReturnOld(tsc.mapTypeTmp); var oldMapType = tsc.SetMapTypeReturnOld(tsc.mapTypeTmp);
var oldDbParams = tsc.SetDbParamsReturnOld(null);
var left = objExp == null ? null : getExp(objExp); var left = objExp == null ? null : getExp(objExp);
tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType); tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType);
tsc.SetDbParamsReturnOld(oldDbParams);
switch (callExp.Method.Name) switch (callExp.Method.Name)
{ {
case "Contains": case "Contains":

View File

@ -104,8 +104,10 @@ namespace FreeSql.Sqlite
tsc.SetMapColumnTmp(null); tsc.SetMapColumnTmp(null);
var args1 = getExp(callExp.Arguments[argIndex]); var args1 = getExp(callExp.Arguments[argIndex]);
var oldMapType = tsc.SetMapTypeReturnOld(tsc.mapTypeTmp); var oldMapType = tsc.SetMapTypeReturnOld(tsc.mapTypeTmp);
var oldDbParams = tsc.SetDbParamsReturnOld(null);
var left = objExp == null ? null : getExp(objExp); var left = objExp == null ? null : getExp(objExp);
tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType); tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType);
tsc.SetDbParamsReturnOld(oldDbParams);
switch (callExp.Method.Name) switch (callExp.Method.Name)
{ {
case "Contains": case "Contains":