Skip to content

Fix: The subquery adds a prefix for the table alias. - #6390

Merged
kenjis merged 2 commits into
codeigniter4:developfrom
iRedds:fix/alias-subquery
Aug 22, 2022
Merged

Fix: The subquery adds a prefix for the table alias.#6390
kenjis merged 2 commits into
codeigniter4:developfrom
iRedds:fix/alias-subquery

Conversation

@iRedds

@iRedds iRedds commented Aug 18, 2022

Copy link
Copy Markdown
Collaborator

Description
https://forum.codeigniter.com/showthread.php?tid=82741&pid=399285#pid399285
When creating a query, table aliases are registered. This prevents the prefix being added to the alias.

Due to the fact that aliases are stored in the property of the BaseConnection class, after compiling the subquery using the BaseBuilder::geCompiledSelect() method, the list of aliases is cleared, which leads to the fact that when compiling the main query, the alias is recognized as a table name and to the alias prefix is added.

This PR prevents resetting alias values.

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

@iRedds
iRedds marked this pull request as draft August 18, 2022 18:50
@iRedds

iRedds commented Aug 18, 2022

Copy link
Copy Markdown
Collaborator Author

Added fixes for BaseBuilder::fromSubquery().
Some of the changes could be optimized, but this is not possible due to the current design of the classes for working with the database.

@iRedds
iRedds marked this pull request as ready for review August 18, 2022 19:51
@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 Aug 18, 2022

@MGatner MGatner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clear explanation! I'm not very familiar with the subquery handling but your test looks good. I'll leave for a few in case anyone else wants to take a look.

@kenjis
kenjis merged commit 4727025 into codeigniter4:develop Aug 22, 2022
@kenjis

kenjis commented Aug 22, 2022

Copy link
Copy Markdown
Member

Thank you.

@iRedds
iRedds deleted the fix/alias-subquery branch August 22, 2022 07:03
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.

3 participants