From 1598eef40b19794cfcebd541552dcb7e0036ff52 Mon Sep 17 00:00:00 2001 From: milimoe Date: Mon, 11 May 2026 19:54:02 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=B0=E5=BD=95=E6=9C=80=E5=90=8E=E4=B8=80?= =?UTF-8?q?=E6=AC=A1=E5=8F=91=E7=94=9F=E7=9A=84=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FunGame.Server/Services/DataUtility/MySQLHelper.cs | 13 +++++++++++++ FunGame.Server/Services/DataUtility/SQLiteHelper.cs | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/FunGame.Server/Services/DataUtility/MySQLHelper.cs b/FunGame.Server/Services/DataUtility/MySQLHelper.cs index 61f7634..68a6e0d 100644 --- a/FunGame.Server/Services/DataUtility/MySQLHelper.cs +++ b/FunGame.Server/Services/DataUtility/MySQLHelper.cs @@ -60,6 +60,11 @@ namespace Milimoe.FunGame.Server.Services.DataUtility /// public override DataSet DataSet => _dataSet; + /// + /// 最后一次执行命令时发生的异常 + /// + public override Exception? LastException => _lastException; + /// /// SQL 语句参数 /// @@ -73,6 +78,7 @@ namespace Milimoe.FunGame.Server.Services.DataUtility private readonly SQLServerInfo? _serverInfo; private int _affectedRows = 0; private long _lastInsertId = 0; + private Exception? _lastException = null; public MySQLHelper(string script = "", CommandType type = CommandType.Text) { @@ -167,6 +173,7 @@ namespace Milimoe.FunGame.Server.Services.DataUtility } catch (Exception e) { + _lastException = e; if (localTransaction) Rollback(); _result = SQLResult.SQLError; ServerHelper.Error(e); @@ -231,6 +238,7 @@ namespace Milimoe.FunGame.Server.Services.DataUtility } catch (Exception e) { + _lastException = e; if (localTransaction) Rollback(); _result = SQLResult.SQLError; ServerHelper.Error(e); @@ -295,6 +303,7 @@ namespace Milimoe.FunGame.Server.Services.DataUtility } catch (Exception e) { + _lastException = e; if (localTransaction) Rollback(); _result = SQLResult.SQLError; ServerHelper.Error(e); @@ -359,6 +368,7 @@ namespace Milimoe.FunGame.Server.Services.DataUtility } catch (Exception e) { + _lastException = e; if (localTransaction) Rollback(); _result = SQLResult.SQLError; ServerHelper.Error(e); @@ -395,6 +405,7 @@ namespace Milimoe.FunGame.Server.Services.DataUtility } catch (Exception e) { + _lastException = e; _result = SQLResult.SQLError; ServerHelper.Error(e); } @@ -416,6 +427,7 @@ namespace Milimoe.FunGame.Server.Services.DataUtility } catch (Exception e) { + _lastException = e; _result = SQLResult.SQLError; ServerHelper.Error(e); } @@ -438,6 +450,7 @@ namespace Milimoe.FunGame.Server.Services.DataUtility } catch (Exception e) { + _lastException = e; ServerHelper.Error(e); _result = SQLResult.SQLError; return false; diff --git a/FunGame.Server/Services/DataUtility/SQLiteHelper.cs b/FunGame.Server/Services/DataUtility/SQLiteHelper.cs index 226fd27..ac4861d 100644 --- a/FunGame.Server/Services/DataUtility/SQLiteHelper.cs +++ b/FunGame.Server/Services/DataUtility/SQLiteHelper.cs @@ -60,6 +60,11 @@ namespace Milimoe.FunGame.Server.Services.DataUtility /// public override DataSet DataSet => _dataSet; + /// + /// 最后一次执行命令时发生的异常 + /// + public override Exception? LastException => _lastException; + /// /// SQL 语句参数 /// @@ -73,6 +78,7 @@ namespace Milimoe.FunGame.Server.Services.DataUtility private readonly SQLServerInfo? _serverInfo; private int _affectedRows = 0; private long _lastInsertId = 0; + private Exception? _lastException = null; public SQLiteHelper(string script = "", CommandType type = CommandType.Text) { @@ -167,6 +173,7 @@ namespace Milimoe.FunGame.Server.Services.DataUtility } catch (Exception e) { + _lastException = e; if (localTransaction) Rollback(); _result = SQLResult.SQLError; ServerHelper.Error(e); @@ -233,6 +240,7 @@ namespace Milimoe.FunGame.Server.Services.DataUtility } catch (Exception e) { + _lastException = e; if (localTransaction) Rollback(); _result = SQLResult.SQLError; ServerHelper.Error(e); @@ -298,6 +306,7 @@ namespace Milimoe.FunGame.Server.Services.DataUtility } catch (Exception e) { + _lastException = e; if (localTransaction) Rollback(); _result = SQLResult.SQLError; ServerHelper.Error(e); @@ -363,6 +372,7 @@ namespace Milimoe.FunGame.Server.Services.DataUtility } catch (Exception e) { + _lastException = e; if (localTransaction) Rollback(); _result = SQLResult.SQLError; ServerHelper.Error(e); @@ -399,6 +409,7 @@ namespace Milimoe.FunGame.Server.Services.DataUtility } catch (Exception e) { + _lastException = e; _result = SQLResult.SQLError; ServerHelper.Error(e); } @@ -420,6 +431,7 @@ namespace Milimoe.FunGame.Server.Services.DataUtility } catch (Exception e) { + _lastException = e; _result = SQLResult.SQLError; ServerHelper.Error(e); } @@ -442,6 +454,7 @@ namespace Milimoe.FunGame.Server.Services.DataUtility } catch (Exception e) { + _lastException = e; ServerHelper.Error(e); _result = SQLResult.SQLError; return false;