From 9377fdffc1a325ba04d4e1bd7861d048228e75b0 Mon Sep 17 00:00:00 2001 From: Kenneth Skovhede Date: Tue, 5 Mar 2024 08:55:13 +0100 Subject: [PATCH] Unified the way the version is extracted from the SQLite library --- .../Main/Operation/SystemInfoHandler.cs | 4 +- .../Library/SQLiteHelper/SQLiteLoader.cs | 22 +++++++++- Duplicati/Server/Program.cs | 43 +++++++++---------- 3 files changed, 43 insertions(+), 26 deletions(-) diff --git a/Duplicati/Library/Main/Operation/SystemInfoHandler.cs b/Duplicati/Library/Main/Operation/SystemInfoHandler.cs index 82efa73ce..59ccd93d3 100644 --- a/Duplicati/Library/Main/Operation/SystemInfoHandler.cs +++ b/Duplicati/Library/Main/Operation/SystemInfoHandler.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2024, The Duplicati Team +// Copyright (C) 2024, The Duplicati Team // https://duplicati.com, hello@duplicati.com // // Permission is hereby granted, free of charge, to any person obtaining a @@ -64,7 +64,7 @@ namespace Duplicati.Library.Main.Operation if (sqlite != null) { - try { sqliteversion = (string)sqlite.GetProperty("SQLiteVersion").GetValue(null, null); } + try { sqliteversion = Duplicati.Library.SQLiteHelper.SQLiteLoader.SQLiteVersion; } catch { } yield return string.Format("SQLite: {0} - {1}", sqliteversion, sqlite.FullName); diff --git a/Duplicati/Library/SQLiteHelper/SQLiteLoader.cs b/Duplicati/Library/SQLiteHelper/SQLiteLoader.cs index c021015b3..5cbb3f4b4 100644 --- a/Duplicati/Library/SQLiteHelper/SQLiteLoader.cs +++ b/Duplicati/Library/SQLiteHelper/SQLiteLoader.cs @@ -23,7 +23,6 @@ using System; using System.IO; using Duplicati.Library.Common; using Duplicati.Library.Common.IO; -using System.Data.SQLite; namespace Duplicati.Library.SQLiteHelper { @@ -179,7 +178,26 @@ namespace Duplicati.Library.SQLiteHelper { get { - return typeof(SQLiteConnection); + return typeof(System.Data.SQLite.SQLiteConnection); + } + } + + /// + /// Returns the version string from the SQLite type + /// + public static string SQLiteVersion + { + get + { + var versionString = SQLiteConnectionType.GetProperty("SQLiteVersion")?.GetValue(null, null) as string; + if (string.IsNullOrWhiteSpace(versionString)) + { + // Support for Microsoft.Data.SQLite + // NOTE: Has an issue with ? as position parameters + var inst = Activator.CreateInstance(SQLiteConnectionType); + versionString = SQLiteConnectionType.GetProperty("ServerVersion")?.GetValue(inst, null) as string; + } + return versionString; } } diff --git a/Duplicati/Server/Program.cs b/Duplicati/Server/Program.cs index c5e405013..82dcf0db8 100644 --- a/Duplicati/Server/Program.cs +++ b/Duplicati/Server/Program.cs @@ -1,23 +1,23 @@ -// Copyright (C) 2024, The Duplicati Team -// https://duplicati.com, hello@duplicati.com -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. +// Copyright (C) 2024, The Duplicati Team +// https://duplicati.com, hello@duplicati.com +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. using System; using System.Collections.Generic; using System.Globalization; @@ -672,8 +672,7 @@ namespace Duplicati.Server else DataFolder = Util.AppendDirSeparator(Environment.ExpandEnvironmentVariables(serverDataFolder).Trim('"')); - var sqliteVersion = new Version((string)Duplicati.Library.SQLiteHelper.SQLiteLoader.SQLiteConnectionType.GetProperty("SQLiteVersion").GetValue(null, null)); - + var sqliteVersion = new Version(Duplicati.Library.SQLiteHelper.SQLiteLoader.SQLiteVersion); if (sqliteVersion < new Version(3, 6, 3)) { //The official Mono SQLite provider is also broken with less than 3.6.3