Skip to content

Commit 361c384

Browse files
andreasjordanclaude
andcommitted
Get-DbaDbMailHistory - Make the Status filter work on case sensitive instances
The sysmail_allitems view emits sent_status in lowercase (unsent, sent, failed, retrying), but the documented -Status values are capitalized and went into the WHERE clause verbatim - on a case sensitive instance -Status Sent matched nothing. The filter now lowercases both sides. The test fixture also inserted importance and sensitivity as "Normal", which violates msdb''s CHECK constraints on a case sensitive instance (they compare against uppercase NORMAL/HIGH/LOW); the fixture now inserts the uppercase values the constraints expect. Verified 11/11 green on SQL05\SQL2025 (case sensitive) and SQL03\SQL2019 (case insensitive). (do Get-DbaDbMailHistory) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 0473789 commit 361c384

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

‎public/Get-DbaDbMailHistory.ps1‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,10 @@ function Get-DbaDbMailHistory {
167167
}
168168

169169
if ($Status) {
170-
$Status = $Status -join "', '"
171-
$wherearray += "sent_status IN ('$Status')"
170+
# The sysmail_allitems view emits sent_status in lowercase, so compare lowercased or the
171+
# documented values (Sent, Unsent, Failed, Retrying) never match on a case sensitive instance.
172+
$Status = ($Status -join "', '").ToLower()
173+
$wherearray += "LOWER(sent_status) IN ('$Status')"
172174
}
173175

174176
$wherearray = $wherearray -join ' AND '

‎tests/Get-DbaDbMailHistory.Tests.ps1‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Describe $CommandName -Tag IntegrationTests {
6868
,[last_mod_date]
6969
,[last_mod_user])
7070
VALUES
71-
($profile_id,'dbatoolssci@dbatools.io',NULL,NULL,'Test Job',NULL,NULL,'A Test Job failed to run','TEXT','Normal','Normal',NULL,'MIME',NULL,NULL,
71+
($profile_id,'dbatoolssci@dbatools.io',NULL,NULL,'Test Job',NULL,NULL,'A Test Job failed to run','TEXT','NORMAL','NORMAL',NULL,'MIME',NULL,NULL,
7272
0,1,256,'',0,0,'2018-12-9 11:44:32.600','dbatools\dbatoolssci',1,1,'2018-12-9 11:44:33.000','2018-12-9 11:44:33.273','sa')"
7373
)
7474

0 commit comments

Comments
 (0)