in reply to SQL Parsing

Hello!

I tried to read all the code but because I am a beginner I was not able to understand it much. With SQL::Parser, Data::Dumper showed that things were parsed well on the sample commands I tried, however I don't understand how the data structures are designed so I don't know how to write methods to grab the relevant information. Can you please give a short explanation or just a list of the data structures (like where_cols, etc.)?

Thanks a lot!

Replies are listed 'Best First'.
Re^2: SQL Parsing
by jZed (Prior) on Jul 11, 2007 at 18:21 UTC
    Here ya go:
    #!/usr/bin/perl use warnings; use strict; use SQL::Statement; my $stmt = SQL::Statement->new(" SELECT a, b FROM tblA LEFT JOIN tblB WHERE c > 10 and tblB.d = 5 "); printf "Tables : %s\nSelect Cols : %s\nWhere Cols : %s\n", join( ', ', @ { $stmt->{org_table_names} } ), join( ', ', map {$_->display_name} $stmt->columns ), join( ', ', keys %{ $stmt->{where_cols} } ), ; # OUTPUT # Tables : tblA, tblB # Select Cols : a, b # Where Cols : tblB.d, c

    Note, that as menolly++ mentioned, columns are only associated with tables if explicitly specified in the SQL.

    And on a different (off) topic : Congratulations! You are customer number 1,000 at jZedHacksRus. Pick up your door prize on the way out.