(
&self,
unparser: &Unparser,
func_name: &str,
args: &[Expr],
)
| 424 | } |
| 425 | |
| 426 | fn round_to_sql_enforce_numeric( |
| 427 | &self, |
| 428 | unparser: &Unparser, |
| 429 | func_name: &str, |
| 430 | args: &[Expr], |
| 431 | ) -> Result<ast::Expr> { |
| 432 | let mut args = unparser.function_args_to_sql(args)?; |
| 433 | |
| 434 | // Enforce the first argument to be Numeric |
| 435 | if let Some(ast::FunctionArg::Unnamed(ast::FunctionArgExpr::Expr(expr))) = |
| 436 | args.first_mut() |
| 437 | { |
| 438 | if let ast::Expr::Cast { data_type, .. } = expr { |
| 439 | // Don't create an additional cast wrapper if we can update the existing one |
| 440 | *data_type = ast::DataType::Numeric(ast::ExactNumberInfo::None); |
| 441 | } else { |
| 442 | // Wrap the expression in a new cast |
| 443 | *expr = ast::Expr::Cast { |
| 444 | kind: ast::CastKind::Cast, |
| 445 | expr: Box::new(expr.clone()), |
| 446 | data_type: ast::DataType::Numeric(ast::ExactNumberInfo::None), |
| 447 | array: false, |
| 448 | format: None, |
| 449 | }; |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | Ok(ast::Expr::Function(Function { |
| 454 | name: ObjectName::from(vec![Ident { |
| 455 | value: func_name.to_string(), |
| 456 | quote_style: None, |
| 457 | span: Span::empty(), |
| 458 | }]), |
| 459 | args: ast::FunctionArguments::List(ast::FunctionArgumentList { |
| 460 | duplicate_treatment: None, |
| 461 | args, |
| 462 | clauses: vec![], |
| 463 | }), |
| 464 | filter: None, |
| 465 | null_treatment: None, |
| 466 | over: None, |
| 467 | within_group: vec![], |
| 468 | parameters: ast::FunctionArguments::None, |
| 469 | uses_odbc_syntax: false, |
| 470 | })) |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | #[derive(Default)] |
no test coverage detected