Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I have downloaded some code which is supposed to convert mssql database create statements into mysql create statements but it isn't working. The create table statement is supposed to have a semi colon at the end but it isn't getting one. Here is the relevant section of code to read in a mssql schema from file and convert to mysql. I'm guessing the faulty bit is in the top few lines
this is what is created - note the absence of semi colonsub convert_schema { my ($name,$schema,$engine) = @_; my $schema2 = ''; my @lines = split "\n",$schema; for (@lines) { # CHANGES FOR ALL TABLES s#[\[\]]##g; # Remove brackets s/\)\n/\);\n/; # Add semicolon to end of table statemen +t s/char \(/char(/; # Remove space between varchar and ( s/ ,/,/g; # Remove space before comma s/ varchar\(\d+\)/ text/ if (m/varchar\((\d+)\)/) and ($1 > 255); +# Use "text" instead of "varchar(n)" if n > 255 s/\)$/\);/; s/ smalldatetime/ varchar(32)/g; # Trouble w/dbSNP dates, like "20 +00-08-25 17:02:00.0" - the .0 at the end. s/ datetime/ varchar(32)/g; s/ real/ float/g; s/ bit/ boolean/g;
here is a mssql create tableCREATE TABLE Allele ( allele_id int NOT NULL, allele varchar(255) NOT NULL, create_time varchar(32) NOT NULL, rev_allele_id int NULL, src varchar(10) NULL, last_updated_time varchar(32) NULL )
I don't understand why this doesnt work. The regular expression looks ok to meCREATE TABLE [Allele] ( [allele_id] [int] NOT NULL , [allele] [varchar] (255) NOT NULL , [create_time] [smalldatetime] NOT NULL , [rev_allele_id] [int] NULL , [src] [varchar] (10) NULL , [last_updated_time] [smalldatetime] NULL )
It seems to be looking for a bracket followed by a new line and replacing with with a bracket followed by a semi colon and a newline? But it isn't working. It isn't detecting the \)\n bit because if i take out the \n bit it replaces all brackets but if i add the \n back it doesn't detect anything thanks for any helps/\)\n/\);\n/;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: regular expression code not working
by AnomalousMonk (Archbishop) on Dec 05, 2010 at 03:00 UTC | |
|
Re: regular expression code not working
by ww (Archbishop) on Dec 04, 2010 at 21:45 UTC | |
|
Re: regular expression code not working
by Anonymous Monk on Dec 04, 2010 at 20:38 UTC | |
|
Re: regular expression code not working
by Anonymous Monk on Dec 04, 2010 at 21:03 UTC | |
by Ratazong (Monsignor) on Dec 04, 2010 at 21:48 UTC |