优化MasterDB导出sqlite性能

This commit is contained in:
Chenx221 2024-10-16 14:31:52 +08:00
parent abb3d6c2ef
commit 79db32b780
3 changed files with 55 additions and 52 deletions

View File

@ -1,6 +1,8 @@
using Microsoft.Data.Sqlite; using Microsoft.Data.Sqlite;
using System.Reflection; using System.Reflection;
using System.Reflection.Metadata;
using System.Text; using System.Text;
using System.Transactions;
namespace EscudeTools namespace EscudeTools
{ {
@ -200,7 +202,7 @@ namespace EscudeTools
//db含有多个sheet每个sheet中col存放标题对应数据库中应该是字段records存放数据对应数据库中应该是记录 //db含有多个sheet每个sheet中col存放标题对应数据库中应该是字段records存放数据对应数据库中应该是记录
using SqliteConnection connection = new($"Data Source={path};"); using SqliteConnection connection = new($"Data Source={path};");
connection.Open(); connection.Open();
using var transaction = connection.BeginTransaction();
foreach (var sheet in db) foreach (var sheet in db)
{ {
using (SqliteCommand createTableCommand = connection.CreateCommand()) using (SqliteCommand createTableCommand = connection.CreateCommand())
@ -259,6 +261,7 @@ namespace EscudeTools
insertDataCommand.Parameters.Clear(); insertDataCommand.Parameters.Clear();
} }
} }
transaction.Commit();
return true; return true;
} }
private static string GetSQLiteColumnType(ushort type) private static string GetSQLiteColumnType(ushort type)

View File

@ -4,59 +4,16 @@
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
if (Directory.Exists(args[0]))
{
string[] files = Directory.GetFiles(args[0], "*.bin");
foreach (string file in files)
{
ScriptManager smr = new();
//目前不支持二次加载
//Todo
//修复
if (smr.LoadScriptFile(file))
{
Console.WriteLine($"Load {file} Success");
}
else
{
Console.WriteLine($"Load {file} Failed");
return;
}
if (smr.ExportDatabase(Path.GetDirectoryName(args[0])))
Console.WriteLine("Export Database Success");
else
{
Console.WriteLine("Export Database Failed");
return;
}
if (smr.ExportMessDatabase(Path.GetDirectoryName(args[0])))
Console.WriteLine("Export Mess Database Success");
else
{
Console.WriteLine("Export Mess Database Failed");
return;
}
}
}
//ScriptManager smr = new();
//smr.LoadScriptFile(args[0]); //加载.bin文件
//smr.ExportDatabase(Path.GetDirectoryName(args[0]));
//smr.ExportMessDatabase(Path.GetDirectoryName(args[0]));
//return;
//if (Directory.Exists(args[0])) //if (Directory.Exists(args[0]))
//{ //{
// string[] files = Directory.GetFiles(args[0], "db_*.bin"); // string[] files = Directory.GetFiles(args[0], "*.bin");
// DatabaseManager dm = new();
// foreach (string file in files) // foreach (string file in files)
// { // {
// if (dm.LoadDatabase(file)) // ScriptManager smr = new();
// //目前不支持二次加载
// //Todo
// //修复
// if (smr.LoadScriptFile(file))
// { // {
// Console.WriteLine($"Load {file} Success"); // Console.WriteLine($"Load {file} Success");
// } // }
@ -66,7 +23,7 @@
// return; // return;
// } // }
// if (dm.ExportDatabase(0, Path.GetDirectoryName(args[0]))) // if (smr.ExportDatabase(Path.GetDirectoryName(args[0])))
// Console.WriteLine("Export Database Success"); // Console.WriteLine("Export Database Success");
// else // else
// { // {
@ -74,11 +31,54 @@
// return; // return;
// } // }
// if (smr.ExportMessDatabase(Path.GetDirectoryName(args[0])))
// Console.WriteLine("Export Mess Database Success");
// else
// {
// Console.WriteLine("Export Mess Database Failed");
// return;
// }
// } // }
//} //}
//ScriptManager smr = new();
//smr.LoadScriptFile(args[0]); //加载.bin文件
//smr.ExportDatabase(Path.GetDirectoryName(args[0]));
//smr.ExportMessDatabase(Path.GetDirectoryName(args[0]));
//return;
if (Directory.Exists(args[0]))
{
string[] files = Directory.GetFiles(args[0], "db_*.bin");
DatabaseManager dm = new();
foreach (string file in files)
{
if (dm.LoadDatabase(file))
{
Console.WriteLine($"Load {file} Success");
}
else
{
Console.WriteLine($"Load {file} Failed");
return;
}
if (dm.ExportDatabase(0, Path.GetDirectoryName(args[0])))
Console.WriteLine("Export Database Success");
else
{
Console.WriteLine("Export Database Failed");
return;
}
}
}
// if (args.Length == 0 || args.Length > 2) // if (args.Length == 0 || args.Length > 2)
// { // {
// Console.WriteLine("Invalid arguments. Use -h for help."); // Console.WriteLine("Invalid arguments. Use -h for help.");

View File

@ -2,7 +2,7 @@
"profiles": { "profiles": {
"EscudeTools": { "EscudeTools": {
"commandName": "Project", "commandName": "Project",
"commandLineArgs": "G:\\x221.local\\lab\\script" "commandLineArgs": "G:\\x221.local\\lab\\db"
} }
} }
} }