perlquestion
som.nitk
I have an update statement which I am parsing with SQL::Parser
<code>
uPdate scott.emp
set ename='SCT%',emp_date=TO_DATE('04/16/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),empno='15645'
WHERE dept=20 and ename IN(select ename from emp where empno='1111');
</code>
But since TO_DATE function cannot be parsed with SQL::Parser hence it throws error:
<code>
Incomplete SET clause! at ./post_audit.pl line 173
Incomplete SET clause! at ./post_audit.pl line 173
</code>
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:
<code>
+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' WHERE 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);
</code>
Error is thrown at line 173 while parsing the statement.
Initially I thought the problem comes from here inside Parser.pm
<code>
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 ( defined($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;
}
</code>
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.
<p>
Thanks!!
</P>