Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
35 changes: 20 additions & 15 deletions src/Microsoft.Data.Sqlite.Core/SqliteConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Runtime.CompilerServices;
using Microsoft.Data.Sqlite.Properties;
using SQLitePCL;
using static SQLitePCL.raw;
Expand Down Expand Up @@ -52,36 +53,40 @@ static SqliteConnection()
?.GetRuntimeMethod("Init", Type.EmptyTypes)
?.Invoke(null, null);

var appDataType = Type.GetType("Windows.Storage.ApplicationData, Windows, ContentType=WindowsRuntime")
?? Type.GetType("Windows.Storage.ApplicationData, Microsoft.Windows.SDK.NET");

var storageFolderType = Type.GetType("Windows.Storage.StorageFolder, Windows, ContentType=WindowsRuntime")
?? Type.GetType("Windows.Storage.StorageFolder, Microsoft.Windows.SDK.NET");

object? currentAppData = 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);
currentAppData = appDataType?.GetRuntimeProperty("Current")?.GetValue(null);
}
catch (TargetInvocationException)
{
// Ignore "The process has no package identity."
}

var localFolder = currentAppData?.GetType()
.GetRuntimeProperty("LocalFolder")?.GetValue(currentAppData);
var localFolderPath = (string?)localFolder?.GetType()
.GetRuntimeProperty("Path")?.GetValue(localFolder);
if (currentAppData != null)
{
var localFolder = appDataType?.GetRuntimeProperty("LocalFolder")?.GetValue(currentAppData);
var localFolderPath = (string?)storageFolderType?.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);
var tempFolder = appDataType?.GetRuntimeProperty("TemporaryFolder")?.GetValue(currentAppData);
var tempFolderPath = (string?)storageFolderType?.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>
Expand Down
4 changes: 4 additions & 0 deletions src/Microsoft.Data.Sqlite.Core/SqliteDataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Data;
using System.Data.Common;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Text;
using System.Threading;
Expand Down Expand Up @@ -311,6 +312,9 @@ public override string GetDataTypeName(int ordinal)
/// </summary>
/// <param name="ordinal">The zero-based column ordinal.</param>
/// <returns>The data type of the column.</returns>
#if NET6_0_OR_GREATER
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.PublicFields)]
#endif
public override Type GetFieldType(int ordinal)
=> _closed
? throw new InvalidOperationException(Resources.DataReaderClosed(nameof(GetFieldType)))
Expand Down
10 changes: 10 additions & 0 deletions src/Microsoft.Data.Sqlite.Core/SqliteDataRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -191,6 +192,9 @@ public virtual string GetDataTypeName(int ordinal)
}
}

#if NET6_0_OR_GREATER
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.PublicFields)]
#endif
public virtual Type GetFieldType(int ordinal)
{
var sqliteType = GetSqliteType(ordinal);
Expand All @@ -207,6 +211,9 @@ public virtual Type GetFieldType(int ordinal)
return GetFieldTypeFromSqliteType(sqliteType);
}

#if NET6_0_OR_GREATER
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.PublicFields)]
#endif
internal static Type GetFieldTypeFromSqliteType(int sqliteType)
{
switch (sqliteType)
Expand All @@ -228,6 +235,9 @@ internal static Type GetFieldTypeFromSqliteType(int sqliteType)
}
}

#if NET6_0_OR_GREATER
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.PublicFields)]
#endif
public static Type GetFieldType(string type)
{
switch (type)
Expand Down