Skip to content

Commit

Permalink
Test on .NET Framework
Browse files Browse the repository at this point in the history
  • Loading branch information
bricelam committed Nov 18, 2021
1 parent 1876c93 commit 2401335
Show file tree
Hide file tree
Showing 16 changed files with 61 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.0.6" PrivateAssets="None" />
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.0.7" PrivateAssets="None" />
<PackageReference Include="Microsoft.Win32.Primitives" Version="4.3.0" />
<PackageReference Include="System.Net.Primitives" Version="4.3.0" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Sqlite/EFCore.Sqlite.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.0.6" PrivateAssets="None" />
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.0.7" PrivateAssets="None" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Microsoft.Data.Sqlite.SqliteTransaction</Description>
</ItemGroup>

<ItemGroup>
<PackageReference Include="SQLitePCLRaw.core" Version="2.0.6" />
<PackageReference Include="SQLitePCLRaw.core" Version="2.0.7" />
</ItemGroup>

<ItemGroup>
Expand Down
42 changes: 40 additions & 2 deletions src/Microsoft.Data.Sqlite.Core/SqliteConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
using System.Data.Common;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using Microsoft.Data.Sqlite.Properties;
using Microsoft.Data.Sqlite.Utilities;
using SQLitePCL;
using static SQLitePCL.raw;

Expand All @@ -23,6 +23,9 @@ public partial class SqliteConnection : DbConnection
{
internal const string MainDatabaseName = "main";

private const int SQLITE_WIN32_DATA_DIRECTORY_TYPE = 1;
private const int SQLITE_WIN32_TEMP_DIRECTORY_TYPE = 2;

private readonly List<WeakReference<SqliteCommand>> _commands = new();

private Dictionary<string, (object? state, strdelegate_collation? collation)>? _collations;
Expand All @@ -44,7 +47,42 @@ public partial class SqliteConnection : DbConnection
private static readonly StateChangeEventArgs _fromOpenToClosedEventArgs = new StateChangeEventArgs(ConnectionState.Open, ConnectionState.Closed);

static SqliteConnection()
=> BundleInitializer.Initialize();
{
Type.GetType("SQLitePCL.Batteries_V2, SQLitePCLRaw.batteries_v2")
?.GetRuntimeMethod("Init", Type.EmptyTypes)
?.Invoke(null, null);

try
{
var currentAppData = Type.GetType("Windows.Storage.ApplicationData, Windows, ContentType=WindowsRuntime")
?? Type.GetType("Windows.Storage.ApplicationData, Microsoft.Windows.SDK.NET")
?.GetRuntimeProperty("Current")?.GetValue(null);

var localFolder = currentAppData?.GetType()
.GetRuntimeProperty("LocalFolder")?.GetValue(currentAppData);
var localFolderPath = (string?)localFolder?.GetType()
.GetRuntimeProperty("Path")?.GetValue(localFolder);
if (localFolderPath != null)
{
var rc = sqlite3_win32_set_directory(SQLITE_WIN32_DATA_DIRECTORY_TYPE, localFolderPath);
Debug.Assert(rc == SQLITE_OK);
}

var tempFolder = currentAppData?.GetType()
.GetRuntimeProperty("TemporaryFolder")?.GetValue(currentAppData);
var tempFolderPath = (string?)tempFolder?.GetType()
.GetRuntimeProperty("Path")?.GetValue(tempFolder);
if (tempFolderPath != null)
{
var rc = sqlite3_win32_set_directory(SQLITE_WIN32_TEMP_DIRECTORY_TYPE, tempFolderPath);
Debug.Assert(rc == SQLITE_OK);
}
}
catch
{
// Ignore "The process has no package identity."
}
}

/// <summary>
/// Initializes a new instance of the <see cref="SqliteConnection" /> class.
Expand Down
47 changes: 0 additions & 47 deletions src/Microsoft.Data.Sqlite.Core/Utilities/ApplicationDataHelper.cs

This file was deleted.

47 changes: 0 additions & 47 deletions src/Microsoft.Data.Sqlite.Core/Utilities/BundleInitializer.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/Microsoft.Data.Sqlite/Microsoft.Data.Sqlite.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Microsoft.Data.Sqlite.SqliteTransaction</Description>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.0.6" PrivateAssets="None" />
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.0.7" PrivateAssets="None" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.0.6" />
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.0.7" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFrameworks>net6.0;net461</TargetFrameworks>
<DefineConstants>$(DefineConstants);E_SQLITE3</DefineConstants>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand All @@ -11,7 +11,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.0.6" />
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.0.7" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFrameworks>net6.0;net461</TargetFrameworks>
<DefineConstants>$(DefineConstants);E_SQLCIPHER</DefineConstants>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand All @@ -11,7 +11,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlcipher" Version="2.0.6" />
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlcipher" Version="2.0.7" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFrameworks>net6.0;net461</TargetFrameworks>
<DefineConstants>$(DefineConstants);SQLITE3</DefineConstants>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand All @@ -11,7 +11,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="SQLitePCLRaw.bundle_sqlite3" Version="2.0.6" />
<PackageReference Include="SQLitePCLRaw.bundle_sqlite3" Version="2.0.7" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFrameworks>net6.0;net461</TargetFrameworks>
<DefineConstants>$(DefineConstants);WINSQLITE3</DefineConstants>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand All @@ -11,7 +11,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="SQLitePCLRaw.bundle_winsqlite3" Version="2.0.6" />
<PackageReference Include="SQLitePCLRaw.bundle_winsqlite3" Version="2.0.7" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public void Functions_dont_bleed_across_connections()

Assert.Same(db, connection2.Handle);
var functions = connection2.ExecuteScalar<string>("SELECT group_concat(name) FROM pragma_function_list;")
.Split(",");
.Split(',');
Assert.DoesNotContain("function1", functions);
Assert.DoesNotContain("aggregate1", functions);
}
Expand All @@ -180,7 +180,7 @@ public void Collations_dont_bleed_across_connections()

Assert.Same(db, connection2.Handle);
var collations = connection2.ExecuteScalar<string>("SELECT group_concat(name) FROM pragma_collation_list;")
.Split(",");
.Split(',');
Assert.DoesNotContain("COLLATION1", collations);
}

Expand Down
2 changes: 1 addition & 1 deletion test/Microsoft.Data.Sqlite.Tests/SqliteConnectionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,7 @@ public void GetSchema_ReservedWords_works()
Assert.Single(dataTable.Columns);
Assert.Contains(
dataTable.Rows.Cast<DataRow>(),
r => r.Field<string>(DbMetaDataColumnNames.ReservedWord) == "SELECT");
r => (string)r[DbMetaDataColumnNames.ReservedWord] == "SELECT");
}
}
}
2 changes: 2 additions & 0 deletions test/Microsoft.Data.Sqlite.Tests/SqliteDataReaderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,7 @@ public void GetTimeSpan_throws_when_non_query()
public void GetDateTimeOffset_throws_when_null()
=> GetX_throws_when_null(r => ((SqliteDataReader)r).GetDateTimeOffset(0));

#if NET6_0_OR_GREATER
[Fact]
public void GetFieldValue_of_DateOnly_works()
=> GetFieldValue_works(
Expand All @@ -711,6 +712,7 @@ public void GetFieldValue_of_TimeOnly_works_with_milliseconds()
=> GetFieldValue_works(
"SELECT '13:10:15.5';",
new TimeOnly(13, 10, 15, 500));
#endif

[Theory]
[InlineData("SELECT 1;", "INTEGER")]
Expand Down
2 changes: 2 additions & 0 deletions test/Microsoft.Data.Sqlite.Tests/SqliteParameterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ public void Bind_works_when_DateTimeOffset_with_SqliteType_Real()
2456761.9680439816,
SqliteType.Real);

#if NET6_0_OR_GREATER
[Fact]
public void Bind_works_when_DateOnly()
=> Bind_works(new DateOnly(2014, 4, 14), "2014-04-14");
Expand All @@ -276,6 +277,7 @@ public void Bind_works_when_TimeOnly_with_milliseconds()
[Fact]
public void Bind_works_when_TimeOnly_with_SqliteType_Real()
=> Bind_works(new TimeOnly(13, 10, 15), 0.5487847222222222, SqliteType.Real);
#endif

[Fact]
public void Bind_works_when_DBNull()
Expand Down

0 comments on commit 2401335

Please sign in to comment.