Skip to content

Commit 7203430

Browse files
Copilotrenemadsen
andcommitted
Debug: Add more SQL generation logging
Added: - GenerateSqlLiteral and GenerateProviderValueSqlLiteral logging in MySqlComplexJsonTypeMapping - MySqlCommandInterceptor class to log all SQL commands being executed This will help capture the actual malformed SQL queries that are causing syntax errors like "near ', ,'" to diagnose why column projections are empty. Co-authored-by: renemadsen <76994+renemadsen@users.noreply.github.com>
1 parent 810c8d4 commit 7203430

2 files changed

Lines changed: 77 additions & 0 deletions

File tree

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright (c) Pomelo Foundation. All rights reserved.
2+
// Licensed under the MIT. See LICENSE in the project root for license information.
3+
4+
using System;
5+
using System.Data.Common;
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
using Microsoft.EntityFrameworkCore.Diagnostics;
9+
10+
namespace Pomelo.EntityFrameworkCore.MySql.Diagnostics
11+
{
12+
/// <summary>
13+
/// Debug interceptor to log SQL commands
14+
/// </summary>
15+
public class MySqlCommandInterceptor : DbCommandInterceptor
16+
{
17+
public override InterceptionResult<DbDataReader> ReaderExecuting(
18+
DbCommand command,
19+
CommandEventData eventData,
20+
InterceptionResult<DbDataReader> result)
21+
{
22+
Console.WriteLine($"[DEBUG SQL] Executing command:");
23+
Console.WriteLine($"[DEBUG SQL] {command.CommandText}");
24+
Console.WriteLine($"[DEBUG SQL] Parameters: {command.Parameters.Count}");
25+
return base.ReaderExecuting(command, eventData, result);
26+
}
27+
28+
public override ValueTask<InterceptionResult<DbDataReader>> ReaderExecutingAsync(
29+
DbCommand command,
30+
CommandEventData eventData,
31+
InterceptionResult<DbDataReader> result,
32+
CancellationToken cancellationToken = default)
33+
{
34+
Console.WriteLine($"[DEBUG SQL] Executing command async:");
35+
Console.WriteLine($"[DEBUG SQL] {command.CommandText}");
36+
Console.WriteLine($"[DEBUG SQL] Parameters: {command.Parameters.Count}");
37+
return base.ReaderExecutingAsync(command, eventData, result, cancellationToken);
38+
}
39+
40+
public override InterceptionResult<int> NonQueryExecuting(
41+
DbCommand command,
42+
CommandEventData eventData,
43+
InterceptionResult<int> result)
44+
{
45+
Console.WriteLine($"[DEBUG SQL NonQuery] Executing command:");
46+
Console.WriteLine($"[DEBUG SQL NonQuery] {command.CommandText}");
47+
return base.NonQueryExecuting(command, eventData, result);
48+
}
49+
50+
public override ValueTask<InterceptionResult<int>> NonQueryExecutingAsync(
51+
DbCommand command,
52+
CommandEventData eventData,
53+
InterceptionResult<int> result,
54+
CancellationToken cancellationToken = default)
55+
{
56+
Console.WriteLine($"[DEBUG SQL NonQuery] Executing command async:");
57+
Console.WriteLine($"[DEBUG SQL NonQuery] {command.CommandText}");
58+
return base.NonQueryExecutingAsync(command, eventData, result, cancellationToken);
59+
}
60+
}
61+
}

src/EFCore.MySql/Storage/Internal/MySqlJsonTypeMapping.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,22 @@ public override Expression CustomizeDataReaderExpression(Expression expression)
102102
Console.WriteLine($"[DEBUG] MySqlComplexJsonTypeMapping: No conversion, calling base.CustomizeDataReaderExpression");
103103
return base.CustomizeDataReaderExpression(expression);
104104
}
105+
106+
public override string GenerateSqlLiteral(object value)
107+
{
108+
Console.WriteLine($"[DEBUG] MySqlComplexJsonTypeMapping.GenerateSqlLiteral called - value type: {value?.GetType()?.Name ?? "null"}");
109+
var result = base.GenerateSqlLiteral(value);
110+
Console.WriteLine($"[DEBUG] MySqlComplexJsonTypeMapping.GenerateSqlLiteral result: {result}");
111+
return result;
112+
}
113+
114+
public override string GenerateProviderValueSqlLiteral(object value)
115+
{
116+
Console.WriteLine($"[DEBUG] MySqlComplexJsonTypeMapping.GenerateProviderValueSqlLiteral called - value type: {value?.GetType()?.Name ?? "null"}");
117+
var result = base.GenerateProviderValueSqlLiteral(value);
118+
Console.WriteLine($"[DEBUG] MySqlComplexJsonTypeMapping.GenerateProviderValueSqlLiteral result: {result}");
119+
return result;
120+
}
105121
}
106122

107123
public class MySqlJsonTypeMapping<T> : MySqlJsonTypeMapping

0 commit comments

Comments
 (0)