Revert "Microsoft.Data.Sqlite"

This reverts commit 73baa18e640534329ed55467bb05f333438d5076.
This commit is contained in:
Natsumi
2025-09-04 01:03:01 +12:00
parent 572872bd95
commit 85885000e2
5 changed files with 44 additions and 57 deletions

View File

@@ -7,12 +7,12 @@
using NLog;
using NLog.Targets;
using System;
using System.Data.SQLite;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Text.Json;
using System.Threading;
using System.Windows.Forms;
using Microsoft.Data.Sqlite;
namespace VRCX
{
@@ -172,7 +172,7 @@ namespace VRCX
#region Handle Database Error
catch (SqliteException e)
catch (SQLiteException e)
{
logger.Fatal(e, "Unhandled SQLite Exception, closing.");
var messageBoxResult = MessageBox.Show(

View File

@@ -1,17 +1,18 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Data.SQLite;
using System.IO;
using System.Text.Json.Nodes;
using System.Threading;
using System.Text.Json;
using Microsoft.Data.Sqlite;
namespace VRCX
{
public class SQLite
{
public static SQLite Instance;
private readonly ReaderWriterLockSlim _connectionLock;
private SqliteConnection _connection;
private readonly ReaderWriterLockSlim m_ConnectionLock;
private SQLiteConnection m_Connection;
static SQLite()
{
@@ -20,7 +21,7 @@ namespace VRCX
public SQLite()
{
_connectionLock = new ReaderWriterLockSlim();
m_ConnectionLock = new ReaderWriterLockSlim();
}
public void Init()
@@ -33,24 +34,18 @@ namespace VRCX
if (!string.IsNullOrEmpty(jsonDataSource))
dataSource = jsonDataSource;
_connection = new SqliteConnection($"Data Source=\"{dataSource}\";Mode=ReadWriteCreate;Cache=Shared;");
_connection.Open();
using var command = _connection.CreateCommand();
command.CommandText = @"PRAGMA locking_mode=NORMAL;
PRAGMA busy_timeout=5000;
PRAGMA journal_mode=WAL;
PRAGMA optimize=0x10002;";
command.ExecuteNonQuery();
m_Connection = new SQLiteConnection($"Data Source=\"{dataSource}\";Version=3;PRAGMA locking_mode=NORMAL;PRAGMA busy_timeout=5000;PRAGMA journal_mode=WAL;PRAGMA optimize=0x10002;", true);
m_Connection.Open();
}
public void Exit()
{
_connection.Close();
_connection.Dispose();
m_Connection.Close();
m_Connection.Dispose();
}
// for Electron
public string ExecuteJson(string sql, IDictionary<string, object>? args = null)
public string ExecuteJson(string sql, IDictionary<string, object> args = null)
{
var result = Execute(sql, args);
if (result.Item1 != null)
@@ -68,17 +63,17 @@ namespace VRCX
});
}
public Tuple<string?, object[][]?> Execute(string sql, IDictionary<string, object>? args = null)
public Tuple<string, object[]> Execute(string sql, IDictionary<string, object> args = null)
{
_connectionLock.EnterReadLock();
m_ConnectionLock.EnterReadLock();
try
{
using var command = new SqliteCommand(sql, _connection);
using var command = new SQLiteCommand(sql, m_Connection);
if (args != null)
{
foreach (var arg in args)
{
command.Parameters.Add(new SqliteParameter(arg.Key, arg.Value));
command.Parameters.Add(new SQLiteParameter(arg.Key, arg.Value));
}
}
@@ -93,37 +88,37 @@ namespace VRCX
}
result.Add(values);
}
return new Tuple<string?, object[][]?>(null, result.ToArray());
return new Tuple<string, object[]>(null, result.ToArray());
}
catch (Exception ex)
{
return new Tuple<string?, object[][]?>(ex.Message, null);
return new Tuple<string, object[]>(ex.Message, null);
}
finally
{
_connectionLock.ExitReadLock();
m_ConnectionLock.ExitReadLock();
}
}
public int ExecuteNonQuery(string sql, IDictionary<string, object>? args = null)
public int ExecuteNonQuery(string sql, IDictionary<string, object> args = null)
{
int result = -1;
_connectionLock.EnterWriteLock();
m_ConnectionLock.EnterWriteLock();
try
{
using var command = new SqliteCommand(sql, _connection);
using var command = new SQLiteCommand(sql, m_Connection);
if (args != null)
{
foreach (var arg in args)
{
command.Parameters.Add(new SqliteParameter(arg.Key, arg.Value));
command.Parameters.Add(new SQLiteParameter(arg.Key, arg.Value));
}
}
result = command.ExecuteNonQuery();
}
finally
{
_connectionLock.ExitWriteLock();
m_ConnectionLock.ExitWriteLock();
}
return result;

View File

@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using Microsoft.Data.Sqlite;
using System.Data.SQLite;
namespace VRCX
{
@@ -16,27 +16,20 @@ namespace VRCX
// Couldn't be me... oh wait
internal class ScreenshotMetadataDatabase
{
private readonly SqliteConnection _sqlite;
private readonly SQLiteConnection _sqlite;
public ScreenshotMetadataDatabase(string databaseLocation)
{
_sqlite = new SqliteConnection($"Data Source=\"{databaseLocation}\";Mode=ReadWriteCreate;Cache=Shared;");
_sqlite = new SQLiteConnection($"Data Source=\"{databaseLocation}\";Version=3;PRAGMA locking_mode=NORMAL;PRAGMA busy_timeout=5000;PRAGMA journal_mode=WAL;PRAGMA optimize=0x10002;", true);
_sqlite.Open();
using var command = _sqlite.CreateCommand();
command.CommandText = @"PRAGMA locking_mode=NORMAL;
PRAGMA busy_timeout=5000;
PRAGMA journal_mode=WAL;
PRAGMA optimize=0x10002;";
command.ExecuteNonQuery();
var createCommand = _sqlite.CreateCommand();
createCommand.CommandText = @"CREATE TABLE IF NOT EXISTS cache (
using var cmd = new SQLiteCommand(_sqlite);
cmd.CommandText = @"CREATE TABLE IF NOT EXISTS cache (
id INTEGER PRIMARY KEY AUTOINCREMENT,
file_path TEXT NOT NULL UNIQUE,
metadata TEXT,
cached_at INTEGER NOT NULL
);";
createCommand.ExecuteNonQuery();
cmd.ExecuteNonQuery();
}
public void AddMetadataCache(string filePath, string metadata)
@@ -53,7 +46,7 @@ namespace VRCX
CachedAt = DateTimeOffset.Now
};
const string sql = "INSERT OR REPLACE INTO cache (file_path, metadata, cached_at) VALUES (@FilePath, @Metadata, @CachedAt);";
using var command = new SqliteCommand(sql, _sqlite);
using var command = new SQLiteCommand(sql, _sqlite);
command.Parameters.AddWithValue("@FilePath", cache.FilePath);
command.Parameters.AddWithValue("@Metadata", cache.Metadata);
command.Parameters.AddWithValue("@CachedAt", cache.CachedAt.Ticks);
@@ -63,12 +56,12 @@ namespace VRCX
public void BulkAddMetadataCache(IEnumerable<MetadataCache> cache)
{
using var transaction = _sqlite.BeginTransaction();
using var command = _sqlite.CreateCommand();
using var command = new SQLiteCommand(_sqlite);
const string sql = "INSERT OR REPLACE INTO cache (file_path, metadata, cached_at) VALUES (@FilePath, @Metadata, @CachedAt);";
command.CommandText = sql;
var filePathParam = command.Parameters.Add("@FilePath", SqliteType.Text);
var metadataParam = command.Parameters.Add("@Metadata", SqliteType.Text);
var cachedAtParam = command.Parameters.Add("@CachedAt", SqliteType.Integer);
var filePathParam = command.Parameters.Add("@FilePath", System.Data.DbType.String);
var metadataParam = command.Parameters.Add("@Metadata", System.Data.DbType.String);
var cachedAtParam = command.Parameters.Add("@CachedAt", System.Data.DbType.Int64);
foreach (var item in cache)
{
var isFileCached = IsFileCached(item.FilePath);
@@ -86,8 +79,7 @@ namespace VRCX
public int IsFileCached(string filePath)
{
const string sql = "SELECT id FROM cache WHERE file_path = @FilePath;";
using var command = _sqlite.CreateCommand();
command.CommandText = sql;
using var command = new SQLiteCommand(sql, _sqlite);
command.Parameters.AddWithValue("@FilePath", filePath);
using var reader = command.ExecuteReader();
var result = new List<int>();
@@ -105,8 +97,7 @@ namespace VRCX
public string? GetMetadata(string filePath)
{
const string sql = "SELECT id, file_path, metadata, cached_at FROM cache WHERE file_path = @FilePath;";
using var command = _sqlite.CreateCommand();
command.CommandText = sql;
using var command = new SQLiteCommand(sql, _sqlite);
command.Parameters.AddWithValue("@FilePath", filePath);
using var reader = command.ExecuteReader();
var result = new List<MetadataCache>();
@@ -130,8 +121,7 @@ namespace VRCX
public string? GetMetadataById(int id)
{
const string sql = "SELECT id, file_path, metadata, cached_at FROM cache WHERE id = @Id;";
using var command = _sqlite.CreateCommand();
command.CommandText = sql;
using var command = new SQLiteCommand(sql, _sqlite);
command.Parameters.AddWithValue("@Id", id);
using var reader = command.ExecuteReader();
var result = new List<MetadataCache>();

View File

@@ -91,7 +91,6 @@
<PackageReference Include="CefSharp.OffScreen.NETCore" Version="138.0.340" />
<PackageReference Include="CefSharp.WinForms.NETCore" Version="138.0.340" />
<PackageReference Include="DiscordRichPresence" Version="1.6.1.70" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="9.0.8" />
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NLog" Version="6.0.3" />
@@ -99,6 +98,8 @@
<PackageReference Include="SharpDX.Mathematics" Version="4.2.0" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.11" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="2.1.7" />
<PackageReference Include="System.Data.SQLite" Version="2.0.1" />
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.119" />
<PackageReference Include="System.Drawing.Common" Version="9.0.8" />
<PackageReference Include="System.Management" Version="9.0.8" />
<PackageReference Include="System.Text.Json" Version="9.0.8" />

View File

@@ -87,7 +87,6 @@
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Data.Sqlite" Version="9.0.8" />
<PackageReference Include="Microsoft.JavaScript.NodeApi" Version="0.9.15" />
<PackageReference Include="Microsoft.JavaScript.NodeApi.Generator" Version="0.9.15" />
<PackageReference Include="DiscordRichPresence" Version="1.6.1.70" />
@@ -95,6 +94,8 @@
<PackageReference Include="NLog" Version="6.0.3" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.11" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="2.1.7" />
<PackageReference Include="System.Data.SQLite" Version="2.0.1" />
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.119" />
<PackageReference Include="System.Drawing.Common" Version="9.0.8" />
<PackageReference Include="System.Management" Version="9.0.8" />
<PackageReference Include="System.Text.Json" Version="9.0.8" />