Bug: DBI queries for NULL #340

Closed
opened 2025-06-20 10:28:46 +00:00 by jamie · 4 comments
jamie commented 2025-06-20 10:28:46 +00:00 (Migrated from git.hazaar.io)

Problem Statement

The Hazaar DBI module currently mishandles search criteria that include null values. When a query is constructed with a condition like ['parent' => null], the query builder incorrectly generates parent = :parent0. This is not valid SQL in PostgreSQL (and other SQL dialects), which requires parent IS NULL for null comparisons.

Who will benefit?

  • Developers using Hazaar DBI with PostgreSQL or other SQL engines that require explicit IS NULL handling.
  • Applications that rely on querying fields that may contain null values.
  • Anyone using the QueryBuilder abstraction for dynamic SQL generation.

Benefits and risks

Benefits:

  • Fixes invalid SQL generation for null values.
  • Improves compatibility with PostgreSQL and standards-compliant SQL databases.
  • Prevents query failures and reduces debugging effort.

Risks:

  • Could cause unintended behavior if existing workarounds depend on the current (incorrect) behavior.
  • May require regression testing to ensure compatibility with various query conditions and drivers.

Proposed solution

Update the query builder logic in Hazaar DBI to:

  • Detect when a search condition value is null.
  • Generate the SQL clause using IS NULL instead of = :param for those cases.
  • Ensure this applies to both WHERE and HAVING conditions as appropriate.

Priority/Severity

  • High (This will bring a huge increase in performance/productivity/usability/legislative cover)
  • Medium (This will bring a good increase in performance/productivity/usability)
  • Low (anything else e.g., trivial, minor improvements)
## Problem Statement The Hazaar DBI module currently mishandles search criteria that include `null` values. When a query is constructed with a condition like `['parent' => null]`, the query builder incorrectly generates `parent = :parent0`. This is not valid SQL in PostgreSQL (and other SQL dialects), which requires `parent IS NULL` for null comparisons. ## Who will benefit? - Developers using Hazaar DBI with PostgreSQL or other SQL engines that require explicit `IS NULL` handling. - Applications that rely on querying fields that may contain `null` values. - Anyone using the QueryBuilder abstraction for dynamic SQL generation. ## Benefits and risks ### Benefits: - Fixes invalid SQL generation for null values. - Improves compatibility with PostgreSQL and standards-compliant SQL databases. - Prevents query failures and reduces debugging effort. ### Risks: - Could cause unintended behavior if existing workarounds depend on the current (incorrect) behavior. - May require regression testing to ensure compatibility with various query conditions and drivers. ## Proposed solution Update the query builder logic in Hazaar DBI to: - Detect when a search condition value is `null`. - Generate the SQL clause using `IS NULL` instead of `= :param` for those cases. - Ensure this applies to both `WHERE` and `HAVING` conditions as appropriate. ## Priority/Severity - [x] High (This will bring a huge increase in performance/productivity/usability/legislative cover) - [ ] Medium (This will bring a good increase in performance/productivity/usability) - [ ] Low (anything else e.g., trivial, minor improvements)
jamie commented 2025-06-20 10:28:47 +00:00 (Migrated from git.hazaar.io)

assigned to @jamie

assigned to @jamie
jamie commented 2025-06-20 10:29:02 +00:00 (Migrated from git.hazaar.io)

created branch 340-bug-dbi-queries-for-null to address this issue

created branch [`340-bug-dbi-queries-for-null`](/hazaar/framework/-/compare/master...340-bug-dbi-queries-for-null) to address this issue
jamie commented 2025-06-20 10:29:12 +00:00 (Migrated from git.hazaar.io)

mentioned in merge request !229

mentioned in merge request !229
jamie commented 2025-06-20 12:49:08 +00:00 (Migrated from git.hazaar.io)

mentioned in commit 82e86f355c

mentioned in commit 82e86f355cb1586f424acdd6ba8e4b42b26a1143
jamie (Migrated from git.hazaar.io) closed this issue 2025-06-20 12:49:08 +00:00
jamie self-assigned this 2025-09-04 01:13:36 +00:00
jamie removed their assignment 2025-09-04 01:13:44 +00:00
jamie self-assigned this 2025-09-04 01:13:49 +00:00
jamie removed their assignment 2025-09-04 01:13:54 +00:00
jamie self-assigned this 2025-09-04 01:14:01 +00:00
jamie removed their assignment 2025-09-04 01:14:06 +00:00
jamie self-assigned this 2025-09-04 01:14:22 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: hazaar/framework#340
No description provided.