Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/Core/Models/GraphQLFilterParsers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ public static Predicate Parse(
predicates.Push(new PredicateOperand(new Predicate(
new PredicateOperand(column),
op,
GenerateRightOperand(ctx, argumentObject, name, processLiterals, value, processLiteral) // right operand
GenerateRightOperand(ctx, argumentObject, name, processLiterals, value, processLiteral, column.ColumnName) // right operand
)));
}

Expand Down Expand Up @@ -760,14 +760,16 @@ public static Predicate Parse(
/// <param name="processLiterals">A function to encode or parameterize literal values for database queries.</param>
/// <param name="value">The value to be used as the right operand in the predicate.</param>
/// <param name="processLiteral">Indicates whether to process the value as a literal using processLiterals, or use its string representation directly.</param>
/// <param name="columnName">The name of the column being filtered, used to look up the column's DbType for proper parameter typing.</param>
/// <returns>A <see cref="PredicateOperand"/> representing the right operand for the predicate.</returns>
private static PredicateOperand GenerateRightOperand(
IMiddlewareContext ctx,
InputObjectType argumentObject,
string operationName,
Func<object, string?, string> processLiterals,
object value,
bool processLiteral)
bool processLiteral,
string? columnName)
{
if (operationName.Equals("in", StringComparison.OrdinalIgnoreCase))
{
Expand All @@ -777,13 +779,13 @@ private static PredicateOperand GenerateRightOperand(
argumentObject.Fields[operationName],
ctx.Variables))
.Where(inValue => inValue is not null)
.Select(inValue => processLiterals(inValue!, null))
.Select(inValue => processLiterals(inValue!, columnName))
.ToList();

return new PredicateOperand("(" + string.Join(", ", encodedParams) + ")");
}

return new PredicateOperand(processLiteral ? processLiterals(value, null) : value.ToString());
return new PredicateOperand(processLiteral ? processLiterals(value, columnName) : value.ToString());
}

private static string EscapeLikeString(string input)
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Resolvers/IQueryExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public Dictionary<string, object> GetResultProperties(
public string GetSessionParamsQuery(HttpContext? httpContext, IDictionary<string, DbConnectionParam> parameters, string dataSourceName);

/// <summary>
/// Helper method to populate DbType for parameter. Currently DbTypes for parameters are only populated for MsSql.
/// Helper method to populate DbType for parameter. Currently DbTypes for parameters are only populated for MsSql and PostgreSql.
/// </summary>
/// <param name="parameterEntry">Entry corresponding to current database parameter to be created.</param>
/// <param name="parameter">Parameter sent to database.</param>
Expand Down
10 changes: 10 additions & 0 deletions src/Core/Resolvers/PostgreSqlExecutor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Data;
using System.Data.Common;
using Azure.Core;
using Azure.DataApiBuilder.Config;
Expand Down Expand Up @@ -146,6 +147,15 @@ private static bool ShouldManagedIdentityAccessBeAttempted(NpgsqlConnectionStrin
return string.IsNullOrEmpty(builder.Password);
}

/// <inheritdoc/>
public static void PopulateDbTypeForParameter(KeyValuePair<string, DbConnectionParam> parameterEntry, DbParameter parameter)
{
if (parameterEntry.Value is not null && parameterEntry.Value.DbType is not null)
{
parameter.DbType = (DbType)parameterEntry.Value.DbType;
}
}

/// <summary>
/// Determines if the saved default azure credential's access token is valid and not expired.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Resolvers/QueryExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ public virtual string GetSessionParamsQuery(HttpContext? httpContext, IDictionar
/// <inheritdoc/>
public virtual void PopulateDbTypeForParameter(KeyValuePair<string, DbConnectionParam> parameterEntry, DbParameter parameter)
{
// DbType for parameter is currently only populated for MsSql which has its own overridden implementation.
// DbType for parameter is currently only populated for MsSql and PostgreSql which has its own overridden implementation.
return;
}

Expand Down
Loading