Cast value to STRING
(
&self,
value: Value,
max_length: Option<usize>,
)
| 5014 | |
| 5015 | /// Cast value to STRING |
| 5016 | fn cast_to_string( |
| 5017 | &self, |
| 5018 | value: Value, |
| 5019 | max_length: Option<usize>, |
| 5020 | ) -> Result<Value, ExecutionError> { |
| 5021 | let string_value = match value { |
| 5022 | Value::String(s) => s, |
| 5023 | Value::Number(n) => { |
| 5024 | if n.fract() == 0.0 { |
| 5025 | format!("{}", n as i64) |
| 5026 | } else { |
| 5027 | format!("{}", n) |
| 5028 | } |
| 5029 | } |
| 5030 | Value::Boolean(b) => { |
| 5031 | if b { |
| 5032 | "true".to_string() |
| 5033 | } else { |
| 5034 | "false".to_string() |
| 5035 | } |
| 5036 | } |
| 5037 | Value::DateTime(dt) => dt.format("%Y-%m-%d %H:%M:%S UTC").to_string(), |
| 5038 | Value::Null => return Ok(Value::Null), |
| 5039 | _ => { |
| 5040 | return Err(ExecutionError::RuntimeError(format!( |
| 5041 | "Cannot cast {:?} to STRING", |
| 5042 | value.type_name() |
| 5043 | ))) |
| 5044 | } |
| 5045 | }; |
| 5046 | |
| 5047 | // Apply max_length constraint if specified |
| 5048 | let final_string = if let Some(max_len) = max_length { |
| 5049 | if string_value.len() > max_len { |
| 5050 | string_value[..max_len].to_string() |
| 5051 | } else { |
| 5052 | string_value |
| 5053 | } |
| 5054 | } else { |
| 5055 | string_value |
| 5056 | }; |
| 5057 | |
| 5058 | Ok(Value::String(final_string)) |
| 5059 | } |
| 5060 | |
| 5061 | /// Cast value to INTEGER |
| 5062 | fn cast_to_integer(&self, value: Value) -> Result<Value, ExecutionError> { |
no test coverage detected