From 97337f31cec684264f6d68771d82f507cb5457b7 Mon Sep 17 00:00:00 2001 From: XerolySkinner Date: Fri, 21 Nov 2025 18:17:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=B8=80=E4=BA=9B=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E5=86=99=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ramitta/Database/SQLite.cs | 28 ++++++++++++++++++++++++---- Ramitta/Ramitta.cs | 9 +++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/Ramitta/Database/SQLite.cs b/Ramitta/Database/SQLite.cs index 2670bb3..ade526f 100644 --- a/Ramitta/Database/SQLite.cs +++ b/Ramitta/Database/SQLite.cs @@ -1,5 +1,6 @@ using System.Data; using System.Data.SQLite; +using static NPOI.HSSF.Util.HSSFColor; namespace Ramitta { @@ -9,14 +10,14 @@ namespace Ramitta private bool disposed = false; // 构造函数,初始化数据库连接 - // 参数: connectionString - 数据库连接字符串 - // 例如: "Data Source=mydatabase.db;Version=3;" - public SQLite(string connectionString) + public SQLite(string file,bool ReadOnly=false) { - db = new SQLiteConnection(connectionString); + var sql = $"Data Source={file};Version=3;{(ReadOnly ? "Read Only=True;" : "")}"; + db = new SQLiteConnection(sql); db.Open(); } + // 创建表:根据表名和字段定义创建表 // 参数: tableName - 表名 // 参数: columns - 字段定义字典,键为字段名,值为字段类型 @@ -32,7 +33,26 @@ namespace Ramitta cmd.ExecuteNonQuery(); } } + // 获取数据库中所有表名 + // 返回: 包含所有表名的字符串列表 + public List GetAllTableNames() + { + List tableNames = new List(); + string query = "SELECT name FROM sqlite_master WHERE type='table';"; + + using (var cmd = new SQLiteCommand(query, db)) + using (var reader = cmd.ExecuteReader()) + { + while (reader.Read()) + { + string tableName = reader.GetString(0); + tableNames.Add(tableName); + } + } + + return tableNames; + } // 向已存在的表中添加新列 // 参数: tableName - 表名 // 参数: columnName - 要添加的列名 diff --git a/Ramitta/Ramitta.cs b/Ramitta/Ramitta.cs index 6cc8830..b226e24 100644 --- a/Ramitta/Ramitta.cs +++ b/Ramitta/Ramitta.cs @@ -381,5 +381,14 @@ namespace Ramitta.lib return stringBuilder.ToString(); } } + + /// + /// һµUUID/GUID + /// + /// ʽΪ: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx + public static string GenerateUUID() + { + return Guid.NewGuid().ToString(); + } } }