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: The subquery adds a prefix for the table alias. #6390

Merged
merged 2 commits into from
Aug 22, 2022

Conversation

iRedds
Copy link
Collaborator

@iRedds iRedds commented Aug 18, 2022

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
Copy link
Collaborator Author

iRedds commented Aug 18, 2022

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
Copy link
Member

@MGatner MGatner left a comment

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
Copy link
Member

kenjis commented Aug 22, 2022

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.

None yet

3 participants