PHP Classes

Parser bug with inserts that have semicolons

Recommend this page to a friend!

      SQL Parser  >  All threads  >  Parser bug with inserts that have...  >  (Un) Subscribe thread alerts  
Subject:Parser bug with inserts that have...
Summary:multi-line inserts when the data has semicolons fails
Messages:2
Author:Jerry Seeger
Date:2014-12-16 21:52:34
 

  1. Parser bug with inserts that have...   Reply   Report abuse  
Picture of Jerry Seeger Jerry Seeger - 2014-12-16 21:52:34
insert statement like

INSERT INTO `my_table` (`id`, `name`)
VALUES
(2,'name with ; in it'),
(55,'name')

will not parse correctly. The line with the ; will be treated as the last line of the query because it matches

preg_match("/(.*);/", $sql_line)

I changed the above to

preg_match("/(.*);^/", $sql_line)

Not sure if that will break something else, as it assumes semicolons to end sql statements are at the ends of lines, but it got me past my immediate hurdle.

  2. Re: Parser bug with inserts that have...   Reply   Report abuse  
Picture of Jerry Seeger Jerry Seeger - 2015-04-23 21:16:18 - In reply to message 1 from Jerry Seeger
Correction to the fix below - brain fart when I typed that. Should be looking for semicolon at end of line:

preg_match("/(.*);$/", $sql_line)