Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [QueryBuilder] where() generates incorrect SQL when using RawSql #7147

Merged
merged 5 commits into from
Jan 20, 2023

Conversation

sclubricants
Copy link
Member

@sclubricants sclubricants commented Jan 17, 2023

This fixes some of the problems noted here #7117 and here #7143

The following was failing before this fix:

        $sql = $this->db->table('auth_bearer')
            ->select('*')
            ->where('expires', new RawSql('DATE_ADD(NOW(), INTERVAL 2 HOUR)'))
            ->getCompiledSelect(true);

        $expected = <<<'SQL'
            SELECT *
            FROM "auth_bearer"
            WHERE "expires" = DATE_ADD(NOW(), INTERVAL 2 HOUR)
            SQL;
        $this->assertSame($expected, $sql);

Generated:

'SELECT *
FROM "auth_bearer"
WHERE DATE_ADD(NOW(), INTERVAL 2 HOUR)'

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

Allow RawSql for both key and value. When key only and value is null then we treat a little different.
RawSql already avoids escape. This was removed for instances where key is RawSql and value isn't
escape is being set false here not to true.
@kenjis kenjis added bug Verified issues on the current code behavior or pull requests that will fix them database Issues or pull requests that affect the database layer labels Jan 17, 2023
Added another test where this makes a difference.
@kenjis kenjis changed the title Bug Fix: Builder where() when using RawSql Bug Fix: Builder where() generates incorrect SQL when using RawSql Jan 18, 2023
@kenjis kenjis changed the title Bug Fix: Builder where() generates incorrect SQL when using RawSql Bug Fix: [QueryBuilder] where() generates incorrect SQL when using RawSql Jan 18, 2023
@kenjis kenjis merged commit 9a71a94 into codeigniter4:develop Jan 20, 2023
@sclubricants sclubricants deleted the FixBuilderWhere branch January 21, 2023 20:10
@kenjis kenjis changed the title Bug Fix: [QueryBuilder] where() generates incorrect SQL when using RawSql fix: [QueryBuilder] where() generates incorrect SQL when using RawSql Feb 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them database Issues or pull requests that affect the database layer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants