Skip to content

Commit a3ec084

Browse files
committed
React to code review.
1 parent 137ce34 commit a3ec084

File tree

1 file changed

+15
-9
lines changed
  • src/OrchardCore/OrchardCore.ContentManagement.GraphQL/Queries/Predicates

1 file changed

+15
-9
lines changed

src/OrchardCore/OrchardCore.ContentManagement.GraphQL/Queries/Predicates/PredicateQuery.cs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public string GetColumnName(string propertyPath)
100100
// aliasPart.Alias -> AliasFieldIndex.Alias
101101
if (_aliases.TryGetValue(propertyPath, out var alias))
102102
{
103-
return Quote(alias);
103+
return EnsureQuotes(alias);
104104
}
105105

106106
var index = IndexOfUnquoted(propertyPath, '.');
@@ -125,36 +125,36 @@ public string GetColumnName(string propertyPath)
125125
{
126126
// Switch the given alias in the path with the mapped alias.
127127
// aliasPart.alias -> AliasPartIndex.Alias
128-
return Quote(tableAlias, columnName);
128+
return EnsureQuotes(tableAlias, columnName);
129129
}
130130
}
131131
else
132132
{
133133
// no property provider exists; hope sql is case-insensitive (will break postgres; property providers must be supplied for postgres)
134134
// Switch the given alias in the path with the mapped alias.
135135
// aliasPart.Alias -> AliasPartIndex.alias
136-
return Quote(tableAlias, propertyPath[(index + 1)..]);
136+
return EnsureQuotes(tableAlias, propertyPath[(index + 1)..]);
137137
}
138138
}
139139

140140
// No aliases registered for this path, return the formatted path.
141-
return Quote(propertyPath);
141+
return EnsureQuotes(propertyPath);
142142
}
143143

144144
public IEnumerable<string> GetUsedAliases()
145145
{
146146
return _usedAliases;
147147
}
148148

149-
private string Quote(string alias)
149+
private string EnsureQuotes(string alias)
150150
{
151151
var index = IndexOfUnquoted(alias, '.');
152152
return index == -1
153153
? (IsQuoted(alias) ? alias : Dialect.QuoteForColumnName(alias))
154-
: Quote(alias[..index], alias[(index + 1)..]);
154+
: EnsureQuotes(alias[..index], alias[(index + 1)..]);
155155
}
156156

157-
private string Quote(string tableAlias, string columnName)
157+
private string EnsureQuotes(string tableAlias, string columnName)
158158
{
159159
if (!IsQuoted(tableAlias))
160160
{
@@ -217,7 +217,13 @@ private static (char startQuote, char endQuote) GetQuoteChars(ISqlDialect dialec
217217
MySqlDialect => ('`', '`'),
218218
PostgreSqlDialect => ('"', '"'),
219219
SqliteDialect or
220-
SqlServerDialect or
221-
_ => ('[', ']')
220+
SqlServerDialect => ('[', ']'),
221+
_ => ExtractQuoteChars(dialect)
222222
};
223+
224+
private static (char startQuote, char endQuote) ExtractQuoteChars(ISqlDialect dialect)
225+
{
226+
var quoted = dialect.QuoteForColumnName("alias");
227+
return (quoted[0], quoted[^1]);
228+
}
223229
}

0 commit comments

Comments
 (0)