I have an update statement which I am parsing with SQL::Parser
uPdate scott.emp set ename='SCT%',emp_date=TO_DATE('04/16/2011 00:00:00', 'MM/DD/YYYY H +H24:MI:SS'),empno='15645' WHERE dept=20 and ename IN(select ename from emp where empno='1111');
But since TO_DATE function cannot be parsed with SQL::Parser hence it throws error:
Incomplete SET clause! at ./post_audit.pl line 173 Incomplete SET clause! at ./post_audit.pl line 173
How do I catch such errors? Does eval do the trick? Did not find proper documentation for the same. Code to parse the SQL statements:
+12 use SQL::Parser; +34 my $statement = "uPdate scott.emp set ename='SCT%',emp_date=TO +_DATE('04/16/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),empno='15645' W +HERE dept=20 and ename IN(select ename from emp where empno='1111')"; +172 my $parser = SQL::Parser->new('AnyData', {RaiseError=>1} ) +; +173 $parser->parse($statement);
Error is thrown at line 173 while parsing the statement. Initially I thought the problem comes from here inside Parser.pm
sub SET_CLAUSE_LIST { my ( $self, $set_string ) = @_; my @sets = split( /,/, $set_string ); my ( @cols, @vals ); for my $set (@sets) { my ( $col, $val ) = split( m/ = /, $set ); return $self->do_err('Incomplete SET clause!') unless ( define +d($col) && defined($val) ); push( @cols, $col ); push( @vals, $val ); } return undef unless ( $self->{struct}->{column_defs} = $self->ROW_VALUE_LIST( + join ',', @cols ) ); return undef unless ( $self->LITERAL_LIST( join ',', @vals ) ); return 1; }
But the problem is not with regex. The problem is with TO_DATE function only. My question is not to fix the given parsed SQL to the Parser, but how to catch such errors and probably print a statement. I could'nt find proper documentation for this.

Thanks!!


In reply to How to catch SQL::Parser errors in Perl by som.nitk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.