Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
visit_statements in datafusion::sql::sqlparser::ast - Rust
[go: Go Back, main page]

Function datafusion::sql::sqlparser::ast::visit_statements

source ·
pub fn visit_statements<V, E, F>(v: &V, f: F) -> ControlFlow<E>
where V: Visit, F: FnMut(&Statement) -> ControlFlow<E>,
Expand description

Invokes the provided closure iteratively with a mutable reference to all statements present in v (e.g. SELECT, CREATE TABLE, etc).

§Example

let sql = "SELECT a FROM foo where x IN (SELECT y FROM bar); CREATE TABLE baz(q int)";
let statements = Parser::parse_sql(&GenericDialect{}, sql)
   .unwrap();

// visit all statements
let mut visited = vec![];
visit_statements(&statements, |stmt| {
  visited.push(format!("STATEMENT: {}", stmt));
  ControlFlow::<()>::Continue(())
});

let expected : Vec<_> = [
  "STATEMENT: SELECT a FROM foo WHERE x IN (SELECT y FROM bar)",
  "STATEMENT: CREATE TABLE baz (q INT)"
]
  .into_iter().map(|s| s.to_string()).collect();

assert_eq!(visited, expected);