Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit60cea7d

Browse files
committed
Update mysql converter, new version released.
1 parentaee52a6 commit60cea7d

File tree

2 files changed

+53
-24
lines changed

2 files changed

+53
-24
lines changed

‎contrib/mysql/my2pg.pl

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3636
# SUCH DAMAGE.
3737
#
38-
# $Id: my2pg.pl,v 1.2 2001/02/10 11:43:33 momjian Exp $
38+
# $Id: my2pg.pl,v 1.3 2001/03/04 15:43:33 momjian Exp $
3939

4040
# TODO:
4141
# + Handle SETs
@@ -46,11 +46,14 @@
4646

4747
#
4848
# $Log: my2pg.pl,v $
49-
# Revision 1.2 2001/02/10 11:43:33 momjian
50-
#cleanup
49+
# Revision 1.3 2001/03/04 15:43:33 momjian
50+
#Update mysql converter, new version released.
5151
#
52-
# Revision 1.1 2001/02/10 11:43:12 momjian
53-
# Add other mysql conversion utility for comparisons.
52+
# Revision 1.17 2001/03/04 13:01:50 fonin
53+
# 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.
54+
#
55+
# Revision 1.16 2001/02/02 08:15:34 fonin
56+
# Sequences should be created BEFORE creating any objects \nthat depends on it.
5457
#
5558
# Revision 1.15 2001/01/30 10:13:36 fonin
5659
# Re-released under BSD-like license.
@@ -59,7 +62,12 @@
5962
# Better -n implementation.
6063
#
6164
# Revision 1.13 2000/12/18 15:26:33 fonin
62-
# 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.
65+
# Added command-line options. -n forces *CHAR DEFAULT '' NOT NULL to be
66+
# converted to *CHAR NULL.
67+
# AUTO_INCREMENT fields converted not in SERIAL but in
68+
# INT* NOT NULL DEFAULT nextval('seqname').
69+
# Documentation refreshed.
70+
# Dump enclosed in single transaction from now.
6371
#
6472
# Revision 1.12 2000/12/14 20:57:15 fonin
6573
# Doublequotation bug fixed (in CREATE INDEX ON TABLE (field1,field2))
@@ -100,7 +108,7 @@
100108
$|=1;
101109

102110
print("------------------------------------------------------------------");
103-
print("\n-- My2Pg\$Revision: 1.2 $\translated dump");
111+
print("\n-- My2Pg\$Revision: 1.3 $\translated dump");
104112
print("\n--");
105113
print("\n------------------------------------------------------------------");
106114

@@ -122,7 +130,7 @@
122130
# push header to libtypes.c
123131
open(LIBTYPES,">$libtypesource");
124132
print LIBTYPES"/******************************************************";
125-
print LIBTYPES"\n * My2Pg\$Revision: 1.2 $\translated dump";
133+
print LIBTYPES"\n * My2Pg\$Revision: 1.3 $\translated dump";
126134
print LIBTYPES"\n * User types definitions";
127135
print LIBTYPES"\n ******************************************************/";
128136
print LIBTYPES"\n\n#include <postgres.h>\n";
@@ -157,13 +165,18 @@
157165
# Convert DATE types
158166
s/datetime/TIMESTAMP/;
159167
s/timestamp\(\d+\)/TIMESTAMP/i;
160-
168+
169+
# small hack - convert "default" to uppercase, because below we
170+
# enclose all lowercase words in double quotes
171+
s/default/DEFAULT/;
172+
161173
# Change all AUTO_INCREMENT fields to SERIAL ones with a pre-defined sequence
162174
if(/([\w\d]+)\sint.*auto_increment/i) {
163175
$tmpseq=new_name("$table_name"."_"."$+"."_SEQ",28);
164176
$seq{$table_name}=$tmpseq;
165177
$primary{$table_name}=$+;
166-
s/(int.*?)DEFAULT\s*?'.*?'(.*?)AUTO_INCREMENT/$1$2DEFAULT nextval\('$tmpseq'\)/i;
178+
s/(int.*?) .*AUTO_INCREMENT/$1 DEFAULT nextval\('$tmpseq'\)/i;
179+
#s/(int.*?)DEFAULT\s*?'.*?'(.*?)AUTO_INCREMENT/$1$2DEFAULT nextval\('$tmpseq'\)/i;
167180
}
168181

169182
# Fix timestamps
@@ -540,9 +553,20 @@
540553
$oldtable=$table_name;
541554
$j=-1;
542555
$check='';
556+
557+
if($seq{$table_name}ne'') {
558+
print"\n\n--";
559+
print"\n-- Sequences for table".uc($table_name);
560+
print"\n--\n";
561+
print"\nCREATE SEQUENCE".$seq{$table_name}.";\n\n";
562+
}
563+
543564
print$types;
544565
$types='';
545-
$dump=~s/,\n\);/\n\);/gmi;
566+
$dump=~s/,\n\).*;/\n\);/gmi;
567+
# removing table options after closing bracket:
568+
# ) TYPE=ISAM PACK_KEYS=1;
569+
$dump=~s/\n\).*/\n\);/gmi;
546570
print$dump;
547571
$dump='';
548572
}
@@ -557,18 +581,18 @@
557581
s/(PRIMARY KEY\(.*\)).*/$1$check\n/i;
558582
}
559583

560-
if(/^\s*KEY (.+)\((.*)\).*/i) {
584+
if(/^\s*KEY ([\w\d_]+)\s*\((.*)\).*/i) {
561585
my$tmpfld=$2;
562586
$tmpfld=~s/\s*,\s*/","/;
563587
$index{$table_name}[++$j]="CREATE INDEX $1_$table_name\_index ON\"$table_name\" (\"$tmpfld\");";
564588
}
565-
if(/^\s*UNIQUE (.+)\((.*)\).*/i) {
589+
if(/^\s*UNIQUE ([\w\d_]+)\s*\((.*)\).*/i) {
566590
my$tmpfld=$2;
567591
$tmpfld=~s/,/","/;
568592
$index{$table_name}[++$j]="CREATE UNIQUE INDEX $1_$table_name\_index ON\"$table_name\" (\"$tmpfld\");";
569593
}
570-
s/^\s*UNIQUE (.+)(\(.*\)).*\n//i;
571-
s/^\s*KEY (.+)(\(.*\)).*\n//i;
594+
s/^\s*UNIQUE (.+).*(\(.*\)).*\n//i;
595+
s/^\s*KEY (.+).*(\(.*\)).*\n//i;
572596

573597
if(!s/INSERT INTO\s+?(.*?)\s+?/INSERT INTO "$1"/i) {
574598
# Quote lowercase identifiers in double quotes
@@ -580,8 +604,15 @@
580604
$dump.=$_;
581605
}
582606

607+
if($seq{$table_name}ne'') {
608+
print"\n\n--";
609+
print"\n-- Sequences for table".uc($table_name);
610+
print"\n--\n";
611+
print"\nCREATE SEQUENCE".$seq{$table_name}.";\n\n";
612+
}
583613
print$types;
584-
$dump=~s/,\n\);/\n\);/gmi;
614+
$dump=~s/,\n\).*;/\n\);/gmi;
615+
$dump=~s/\n\).*/\n\);/gmi;
585616
print$dump;
586617

587618
# Output indices for tables
@@ -594,8 +625,6 @@
594625
}
595626

596627
}
597-
print("\n\nEND;\n");
598-
print("\nBEGIN;\n");
599628

600629
while(my($table,$s)=each(%seq)) {
601630
print"\n\n--";
@@ -604,17 +633,16 @@
604633

605634
# setting SERIAL sequence values right
606635
if($primary{$table}ne'') {
607-
print"\nCREATE SEQUENCE".$seq{$table}.";";
608636
print"\nSELECT SETVAL('".$seq{$table}."',(select case when max(\"".$primary{$table}."\")>0 then max(\"".$primary{$table}."\")+1 else 1 end from\"$table\"));";
609637
}
610638
}
611639

612-
print("\n\nEND;\n");
640+
print("\n\nCOMMIT;\n");
613641
close(LIBTYPES);
614642

615643
open(MAKE,">Makefile");
616644
print MAKE"#
617-
# My2Pg\$Revision: 1.2 $\translated dump
645+
# My2Pg\$Revision: 1.3 $\translated dump
618646
# Makefile
619647
#
620648
@@ -665,7 +693,8 @@ ()
665693
666694
This program is distributed in the hope that it will be useful,
667695
but WITHOUT ANY WARRANTY; without even the implied warranty of
668-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
696+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
697+
GNU General Public License for more details.
669698
670699
SYNTAX:
671700
my2pg [-hn]

‎src/include/nodes/plannodes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: plannodes.h,v 1.47 2001/01/24 19:43:26 momjian Exp $
10+
* $Id: plannodes.h,v 1.48 2001/03/04 15:43:33 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -420,7 +420,7 @@ typedef struct Tee
420420
List*rtentries;/* the range table for the plan below the
421421
* Tee may be different than the parent
422422
* plans */
423-
}Tee;
423+
}Tee;
424424

425425
#endif
426426

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp