add live select pannel

This commit is contained in:
CroakFang
2023-01-20 07:13:54 +08:00
parent 3b18268252
commit a4dc2516e3
1543 changed files with 107369 additions and 9227 deletions
@@ -0,0 +1,149 @@
using System;
using System.Text;
using UnityEngine;
namespace Sqlite3Plugin
{
public class DBProxy : IDisposable
{
public IntPtr DBHandle { get; private set; }
public string dbPath { get; private set; }
public bool IsOpened()
{
return DBHandle != IntPtr.Zero;
}
~DBProxy()
{
CloseDB();
}
public DBProxy()
{
dbPath = null;
DBHandle = IntPtr.Zero;
}
public bool Open(string fileName)
{
IntPtr ppDB = IntPtr.Zero;
int num = Sqlite3LibImport.sqlite3_open_v2(Encoding.UTF8.GetBytes(fileName + "\0"), out ppDB, 1, IntPtr.Zero);
DBHandle = ppDB;
bool num2 = num == 0;
if (num2)
{
Exec("pragma journal_mode=OFF");
Exec("pragma synchronous=0");
Exec("pragma locking_mode=EXCLUSIVE");
}
else
{
Debug.LogError("sqlite3_open failed: " + num);
}
dbPath = fileName;
return num2;
}
public bool OpenWritable(string fileName)
{
IntPtr ppDB = IntPtr.Zero;
byte[] bytes = Encoding.UTF8.GetBytes(fileName + "\0");
bool flag = true;
try
{
int num = Sqlite3LibImport.sqlite3_open(bytes, out ppDB);
DBHandle = ppDB;
flag = num == 0;
if (flag)
{
Exec("pragma journal_mode=MEMORY");
Exec("pragma synchronous=1");
Exec("pragma locking_mode=EXCLUSIVE");
}
else
{
Debug.LogError("sqlite3_open failed: " + num);
}
dbPath = fileName;
return flag;
}
catch (Exception exception)
{
Debug.LogException(exception);
return false;
}
}
public bool Begin()
{
return Exec("BEGIN;");
}
public bool Commit()
{
return Exec("COMMIT;");
}
public bool Rollback()
{
return Exec("ROLLBACK;");
}
public bool Vacuum()
{
return Exec("VACUUM;");
}
public virtual void Dispose()
{
CloseDB();
}
protected virtual void Dispose(bool disposing)
{
CloseDB();
}
private void Terminate()
{
CloseDB();
}
public void CloseDB()
{
if (DBHandle != IntPtr.Zero)
{
int num = Sqlite3LibImport.sqlite3_close(DBHandle);
if (num != 0)
{
Debug.LogError("failed to close db at " + dbPath + ": " + num);
}
DBHandle = IntPtr.Zero;
}
}
public bool Exec(string sql)
{
byte[] bytes = Encoding.UTF8.GetBytes(sql + "\0");
byte[] pzErrMsg;
int num = Sqlite3LibImport.sqlite3_exec(DBHandle, bytes, IntPtr.Zero, IntPtr.Zero, out pzErrMsg);
if (num != 0)
{
Debug.LogError($"sqlite3_exec failed({num}) with sql: {sql}");
}
return num == 0;
}
public Query Query(string sql)
{
return new Query(this, sql);
}
public PreparedQuery PreparedQuery(string sql)
{
return new PreparedQuery(this, sql);
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 99c410ac21800984da50ca58298127cd
timeCreated: 1528615027
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,65 @@
using System;
using System.Text;
using UnityEngine;
namespace Sqlite3Plugin
{
public class PreparedQuery : Query
{
public PreparedQuery(DBProxy proxy, string sql)
: base(proxy, sql)
{
}
public bool BindText(int idx, string text)
{
byte[] bytes = Encoding.UTF8.GetBytes(text);
int num = Sqlite3LibImport.sqlite3_bind_text(_stmt, idx, bytes, bytes.Length, IntPtr.Zero);
if (num != 0)
{
Debug.LogError($"sqlite3_bind_text error at idx {idx}: {num}");
}
return num == 0;
}
public bool BindBlob(int idx, byte[] byteArray)
{
int num = Sqlite3LibImport.sqlite3_bind_blob(_stmt, idx, byteArray, byteArray.Length, IntPtr.Zero);
if (num != 0)
{
Debug.LogError($"sqlite3_bind_blob error at idx {idx}: {num}");
}
return num == 0;
}
public bool BindInt(int idx, int iValue)
{
int num = Sqlite3LibImport.sqlite3_bind_int(_stmt, idx, iValue);
if (num != 0)
{
Debug.LogError($"sqlite3_bind_int error at idx {idx}: {num}");
}
return num == 0;
}
public bool BindDouble(int idx, double rValue)
{
int num = Sqlite3LibImport.sqlite3_bind_double(_stmt, idx, rValue);
if (num != 0)
{
Debug.LogError($"sqlite3_bind_double error at idx {idx}: {num}");
}
return num == 0;
}
public bool Reset()
{
int num = Sqlite3LibImport.sqlite3_reset(_stmt);
if (num != 0)
{
Debug.LogError($"sqlite3_reset error: {num}");
}
return num == 0;
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: f58651761a282bb418e7ed2192c87aca
timeCreated: 1528615027
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,89 @@
using System;
using System.Runtime.InteropServices;
using System.Text;
using UnityEngine;
namespace Sqlite3Plugin
{
public class Query : IDisposable
{
protected DBProxy _proxy;
protected IntPtr _stmt = IntPtr.Zero;
public Query(DBProxy proxy, string sql)
{
_Setup(proxy, sql);
}
protected void _Setup(DBProxy proxy, string sql)
{
_proxy = proxy;
byte[] bytes = Encoding.UTF8.GetBytes(sql);
IntPtr ppStmt;
int num = Sqlite3LibImport.sqlite3_prepare_v2(proxy.DBHandle, bytes, bytes.Length, out ppStmt, IntPtr.Zero);
if (num != 0)
{
throw new Exception($"sqlite3_prepare_v2 failed({num}) with sql: {sql}");
}
_stmt = ppStmt;
}
public virtual void Dispose()
{
if (_stmt != IntPtr.Zero)
{
int num = Sqlite3LibImport.sqlite3_finalize(_stmt);
if (num != 0)
{
Debug.LogError("sqlite3_finalize error: " + num);
}
_stmt = IntPtr.Zero;
}
}
public bool Step()
{
return Sqlite3LibImport.sqlite3_step(_stmt) == 100;
}
public bool Exec()
{
return Sqlite3LibImport.sqlite3_step(_stmt) == 101;
}
public int GetInt(int idx)
{
return Sqlite3LibImport.sqlite3_column_int(_stmt, idx);
}
public double GetDouble(int idx)
{
return Sqlite3LibImport.sqlite3_column_double(_stmt, idx);
}
public string GetText(int idx)
{
return Marshal.PtrToStringAnsi(Sqlite3LibImport.sqlite3_column_text(_stmt, idx));
}
public byte[] GetBlob(int idx)
{
int num = Sqlite3LibImport.sqlite3_column_bytes(_stmt, idx);
if (num == 0)
{
Debug.LogError("null blob at idx: " + idx);
return null;
}
IntPtr source = Sqlite3LibImport.sqlite3_column_blob(_stmt, idx);
byte[] array = new byte[num];
Marshal.Copy(source, array, 0, num);
return array;
}
public bool IsNull(int idx)
{
return Sqlite3LibImport.sqlite3_column_type(_stmt, idx) == 5;
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 80df7dddd4b1f21428f832aefa558a78
timeCreated: 1528615027
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,68 @@
using System;
using System.Runtime.InteropServices;
namespace Sqlite3Plugin
{
public static class Sqlite3LibImport
{
private const string LibraryName = "libsqlcipher";
[DllImport("libsqlcipher")]
public static extern int sqlite3_open(byte[] zFilename, out IntPtr ppDB);
[DllImport("libsqlcipher")]
public static extern int sqlite3_open_v2(byte[] zFilename, out IntPtr ppDB, int flags, IntPtr zVfs);
[DllImport("libsqlcipher")]
public static extern int sqlite3_close(IntPtr db);
[DllImport("libsqlcipher")]
public static extern int sqlite3_exec(IntPtr db, byte[] zSql, IntPtr xCallback, IntPtr pArg, out byte[] pzErrMsg);
[DllImport("libsqlcipher")]
public static extern int sqlite3_prepare_v2(IntPtr db, byte[] zSql, int nBytes, out IntPtr ppStmt, IntPtr pzTail);
[DllImport("libsqlcipher")]
public static extern int sqlite3_bind_text(IntPtr pStmt, int i, byte[] zData, int nData, IntPtr xDel);
[DllImport("libsqlcipher")]
public static extern int sqlite3_bind_blob(IntPtr pStmt, int i, byte[] zData, int nData, IntPtr xDel);
[DllImport("libsqlcipher")]
public static extern int sqlite3_bind_int(IntPtr pStmt, int i, int iValue);
[DllImport("libsqlcipher")]
public static extern int sqlite3_bind_double(IntPtr pStmt, int i, double rValue);
[DllImport("libsqlcipher")]
public static extern int sqlite3_bind_null(IntPtr pStmt, int i);
[DllImport("libsqlcipher")]
public static extern int sqlite3_reset(IntPtr pStmt);
[DllImport("libsqlcipher")]
public static extern int sqlite3_step(IntPtr pStmt);
[DllImport("libsqlcipher")]
public static extern int sqlite3_finalize(IntPtr pStmt);
[DllImport("libsqlcipher")]
public static extern int sqlite3_column_int(IntPtr pStmt, int i);
[DllImport("libsqlcipher")]
public static extern double sqlite3_column_double(IntPtr pStmt, int i);
[DllImport("libsqlcipher")]
public static extern int sqlite3_column_bytes(IntPtr pStmt, int i);
[DllImport("libsqlcipher")]
public static extern IntPtr sqlite3_column_blob(IntPtr pStmt, int i);
[DllImport("libsqlcipher")]
public static extern IntPtr sqlite3_column_text(IntPtr pStmt, int i);
[DllImport("libsqlcipher")]
public static extern int sqlite3_column_type(IntPtr pStmt, int i);
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: af02d500703469649a53b3b20e7e7130
timeCreated: 1528615027
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: