-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Prevent unexpected combinations of statements and clauses groups from executing #6314
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
Prevent unexpected combinations of statements and clauses groups from executing #6314
Conversation
|
r? @mercmobily |
b8b071a to
802b2b6
Compare
|
(This needs a re-run of the one CI task - it failed on a network error updating coveralls) |
| // here is intentionally not complete; it's just checking the things that allow users | ||
| // to make dangerous errors. | ||
| const invalid = invalidClauses[verb]; | ||
| for (let i = 0; i < invalid.length; i++) { |
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 not use for of?
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.
Combination of:
- presuming it's a hot path, so avoiding extra garbage and/or cpu overhead generated by the iterator protocol
- this loop pattern is generally so recognizable that I don't expect it to be a legibility disadvantage
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.
Let me know if you'd prefer I changed this
kibertoad
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.
this behaviour needs to be documented
… executing Fixes knex#4070 Clauses such as "HAVING" and "WHERE" have no effect on "DELETE" or "TRUNCATE" statements. Due to the architecture of knex, dialects override various base methods for building specific statements. The methods implementing these statements don't explicitly check for the presence of clauses that a user might expect to have an effect, but there isn't a good place to ensure that such queries fail systematically. This commit introduces a "_preValidate" method on the root QueryCompiler class and a set of disallowed verb/clause combinations that will throw an error before doing any SQL-building work. This should make it consistent to prevent anything like `knex.having(...).del()` from unintentionally deleting all rows. The current configuration disallows "HAVING" from "DELETE" statements, and both "WHERE" and "HAVING" from "TRUNCATE" statements.
sqlite and mssql technically support these, but support is not implemented in knex yet
- Move delete + limit test to unit test - Consolidate "invalid combination" tests - Also exercise "implied" where/having
e7f575f to
1f51849
Compare
|
(rebased onto master) |
Fixes #4070, #6074
Clauses such as "HAVING" and "WHERE" have no effect on "DELETE" or "TRUNCATE" statements. Due to the architecture of knex, dialects override various base methods for building specific statements. The methods implementing these statements don't explicitly check for the presence of clauses that a user might expect to have an effect, but there isn't a good place to ensure that such queries fail systematically.
This commit introduces a "_preValidate" method on the root QueryCompiler class and a set of disallowed verb/clause combinations that will throw an error before doing any SQL-building work. This should make it consistent to prevent anything like
knex.having(...).del()from unintentionally deleting all rows.The current configuration disallows "HAVING" from "DELETE" statements, and both "WHERE" and "HAVING" from "TRUNCATE" statements.
Update:
Now also rejects "LIMIT" from "DELETE" and "TRUNCATE"
DRI:@myndzi