Skip to content

Commit

Permalink
Wrap all math operations in parens
Browse files Browse the repository at this point in the history
Previously if you used local variables or parens in Rust to override the
default order of operations, we would completely lose that information
in the generated SQL. This would at best result in an unexpected value,
but at worse would cause a query like `now + 2.minutes() * (some_int +
1)` to result in a runtime error complaining that there's no operator
for `interval + integer`

I intend to backport this to 1.4

Fixes diesel-rs#2017
  • Loading branch information
sgrif authored and pietgeursen committed May 16, 2019
1 parent 8d5739a commit 747b1ff
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ for Rust libraries in [RFC #1105](https://github.com/rust-lang/rfcs/blob/master/
have been. All types in Diesel are now correctly only considered
non-aggregate if their parts are.

* Parenthesis are now inserted around all mathematical operations. This means
that `(2.into_sql() + 3) * 4` will correctly evaluate to 20 as expected.
Previously we would generate SQL that evaluated to 14. This could even result
in runtime errors if multiple types were involved (for example, `interval *
(integer + 1)`)

### Deprecated

* `diesel_(prefix|postfix|infix)_operator!` have been deprecated. These macros
Expand Down

0 comments on commit 747b1ff

Please sign in to comment.