i am under the weather at the moment and unable to think my way out of a paper bag. so apologies for burdening people with the following question. All help gratefully received, however!
imagine a typical multi value mysql insert similar to the following:
assumptions
1. there is no limit to the number of inserts in the sql
2. there is no restriction on the text that is contained in each value within each insert, although you can assume that the values are escaped where necessary.
I need to be able to separate out each of the sets of values for each insert. so that I want, for example, an array of inserts
the various regex that i have written to solve this problem have worked for a while but recently barfed when dealing with code inside one of the value pairs. I was splitting on '),' as a pattern (actually a bit more complex than that but the point is clear) and that was obviously matching bits of the code too.
so I need a solution that will split the elements for me. this can either be a regex or a parser, i don't mind. I have a feeling that a regex is going to be very difficult indeed and that a parser might be the best bet. But, as I said, I don't trust my judgment at the moment and so am looking to you for ideas and assistance.
For those interested in the why of this request: I am the author and maintainer of a plugin for wordpress that allows users to switch from mysql to other database backends. The main alternative is sqlite. sqlite does not support compound inserts and so I need to split the query into multiples or convert it into a single union of selects. In either case I need to be able to dissect the values clause.
Justin
imagine a typical multi value mysql insert similar to the following:
Code:
Insert into table (field1, field2, field3) values ('value1', 'value2', 'value3'), ('a note about a php function, called is_function(), is sometimes useful', 'value2', 'value3'), (.......)
assumptions
1. there is no limit to the number of inserts in the sql
2. there is no restriction on the text that is contained in each value within each insert, although you can assume that the values are escaped where necessary.
I need to be able to separate out each of the sets of values for each insert. so that I want, for example, an array of inserts
Code:
0=> "('value1', 'value2', 'value3')",
1=> "('a note about a php function, called is_function(), is sometimes useful', 'value2', 'value3')",
2=> (.......) etc
the various regex that i have written to solve this problem have worked for a while but recently barfed when dealing with code inside one of the value pairs. I was splitting on '),' as a pattern (actually a bit more complex than that but the point is clear) and that was obviously matching bits of the code too.
so I need a solution that will split the elements for me. this can either be a regex or a parser, i don't mind. I have a feeling that a regex is going to be very difficult indeed and that a parser might be the best bet. But, as I said, I don't trust my judgment at the moment and so am looking to you for ideas and assistance.
For those interested in the why of this request: I am the author and maintainer of a plugin for wordpress that allows users to switch from mysql to other database backends. The main alternative is sqlite. sqlite does not support compound inserts and so I need to split the query into multiples or convert it into a single union of selects. In either case I need to be able to dissect the values clause.
Justin