Translates into IS NULL if possible
(name: &str, args: &[rq::Expr], ctx: &mut Context)
| 142 | |
| 143 | /// Translates into IS NULL if possible |
| 144 | fn process_null(name: &str, args: &[rq::Expr], ctx: &mut Context) -> Result<sql_ast::Expr> { |
| 145 | let (a, b) = (&args[0], &args[1]); |
| 146 | let operand = if matches!(a.kind, rq::ExprKind::Literal(Literal::Null)) { |
| 147 | b |
| 148 | } else { |
| 149 | a |
| 150 | }; |
| 151 | |
| 152 | // If this were an Enum, we could match on it (see notes in `std.rs`). |
| 153 | if name == "std.eq" { |
| 154 | let strength = sql_ast::Expr::IsNull(Box::new(sql_ast::Expr::Value(Value::Null.into()))) |
| 155 | .binding_strength(); |
| 156 | let expr = translate_operand(operand.clone(), true, strength, Associativity::Both, ctx)?; |
| 157 | let expr = Box::new(expr.into_ast()); |
| 158 | Ok(sql_ast::Expr::IsNull(expr)) |
| 159 | } else if name == "std.ne" { |
| 160 | let strength = sql_ast::Expr::IsNotNull(Box::new(sql_ast::Expr::Value(Value::Null.into()))) |
| 161 | .binding_strength(); |
| 162 | let expr = translate_operand(operand.clone(), true, strength, Associativity::Both, ctx)?; |
| 163 | let expr = Box::new(expr.into_ast()); |
| 164 | Ok(sql_ast::Expr::IsNotNull(expr)) |
| 165 | } else { |
| 166 | unreachable!() |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | /// Translates into IN (v1, v2, ...) if possible |
| 171 | fn process_array_in( |
no test coverage detected