Skip to content

Commit 3b9f3cb

Browse files
blehnenclaude
andcommitted
fix(relational): bind @status param with casing matching SQL for SQLite (#155)
The GetQueueCount status-filtered path bound the parameter as "@Status" while all three transport SQL texts use lowercase "@status". Npgsql and Microsoft.Data.SqlClient match parameter names case-insensitively, so PG and SQL Server worked, but System.Data.SQLite binds case-sensitively and threw "Insufficient parameters supplied to the command". This path was previously dead (the status-filtered admin Count was never exercised), so the latent mismatch only surfaced once the new #155 regression test enabled status filtering on SQLite. Align the parameter name to the SQL placeholder casing and harden the unit test to assert the exact "@status" name (the FakeCommandStringCache now mirrors the real lowercase SQL). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent c7a212c commit 3b9f3cb

3 files changed

Lines changed: 10 additions & 5 deletions

File tree

Source/DotNetWorkQueue.Transport.RelationalDatabase.Tests/Basic/QueryPrepareHandler/FakeCommandStringCache.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ protected override void BuildCommands()
1616
CommandCache[CommandStringTypes.GetDashboardMessages] = "SELECT messages{0} ORDER BY QueuedDateTime DESC";
1717
CommandCache[CommandStringTypes.GetDashboardMessageCount] = "SELECT COUNT(*) FROM meta";
1818
CommandCache[CommandStringTypes.GetQueueCountAll] = "SELECT COUNT(*) FROM meta";
19-
CommandCache[CommandStringTypes.GetQueueCountStatus] = "SELECT COUNT(*) FROM meta WHERE Status = @Status";
19+
CommandCache[CommandStringTypes.GetQueueCountStatus] = "select count(*) from meta where status = @status";
2020
CommandCache[CommandStringTypes.GetDashboardMessageDetail] = "SELECT detail{0} WHERE QueueID = @QueueId";
2121
CommandCache[CommandStringTypes.GetDashboardStaleMessages] = "SELECT stale{0}";
2222
CommandCache[CommandStringTypes.GetDashboardErrorMessages] = "SELECT errors";

Source/DotNetWorkQueue.Transport.RelationalDatabase.Tests/Basic/QueryPrepareHandler/GetQueueCountQueryPrepareHandlerTests.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,14 @@ public void Handle_With_Status_And_StatusEnabled_Binds_Int_Not_Enum()
4242
handler.Handle(new GetQueueCountQuery("conn", QueueStatusAdmin.Waiting), command, CommandStringTypes.GetQueueCountStatus);
4343

4444
var parameters = (DataParameterCollection)command.Parameters;
45-
var status = parameters.First(p => p.ParameterName == "@Status");
45+
// Parameter name must match the SQL placeholder casing exactly. System.Data.SQLite binds
46+
// parameters case-sensitively, so "@Status" against a "@status" placeholder throws
47+
// "Insufficient parameters supplied to the command" (issue #155 follow-up).
48+
Assert.AreEqual(1, parameters.Count);
49+
var status = parameters.First();
50+
Assert.AreEqual("@status", status.ParameterName);
4651
Assert.AreEqual(DbType.Int32, status.DbType);
47-
Assert.IsInstanceOfType(status.Value, typeof(int), "@Status must be bound as an int, not the QueueStatusAdmin enum");
52+
Assert.IsInstanceOfType(status.Value, typeof(int), "@status must be bound as an int, not the QueueStatusAdmin enum");
4853
Assert.AreEqual((int)QueueStatusAdmin.Waiting, status.Value);
4954
}
5055

@@ -56,7 +61,7 @@ public void Handle_With_Status_Uses_StatusFiltered_Command()
5661

5762
handler.Handle(new GetQueueCountQuery("conn", QueueStatusAdmin.Processing), command, CommandStringTypes.GetQueueCountStatus);
5863

59-
StringAssert.Contains(command.CommandText, "@Status");
64+
StringAssert.Contains(command.CommandText, "@status");
6065
}
6166

6267
[TestMethod]

Source/DotNetWorkQueue.Transport.RelationalDatabase/Basic/QueryPrepareHandler/GetQueueCountQueryPrepareHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void Handle(GetQueueCountQuery query, IDbCommand dbCommand, CommandString
4848
{
4949
dbCommand.CommandText = _commandCache.GetCommand(CommandStringTypes.GetQueueCountStatus);
5050
var status = dbCommand.CreateParameter();
51-
status.ParameterName = "@Status";
51+
status.ParameterName = "@status";
5252
status.DbType = DbType.Int32;
5353
status.Value = (int)query.Status.Value;
5454
dbCommand.Parameters.Add(status);

0 commit comments

Comments
 (0)