mirror of
https://github.com/vrcx-team/VRCX.git
synced 2026-04-06 00:32:02 +02:00
81 lines
2.4 KiB
C#
81 lines
2.4 KiB
C#
using CefSharp;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.SQLite;
|
|
using System.Threading;
|
|
using System.Windows.Forms;
|
|
|
|
namespace VRCX
|
|
{
|
|
public class SQLite
|
|
{
|
|
private static readonly ReaderWriterLockSlim m_Lock = new ReaderWriterLockSlim();
|
|
private static SQLiteConnection m_Connection;
|
|
|
|
public static void Init()
|
|
{
|
|
m_Connection = new SQLiteConnection($"Data Source={Application.StartupPath}/VRCX.sqlite;Version=3");
|
|
m_Connection.Open();
|
|
}
|
|
|
|
public static void Exit()
|
|
{
|
|
m_Connection.Close();
|
|
m_Connection.Dispose();
|
|
}
|
|
|
|
public int ExecuteNonQuery(string sql, IDictionary<string, object> param = null)
|
|
{
|
|
m_Lock.EnterWriteLock();
|
|
try
|
|
{
|
|
using (var C = new SQLiteCommand(sql, m_Connection))
|
|
{
|
|
if (param != null)
|
|
{
|
|
foreach (var prop in param)
|
|
{
|
|
C.Parameters.Add(new SQLiteParameter("@" + prop.Key, prop.Value));
|
|
}
|
|
}
|
|
return C.ExecuteNonQuery();
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
m_Lock.ExitWriteLock();
|
|
}
|
|
}
|
|
|
|
public void Execute(IJavascriptCallback callback, string sql, IDictionary<string, object> param = null)
|
|
{
|
|
m_Lock.EnterReadLock();
|
|
try
|
|
{
|
|
using (var C = new SQLiteCommand(sql, m_Connection))
|
|
{
|
|
if (param != null)
|
|
{
|
|
foreach (var prop in param)
|
|
{
|
|
C.Parameters.Add(new SQLiteParameter("@" + prop.Key, prop.Value));
|
|
}
|
|
}
|
|
using (var R = C.ExecuteReader())
|
|
{
|
|
while (R.Read())
|
|
{
|
|
var row = new object[R.FieldCount];
|
|
R.GetValues(row);
|
|
callback.ExecuteAsync(row);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
m_Lock.ExitReadLock();
|
|
}
|
|
}
|
|
}
|
|
} |