in reply to How to parse an SQL query into an XML tree?
The module will handle implicit and explicit joins, column and table alias, complex nested where clauses, and more. It doesn't yet handle subqueries.use SQL::Statement my $parser = SQL::Parser->new(); $parser->{PrintError}=0; $parser->{RaiseError}=1; for my $sql(<DATA>) { my $stmt = SQL::Statement->new($sql,$parser); printf "Command %s\n",$stmt->command; printf "Num Pholders %s\n",scalar $stmt->params; printf "Columns %s\n", join',', map{$_->name} $stmt->columns; printf "Tables %s\n",join',',$stmt->tables; printf "Where op %s\n",join',',$stmt->where->op; printf "Order Cols %s\n",join',',map{$_->column}$stmt->order; }
|
|---|