how to invoke a set of update statements
Posted: Tue Dec 12, 2006 3:05 am
Hi people
I have a file that contains many SQL statements that are generated in runtime.
These are queries in the following syntax:
Basically, the queries in the file fall under 4 formats:
1) drop table statements
2) create table statements
3) comments
4) insert statements
The file can be very large.
I need some way of invoking ALL the queries in the file using function mysql_query.
Initially what I did was to split the content of the file by ';'
each splitted part was invoked separately. This worked fine, until a semicolon was found in one of the "insert into" statements and that broke my code:
I am looking for a robust way to parse a file that contains SQL statements.
Possibly using regular expressions can achieve a more robust parsing.
If I can invoke all the sql statements in the file without any parsing, that would be perfect
any suggestions?
regards
I have a file that contains many SQL statements that are generated in runtime.
These are queries in the following syntax:
Code: Select all
DROP TABLE IF EXISTS `table1`;
CREATE TABLE `table1` (
`ID` int(10) unsigned not null,
...
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
# comment here
insert into table1 (`ID`, ....) values (1, ...);
insert into table1 (`ID`, ....) values (2, ...);
insert into table1 (`ID`, ....) values (3, ...);1) drop table statements
2) create table statements
3) comments
4) insert statements
The file can be very large.
I need some way of invoking ALL the queries in the file using function mysql_query.
Initially what I did was to split the content of the file by ';'
each splitted part was invoked separately. This worked fine, until a semicolon was found in one of the "insert into" statements and that broke my code:
Code: Select all
insert into table1 (`ID`, `Text`) values (1, 'This string contains ;');Possibly using regular expressions can achieve a more robust parsing.
If I can invoke all the sql statements in the file without any parsing, that would be perfect
any suggestions?
regards