forked from Uahh/ToastFish
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabaseViewer.exe.cs
More file actions
156 lines (144 loc) · 5.67 KB
/
DatabaseViewer.exe.cs
File metadata and controls
156 lines (144 loc) · 5.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
using System;
using System.Data.SQLite;
using System.IO;
class Program
{
static void Main(string[] args)
{
try
{
string dbPath = @".\Resources\inami.db";
if (!File.Exists(dbPath))
{
Console.WriteLine($"数据库文件不存在: {dbPath}");
Console.WriteLine("请确保在ToastFish程序目录下运行此工具");
Console.ReadKey();
return;
}
string connectionString = $"Data Source={dbPath};Version=3;";
using (SQLiteConnection connection = new SQLiteConnection(connectionString))
{
connection.Open();
Console.WriteLine("数据库连接成功!");
Console.WriteLine("==================");
// 查询所有表
string sql = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;";
using (SQLiteCommand command = new SQLiteCommand(sql, connection))
{
using (SQLiteDataReader reader = command.ExecuteReader())
{
Console.WriteLine("数据库中的所有表:");
int tableCount = 0;
while (reader.Read())
{
string tableName = reader["name"].ToString();
tableCount++;
Console.WriteLine($"{tableCount}. {tableName}");
// 特别标记可能的日语表
if (tableName.ToLower().Contains("jp") ||
tableName.ToLower().Contains("japan") ||
tableName.ToLower().Contains("std") ||
tableName.ToLower().Contains("mid"))
{
Console.WriteLine($" *** 可能的日语表 ***");
}
}
if (tableCount == 0)
{
Console.WriteLine("没有找到任何表!");
}
}
}
Console.WriteLine("\n==================");
Console.WriteLine("查找包含日语相关字段的表...");
// 查找包含日语相关字段的表
string[] possibleTables = GetAllTables(connection);
foreach (string table in possibleTables)
{
if (HasJapaneseColumns(connection, table))
{
Console.WriteLine($"\n表 '{table}' 包含日语相关字段:");
ShowTableStructure(connection, table);
}
}
}
}
catch (Exception ex)
{
Console.WriteLine($"错误: {ex.Message}");
}
Console.WriteLine("\n按任意键退出...");
Console.ReadKey();
}
static string[] GetAllTables(SQLiteConnection connection)
{
var tables = new System.Collections.Generic.List<string>();
string sql = "SELECT name FROM sqlite_master WHERE type='table';";
using (SQLiteCommand command = new SQLiteCommand(sql, connection))
{
using (SQLiteDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
tables.Add(reader["name"].ToString());
}
}
}
return tables.ToArray();
}
static bool HasJapaneseColumns(SQLiteConnection connection, string tableName)
{
try
{
string sql = $"PRAGMA table_info({tableName});";
using (SQLiteCommand command = new SQLiteCommand(sql, connection))
{
using (SQLiteDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
string columnName = reader["name"].ToString().ToLower();
if (columnName.Contains("hiragana") ||
columnName.Contains("katakana") ||
columnName.Contains("romaji") ||
columnName.Contains("jp") ||
columnName.Contains("japanese"))
{
return true;
}
}
}
}
}
catch
{
// 忽略错误
}
return false;
}
static void ShowTableStructure(SQLiteConnection connection, string tableName)
{
try
{
string sql = $"PRAGMA table_info({tableName});";
using (SQLiteCommand command = new SQLiteCommand(sql, connection))
{
using (SQLiteDataReader reader = command.ExecuteReader())
{
Console.WriteLine(" 列名\t\t类型");
Console.WriteLine(" ----------------");
while (reader.Read())
{
string colName = reader["name"].ToString();
string colType = reader["type"].ToString();
Console.WriteLine($" {colName}\t\t{colType}");
}
}
}
}
catch (Exception ex)
{
Console.WriteLine($" 无法读取表结构: {ex.Message}");
}
}
}