MCPcopy Create free account
hub / github.com/erans/pgsqlite / is_computed_expression

Function is_computed_expression

src/validator/numeric_validator.rs:569–616  ·  view source on GitHub ↗

Check if a value is a computed expression that shouldn't be validated

(value: &str)

Source from the content-addressed store, hash-verified

567
568/// Check if a value is a computed expression that shouldn't be validated
569fn is_computed_expression(value: &str) -> bool {
570 let trimmed = value.trim();
571
572 // Skip validation for:
573 // 1. Expressions with arithmetic operators (but not leading minus for negative numbers)
574 // 2. Function calls
575 // 3. Column references
576 // 4. CASE expressions
577 // 5. Subqueries
578
579 // Check for arithmetic operators, but handle negative numbers correctly
580 if trimmed.contains('+') ||
581 trimmed.contains('*') ||
582 trimmed.contains('/') ||
583 trimmed.contains('%') {
584 return true;
585 }
586
587 // Check for minus sign that's not at the beginning (indicating subtraction)
588 if let Some(minus_pos) = trimmed.find('-')
589 && minus_pos > 0 {
590 return true; // It's subtraction, not a negative number
591 }
592
593 // Check for function calls, subqueries, or CASE expressions
594 if trimmed.contains('(') ||
595 trimmed.contains("CASE") ||
596 trimmed.contains("SELECT") {
597 return true;
598 }
599
600 // Check if it's a literal value (quoted string or simple number)
601 if trimmed.starts_with('\'') && trimmed.ends_with('\'') {
602 return false; // It's a quoted string literal
603 }
604
605 // Check if it's a simple number (including negative numbers)
606 if trimmed.chars().all(|c| c.is_ascii_digit() || c == '.' || c == '-') {
607 // Make sure there's at most one minus sign and it's at the beginning
608 let minus_count = trimmed.chars().filter(|&c| c == '-').count();
609 if minus_count <= 1 && (minus_count == 0 || trimmed.starts_with('-')) {
610 return false; // It's a simple number literal
611 }
612 }
613
614 // Everything else is considered a computed expression or column reference
615 true
616}
617
618/// Split comma-separated assignments, handling quoted strings
619fn split_assignments(assignments_str: &str) -> Vec<String> {

Callers 1

parse_update_statementFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected