Skip to content

Commit 6d483a5

Browse files
committed
- 修复 MySql AsTreeCte cte_path 可能长度过短问题;
1 parent 3cb53df commit 6d483a5

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

FreeSql/Extensions/FreeSqlGlobalExtensions.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,7 @@ WHERE @cte_ids IS NOT NULL
733733
}
734734

735735
var sql1ctePath = "";
736+
var wct2ctePath = "";
736737
if (pathSelector != null)
737738
{
738739
select._tables[0].Parameter = pathSelector?.Parameters[0];
@@ -750,9 +751,18 @@ WHERE @cte_ids IS NOT NULL
750751
case DataType.Firebird:
751752
case DataType.ClickHouse:
752753
sql1ctePath = select._commonExpression.ExpressionWhereLambda(select._tables, select._tableRule, Expression.Call(typeof(Convert).GetMethod("ToString", new Type[] { typeof(string) }), pathSelector?.Body), select._diymemexpWithTempQuery, null, null);
754+
wct2ctePath = sql1ctePath = select._commonExpression.ExpressionWhereLambda(select._tables, select._tableRule, pathSelector?.Body, select._diymemexpWithTempQuery, null, null);
755+
break;
756+
case DataType.MySql:
757+
case DataType.OdbcMySql:
758+
case DataType.CustomMySql:
759+
sql1ctePath = select._commonExpression.ExpressionWhereLambda(select._tables, select._tableRule, pathSelector?.Body, select._diymemexpWithTempQuery, null, null);
760+
sql1ctePath = $"CAST({sql1ctePath} as char(2000))";
761+
wct2ctePath = sql1ctePath;
753762
break;
754763
default:
755764
sql1ctePath = select._commonExpression.ExpressionWhereLambda(select._tables, select._tableRule, pathSelector?.Body, select._diymemexpWithTempQuery, null, null);
765+
wct2ctePath = sql1ctePath;
756766
break;
757767
}
758768
sql1ctePath = $"{sql1ctePath} as cte_path, ";
@@ -770,7 +780,6 @@ WHERE @cte_ids IS NOT NULL
770780
if (pathSelector != null)
771781
{
772782
select._tables[0].Parameter = pathSelector?.Parameters[0];
773-
var wct2ctePath = select._commonExpression.ExpressionWhereLambda(select._tables, select._tableRule, pathSelector?.Body, select._diymemexpWithTempQuery, null, null);
774783
sql2ctePath = select._commonUtils.StringConcat(
775784
new string[] {
776785
up == false ? "wct1.cte_path" : wct2ctePath,

0 commit comments

Comments
 (0)