From: Bruce Momjian Date: Sun, 4 Mar 2001 15:43:33 +0000 (+0000) Subject: Update mysql converter, new version released. X-Git-Url: http://waps.l3s.uni-hannover.de/gitweb/?a=commitdiff_plain;h=12ea0bb937b62edae110aec8c24324c64923adb3;p=users%2Fbernd%2Fpostgres.git Update mysql converter, new version released. --- diff --git a/contrib/mysql/my2pg.pl b/contrib/mysql/my2pg.pl index 8a4aa15f3f..a160e80104 100755 --- a/contrib/mysql/my2pg.pl +++ b/contrib/mysql/my2pg.pl @@ -46,8 +46,11 @@ # # $Log: my2pg.pl,v $ -# Revision 1.1 2001/02/10 11:43:12 momjian -# Add other mysql conversion utility for comparisons. +# Revision 1.17 2001/03/04 13:01:50 fonin +# Fixes to make work it right with MySQL 3.23 dumps. Tested on mysqldump 8.11. Also, AUTO_INCREMENT->SERIAL fields no more have DEFAULT and NOT NULL definitions. +# +# Revision 1.16 2001/02/02 08:15:34 fonin +# Sequences should be created BEFORE creating any objects \nthat depends on it. # # Revision 1.15 2001/01/30 10:13:36 fonin # Re-released under BSD-like license. @@ -56,7 +59,12 @@ # Better -n implementation. # # Revision 1.13 2000/12/18 15:26:33 fonin -# Added command-line options. -n forces *CHAR DEFAULT '' NOT NULL to be converted to *CHAR NULL.\nAUTO_INCREMENT fields converted not in SERIAL but in INT* NOT NULL DEFAULT nextval('seqname').\nDocumentation refreshed.\nDump enclosed in single transaction from now. +# Added command-line options. -n forces *CHAR DEFAULT '' NOT NULL to be +# converted to *CHAR NULL. +# AUTO_INCREMENT fields converted not in SERIAL but in +# INT* NOT NULL DEFAULT nextval('seqname'). +# Documentation refreshed. +# Dump enclosed in single transaction from now. # # Revision 1.12 2000/12/14 20:57:15 fonin # Doublequotation bug fixed (in CREATE INDEX ON TABLE (field1,field2)) @@ -97,7 +105,7 @@ if($opts{n} ne '') { $|=1; print("------------------------------------------------------------------"); -print("\n-- My2Pg \$Revision: 1.2 $ \translated dump"); +print("\n-- My2Pg \$Revision: 1.3 $ \translated dump"); print("\n--"); print("\n------------------------------------------------------------------"); @@ -119,7 +127,7 @@ $libtypename.='/libtypes.so'; # push header to libtypes.c open(LIBTYPES,">$libtypesource"); print LIBTYPES "/******************************************************"; -print LIBTYPES "\n * My2Pg \$Revision: 1.2 $ \translated dump"; +print LIBTYPES "\n * My2Pg \$Revision: 1.3 $ \translated dump"; print LIBTYPES "\n * User types definitions"; print LIBTYPES "\n ******************************************************/"; print LIBTYPES "\n\n#include \n"; @@ -154,13 +162,18 @@ while (<>) { # Convert DATE types s/datetime/TIMESTAMP/; s/timestamp\(\d+\)/TIMESTAMP/i; - + +# small hack - convert "default" to uppercase, because below we +# enclose all lowercase words in double quotes + s/default/DEFAULT/; + # Change all AUTO_INCREMENT fields to SERIAL ones with a pre-defined sequence if(/([\w\d]+)\sint.*auto_increment/i) { $tmpseq=new_name("$table_name"."_"."$+"."_SEQ",28); $seq{$table_name}=$tmpseq; $primary{$table_name}=$+; - s/(int.*?)DEFAULT\s*?'.*?'(.*?)AUTO_INCREMENT/$1$2DEFAULT nextval\('$tmpseq'\)/i; + s/(int.*?) .*AUTO_INCREMENT/$1 DEFAULT nextval\('$tmpseq'\)/i; + #s/(int.*?)DEFAULT\s*?'.*?'(.*?)AUTO_INCREMENT/$1$2DEFAULT nextval\('$tmpseq'\)/i; } # Fix timestamps @@ -537,9 +550,20 @@ CREATE OPERATOR <> ( $oldtable=$table_name; $j=-1; $check=''; + + if($seq{$table_name} ne '') { + print "\n\n--"; + print "\n-- Sequences for table ".uc($table_name); + print "\n--\n"; + print "\nCREATE SEQUENCE ".$seq{$table_name}.";\n\n"; + } + print $types; $types=''; - $dump=~s/,\n\);/\n\);/gmi; + $dump=~s/,\n\).*;/\n\);/gmi; +# removing table options after closing bracket: +# ) TYPE=ISAM PACK_KEYS=1; + $dump=~s/\n\).*/\n\);/gmi; print $dump; $dump=''; } @@ -554,18 +578,18 @@ CREATE OPERATOR <> ( s/(PRIMARY KEY \(.*\)).*/$1$check\n/i; } - if(/^\s*KEY (.+) \((.*)\).*/i) { + if(/^\s*KEY ([\w\d_]+)\s*\((.*)\).*/i) { my $tmpfld=$2; $tmpfld=~s/\s*,\s*/","/; $index{$table_name}[++$j]="CREATE INDEX $1_$table_name\_index ON \"$table_name\" (\"$tmpfld\");"; } - if(/^\s*UNIQUE (.+) \((.*)\).*/i) { + if(/^\s*UNIQUE ([\w\d_]+)\s*\((.*)\).*/i) { my $tmpfld=$2; $tmpfld=~s/,/","/; $index{$table_name}[++$j]="CREATE UNIQUE INDEX $1_$table_name\_index ON \"$table_name\" (\"$tmpfld\");"; } - s/^\s*UNIQUE (.+) (\(.*\)).*\n//i; - s/^\s*KEY (.+) (\(.*\)).*\n//i; + s/^\s*UNIQUE (.+).*(\(.*\)).*\n//i; + s/^\s*KEY (.+).*(\(.*\)).*\n//i; if(!s/INSERT INTO\s+?(.*?)\s+?/INSERT INTO "$1" /i) { # Quote lowercase identifiers in double quotes @@ -577,8 +601,15 @@ CREATE OPERATOR <> ( $dump.=$_; } +if($seq{$table_name} ne '') { + print "\n\n--"; + print "\n-- Sequences for table ".uc($table_name); + print "\n--\n"; + print "\nCREATE SEQUENCE ".$seq{$table_name}.";\n\n"; +} print $types; -$dump=~s/,\n\);/\n\);/gmi; +$dump=~s/,\n\).*;/\n\);/gmi; +$dump=~s/\n\).*/\n\);/gmi; print $dump; # Output indices for tables @@ -591,8 +622,6 @@ while(my($table,$ind)=each(%index)) { } } -print("\n\nEND;\n"); -print("\nBEGIN;\n"); while(my($table,$s)=each(%seq)) { print "\n\n--"; @@ -601,17 +630,16 @@ while(my($table,$s)=each(%seq)) { # setting SERIAL sequence values right if($primary{$table} ne '') { - print "\nCREATE SEQUENCE ".$seq{$table}.";"; print "\nSELECT SETVAL('".$seq{$table}."',(select case when max(\"".$primary{$table}."\")>0 then max(\"".$primary{$table}."\")+1 else 1 end from \"$table\"));"; } } -print("\n\nEND;\n"); +print("\n\nCOMMIT;\n"); close(LIBTYPES); open(MAKE,">Makefile"); print MAKE "# -# My2Pg \$Revision: 1.2 $ \translated dump +# My2Pg \$Revision: 1.3 $ \translated dump # Makefile # @@ -662,7 +690,8 @@ Copyright (c) 2000 Valentine Danilchuk This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. SYNTAX: my2pg [-hn] diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h index 0edf4b2f03..9acaaa8f50 100644 --- a/src/include/nodes/plannodes.h +++ b/src/include/nodes/plannodes.h @@ -420,7 +420,7 @@ typedef struct Tee List *rtentries; /* the range table for the plan below the * Tee may be different than the parent * plans */ -} Tee; +} Tee; #endif