sql::ast

Function visit_statements_mut

pub fn visit_statements_mut<V, E, F>(v: &mut V, f: F) -> ControlFlow<E>
where V: VisitMut, F: FnMut(&mut Statement) -> ControlFlow<E>,
Expand description

Invokes the provided closure on all statements (e.g. SELECT, CREATE TABLE, etc) present in v

ยงExample

let sql = "SELECT x FROM foo LIMIT 9+$limit; SELECT * FROM t LIMIT f()";
let mut statements = Parser::parse_sql(&GenericDialect{}, sql).unwrap();

// Remove all select limits in outer statements (not in sub-queries)
visit_statements_mut(&mut statements, |stmt| {
  if let Statement::Query(q) = stmt {
     q.limit = None
  }
  ControlFlow::<()>::Continue(())
});

assert_eq!(statements[0].to_string(), "SELECT x FROM foo");
assert_eq!(statements[1].to_string(), "SELECT * FROM t");