- 增加 WithTempQuery + FromQuery 嵌套查询功能;#1192

This commit is contained in:
2881099
2022-07-25 13:02:01 +08:00
parent ef69eba405
commit 1ee6ecf16f
25 changed files with 1778 additions and 208 deletions

View File

@@ -703,10 +703,10 @@ JOIN {select._commonUtils.QuoteSqlName(tbDbName)} a ON cte_tbc.cte_id = a.{selec
case DataType.OdbcSqlServer:
case DataType.Firebird:
case DataType.ClickHouse:
sql1ctePath = select._commonExpression.ExpressionWhereLambda(select._tables, select._tableRule, Expression.Call(typeof(Convert).GetMethod("ToString", new Type[] { typeof(string) }), pathSelector?.Body), null, null, null);
sql1ctePath = select._commonExpression.ExpressionWhereLambda(select._tables, select._tableRule, Expression.Call(typeof(Convert).GetMethod("ToString", new Type[] { typeof(string) }), pathSelector?.Body), select._diymemexpWithTempQuery, null, null);
break;
default:
sql1ctePath = select._commonExpression.ExpressionWhereLambda(select._tables, select._tableRule, pathSelector?.Body, null, null, null);
sql1ctePath = select._commonExpression.ExpressionWhereLambda(select._tables, select._tableRule, pathSelector?.Body, select._diymemexpWithTempQuery, null, null);
break;
}
sql1ctePath = $"{sql1ctePath} as cte_path, ";
@@ -724,7 +724,7 @@ JOIN {select._commonUtils.QuoteSqlName(tbDbName)} a ON cte_tbc.cte_id = a.{selec
if (pathSelector != null)
{
select._tables[0].Parameter = pathSelector?.Parameters[0];
var wct2ctePath = select._commonExpression.ExpressionWhereLambda(select._tables, select._tableRule, pathSelector?.Body, null, null, null);
var wct2ctePath = select._commonExpression.ExpressionWhereLambda(select._tables, select._tableRule, pathSelector?.Body, select._diymemexpWithTempQuery, null, null);
sql2ctePath = select._commonUtils.StringConcat(
new string[] {
up == false ? "wct1.cte_path" : wct2ctePath,

View File

@@ -233,6 +233,12 @@ namespace System.Linq.Expressions
test.Visit(exp);
return test.Result;
}
public static ParameterExpression GetParameter(this Expression exp)
{
var test = new GetParameterExpressionVisitor();
test.Visit(exp);
return test.Result;
}
static ConcurrentDictionary<Type, ConcurrentDictionary<string, MethodInfo>> _dicTypeMethod = new ConcurrentDictionary<Type, ConcurrentDictionary<string, MethodInfo>>();
public static bool IsStringJoin(this MethodCallExpression exp, out Expression tolistObjectExpOut, out MethodInfo toListMethodOut, out LambdaExpression toListArgs0Out)
@@ -357,4 +363,15 @@ namespace System.Linq.Expressions
return node;
}
}
internal class GetParameterExpressionVisitor : ExpressionVisitor
{
public ParameterExpression Result { get; private set; }
protected override Expression VisitParameter(ParameterExpression node)
{
if (Result == null) Result = node;
return node;
}
}
}