in reply to Re: Parse and change an SQL statement
in thread Parse and change an SQL statement

I tried this and it works:
use Modern::Perl; use Data::Dump qw /dump/; use SQL::Parser; use SQL::Statement; my $SqlParser = SQL::Parser->new() or die "Could not create an SQL::Pa +rser"; my $parse = SQL::Statement->new('SELECT fie, max(foo), count(baz) FROM + bar JOIN fee WHERE foo > 10', $SqlParser); my @columns = $parse->column_defs(); say dump @columns;

Output:


  { fullorg => "fie", type => "column", value => "fie" },
  {
    alias    => "MAX",
    arg      => { fullorg => "foo", type => "column", value => "foo" },
    argstr   => "foo",
    distinct => "ALL",
    fullorg  => "max (foo)",
    name     => "MAX",
    type     => "setfunc",
  },
  {
    alias    => "COUNT",
    arg      => { fullorg => "baz", type => "column", value => "baz" },
    argstr   => "baz",
    distinct => "ALL",
    fullorg  => "count (baz)",
    name     => "COUNT",
    type     => "setfunc",
  },

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

My blog: Imperial Deltronics