Skip to content

Commit d11516d

Browse files
authored
Merge pull request #31601 from dotnet-maestro-bot/merge/release/8.0-to-main
[automated] Merge branch 'release/8.0' => 'main'
2 parents 8c2a0ba + f8b8650 commit d11516d

File tree

16 files changed

+307
-49
lines changed

16 files changed

+307
-49
lines changed

benchmark/EFCore.Sqlite.Benchmarks/EFCore.Sqlite.Benchmarks.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
</ItemGroup>
1717

1818
<ItemGroup>
19-
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.1.6-pre20230809203314" />
19+
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.1.6" />
2020
</ItemGroup>
2121

2222
<ItemGroup>

src/EFCore.Sqlite.Core/Query/Internal/SqliteQuerySqlGenerator.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,27 @@ protected override Expression VisitSqlUnary(SqlUnaryExpression sqlUnaryExpressio
313313
{
314314
switch (sqlUnaryExpression.OperatorType)
315315
{
316+
case ExpressionType.Convert:
317+
if (sqlUnaryExpression.Operand.Type == typeof(char)
318+
&& sqlUnaryExpression.Type.IsInteger())
319+
{
320+
Sql.Append("unicode(");
321+
Visit(sqlUnaryExpression.Operand);
322+
Sql.Append(")");
323+
324+
return sqlUnaryExpression;
325+
}
326+
else if (sqlUnaryExpression.Operand.Type.IsInteger()
327+
&& sqlUnaryExpression.Type == typeof(char))
328+
{
329+
Sql.Append("char(");
330+
Visit(sqlUnaryExpression.Operand);
331+
Sql.Append(")");
332+
333+
return sqlUnaryExpression;
334+
}
335+
goto default;
336+
316337
case ExpressionType.Not when sqlUnaryExpression.Type == typeof(bool):
317338
switch (sqlUnaryExpression.Operand)
318339
{

src/EFCore.Sqlite/EFCore.Sqlite.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
</ItemGroup>
4848

4949
<ItemGroup>
50-
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.1.6-pre20230809203314" />
50+
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.1.6" />
5151
</ItemGroup>
5252

5353
<ItemGroup>

src/Microsoft.Data.Sqlite.Core/Microsoft.Data.Sqlite.Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Microsoft.Data.Sqlite.SqliteTransaction</Description>
4040
</ItemGroup>
4141

4242
<ItemGroup>
43-
<PackageReference Include="SQLitePCLRaw.core" Version="2.1.6-pre20230809203314" />
43+
<PackageReference Include="SQLitePCLRaw.core" Version="2.1.6" />
4444
</ItemGroup>
4545

4646
<ItemGroup>

src/Microsoft.Data.Sqlite.Core/SqliteConnection.cs

Lines changed: 70 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
using System.Data.Common;
88
using System.Diagnostics;
99
using System.Diagnostics.CodeAnalysis;
10+
using System.IO;
1011
using System.Reflection;
12+
using System.Runtime.InteropServices;
1113
using Microsoft.Data.Sqlite.Properties;
1214
using SQLitePCL;
1315
using static SQLitePCL.raw;
@@ -52,38 +54,50 @@ static SqliteConnection()
5254
?.GetRuntimeMethod("Init", Type.EmptyTypes)
5355
?.Invoke(null, null);
5456

55-
var appDataType = Type.GetType("Windows.Storage.ApplicationData, Windows, ContentType=WindowsRuntime")
56-
?? Type.GetType("Windows.Storage.ApplicationData, Microsoft.Windows.SDK.NET");
57-
58-
var storageFolderType = Type.GetType("Windows.Storage.StorageFolder, Windows, ContentType=WindowsRuntime")
59-
?? Type.GetType("Windows.Storage.StorageFolder, Microsoft.Windows.SDK.NET");
60-
61-
object? currentAppData = null;
62-
try
57+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
6358
{
64-
currentAppData = appDataType?.GetRuntimeProperty("Current")?.GetValue(null);
65-
}
66-
catch (TargetInvocationException)
67-
{
68-
// Ignore "The process has no package identity."
69-
}
59+
Type? appDataType = null;
60+
Type? storageFolderType = null;
61+
try
62+
{
63+
appDataType = Type.GetType("Windows.Storage.ApplicationData, Windows, ContentType=WindowsRuntime")
64+
?? Type.GetType("Windows.Storage.ApplicationData, Microsoft.Windows.SDK.NET");
7065

71-
if (currentAppData != null)
72-
{
73-
var localFolder = appDataType?.GetRuntimeProperty("LocalFolder")?.GetValue(currentAppData);
74-
var localFolderPath = (string?)storageFolderType?.GetRuntimeProperty("Path")?.GetValue(localFolder);
75-
if (localFolderPath != null)
66+
storageFolderType = Type.GetType("Windows.Storage.StorageFolder, Windows, ContentType=WindowsRuntime")
67+
?? Type.GetType("Windows.Storage.StorageFolder, Microsoft.Windows.SDK.NET");
68+
}
69+
catch (FileLoadException)
7670
{
77-
var rc = sqlite3_win32_set_directory(SQLITE_WIN32_DATA_DIRECTORY_TYPE, localFolderPath);
78-
Debug.Assert(rc == SQLITE_OK);
71+
// Ignore "Could not load assembly."
7972
}
8073

81-
var tempFolder = appDataType?.GetRuntimeProperty("TemporaryFolder")?.GetValue(currentAppData);
82-
var tempFolderPath = (string?)storageFolderType?.GetRuntimeProperty("Path")?.GetValue(tempFolder);
83-
if (tempFolderPath != null)
74+
object? currentAppData = null;
75+
try
76+
{
77+
currentAppData = appDataType?.GetRuntimeProperty("Current")?.GetValue(null);
78+
}
79+
catch (TargetInvocationException)
8480
{
85-
var rc = sqlite3_win32_set_directory(SQLITE_WIN32_TEMP_DIRECTORY_TYPE, tempFolderPath);
86-
Debug.Assert(rc == SQLITE_OK);
81+
// Ignore "The process has no package identity."
82+
}
83+
84+
if (currentAppData != null)
85+
{
86+
var localFolder = appDataType?.GetRuntimeProperty("LocalFolder")?.GetValue(currentAppData);
87+
var localFolderPath = (string?)storageFolderType?.GetRuntimeProperty("Path")?.GetValue(localFolder);
88+
if (localFolderPath != null)
89+
{
90+
var rc = sqlite3_win32_set_directory(SQLITE_WIN32_DATA_DIRECTORY_TYPE, localFolderPath);
91+
Debug.Assert(rc == SQLITE_OK);
92+
}
93+
94+
var tempFolder = appDataType?.GetRuntimeProperty("TemporaryFolder")?.GetValue(currentAppData);
95+
var tempFolderPath = (string?)storageFolderType?.GetRuntimeProperty("Path")?.GetValue(tempFolder);
96+
if (tempFolderPath != null)
97+
{
98+
var rc = sqlite3_win32_set_directory(SQLITE_WIN32_TEMP_DIRECTORY_TYPE, tempFolderPath);
99+
Debug.Assert(rc == SQLITE_OK);
100+
}
87101
}
88102
}
89103
}
@@ -821,22 +835,24 @@ private void CreateAggregateCore<TAccumulate, TResult>(
821835
delegate_function_aggregate_step? func_step = null;
822836
if (func != null)
823837
{
824-
func_step = (ctx, user_data, args) =>
838+
func_step = static (ctx, user_data, args) =>
825839
{
826-
var context = (AggregateContext<TAccumulate>)user_data;
840+
var definition = (AggregateDefinition<TAccumulate, TResult>)user_data;
841+
ctx.state ??= new AggregateContext<TAccumulate>(definition.Seed);
842+
843+
var context = (AggregateContext<TAccumulate>)ctx.state;
827844
if (context.Exception != null)
828845
{
829846
return;
830847
}
831848

832849
// TODO: Avoid allocation when niladic
833-
var reader = new SqliteParameterReader(name, args);
850+
var reader = new SqliteParameterReader(definition.Name, args);
834851

835852
try
836853
{
837-
// TODO: Avoid closure by passing func via user_data
838854
// NB: No need to set ctx.state since we just mutate the instance
839-
context.Accumulate = func(context.Accumulate, reader);
855+
context.Accumulate = definition.Func!(context.Accumulate, reader);
840856
}
841857
catch (Exception ex)
842858
{
@@ -848,16 +864,18 @@ private void CreateAggregateCore<TAccumulate, TResult>(
848864
delegate_function_aggregate_final? func_final = null;
849865
if (resultSelector != null)
850866
{
851-
func_final = (ctx, user_data) =>
867+
func_final = static (ctx, user_data) =>
852868
{
853-
var context = (AggregateContext<TAccumulate>)user_data;
869+
var definition = (AggregateDefinition<TAccumulate, TResult>)user_data;
870+
ctx.state ??= new AggregateContext<TAccumulate>(definition.Seed);
871+
872+
var context = (AggregateContext<TAccumulate>)ctx.state;
854873

855874
if (context.Exception == null)
856875
{
857876
try
858877
{
859-
// TODO: Avoid closure by passing resultSelector via user_data
860-
var result = resultSelector(context.Accumulate);
878+
var result = definition.ResultSelector!(context.Accumulate);
861879

862880
new SqliteResultBinder(ctx, result).Bind();
863881
}
@@ -881,7 +899,7 @@ private void CreateAggregateCore<TAccumulate, TResult>(
881899
}
882900

883901
var flags = isDeterministic ? SQLITE_DETERMINISTIC : 0;
884-
var state = new AggregateContext<TAccumulate>(seed);
902+
var state = new AggregateDefinition<TAccumulate, TResult>(name, seed, func, resultSelector);
885903

886904
if (State == ConnectionState.Open)
887905
{
@@ -915,6 +933,22 @@ private void CreateAggregateCore<TAccumulate, TResult>(
915933
return values;
916934
}
917935

936+
private sealed class AggregateDefinition<TAccumulate, TResult>
937+
{
938+
public AggregateDefinition(string name, TAccumulate seed, Func<TAccumulate, SqliteValueReader, TAccumulate>? func, Func<TAccumulate, TResult>? resultSelector)
939+
{
940+
Name = name;
941+
Seed = seed;
942+
Func = func;
943+
ResultSelector = resultSelector;
944+
}
945+
946+
public string Name { get; }
947+
public TAccumulate Seed { get; }
948+
public Func<TAccumulate, SqliteValueReader, TAccumulate>? Func { get; }
949+
public Func<TAccumulate, TResult>? ResultSelector { get; }
950+
}
951+
918952
private sealed class AggregateContext<T>
919953
{
920954
public AggregateContext(T seed)

src/Microsoft.Data.Sqlite/Microsoft.Data.Sqlite.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Microsoft.Data.Sqlite.SqliteTransaction</Description>
2424
</PropertyGroup>
2525

2626
<ItemGroup>
27-
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.1.6-pre20230809203314" />
27+
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.1.6" />
2828
</ItemGroup>
2929

3030
<ItemGroup>

test/EFCore.Design.Tests/EFCore.Design.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
<ItemGroup>
5858
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="$(MicrosoftCodeAnalysisVersion)" />
5959
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="$(MicrosoftExtensionsDependencyModelVersion)" />
60-
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.1.6-pre20230809203314" />
60+
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.1.6" />
6161
</ItemGroup>
6262

6363
</Project>

test/EFCore.NativeAotTests/EFCore.NativeAotTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<ItemGroup>
2020
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="$(MicrosoftExtensionsConfigurationEnvironmentVariablesVersion)" />
2121
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="$(MicrosoftExtensionsConfigurationJsonVersion)" />
22-
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.1.6-pre20230809203314" />
22+
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.1.6" />
2323
</ItemGroup>
2424

2525
</Project>

0 commit comments

Comments
 (0)