Skip Menu |

This queue is for tickets about the SQL-Statement CPAN distribution.

Report information
The Basics
Id: 31730
Status: resolved
Worked: 4 hours (240 min)
Priority: 0/
Queue: SQL-Statement

People
Owner: Nobody in particular
Requestors: n [...] shaplov.ru
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.15
Fixed in: (no value)



Subject: Problems with parsing multiline INSERT statment
This example works well: use SQL::Statement; use Data::Dumper; my $parser = SQL::Parser->new(); $parser->{RaiseError}=1; $parser->{PrintError}=1; my $sql = "INSERT INTO aaa VALUES ('aaa','bbb','ccc'), ('sss','ddd','eee')"; my $stmt = SQL::Statement->new($sql,$parser); my @rowValues = $stmt->row_values(); print Dumper(\@rowValues); but if fails when last or first member of inserted data is numeric my $sql = "INSERT INTO aaa VALUES ('aaa','bbb''111), ('sss','ddd','eee')"; or my $sql = "INSERT INTO aaa VALUES ('aaa','bbb','ccc'), (222,'ddd','eee')"; Other examples seems to work well: my $sql = "INSERT INTO aaa VALUES ('aaa','bbb',111)"; my $sql = "INSERT INTO aaa VALUES ('aaa','bbb','ccc'), ('sss','ddd',222)"; my $sql = "INSERT INTO aaa VALUES (222,'bbb','ccc'), ('sss','ddd','eee')"; PS: $ perl -e'use SQL::Statement; print $SQL::Statement::VERSION,"\n"' 1.15 $ perl -v This is perl, v5.8.8 built for i486-linux-gnu-thread-multi Copyright 1987-2006, Larry Wall
I typed your examples into a test script (see attachment) and got following errors: $VAR1 = \'INSERT INTO aaa VALUES (\'aaa\',\'bbb\',\'ccc\'), (\'sss\',\'ddd\',\'eee\')'; $VAR1 = [ 'aaa', 'bbb', 'ccc', 'sss', 'ddd', 'eee' ]; $VAR1 = \'INSERT INTO aaa VALUES (\'aaa\',\'bbb\',111), (\'sss\',\'ddd\',\'eee\')'; SQL ERROR: '111)' is not a valid value or is not quoted! $VAR1 = \'INSERT INTO aaa VALUES (\'aaa\',\'bbb\',\'ccc\'), (222,\'ddd\',\'eee\')'; SQL ERROR: '(222' is not a valid value or is not quoted! $VAR1 = \'INSERT INTO aaa VALUES (\'aaa\',\'bbb\',111)'; $VAR1 = [ 'aaa', 'bbb', '111' ]; $VAR1 = \'INSERT INTO aaa VALUES (\'aaa\',\'bbb\',\'ccc\'), (\'sss\',\'ddd\',222)'; $VAR1 = [ 'aaa', 'bbb', 'ccc', 'sss', 'ddd', '222' ]; $VAR1 = \'INSERT INTO aaa VALUES (222,\'bbb\',\'ccc\'), (\'sss\',\'ddd\',\'eee\')'; $VAR1 = [ '222', 'bbb', 'ccc', 'sss', 'ddd', 'eee' ]; Can you explain in detail where you detected a behaviour which is an error?
#!/usr/bin/perl use SQL::Statement; use Data::Dumper; my $parser = SQL::Parser->new( 'ANSI', { RaiseError => 0, PrintError => 0 } ); foreach my $sql ( "INSERT INTO aaa VALUES ('aaa','bbb','ccc'), ('sss','ddd','eee')", "INSERT INTO aaa VALUES ('aaa','bbb',111), ('sss','ddd','eee')", "INSERT INTO aaa VALUES ('aaa','bbb','ccc'), (222,'ddd','eee')", "INSERT INTO aaa VALUES ('aaa','bbb',111)", "INSERT INTO aaa VALUES ('aaa','bbb','ccc'), ('sss','ddd',222)", "INSERT INTO aaa VALUES (222,'bbb','ccc'), ('sss','ddd','eee')", ) { print( Dumper( \$sql ) ); my $stmt = SQL::Statement->new($sql,$parser); if( defined($parser->structure()->{errstr} ) ) { print( $parser->structure()->{errstr} ); next; } my @rowValues = $stmt->row_values(); print Dumper(\@rowValues); }
Subject: Re: [rt.cpan.org #31730] Problems with parsing multiline INSERT statment
Date: Sun, 4 Jan 2009 22:49:29 +0300
To: bug-SQL-Statement [...] rt.cpan.org, Dan [...] DWright.Org
From: Nikolay Shaplov <n [...] shaplov.ru>
On Sun, 04 Jan 2009 14:23:46 -0500 "Jens Rehsack via RT" <bug-SQL-Statement@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=31730 > > > I typed your examples into a test script (see attachment) and got > following errors: > > $VAR1 = \'INSERT INTO aaa VALUES (\'aaa\',\'bbb\',\'ccc\'), > (\'sss\',\'ddd\',\'eee\')'; > $VAR1 = [ > 'aaa', > 'bbb', > 'ccc', > 'sss', > 'ddd', > 'eee' > ]; > $VAR1 = \'INSERT INTO aaa VALUES (\'aaa\',\'bbb\',111), > (\'sss\',\'ddd\',\'eee\')'; > SQL ERROR: '111)' is not a valid value or is not quoted! > > $VAR1 = \'INSERT INTO aaa VALUES (\'aaa\',\'bbb\',\'ccc\'), > (222,\'ddd\',\'eee\')'; > SQL ERROR: '(222' is not a valid value or is not quoted! > > $VAR1 = \'INSERT INTO aaa VALUES (\'aaa\',\'bbb\',111)'; > $VAR1 = [ > 'aaa', > 'bbb', > '111' > ]; > $VAR1 = \'INSERT INTO aaa VALUES (\'aaa\',\'bbb\',\'ccc\'), > (\'sss\',\'ddd\',222)'; > $VAR1 = [ > 'aaa', > 'bbb', > 'ccc', > 'sss', > 'ddd', > '222' > ]; > $VAR1 = \'INSERT INTO aaa VALUES (222,\'bbb\',\'ccc\'), > (\'sss\',\'ddd\',\'eee\')'; > $VAR1 = [ > '222', > 'bbb', > 'ccc', > 'sss', > 'ddd', > 'eee' > ]; > > Can you explain in detail where you detected a behaviour which is an > error?
I did not remember exactly, it was long time ago, but as far as I can remember that problem was first, with error you've received in your example (the sql statement is correct, when there is no quotes around numbers, but program gives an error). The second problem were that multi-line insert is possible (one can insert more than one line in one insert command), but if I do it with your module, it will treat such insert statement as a single line insert statement all member of all lines will be treated as a singe line. This is not the behaviour I would expect in such case. Still it was some time ago. I can forget something...
The real problem was, that neither SQL::Parser nor SQL::Statement was aware of INSERT commands which affects more than one row. So the '),(' was always parsed as part of the first value of the second row, which causes the error you recognized. Fixed in 1.23.