http://qs321.pair.com?node_id=1033662

som.nitk has asked for the wisdom of the Perl Monks concerning the following question:

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!!