Skip to content

Commit a2bb191

Browse files
[BUG4] Strip ident quotes in offline SELECT codegen + 0.9.1-beta
PostgresCli.InferColumnTypesFromSql parsed `"Id"` and `"fhir_Patient"."Active"` from user SQL and emitted the quote chars verbatim into the C# property name, producing uncompilable .g.cs (`public string? "Id" { get; init; }`). Fix: StripIdentifierQuotes() removes a single surrounding pair of double quotes from the parsed column ref before it becomes a C# identifier. SQL constant emission unchanged — quoted SQL still round-trips correctly via the verbatim "" escape. Verified locally with repro: - input: SELECT "Id", "fhir_Patient"."Active" FROM "fhir_Patient" - before: public string? "Id" { get; init; } (broken) - after: public string? Id { get; init; } (compiles) Bump Directory.Build.props to 0.9.1-beta.
1 parent 8a5c588 commit a2bb191

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

DataProvider/DataProvider/PostgresCli.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ private static (string name, string sqlType) ParseColumnDefinition(
456456
if (asMatch.Success)
457457
{
458458
var expr = asMatch.Groups[1].Value.Trim();
459-
var alias = asMatch.Groups[2].Value.Trim();
459+
var alias = StripIdentifierQuotes(asMatch.Groups[2].Value.Trim());
460460
var type = InferTypeFromExpression(expr, schema);
461461
return (alias, type);
462462
}
@@ -465,9 +465,15 @@ private static (string name, string sqlType) ParseColumnDefinition(
465465
var colRef = colDef.Trim();
466466
if (colRef.Contains('.'))
467467
{
468+
// BUG4 fix: split on dot but only outside quoted segments. A
469+
// qualified ref like "fhir_Patient"."Active" must split on the
470+
// middle dot, not the dots inside quoted parts (there aren't
471+
// any here, but the simple Split is fine). Then strip the
472+
// surrounding `"` chars from the tail.
468473
var parts = colRef.Split('.');
469474
colRef = parts[^1];
470475
}
476+
colRef = StripIdentifierQuotes(colRef);
471477

472478
// Try to get type from schema
473479
if (schema != null)
@@ -488,6 +494,21 @@ private static (string name, string sqlType) ParseColumnDefinition(
488494
return (colRef, "text");
489495
}
490496

497+
/// <summary>
498+
/// BUG4 fix: removes a single pair of surrounding double-quote characters
499+
/// from a Postgres identifier reference. The offline SQL parser must not
500+
/// leak `"` characters into the C# property name — they're invalid in C#
501+
/// identifiers and produce uncompilable .g.cs.
502+
/// </summary>
503+
private static string StripIdentifierQuotes(string identifier)
504+
{
505+
if (identifier.Length >= 2 && identifier[0] == '"' && identifier[^1] == '"')
506+
{
507+
return identifier[1..^1];
508+
}
509+
return identifier;
510+
}
511+
491512
private static string InferTypeFromExpression(string expr, SchemaDefinition? schema)
492513
{
493514
var lower = expr.ToLowerInvariant().Trim();

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<NuGetAudit>false</NuGetAudit>
55
<NuGetAuditMode>disabled</NuGetAuditMode>
66
<RestoreAuditProperties>false</RestoreAuditProperties>
7-
<Version>0.9.0-beta</Version>
7+
<Version>0.9.1-beta</Version>
88
<Authors>ChristianFindlay</Authors>
99
<Company>MelbourneDeveloper</Company>
1010
<PackageLicenseExpression>MIT</PackageLicenseExpression>

0 commit comments

Comments
 (0)