brozzis has asked for the wisdom of the Perl Monks concerning the following question:
Hi all
I've a simple problem I can't solve by myself, I apologize for that.
I want to clean up a mysql database, derived by ms access, with spaces where they shouldn't be, parsing/reading a mysqldump and converting spaces into underscores...
for example:
I would like this converted to:create table `table name`( `field name1` type1 not null default 'x', `field name2` type2 default null, ... primary key (`pk name`), key `key name` (`field name1`, `field name2`) ) engine=other things here;
this means that everything in the format of:create table `table_name`( `field_name1` type1 not null default 'x', `field_name2` type2 default null, ... primary key (`pk_name`), key `key_name` (`field_name1`, `field_name2`) ) engine=other things here;
m/`\w+\s+\w+[\s+\w+]+`/ # backticks
should be transformed into a string with spaces converted to underscores (another option could be the camel case: something like `field name` into: `fieldName`)
I understand there must be a very efficient and compact solution, but I'm losing myself in a sql parsing without success.
Please enlighten my way...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regexp in mysqldump
by moritz (Cardinal) on Apr 15, 2010 at 20:39 UTC | |
by AnomalousMonk (Archbishop) on Apr 15, 2010 at 22:39 UTC | |
by NetWallah (Canon) on Apr 15, 2010 at 22:44 UTC | |
by brozzis (Sexton) on Apr 16, 2010 at 14:57 UTC | |
by JavaFan (Canon) on Apr 16, 2010 at 15:57 UTC | |
|
Re: Regexp in mysqldump
by clueless newbie (Curate) on Apr 16, 2010 at 12:47 UTC | |
by clueless newbie (Curate) on Apr 16, 2010 at 16:02 UTC |