Skip to content

Conversation

@nreynis
Copy link

@nreynis nreynis commented Aug 21, 2020

Q A
Type improvement
BC Break no
Fixed issues #3601

Summary

Throw a QueryException when using the query builder improperly.

@nreynis nreynis force-pushed the 3601-query-exception-improper-from branch 3 times, most recently from 4ffb029 to 4e3b8b8 Compare August 21, 2020 20:59
@greg0ire
Copy link
Member

I have asked you some changes, and had a quick look at the CI, these issues look like they could be transient. When you address the changes I asked, that will trigger a new build and we will see if they are indeed transient or not.

@nreynis nreynis force-pushed the 3601-query-exception-improper-from branch 2 times, most recently from 1135c14 to 211366d Compare August 22, 2020 12:06
@greg0ire
Copy link
Member

Looks like the build issues were indeed transient 👍

greg0ire
greg0ire previously approved these changes Aug 22, 2020
@greg0ire greg0ire requested a review from morozov August 22, 2020 12:17
Copy link
Member

@morozov morozov left a comment

Choose a reason for hiding this comment

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

2.10.x looks like a wrong target branch. It's not a bug in a way that something doesn't work as documented, and it may be a breaking change since it throws new exceptions. Please reconsider the target branch.

->from('users');
$this->expectException(QueryException::class);
$this->expectExceptionMessage(
'There is no currently registered FROM clause.'
Copy link
Member

Choose a reason for hiding this comment

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

I don't get this exception message. Why should there be a FROM clause in an UPDATE statement?

Copy link
Author

Choose a reason for hiding this comment

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

Changed the error message to be more focused on the functional part, and less on the internal structure.

->from('users');
$this->expectException(QueryException::class);
$this->expectExceptionMessage(
'There is no currently registered FROM clause.'
Copy link
Member

Choose a reason for hiding this comment

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

Why should there be a FROM clause in an INSERT statement?

Copy link
Author

Choose a reason for hiding this comment

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

Changed the error message to be more focused on the functional part, and less on the internal structure.

@nreynis
Copy link
Author

nreynis commented Aug 22, 2020

2.10.x looks like a wrong target branch. It's not a bug in a way that something doesn't work as documented, and it may be a breaking change since it throws new exceptions. Please reconsider the target branch.

It can't really be a breaking change: the existing code already throw. The goal is more to handle the misuse and return a less confusing exception. Also execute and getSQL methods already throw a DBALException.

The only way it could break something is if it were deliberately abusing the QueryBuilder to make it throw a specific exception.

But I have no problem targeting any branch you see fit.

@morozov
Copy link
Member

morozov commented Aug 22, 2020

It can't really be a breaking change: the existing code already throw.

Thanks for the confirmation. Then it's safe to have these changes in 2.11.0.

@morozov
Copy link
Member

morozov commented Sep 13, 2020

Please retarget (#4219 (comment)).

@nreynis nreynis force-pushed the 3601-query-exception-improper-from branch from 9bb0e7c to 6cd4e05 Compare September 14, 2020 05:12
@nreynis nreynis changed the base branch from 2.10.x to 2.11.x September 14, 2020 05:12
Copy link
Member

@greg0ire greg0ire left a comment

Choose a reason for hiding this comment

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

@morozov should OP do :%s/TableName/Table/?

/**
* @throws QueryException
*/
private function assertHasSingleFromClause(): void
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
private function assertHasSingleFromClause(): void
private function assertHasSingleTableName(): void

*/
private function assertHasSingleFromClause(): void
{
if (! array_key_exists('table', $this->sqlParts['from'])) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (! array_key_exists('table', $this->sqlParts['from'])) {
/* INSERT and UPDATE statements do not use FROM clause
but the table name is still stored in $this->sqlParts['from']
in these cases */
if (! array_key_exists('table', $this->sqlParts['from'])) {

*/
private function getSQLForInsert()
{
$this->assertHasSingleFromClause();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
$this->assertHasSingleFromClause();
$this->assertHasSingleTableName();

*/
private function getSQLForUpdate()
{
$this->assertHasSingleFromClause();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
$this->assertHasSingleFromClause();
$this->assertHasSingleTableName();

*/
private function getSQLForDelete()
{
$this->assertHasSingleFromClause();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
$this->assertHasSingleFromClause();
$this->assertHasSingleTableName();


public static function uninitializedTableName(): self
{
return new self('There is no currently registered table name.');
Copy link
Member

Choose a reason for hiding this comment

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

That message is misleading, it will be used when there are 2 registered table names. The name of the method is misleading too.

Copy link
Author

Choose a reason for hiding this comment

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

Have you a suggestion?

@morozov
Copy link
Member

morozov commented Sep 14, 2020

@morozov should OP do :%s/TableName/Table/?

Makes sense. I'm not going to spend much time on this personally (#4220 (comment)).

@morozov morozov changed the base branch from 2.11.x to 2.12.x November 29, 2020 21:38
@morozov morozov closed this Apr 21, 2021
@morozov morozov deleted the branch doctrine:2.12.x April 21, 2021 16:26
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants