From 4f25c2756bc004d9ca1fadf67125c11d5034f22f Mon Sep 17 00:00:00 2001 From: JonKazama-Hellion Date: Sat, 2 May 2026 02:56:40 +0200 Subject: [PATCH] =?UTF-8?q?Tighten=20DbViewer=20paging=20=E2=80=94=20int?= =?UTF-8?q?=20constant=20and=20matching=20SQL=20parameter=20name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Audit findings M-1 and M-2. Two small consistency issues in the upstream DbViewer paging path that we now own as a fork: - RowPerPage is a row count and should be an int. The upstream declaration was 1000.0f, which forced an implicit float divide in Math.Ceiling and an implicit float-to-integer conversion when SQLite bound the LIMIT parameter. Switching the constant to int and casting Count to double right at the division keeps the ceiling math intact while making the type story honest. - GetPagedDateRange's SQL uses the placeholder $OffsetCount, but the matching AddWithValue call passed the unprefixed name "OffsetCount". Microsoft.Data.Sqlite tolerates this today, so paging still worked; another provider or a stricter future version would not. Re-aligned the parameter name with the SQL. No behavioural change for users — paging continues to return 1000 rows per page. The fixes are kept on the fork rather than offered upstream because the project's recent triage history makes a non-trivial PR turnaround unlikely. --- ChatTwo/MessageStore.cs | 2 +- ChatTwo/Ui/DbViewer.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ChatTwo/MessageStore.cs b/ChatTwo/MessageStore.cs index cd05ad2..3dee96c 100644 --- a/ChatTwo/MessageStore.cs +++ b/ChatTwo/MessageStore.cs @@ -724,7 +724,7 @@ internal class MessageStore : IDisposable cmd.Parameters.AddWithValue("$After", ((DateTimeOffset) after).ToUnixTimeMilliseconds()); cmd.Parameters.AddWithValue("$Before", ((DateTimeOffset) before).ToUnixTimeMilliseconds()); cmd.Parameters.AddWithValue("$Offset", DbViewer.RowPerPage * page); - cmd.Parameters.AddWithValue("OffsetCount", DbViewer.RowPerPage); + cmd.Parameters.AddWithValue("$OffsetCount", DbViewer.RowPerPage); return new MessageEnumerator(cmd.ExecuteReader()); } diff --git a/ChatTwo/Ui/DbViewer.cs b/ChatTwo/Ui/DbViewer.cs index e04992e..2304a66 100644 --- a/ChatTwo/Ui/DbViewer.cs +++ b/ChatTwo/Ui/DbViewer.cs @@ -22,7 +22,7 @@ namespace ChatTwo.Ui; public class DbViewer : Window { - public const float RowPerPage = 1000.0f; + public const int RowPerPage = 1000; private readonly Plugin Plugin; @@ -88,7 +88,7 @@ public class DbViewer : Window public override void Draw() { - var totalPages = (int)Math.Ceiling(Count / RowPerPage); + var totalPages = (int)Math.Ceiling((double)Count / RowPerPage); if (totalPages < 1) totalPages = 1;