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

Function test_python_parameter_substitution

src/query/parameter_parser.rs:516–541  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

514
515 #[test]
516 fn test_python_parameter_substitution() {
517 let mut values = std::collections::HashMap::new();
518 values.insert("user_id".to_string(), "42".to_string());
519 values.insert("name".to_string(), "'John Doe'".to_string());
520
521 // Simple substitution
522 let result = ParameterParser::substitute_python_parameters(
523 "SELECT * FROM users WHERE id = %(user_id)s",
524 &values
525 ).unwrap();
526 assert_eq!(result, "SELECT * FROM users WHERE id = 42");
527
528 // Multiple parameters
529 let result = ParameterParser::substitute_python_parameters(
530 "INSERT INTO users (name, id) VALUES (%(name)s, %(user_id)s)",
531 &values
532 ).unwrap();
533 assert_eq!(result, "INSERT INTO users (name, id) VALUES ('John Doe', 42)");
534
535 // Parameters in string literals should NOT be substituted
536 let result = ParameterParser::substitute_python_parameters(
537 "SELECT 'test %(user_id)s' FROM users WHERE id = %(user_id)s",
538 &values
539 ).unwrap();
540 assert_eq!(result, "SELECT 'test %(user_id)s' FROM users WHERE id = 42");
541 }
542
543 #[test]
544 fn test_python_parameter_counting() {

Callers

nothing calls this directly

Calls 1

insertMethod · 0.45

Tested by

no test coverage detected