Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions FreeSql/Internal/CommonExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -368,16 +368,16 @@ void LocalSetFieldAlias(ref int localIndex, bool isdiymemexp)
ReadAnonymousField(_tables, _tableRule, field, child, ref index, initExpArg, select, diymemexp, whereGlobalFilter, findIncludeMany, findSubSelectMany, false);
}
}
else if (isAllDtoMap && _tables != null && _tables.Any() &&
else if (isAllDtoMap && _tables != null && _tables.Any() &&
(
initExp.NewExpression.Type != _tables[0].Table.Type ||
!initExp.Bindings.Any(a =>
!initExp.Bindings.Any(a =>
// #2241 如果 new Dto 和 T 相同,并且未使用过例如:Name = t.Name,则也认为是 Dto 自动赋加所有属性来查询
{
var aExp = a as MemberAssignment;
if (aExp == null) return false;
if (aExp.Expression is MemberExpression aExpRight == false) return false;
if (aExpRight.Expression == _tables[0].Parameter &&
if (aExpRight.Expression == _tables[0].Parameter &&
aExpRight.Member.Name == a.Member.Name) return true;
return false;
})
Expand Down Expand Up @@ -495,7 +495,7 @@ void LocalSetFieldAlias(ref int localIndex, bool isdiymemexp)
break;
}
var mapType = initExpArg.Type;
if (dtoTable?.ColumnsByCs.TryGetValue(initExp.Bindings[a].Member.Name, out var dtoCol) == true &&
if (dtoTable?.ColumnsByCs.TryGetValue(initExp.Bindings[a].Member.Name, out var dtoCol) == true &&
dtoCol.Attribute.IsIgnore != true)
mapType = dtoCol.Attribute.MapType;
var child = new ReadAnonymousTypeInfo
Expand Down Expand Up @@ -816,6 +816,12 @@ public string[] ExpressionSelectColumns_MemberAccess_New_NewArrayInit(List<Selec
{ ExpressionType.MultiplyChecked, "*" },
};

public string ExpressionSetLambda(TableInfo table, Expression exp)
{
var sql = ExpressionLambdaToSql(exp, new ExpTSC { _tables = null, _tableRule = null, _selectColumnMap = null, diymemexp = null, tbtype = SelectTableInfoType.From, isQuoteName = true, isDisableDiyParse = false, style = ExpressionStyle.Set, currentTable = table, dbParams = null });
return GetBoolString(exp, SearchColumnByField(null, null, sql), sql);
}

public string ExpressionWhereLambdaNoneForeignObject(List<SelectTableInfo> _tables, Func<Type, string, string> _tableRule, TableInfo table, List<SelectColumnInfo> _selectColumnMap, Expression exp, BaseDiyMemberExpression diymemexp, List<DbParameter> dbParams)
{
var sql = ExpressionLambdaToSql(exp, new ExpTSC { _tables = _tables, _tableRule = _tableRule, _selectColumnMap = _selectColumnMap, diymemexp = diymemexp, tbtype = SelectTableInfoType.From, isQuoteName = true, isDisableDiyParse = false, style = ExpressionStyle.Where, currentTable = table, dbParams = dbParams });
Expand Down Expand Up @@ -1530,7 +1536,7 @@ public string ExpressionLambdaToSql(Expression exp, ExpTSC tsc)
typeof(ISelect0).IsAssignableFrom(arg3ExpNewArray.Expressions[0].Type))
{
Array arg3Values = Array.CreateInstance(arg3ExpNewArray.Expressions[0].Type, arg3ExpNewArray.Expressions.Count);
for (var arg3Idx = 0;arg3Idx < arg3ExpNewArray.Expressions.Count; arg3Idx++)
for (var arg3Idx = 0; arg3Idx < arg3ExpNewArray.Expressions.Count; arg3Idx++)
{
var arg3ExpNewArrayTables = fsqltables.Select(tbcopy => new SelectTableInfo
{
Expand Down Expand Up @@ -2109,7 +2115,7 @@ exp4.Expression is BinaryExpression exp4BinaryExp &&
else if (expStackItem.Member.MemberType == MemberTypes.Field)
firstValue = ((FieldInfo)expStackItem.Member).GetValue(firstValue);
}
return formatSql(firstValue, tsc.mapType, tsc.mapColumnTmp, tsc.dbParams);
return formatSql(firstValue, tsc.mapType, tsc.mapColumnTmp, tsc.dbParams, tsc.style);
}
return formatSql(Expression.Lambda(exp).Compile().DynamicInvoke(), tsc.mapType, tsc.mapColumnTmp, tsc.dbParams);
}
Expand Down Expand Up @@ -2592,7 +2598,7 @@ public static object ExpressionGetValue(Expression exp, out bool success)

public enum ExpressionStyle
{
Where, AsSelect, SelectColumns, ReturnISelect
Where, AsSelect, SelectColumns, ReturnISelect, Set
}
public class ExpTSC
{
Expand Down Expand Up @@ -2836,7 +2842,7 @@ protected override Expression VisitMember(MemberExpression node)
}
}

public string formatSql(object obj, Type mapType, ColumnInfo mapColumn, List<DbParameter> dbParams)
public string formatSql(object obj, Type mapType, ColumnInfo mapColumn, List<DbParameter> dbParams, ExpressionStyle? style = null)
{
//参数化设置,日后优化
if (_common.CodeFirst.IsGenerateCommandParameterWithLambda && dbParams != null)
Expand All @@ -2859,7 +2865,7 @@ public string formatSql(object obj, Type mapType, ColumnInfo mapColumn, List<DbP
return _common.QuoteParamterName(paramName);
}
}
return string.Format(CultureInfo.InvariantCulture, "{0}", _ado.AddslashesProcessParam(obj, mapType, mapColumn));
return string.Format(CultureInfo.InvariantCulture, "{0}", _ado.AddslashesProcessParam(obj, mapType, mapColumn, style));
//return string.Concat(_ado.AddslashesProcessParam(obj, mapType, mapColumn));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Globalization;
using System.Text;
using System.Text.RegularExpressions;
using FreeSql.Internal;

namespace FreeSql.Internal.CommonProvider
{
Expand All @@ -21,7 +22,8 @@ public object AddslashesTypeHandler(Type type, object param)
return null;
}

public abstract object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn);
public abstract object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn, CommonExpression.ExpressionStyle? style = null);

public string Addslashes(string filter, params object[] parms)
{
if (filter == null || parms == null) return string.Empty;
Expand All @@ -36,9 +38,10 @@ public string Addslashes(string filter, params object[] parms)
}
try { string ret = string.Format(CultureInfo.InvariantCulture, filter, nparms); return ret; } catch { return filter; }
}

static ConcurrentDictionary<int, Regex> _dicAddslashesReplaceIsNull = new ConcurrentDictionary<int, Regex>();

protected string AddslashesIEnumerable(object param, Type mapType, ColumnInfo mapColumn)
protected virtual string AddslashesIEnumerable(object param, Type mapType, ColumnInfo mapColumn, CommonExpression.ExpressionStyle? style = null)
{
var sb = new StringBuilder();
var ie = param as IEnumerable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System.Data.Common;
using System.Linq;
using System.Threading;

namespace FreeSql.ClickHouse
{
class ClickHouseAdo : FreeSql.Internal.CommonProvider.AdoProvider
Expand Down Expand Up @@ -41,7 +40,7 @@ public ClickHouseAdo(CommonUtils util, string masterConnectionString, string[] s
SlavePools.Add(slavePool);
});
}
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn, CommonExpression.ExpressionStyle? style)
{
if (param == null) return "NULL";
if (mapType != null && mapType != param.GetType() && (param is IEnumerable == false))
Expand Down
2 changes: 1 addition & 1 deletion Providers/FreeSql.Provider.Custom/CustomAdo/CustomAdo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public CustomAdo(CommonUtils util, string masterConnectionString, string[] slave
}
CustomAdapter Adapter => (_util == null ? FreeSqlCustomAdapterGlobalExtensions.DefaultAdapter : _util._orm.GetCustomAdapter());

public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn, CommonExpression.ExpressionStyle? style)
{
if (param == null) return "NULL";
if (mapType != null && mapType != param.GetType() && (param is IEnumerable == false))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Data.Common;
using System.Text;
using System.Threading;

namespace FreeSql.Custom.MySql
{
public class CustomMySqlAdo : FreeSql.Internal.CommonProvider.AdoProvider
Expand All @@ -26,7 +25,7 @@ public CustomMySqlAdo(CommonUtils util, string masterConnectionString, string[]
}
throw new Exception(CoreErrorStrings.S_CustomAdapter_OnlySuppport_UseConnectionFactory);
}
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn, CommonExpression.ExpressionStyle? style)
{
if (param == null) return "NULL";
if (mapType != null && mapType != param.GetType() && (param is IEnumerable == false))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static string GetUserId(string connectionString)
return userIdMatch.Groups[2].Value.Trim().ToUpper();
}

public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn, CommonExpression.ExpressionStyle? style)
{
if (param == null) return "NULL";
if (mapType != null && mapType != param.GetType() && (param is IEnumerable == false))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public CustomPostgreSQLAdo(CommonUtils util, string masterConnectionString, stri
throw new Exception(CoreErrorStrings.S_CustomAdapter_OnlySuppport_UseConnectionFactory);
}

public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn, CommonExpression.ExpressionStyle? style)
{
if (param == null) return "NULL";
if (mapType != null && mapType != param.GetType() && (param is IEnumerable == false))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public CustomSqlServerAdo(CommonUtils util, string masterConnectionString, strin
}

string[] ncharDbTypes = new[] { "NVARCHAR", "NCHAR", "NTEXT" };
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn, CommonExpression.ExpressionStyle? style)
{
if (param == null) return "NULL";
if (mapType != null && mapType != param.GetType() && (param is IEnumerable == false))
Expand Down
2 changes: 1 addition & 1 deletion Providers/FreeSql.Provider.Dameng/DamengAdo/DamengAdo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public DamengAdo(CommonUtils util, string masterConnectionString, string[] slave
SlavePools.Add(slavePool);
});
}
public override object AddslashesProcessParam(object param, Type mapType, Internal.Model.ColumnInfo mapColumn)
public override object AddslashesProcessParam(object param, Type mapType, Internal.Model.ColumnInfo mapColumn, CommonExpression.ExpressionStyle? style)
{
if (param == null) return "NULL";
if (mapType != null && mapType != param.GetType() && (param is IEnumerable == false))
Expand Down
2 changes: 1 addition & 1 deletion Providers/FreeSql.Provider.Duckdb/DuckdbAdo/DuckdbAdo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public DuckdbAdo(CommonUtils util, string masterConnectionString, string[] slave
SlavePools.Add(slavePool);
});
}
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn, CommonExpression.ExpressionStyle? style)
{
if (param == null) return "NULL";
if (mapType != null && mapType != param.GetType() && (param is IEnumerable == false))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public string ServerVersion
}
string _serverVersion;

public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn, CommonExpression.ExpressionStyle? style)
{
if (param == null) return "NULL";
if (mapType != null && mapType != param.GetType() && (param is IEnumerable == false))
Expand Down
2 changes: 1 addition & 1 deletion Providers/FreeSql.Provider.GBase/GBaseAdo/GBaseAdo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public GBaseAdo(CommonUtils util, string masterConnectionString, string[] slaveC
});
}

public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn, CommonExpression.ExpressionStyle? style)
{
if (param == null) return "NULL";
if (mapType != null && mapType != param.GetType() && (param is IEnumerable == false))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public KingbaseESAdo(CommonUtils util, string masterConnectionString, string[] s
SlavePools.Add(slavePool);
});
}
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn, CommonExpression.ExpressionStyle? style)
{
if (param == null) return "NULL";
if (mapType != null && mapType != param.GetType() && (param is IEnumerable == false || param is JToken || param is JObject || param is JArray))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public MsAccessAdo(CommonUtils util, string masterConnectionString, string[] sla
});
}

public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn, CommonExpression.ExpressionStyle? style)
{
if (param == null) return "NULL";
if (mapType != null && mapType != param.GetType() && (param is IEnumerable == false))
Expand Down
2 changes: 1 addition & 1 deletion Providers/FreeSql.Provider.MySql/MySqlAdo/MySqlAdo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public MySqlAdo(CommonUtils util, string masterConnectionString, string[] slaveC
SlavePools.Add(slavePool);
});
}
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn, CommonExpression.ExpressionStyle? style)
{
if (param == null) return "NULL";
if (mapType != null && mapType != param.GetType() && (param is IEnumerable == false))
Expand Down
2 changes: 1 addition & 1 deletion Providers/FreeSql.Provider.Odbc/Default/OdbcAdo/OdbcAdo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public OdbcAdo(CommonUtils util, string masterConnectionString, string[] slaveCo
}
OdbcAdapter Adapter => (_util == null ? FreeSqlOdbcGlobalExtensions.DefaultOdbcAdapter : _util._orm.GetOdbcAdapter());

public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn, CommonExpression.ExpressionStyle? style)
{
if (param == null) return "NULL";
if (mapType != null && mapType != param.GetType() && (param is IEnumerable == false))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public OdbcMySqlAdo(CommonUtils util, string masterConnectionString, string[] sl
SlavePools.Add(slavePool);
});
}
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn, CommonExpression.ExpressionStyle? style)
{
if (param == null) return "NULL";
if (mapType != null && mapType != param.GetType() && (param is IEnumerable == false))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public OdbcOracleAdo(CommonUtils util, string masterConnectionString, string[] s
SlavePools.Add(slavePool);
});
}
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn, CommonExpression.ExpressionStyle? style)
{
if (param == null) return "NULL";
if (mapType != null && mapType != param.GetType() && (param is IEnumerable == false))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public OdbcPostgreSQLAdo(CommonUtils util, string masterConnectionString, string
});
}

public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn, CommonExpression.ExpressionStyle? style)
{
if (param == null) return "NULL";
if (mapType != null && mapType != param.GetType() && (param is IEnumerable == false))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public OdbcSqlServerAdo(CommonUtils util, string masterConnectionString, string[
}

string[] ncharDbTypes = new[] { "NVARCHAR", "NCHAR", "NTEXT" };
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn, CommonExpression.ExpressionStyle? style)
{
if (param == null) return "NULL";
if (mapType != null && mapType != param.GetType() && (param is IEnumerable == false))
Expand Down
2 changes: 1 addition & 1 deletion Providers/FreeSql.Provider.Oracle/OracleAdo/OracleAdo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public OracleAdo(CommonUtils util, string masterConnectionString, string[] slave
SlavePools.Add(slavePool);
});
}
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn)
public override object AddslashesProcessParam(object param, Type mapType, ColumnInfo mapColumn, CommonExpression.ExpressionStyle? style)
{
if (param == null) return "NULL";
if (mapType != null && mapType != param.GetType() && (param is IEnumerable == false))
Expand Down
Loading