DBI::Statement parsing
- From: cougar@xxxxxxxxxxx (John Cougar)
- Date: Wed, 26 Oct 2005 16:02:20 +1000
Heya DBI-Users
Can anyone help a DBI::Statement newbie with the following problems:
1. When parsing a SQL string, is there a preferred way for initially testing
whether the statement did or did not parse successfully?
I am currently testing the $stmt->{original_string} element in the return
hash from creating the statement object; this element seems to only be
instantiated when the parsing succeeds. Would this be considered a valid way
to test?
Personally, I would prefer a method that could return a (documented) success
indication (like $stmt->isOK() == TRUE, or summit ...), but this seems
somewhat esoteric; the doco for the return hash is rather light-on, however,
causing quite a bit of guesswork on part of the developer.
2. The parsing seems to be very weak? I tried the ANSI dialect, and the
parser seemed to accept just about any string without raising an error. I am
having more success with the Anydata dialect, but even this seems to let a
lot of things slip through ...
For instance:
"SELECT c1, c2 FROM x WHERE" seems to parse successfully, no error raised
for the empty WHERE-clause ... and things like that.
"SELECT *, junk FROM x" parses successfully!?
Is this anyone else's experience also?
Code frag below sig.
Cheers and ta if you can help,
John.
_______
+------------------ ////////------+----------------------------+
| John V Cougar __/ / | Voice: +61 2 6208 1683 |
| System Engineer / / /\ DBA +----------------------------+
| Telstra Internet \/_/ \ Devel | E-Mail: cougar@xxxxxxxxxxx |
+-------------------\____/ -------+----------------------------+
use SQL::Statement;
use strict;
use Data::Dumper;
my $parser = SQL::Parser->new('AnyData', {RaiseError=>0, PrintError=>0});
my $sql = "SELECT *, junk FROM x";
my $stmt = SQL::Statement->new( $sql, $parser );
if( defined $stmt->{original_string} ) {
print "Success: [$sql] looks like an SQL String\n";
} else {
print "ERROR: [$stmt->{errstr}]\n";
}
print Dumper( $stmt );
.
- Follow-Ups:
- Re: DBI::Statement parsing
- From: Jeff Zucker
- Re: DBI::Statement parsing
- Prev by Date: Re: DBD::Oracle & 10.1 client
- Next by Date: Install with ppm of DBD::Oracle
- Previous by thread: ANNOUNCE: MySQL 5.0 now final/stable/GA
- Next by thread: Re: DBI::Statement parsing
- Index(es):