On 18/08/2009 11:28 PM, Beau Wilkinson wrote: > That said, if you're in posession of the source code, > you can certainly hack something up to support that. > A better option might be to pre-process the MySQL file > using C, Perl, XSLT (just kidding - don't use XSLT) > or whatever else you prefer for this kind of rote file manipulation
"rote" is relative; it's certainly just a flick of the wrist if you're willing to bet on there being no ')' characters in the text literals, otherwise it gets a bit hairy... Here's an attempt at something fairly general using Python regular expressions; just point this at the remainder of the statement after the VALUES keyword: import re value_literal = r""" (?: ' (?: [^'] | '' ) * ' # text literal | [^,)\s] + # any other literal ) """ value_list_re = r"\(\s*LIT\s*(?:,\s*LIT\s*)*\)".replace("LIT", value_literal) data = """ (1,'PENELOPE','GUINESS','2006-02-15 04:34:33'), (2,'NICK','WAHLBERG', '2006-02-15 04:34:33'),(3,'ED','CHASE','2006-02-15 04:34:33'), (4,'Seamus', 'O''Reilly'),(4.1,x'f00baa'),(5678), (6, 'William','Pitt (the Elder)'),(6.1, 'Willie', 'Pitt (the Younger)'), ( 7 , 'spaced' , 'out' ) """ rx = re.compile(value_list_re, re.VERBOSE) for vlist in rx.findall(data): print vlist and here's the output: (1,'PENELOPE','GUINESS','2006-02-15 04:34:33') (2,'NICK','WAHLBERG', '2006-02-15 04:34:33') (3,'ED','CHASE','2006-02-15 04:34:33') (4,'Seamus', 'O''Reilly') (4.1,x'f00baa') (5678) (6, 'William','Pitt (the Elder)') (6.1, 'Willie', 'Pitt (the Younger)') ( 7 , 'spaced' , 'out' ) Cheers, John _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users