Render binary operator expression handling precedence and parenthesis.
(
&self,
context: &mut Context,
out: &mut DynQuery,
value: &BinaryOp<&dyn Expression, &dyn Expression>,
)
| 760 | } |
| 761 | |
| 762 | /// Render binary operator expression handling precedence and parenthesis. |
| 763 | fn write_binary_op( |
| 764 | &self, |
| 765 | context: &mut Context, |
| 766 | out: &mut DynQuery, |
| 767 | value: &BinaryOp<&dyn Expression, &dyn Expression>, |
| 768 | ) { |
| 769 | if value.op == BinaryOpType::Alias && context.fragment == Fragment::SqlSelectOrderBy { |
| 770 | return value.lhs.write_query(self.as_dyn(), context, out); |
| 771 | } |
| 772 | let (prefix, infix, suffix, lhs_parenthesized, rhs_parenthesized) = |
| 773 | self.expression_binary_op_fragments(context, value.op); |
| 774 | let precedence = self.expression_binary_op_precedence(&value.op); |
| 775 | out.push_str(prefix); |
| 776 | possibly_parenthesized!( |
| 777 | out, |
| 778 | !lhs_parenthesized && value.lhs.precedence(self.as_dyn()) < precedence, |
| 779 | value.lhs.write_query(self.as_dyn(), context, out) |
| 780 | ); |
| 781 | out.push_str(infix); |
| 782 | let mut context = context.switch_fragment(if value.op == BinaryOpType::Alias { |
| 783 | Fragment::Aliasing |
| 784 | } else { |
| 785 | context.fragment |
| 786 | }); |
| 787 | possibly_parenthesized!( |
| 788 | out, |
| 789 | !rhs_parenthesized && value.rhs.precedence(self.as_dyn()) <= precedence, |
| 790 | value |
| 791 | .rhs |
| 792 | .write_query(self.as_dyn(), &mut context.current, out) |
| 793 | ); |
| 794 | out.push_str(suffix); |
| 795 | } |
| 796 | |
| 797 | fn write_cast( |
no test coverage detected