Skip to content

Commit

Permalink
Sync to 9.0.0-preview.3.24172.4 (#3153)
Browse files Browse the repository at this point in the history
* Implement quoting for custom SqlExpressions
* Type mapping visitor changes
* React to SqlConstantExpression changes
  • Loading branch information
roji committed Apr 12, 2024
1 parent 17fa8de commit f38a96c
Show file tree
Hide file tree
Showing 36 changed files with 621 additions and 626 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Expand Up @@ -11,7 +11,7 @@ on:
pull_request:

env:
dotnet_sdk_version: '8.0.100'
dotnet_sdk_version: '9.0.100-preview.3.24204.13'
postgis_version: 3
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Expand Up @@ -27,7 +27,7 @@ on:
- cron: '30 22 * * 6'

env:
dotnet_sdk_version: '8.0.100'
dotnet_sdk_version: '9.0.100-preview.3.24204.13'

jobs:
analyze:
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Expand Up @@ -12,7 +12,7 @@
<ImplicitUsings>true</ImplicitUsings>
<GenerateDocumentationFile>true</GenerateDocumentationFile>

<Copyright>Copyright 2023 © The Npgsql Development Team</Copyright>
<Copyright>Copyright 2024 © The Npgsql Development Team</Copyright>
<Company>Npgsql</Company>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<PackageLicenseExpression>PostgreSQL</PackageLicenseExpression>
Expand Down
12 changes: 8 additions & 4 deletions Directory.Packages.props
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<EFCoreVersion>9.0.0-preview.2.24128.4</EFCoreVersion>
<MicrosoftExtensionsVersion>9.0.0-preview.2.24128.5</MicrosoftExtensionsVersion>
<EFCoreVersion>9.0.0-preview.3.24172.4</EFCoreVersion>
<MicrosoftExtensionsVersion>9.0.0-preview.3.24172.9</MicrosoftExtensionsVersion>
<NpgsqlVersion>8.0.2</NpgsqlVersion>
</PropertyGroup>

Expand All @@ -23,8 +23,12 @@

<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageVersion Include="xunit" Version="2.6.1" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.6" />
<!-- <PackageVersion Include="xunit" Version="2.6.7-pre.5" />-->
<!-- <PackageVersion Include="xunit.runner.visualstudio" Version="2.5.7-pre.8" />-->
<PackageVersion Include="xunit" Version="2.7.1" />
<PackageVersion Include="xunit.assert" Version="2.7.1" />
<PackageVersion Include="xunit.core" Version="2.7.1" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.7" />
<PackageVersion Include="GitHubActionsTestLogger" Version="2.3.3" />
</ItemGroup>
</Project>
207 changes: 1 addition & 206 deletions EFCore.PG.sln.DotSettings

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions global.json
@@ -1,7 +1,7 @@
{
"sdk": {
"version": "8.0.100-rc.2.23502.2",
"version": "9.0.100-preview.3.24204.13",
"rollForward": "latestMajor",
"allowPrerelease": "true"
"allowPrerelease": true
}
}
Expand Up @@ -9,6 +9,9 @@ private PendingDateTimeZoneProviderExpression()
{
}

public override Expression Quote()
=> throw new UnreachableException("PendingDateTimeZoneProviderExpression is a temporary tree representation and should never be quoted");

protected override void Print(ExpressionPrinter expressionPrinter)
=> expressionPrinter.Append("TZDB");
}
Expand Up @@ -12,6 +12,9 @@ internal PendingZonedDateTimeExpression(SqlExpression operand, SqlExpression tim

internal SqlExpression TimeZoneId { get; }

public override Expression Quote()
=> throw new UnreachableException("PendingDateTimeZoneProviderExpression is a temporary tree representation and should never be quoted");

protected override void Print(ExpressionPrinter expressionPrinter)
{
expressionPrinter.Visit(Operand);
Expand Down
1 change: 1 addition & 0 deletions src/EFCore.PG/EFCore.PG.csproj
Expand Up @@ -9,6 +9,7 @@
<Description>PostgreSQL/Npgsql provider for Entity Framework Core.</Description>
<PackageTags>npgsql;postgresql;postgres;Entity Framework Core;entity-framework-core;ef;efcore;orm;sql</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>
<NoWarn>EF1003</NoWarn> <!-- Precompiled query is experimental -->
</PropertyGroup>

<ItemGroup>
Expand Down
Expand Up @@ -78,7 +78,7 @@ public NpgsqlObjectToStringTranslator(IRelationalTypeMappingSource typeMappingSo
_sqlExpressionFactory.Equal(instance, _sqlExpressionFactory.Constant(true)),
_sqlExpressionFactory.Constant(true.ToString()))
},
_sqlExpressionFactory.Constant(null))
_sqlExpressionFactory.Constant(null, typeof(string)))
: _sqlExpressionFactory.Case(
new[]
{
Expand Down
12 changes: 12 additions & 0 deletions src/EFCore.PG/Query/Expressions/Internal/PgAllExpression.cs
Expand Up @@ -8,6 +8,8 @@
/// </remarks>
public class PgAllExpression : SqlExpression, IEquatable<PgAllExpression>
{
private static ConstructorInfo? _quotingConstructor;

/// <inheritdoc />
public override Type Type
=> typeof(bool);
Expand Down Expand Up @@ -63,6 +65,16 @@ public virtual PgAllExpression Update(SqlExpression item, SqlExpression array)
? new PgAllExpression(item, array, OperatorType, TypeMapping)
: this;

/// <inheritdoc />
public override Expression Quote()
=> New(
_quotingConstructor ??= typeof(PgAllExpression).GetConstructor(
[typeof(SqlExpression), typeof(SqlExpression), typeof(PgAllOperatorType), typeof(RelationalTypeMapping)])!,
Item.Quote(),
Array.Quote(),
Constant(OperatorType),
RelationalExpressionQuotingUtilities.QuoteTypeMapping(TypeMapping));

/// <inheritdoc />
protected override Expression VisitChildren(ExpressionVisitor visitor)
=> Update((SqlExpression)visitor.Visit(Item), (SqlExpression)visitor.Visit(Array));
Expand Down
12 changes: 12 additions & 0 deletions src/EFCore.PG/Query/Expressions/Internal/PgAnyExpression.cs
Expand Up @@ -11,6 +11,8 @@
/// </remarks>
public class PgAnyExpression : SqlExpression, IEquatable<PgAnyExpression>
{
private static ConstructorInfo? _quotingConstructor;

/// <inheritdoc />
public override Type Type
=> typeof(bool);
Expand Down Expand Up @@ -74,6 +76,16 @@ public virtual PgAnyExpression Update(SqlExpression item, SqlExpression array)
? new PgAnyExpression(item, array, OperatorType, TypeMapping)
: this;

/// <inheritdoc />
public override Expression Quote()
=> New(
_quotingConstructor ??= typeof(PgAnyExpression).GetConstructor(
[typeof(SqlExpression), typeof(SqlExpression), typeof(PgAllOperatorType), typeof(RelationalTypeMapping)])!,
Item.Quote(),
Array.Quote(),
Constant(OperatorType),
RelationalExpressionQuotingUtilities.QuoteTypeMapping(TypeMapping));

/// <inheritdoc />
protected override Expression VisitChildren(ExpressionVisitor visitor)
=> Update((SqlExpression)visitor.Visit(Item), (SqlExpression)visitor.Visit(Array));
Expand Down
13 changes: 13 additions & 0 deletions src/EFCore.PG/Query/Expressions/Internal/PgArrayIndexExpression.cs
Expand Up @@ -9,6 +9,8 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query.Expressions.Internal;
/// </remarks>
public class PgArrayIndexExpression : SqlExpression, IEquatable<PgArrayIndexExpression>
{
private static ConstructorInfo? _quotingConstructor;

/// <summary>
/// The array being indexed.
/// </summary>
Expand Down Expand Up @@ -75,6 +77,17 @@ public virtual PgArrayIndexExpression Update(SqlExpression array, SqlExpression
? this
: new PgArrayIndexExpression(array, index, IsNullable, Type, TypeMapping);

/// <inheritdoc />
public override Expression Quote()
=> New(
_quotingConstructor ??= typeof(PgArrayIndexExpression).GetConstructor(
[typeof(SqlExpression), typeof(SqlExpression), typeof(bool), typeof(Type), typeof(RelationalTypeMapping)])!,
Array.Quote(),
Index.Quote(),
Constant(IsNullable),
Constant(Type),
RelationalExpressionQuotingUtilities.QuoteTypeMapping(TypeMapping));

/// <inheritdoc />
protected override Expression VisitChildren(ExpressionVisitor visitor)
=> Update((SqlExpression)visitor.Visit(Array), (SqlExpression)visitor.Visit(Index));
Expand Down
14 changes: 14 additions & 0 deletions src/EFCore.PG/Query/Expressions/Internal/PgArraySliceExpression.cs
Expand Up @@ -8,6 +8,8 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query.Expressions.Internal;
/// </remarks>
public class PgArraySliceExpression : SqlExpression, IEquatable<PgArraySliceExpression>
{
private static ConstructorInfo? _quotingConstructor;

/// <summary>
/// The array being sliced.
/// </summary>
Expand Down Expand Up @@ -72,6 +74,18 @@ public virtual PgArraySliceExpression Update(SqlExpression array, SqlExpression?
? this
: new PgArraySliceExpression(array, lowerBound, upperBound, IsNullable, Type, TypeMapping);

/// <inheritdoc />
public override Expression Quote()
=> New(
_quotingConstructor ??= typeof(PgArraySliceExpression).GetConstructor(
[typeof(SqlExpression), typeof(SqlExpression), typeof(SqlExpression), typeof(bool), typeof(Type), typeof(RelationalTypeMapping)])!,
Array.Quote(),
RelationalExpressionQuotingUtilities.VisitOrNull(LowerBound),
RelationalExpressionQuotingUtilities.VisitOrNull(UpperBound),
Constant(IsNullable),
Constant(Type),
RelationalExpressionQuotingUtilities.QuoteTypeMapping(TypeMapping));

/// <inheritdoc />
protected override Expression VisitChildren(ExpressionVisitor visitor)
=> Update(
Expand Down
13 changes: 13 additions & 0 deletions src/EFCore.PG/Query/Expressions/Internal/PgBinaryExpression.cs
Expand Up @@ -7,6 +7,8 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query.Expressions.Internal;
/// </summary>
public class PgBinaryExpression : SqlExpression
{
private static ConstructorInfo? _quotingConstructor;

/// <summary>
/// Creates a new instance of the <see cref="PgBinaryExpression" /> class.
/// </summary>
Expand Down Expand Up @@ -74,6 +76,17 @@ public virtual PgBinaryExpression Update(SqlExpression left, SqlExpression right
: this;
}

/// <inheritdoc />
public override Expression Quote()
=> New(
_quotingConstructor ??= typeof(PgBinaryExpression).GetConstructor(
[typeof(PgExpressionType), typeof(SqlExpression), typeof(SqlExpression), typeof(Type), typeof(RelationalTypeMapping)])!,
Constant(OperatorType),
Left.Quote(),
Right.Quote(),
Constant(Type),
RelationalExpressionQuotingUtilities.QuoteTypeMapping(TypeMapping));

/// <inheritdoc />
protected override void Print(ExpressionPrinter expressionPrinter)
{
Expand Down
12 changes: 12 additions & 0 deletions src/EFCore.PG/Query/Expressions/Internal/PgILikeExpression.cs
Expand Up @@ -6,6 +6,8 @@
// ReSharper disable once InconsistentNaming
public class PgILikeExpression : SqlExpression, IEquatable<PgILikeExpression>
{
private static ConstructorInfo? _quotingConstructor;

/// <summary>
/// The match expression.
/// </summary>
Expand Down Expand Up @@ -60,6 +62,16 @@ protected override Expression VisitChildren(ExpressionVisitor visitor)
? this
: new PgILikeExpression(match, pattern, escapeChar, TypeMapping);

/// <inheritdoc />
public override Expression Quote()
=> New(
_quotingConstructor ??= typeof(PgILikeExpression).GetConstructor(
[typeof(SqlExpression), typeof(SqlExpression), typeof(SqlExpression), typeof(RelationalTypeMapping)])!,
Match.Quote(),
Pattern.Quote(),
RelationalExpressionQuotingUtilities.VisitOrNull(EscapeChar),
RelationalExpressionQuotingUtilities.QuoteTypeMapping(TypeMapping));

/// <inheritdoc />
public override bool Equals(object? obj)
=> obj is PgILikeExpression other && Equals(other);
Expand Down
Expand Up @@ -5,6 +5,8 @@
/// </summary>
public class PgJsonTraversalExpression : SqlExpression, IEquatable<PgJsonTraversalExpression>
{
private static ConstructorInfo? _quotingConstructor;

/// <summary>
/// The match expression.
/// </summary>
Expand Down Expand Up @@ -56,6 +58,17 @@ public virtual PgJsonTraversalExpression Update(SqlExpression expression, IReadO
? this
: new PgJsonTraversalExpression(expression, path, ReturnsText, Type, TypeMapping);

/// <inheritdoc />
public override Expression Quote()
=> New(
_quotingConstructor ??= typeof(PgJsonTraversalExpression).GetConstructor(
[typeof(SqlExpression), typeof(IReadOnlyList<SqlExpression>), typeof(bool), typeof(Type), typeof(RelationalTypeMapping)])!,
Expression.Quote(),
NewArrayInit(typeof(SqlExpression), initializers: Path.Select(a => a.Quote())),
Constant(ReturnsText),
Constant(Type),
RelationalExpressionQuotingUtilities.QuoteTypeMapping(TypeMapping));

/// <summary>
/// Appends an additional path component to this <see cref="PgJsonTraversalExpression" /> and returns the result.
/// </summary>
Expand Down
11 changes: 11 additions & 0 deletions src/EFCore.PG/Query/Expressions/Internal/PgNewArrayExpression.cs
Expand Up @@ -5,6 +5,8 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query.Expressions.Internal;
/// </summary>
public class PgNewArrayExpression : SqlExpression
{
private static ConstructorInfo? _quotingConstructor;

/// <summary>
/// Creates a new instance of the <see cref="PgNewArrayExpression" /> class.
/// </summary>
Expand Down Expand Up @@ -74,6 +76,15 @@ public virtual PgNewArrayExpression Update(IReadOnlyList<SqlExpression> expressi
: new PgNewArrayExpression(expressions, Type, TypeMapping);
}

/// <inheritdoc />
public override Expression Quote()
=> New(
_quotingConstructor ??= typeof(PgNewArrayExpression).GetConstructor(
[typeof(IReadOnlyList<SqlExpression>), typeof(Type), typeof(RelationalTypeMapping)])!,
NewArrayInit(typeof(SqlExpression), initializers: Expressions.Select(a => a.Quote())),
Constant(Type),
RelationalExpressionQuotingUtilities.QuoteTypeMapping(TypeMapping));

/// <inheritdoc />
protected override void Print(ExpressionPrinter expressionPrinter)
{
Expand Down
12 changes: 12 additions & 0 deletions src/EFCore.PG/Query/Expressions/Internal/PgRegexMatchExpression.cs
Expand Up @@ -7,6 +7,8 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query.Expressions.Internal;
/// </summary>
public class PgRegexMatchExpression : SqlExpression, IEquatable<PgRegexMatchExpression>
{
private static ConstructorInfo? _quotingConstructor;

/// <inheritdoc />
public override Type Type
=> typeof(bool);
Expand Down Expand Up @@ -58,6 +60,16 @@ public virtual PgRegexMatchExpression Update(SqlExpression match, SqlExpression
? new PgRegexMatchExpression(match, pattern, Options, TypeMapping)
: this;

/// <inheritdoc />
public override Expression Quote()
=> New(
_quotingConstructor ??= typeof(PgRegexMatchExpression).GetConstructor(
[typeof(SqlExpression), typeof(SqlExpression), typeof(RegexOptions), typeof(RelationalTypeMapping)])!,
Match.Quote(),
Pattern.Quote(),
Constant(Options),
RelationalExpressionQuotingUtilities.QuoteTypeMapping(TypeMapping));

/// <inheritdoc />
public virtual bool Equals(PgRegexMatchExpression? other)
=> ReferenceEquals(this, other)
Expand Down
16 changes: 15 additions & 1 deletion src/EFCore.PG/Query/Expressions/Internal/PgRowValueExpression.cs
Expand Up @@ -11,13 +11,18 @@ namespace Npgsql.EntityFrameworkCore.PostgreSQL.Query.Expressions.Internal;
/// </remarks>
public class PgRowValueExpression : SqlExpression, IEquatable<PgRowValueExpression>
{
private static ConstructorInfo? _quotingConstructor;

/// <summary>
/// The values of this PostgreSQL row value expression.
/// </summary>
public virtual IReadOnlyList<SqlExpression> Values { get; }

/// <inheritdoc />
public PgRowValueExpression(IReadOnlyList<SqlExpression> values, Type type, RelationalTypeMapping? typeMapping = null)
public PgRowValueExpression(
IReadOnlyList<SqlExpression> values,
Type type,
RelationalTypeMapping? typeMapping = null)
: base(type, typeMapping)
{
Check.NotNull(values, nameof(values));
Expand Down Expand Up @@ -64,6 +69,15 @@ public virtual PgRowValueExpression Update(IReadOnlyList<SqlExpression> values)
? this
: new PgRowValueExpression(values, Type);

/// <inheritdoc />
public override Expression Quote()
=> New(
_quotingConstructor ??= typeof(PgRowValueExpression).GetConstructor(
[typeof(IReadOnlyList<SqlExpression>), typeof(Type), typeof(RelationalTypeMapping)])!,
NewArrayInit(typeof(SqlExpression), initializers: Values.Select(a => a.Quote())),
Constant(Type),
RelationalExpressionQuotingUtilities.QuoteTypeMapping(TypeMapping));

/// <inheritdoc />
protected override void Print(ExpressionPrinter expressionPrinter)
{
Expand Down
Expand Up @@ -9,6 +9,8 @@
/// </summary>
public class PgUnknownBinaryExpression : SqlExpression, IEquatable<PgUnknownBinaryExpression>
{
private static ConstructorInfo? _quotingConstructor;

/// <summary>
/// The left-hand expression.
/// </summary>
Expand Down Expand Up @@ -59,6 +61,17 @@ public virtual PgUnknownBinaryExpression Update(SqlExpression left, SqlExpressio
? this
: new PgUnknownBinaryExpression(left, right, Operator, Type, TypeMapping);

/// <inheritdoc />
public override Expression Quote()
=> New(
_quotingConstructor ??= typeof(PgUnknownBinaryExpression).GetConstructor(
[typeof(SqlExpression), typeof(SqlExpression), typeof(string), typeof(Type), typeof(RelationalTypeMapping)])!,
Left.Quote(),
Right.Quote(),
Constant(Operator),
Constant(Type),
RelationalExpressionQuotingUtilities.QuoteTypeMapping(TypeMapping));

/// <inheritdoc />
public virtual bool Equals(PgUnknownBinaryExpression? other)
=> ReferenceEquals(this, other)
Expand Down

0 comments on commit f38a96c

Please sign in to comment.