-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Throw QueryException on improperly initialized from clause #4219
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
Throw QueryException on improperly initialized from clause #4219
Conversation
4ffb029 to
4e3b8b8
Compare
|
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. |
1135c14 to
211366d
Compare
|
Looks like the build issues were indeed transient 👍 |
morozov
left a comment
There was a problem hiding this 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.' |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.' |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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 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. |
Thanks for the confirmation. Then it's safe to have these changes in |
211366d to
ebfc170
Compare
ebfc170 to
9bb0e7c
Compare
|
Please retarget (#4219 (comment)). |
9bb0e7c to
6cd4e05
Compare
greg0ire
left a comment
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| private function assertHasSingleFromClause(): void | |
| private function assertHasSingleTableName(): void |
| */ | ||
| private function assertHasSingleFromClause(): void | ||
| { | ||
| if (! array_key_exists('table', $this->sqlParts['from'])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| $this->assertHasSingleFromClause(); | |
| $this->assertHasSingleTableName(); |
| */ | ||
| private function getSQLForUpdate() | ||
| { | ||
| $this->assertHasSingleFromClause(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| $this->assertHasSingleFromClause(); | |
| $this->assertHasSingleTableName(); |
| */ | ||
| private function getSQLForDelete() | ||
| { | ||
| $this->assertHasSingleFromClause(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| $this->assertHasSingleFromClause(); | |
| $this->assertHasSingleTableName(); |
|
|
||
| public static function uninitializedTableName(): self | ||
| { | ||
| return new self('There is no currently registered table name.'); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you a suggestion?
Makes sense. I'm not going to spend much time on this personally (#4220 (comment)). |
Summary
Throw a QueryException when using the query builder improperly.