MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / convert_value

Function convert_value

nodedb-sql/src/resolver/expr/value.rs:14–41  ·  view source on GitHub ↗

Convert a sqlparser `Value` to our `SqlValue`. Number literal routing: - Pure integers → `SqlValue::Int`. - Numbers with `.`, `e`, or `E` → `SqlValue::Decimal` (exact arithmetic). - If decimal parse fails → fallback to `SqlValue::Float`, then `SqlValue::String`.

(val: &Value)

Source from the content-addressed store, hash-verified

12/// - Numbers with `.`, `e`, or `E` → `SqlValue::Decimal` (exact arithmetic).
13/// - If decimal parse fails → fallback to `SqlValue::Float`, then `SqlValue::String`.
14pub fn convert_value(val: &Value) -> Result<SqlValue> {
15 match val {
16 Value::Number(n, _) => {
17 if let Ok(i) = n.parse::<i64>() {
18 Ok(SqlValue::Int(i))
19 } else if n.contains('.') || n.contains('e') || n.contains('E') {
20 // Fractional or scientific notation: prefer exact Decimal.
21 if let Ok(d) = rust_decimal::Decimal::from_str_exact(n) {
22 Ok(SqlValue::Decimal(d))
23 } else if let Ok(f) = n.parse::<f64>() {
24 Ok(SqlValue::Float(f))
25 } else {
26 Ok(SqlValue::String(n.clone()))
27 }
28 } else if let Ok(f) = n.parse::<f64>() {
29 Ok(SqlValue::Float(f))
30 } else {
31 Ok(SqlValue::String(n.clone()))
32 }
33 }
34 Value::SingleQuotedString(s) => Ok(SqlValue::String(s.clone())),
35 Value::Boolean(b) => Ok(SqlValue::Bool(*b)),
36 Value::Null => Ok(SqlValue::Null),
37 _ => Err(SqlError::Unsupported {
38 detail: format!("value literal: {val}"),
39 }),
40 }
41}
42
43/// Parse an interval string to microseconds.
44///

Callers 2

expr_to_sql_valueFunction · 0.85
convert_expr_innerFunction · 0.85

Calls 2

containsMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected