Skip to content

fix the negation evaluations in fake sql#59

Merged
aaronm67 merged 1 commit intomasterfrom
support-not-statements
Aug 14, 2025
Merged

fix the negation evaluations in fake sql#59
aaronm67 merged 1 commit intomasterfrom
support-not-statements

Conversation

@hedyyytang
Copy link
Copy Markdown
Contributor

@hedyyytang hedyyytang commented Aug 14, 2025

What's changed
Negate both results from the binary operation evaluation to ensure negation is correctly applied.

How negation works

Negated Property - indicates an expression needs to be negated, NegatedInt - used in bitwise XOR operation
True 1
False 0

If a 1 needs to be negated, 1 ^ 1  = 0

If a 0 needs to be negated, 0 ^ 1 = 1


If 1 doesn’t need to be negated, 1 ^ 0  = 1

If 0 doesn’t need to be negated, 0 ^ 0  =  0

NOTE:
There is some parsing issue where when a single NOT statement is applied directly after WHERE clause, the negated property is not set correctly. Took a look but couldn't fix it in a short time so gonna leave it for now. We don't write NOT for a single statement anyways since we use != or NOT IN directly.

Example

Prior to the change, the following query will return the count 9, because NOT (powerups > :powerups) is always true, and the result doesn't filter out the character luigi, who has nes console and 5 powerups.

        // greater than
        $pdo = self::getConnectionToFullDB(false);
        $query = $pdo->prepare("SELECT COUNT(*) as 'count' FROM `video_game_characters` WHERE `console` = :console AND NOT (`powerups` > :powerups)");
        $query->bindValue(':console', 'nes');
        $query->bindValue(':powerups', 3);
        $query->execute();

        $query->fetchAll(\PDO::FETCH_ASSOC));

After the change, the count result is 8.

Tests
Added unit tests

@hedyyytang hedyyytang changed the title fix the negation operations in fake sql fix the negation evaluations in fake sql Aug 14, 2025
@hedyyytang hedyyytang force-pushed the support-not-statements branch from dec4143 to 465f970 Compare August 14, 2025 13:54
@aaronm67 aaronm67 merged commit 696de1c into master Aug 14, 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