From 86b951f50f31a2cf779bc951d49d9995a0a3ac92 Mon Sep 17 00:00:00 2001 From: Andrei Tudor Date: Tue, 18 Jun 2024 17:54:20 +0300 Subject: [PATCH] Fixed crash on AppVersion after the removal of Version key in the EnviromentVariables dictionary. Added new SqlDatabase functions: ReadDataArrayAsync and ReadDataAsync with query + parameters of the query. --- Directory.Build.props | 6 -- DiscordBotCore/Database/SqlDatabase.cs | 57 +++++++++++++++++++ .../Interfaces/Updater/AppVersion.cs | 3 +- SethDiscordBot.sln | 7 +++ 4 files changed, 66 insertions(+), 7 deletions(-) delete mode 100644 Directory.Build.props diff --git a/Directory.Build.props b/Directory.Build.props deleted file mode 100644 index 5d8722e..0000000 --- a/Directory.Build.props +++ /dev/null @@ -1,6 +0,0 @@ - - - enable - 11.0.2 - - diff --git a/DiscordBotCore/Database/SqlDatabase.cs b/DiscordBotCore/Database/SqlDatabase.cs index 9fe8865..ce34f01 100644 --- a/DiscordBotCore/Database/SqlDatabase.cs +++ b/DiscordBotCore/Database/SqlDatabase.cs @@ -385,6 +385,37 @@ public class SqlDatabase return null; } + /// + /// Read data from the result table and return the first row + /// + /// The query + /// The parameters of the query + /// The result is a string that has all values separated by space character + public async Task ReadDataAsync(string query, params KeyValuePair[] parameters) + { + if (!_connection.State.HasFlag(ConnectionState.Open)) + await _connection.OpenAsync(); + + var command = new SQLiteCommand(query, _connection); + foreach (var parameter in parameters) + { + var p = CreateParameter(parameter); + if (p is not null) + command.Parameters.Add(p); + } + + var reader = await command.ExecuteReaderAsync(); + + var values = new object[reader.FieldCount]; + if (reader.Read()) + { + reader.GetValues(values); + return string.Join(" ", values); + } + + return null; + } + /// /// Read data from the result table and return the first row /// @@ -429,6 +460,32 @@ public class SqlDatabase return null; } + public async Task ReadDataArrayAsync(string query, params KeyValuePair[] parameters) + { + if (!_connection.State.HasFlag(ConnectionState.Open)) + await _connection.OpenAsync(); + + var command = new SQLiteCommand(query, _connection); + foreach (var parameter in parameters) + { + var p = CreateParameter(parameter); + if (p is not null) + command.Parameters.Add(p); + } + + var reader = await command.ExecuteReaderAsync(); + + var values = new object[reader.FieldCount]; + if (reader.Read()) + { + reader.GetValues(values); + return values; + } + + return null; + + } + /// /// Read data from the result table and return the first row diff --git a/DiscordBotCore/Interfaces/Updater/AppVersion.cs b/DiscordBotCore/Interfaces/Updater/AppVersion.cs index 68bd2f0..5198abd 100644 --- a/DiscordBotCore/Interfaces/Updater/AppVersion.cs +++ b/DiscordBotCore/Interfaces/Updater/AppVersion.cs @@ -1,4 +1,5 @@ using System; +using System.Reflection; namespace DiscordBotCore.Interfaces.Updater { @@ -12,7 +13,7 @@ namespace DiscordBotCore.Interfaces.Updater public int PatchVersion { get; set; } - public static readonly AppVersion CurrentAppVersion = new AppVersion(Application.CurrentApplication.ApplicationEnvironmentVariables["Version"]); + public static readonly AppVersion CurrentAppVersion = new AppVersion(Assembly.GetEntryAssembly().GetName().Version.ToString()); private readonly char _Separator = '.'; diff --git a/SethDiscordBot.sln b/SethDiscordBot.sln index 2ce2853..a062e99 100644 --- a/SethDiscordBot.sln +++ b/SethDiscordBot.sln @@ -12,6 +12,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Plugins", "Plugins", "{8FAE EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MusicPlayer", "..\SethPlugins\MusicPlayer\MusicPlayer.csproj", "{F094D29D-6F1A-46BC-8B1F-88F3D98FCA84}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LevelingSystem", "..\SethPlugins\LevelingSystem\LevelingSystem.csproj", "{39EF14F8-7E67-4C14-A4F1-E706CFF61192}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -34,12 +36,17 @@ Global {F094D29D-6F1A-46BC-8B1F-88F3D98FCA84}.Debug|Any CPU.Build.0 = Debug|Any CPU {F094D29D-6F1A-46BC-8B1F-88F3D98FCA84}.Release|Any CPU.ActiveCfg = Release|Any CPU {F094D29D-6F1A-46BC-8B1F-88F3D98FCA84}.Release|Any CPU.Build.0 = Release|Any CPU + {39EF14F8-7E67-4C14-A4F1-E706CFF61192}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {39EF14F8-7E67-4C14-A4F1-E706CFF61192}.Debug|Any CPU.Build.0 = Debug|Any CPU + {39EF14F8-7E67-4C14-A4F1-E706CFF61192}.Release|Any CPU.ActiveCfg = Release|Any CPU + {39EF14F8-7E67-4C14-A4F1-E706CFF61192}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution {F094D29D-6F1A-46BC-8B1F-88F3D98FCA84} = {8FAEFF5E-F749-435C-BB7B-D57C0F8B17FC} + {39EF14F8-7E67-4C14-A4F1-E706CFF61192} = {8FAEFF5E-F749-435C-BB7B-D57C0F8B17FC} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {3FB3C5DE-ED21-4D2E-ABDD-3A00EE4A2FFF}