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!!
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.