Skip to content

ensures double negative is evaluated correctly#61

Merged
hedyyytang merged 1 commit intomasterfrom
allows-double-negative
Aug 25, 2025
Merged

ensures double negative is evaluated correctly#61
hedyyytang merged 1 commit intomasterfrom
allows-double-negative

Conversation

@hedyyytang
Copy link
Copy Markdown
Contributor

@hedyyytang hedyyytang commented Aug 25, 2025

what's changed
Update the negate function in BinaryOperatorExpression to negate the existing value. This allows expressions with double negative, such as NOT (:gameboy IS NOT NULL), to negate correctly.

Example
Prior to the change, the following query will return count 16 because NOT ("gameboy" IS NOT NULL) is evaluated to TRUE and making the whole WHERE clause always TRUE. The expression, NOT ("gameboy" IS NOT NULL) should be FALSE because if "gameboy" IS NOT NULL is true, then NOT(TRUE) is FALSE

$query = $pdo->prepare("SELECT COUNT(*) as 'count' FROM `video_game_characters` WHERE (:console IS NOT NULL AND `console` = :console) OR NOT (:console IS NOT NULL)");
        $query->bindValue(':console', 'gameboy');
        $query->execute();

After the change, the query returns 1 correctly.

Tests
Add tests with queries involving IS NULL AND IS NOT NULL

@hedyyytang hedyyytang merged commit 25c92ff into master Aug 25, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants