Skip to content

Commit 01017e3

Browse files
Copilotrenemadsen
andcommitted
Debug: Add SQL generation logging directly in SQL generators
Added Console.WriteLine logging in: - MySqlUpdateSqlGenerator.AppendUpdateOperation: Logs UPDATE SQL as it's generated - MySqlQuerySqlGenerator.VisitSelect: Logs SELECT query info and partial SQL This will capture the actual malformed SQL queries directly during generation, showing the empty columns that cause the "near ', ,'" syntax errors. Co-authored-by: renemadsen <76994+renemadsen@users.noreply.github.com>
1 parent 7203430 commit 01017e3

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

src/EFCore.MySql/Query/ExpressionVisitors/Internal/MySqlQuerySqlGenerator.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,5 +1023,22 @@ protected override void CheckComposableSql(string sql)
10231023
// MySQL supports CTE (WITH) expressions within subqueries, as well as others,
10241024
// so we allow any raw SQL to be composed over.
10251025
}
1026+
1027+
protected override Expression VisitSelect(SelectExpression selectExpression)
1028+
{
1029+
Console.WriteLine($"[DEBUG SQL] VisitSelect called - Tables: {selectExpression.Tables.Count}, Projection: {selectExpression.Projection.Count}");
1030+
var result = base.VisitSelect(selectExpression);
1031+
1032+
// Log current SQL state after SELECT is generated
1033+
var currentSql = Sql.ToString();
1034+
var lastSelect = currentSql.LastIndexOf("SELECT");
1035+
if (lastSelect >= 0)
1036+
{
1037+
var sqlFragment = currentSql.Substring(lastSelect, Math.Min(200, currentSql.Length - lastSelect));
1038+
Console.WriteLine($"[DEBUG SQL] After VisitSelect: {sqlFragment}");
1039+
}
1040+
1041+
return result;
1042+
}
10261043
}
10271044
}

src/EFCore.MySql/Update/Internal/MySqlUpdateSqlGenerator.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,20 @@ public override ResultSetMapping AppendUpdateOperation(
181181
IReadOnlyModificationCommand command,
182182
int commandPosition,
183183
out bool requiresTransaction)
184-
=> _options.ServerVersion.Supports.Returning
184+
{
185+
var startLength = commandStringBuilder.Length;
186+
var result = _options.ServerVersion.Supports.Returning
185187
? AppendUpdateReturningOperation(commandStringBuilder, command, commandPosition, out requiresTransaction)
186188
: base.AppendUpdateOperation(commandStringBuilder, command, commandPosition, out requiresTransaction);
189+
190+
// Debug: Log the generated SQL
191+
var generatedSql = commandStringBuilder.ToString(startLength, commandStringBuilder.Length - startLength);
192+
Console.WriteLine($"[DEBUG SQL Generated] AppendUpdateOperation:");
193+
Console.WriteLine(generatedSql);
194+
Console.WriteLine($"[DEBUG SQL Generated] Table: {command.TableName}, Columns: {command.ColumnModifications.Count}");
195+
196+
return result;
197+
}
187198

188199
/// <summary>
189200
/// Appends SQL for updating a row to the commands being built, via an UPDATE containing a RETURNING clause

0 commit comments

Comments
 (0)