yiisoft / yiisoft/db

New unexprected behaviour in 2.0 version

Open
#1,140 20 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
216
Forks
51
Avg merge
3d 10h
Merged PRs (30d)
2

Description

Description

Same expression with same names param are now renamed and this breaks all queries with select and groups by same expression. In prepared statement params names are different and PostgreSQL serer refuses to execute such query.

How reproduce:

    public function testQuery(): void
    {
        $expr = new Expression("(site_id = :site)", ['site' => 1]);
        $sql = new Query($this->db())
            ->select($expr)
            ->from('users')
            ->groupBy($expr)
            ->createCommand()
            ->getSql();


        $this->assertSame('SELECT (site_id = :site) FROM "users" GROUP BY (site_id = :site)', $sql);
    }
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'SELECT (site_id = :site) FROM "users" GROUP BY (site_id = :site)'
+'SELECT (site_id = :site) FROM "users" GROUP BY (site_id = :site_0)'
Package version

2.0

PHP version

8.5

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided Query, Expression, select, and groupBy reproduction and inspect how repeated expression parameters are renamed when SQL is generated. Compare the generated SQL and prepared-statement parameters for PostgreSQL, then add or update a regression test using the shown assertion. Done means identical named parameters remain valid when the same expression is used in SELECT and GROUP BY.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, postgresql
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.