From cb89572ef8a96b1be11daa32c2f85fdcd1e591f9 Mon Sep 17 00:00:00 2001 From: Kenneth Skovhede Date: Mon, 7 Jul 2025 17:04:07 +0200 Subject: [PATCH] Setting DBNull.Value for null values --- .../Library/Main/Database/ExtensionMethods.cs | 20 +++---------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/Duplicati/Library/Main/Database/ExtensionMethods.cs b/Duplicati/Library/Main/Database/ExtensionMethods.cs index a13f8e413..92589c59c 100644 --- a/Duplicati/Library/Main/Database/ExtensionMethods.cs +++ b/Duplicati/Library/Main/Database/ExtensionMethods.cs @@ -663,7 +663,7 @@ public static partial class ExtensionMethods public static SqliteCommand SetParameterValues(this SqliteCommand self, Dictionary values) { foreach (var kvp in values) - self.Parameters[kvp.Key].Value = kvp.Value; + self.Parameters[kvp.Key].Value = kvp.Value ?? DBNull.Value; return self; } @@ -753,7 +753,7 @@ public static partial class ExtensionMethods where T : IDbCommand { foreach (var kvp in values) - ((IDataParameter)self.Parameters[kvp.Key]!).Value = kvp.Value; + ((IDataParameter)self.Parameters[kvp.Key]!).Value = kvp.Value ?? DBNull.Value; return self; } @@ -772,21 +772,7 @@ public static partial class ExtensionMethods if (value is not null && value is System.Collections.IEnumerable && value is not string) throw new ArgumentException($"Cannot set parameter '{name}' to an array or enumerable type, as the SQLite bindings does not support it.", nameof(value)); #endif - ((IDataParameter)self.Parameters[name]!).Value = value; - return self; - } - - /// - /// Sets the transaction for the command. - /// - /// The type of the command - /// The command to set the transaction for - /// The transaction to set for the command - /// The command with the transaction set - public static T SetTransaction(this T self, IDbTransaction? transaction) - where T : IDbCommand - { - self.Transaction = transaction; + ((IDataParameter)self.Parameters[name]!).Value = value ?? DBNull.Value; return self; }