3 |
# PostgreSQL to InterBase dump file converter |
# PostgreSQL to InterBase dump file converter |
4 |
# |
# |
5 |
# usage: |
# usage: |
6 |
# cat pg_db_name | ./mysql2pgsql > interbase.sql |
# cat pg_db_name | ./pgsql2interbase > interbase.sql |
7 |
# |
# |
8 |
# Convert PostgresSQL database dump file to something readable by isql ! |
# Convert PostgresSQL database dump file to something readable by isql ! |
9 |
|
|
28 |
while(<>) { |
while(<>) { |
29 |
chomp; |
chomp; |
30 |
|
|
31 |
# print "- $create:$_-\n"; |
# warn "- $create:$_-\n"; |
32 |
|
|
33 |
if (/CREATE\s+TABLE\s+"([^"]+)"/i) { |
if (/CREATE\s+TABLE\s+"([^"]+)"/i) { |
34 |
$table=$1 if (defined($1)); |
$table=$1 if (defined($1)); |
68 |
# bool -> char(1) |
# bool -> char(1) |
69 |
if (/bool/i) { |
if (/bool/i) { |
70 |
s/\w*bool/ char(1)/gi; |
s/\w*bool/ char(1)/gi; |
71 |
print STDERR "Warning: bool emulated by char(1)\n\n"; |
warn "Warning: bool emulated by char(1)\n\n"; |
72 |
} |
} |
73 |
|
|
74 |
# datetime -> timestamp |
# datetime -> timestamp |
75 |
s/datetime/timestamp/gi; |
s/datetime/timestamp/gi; |
76 |
|
|
|
# nuke quotes |
|
|
s/"([^"]+)"/$1/g; |
|
|
|
|
77 |
} else { # not inside create table |
} else { # not inside create table |
78 |
|
|
79 |
if (/CREATE SEQUENCE "(\w+)_seq" start (\d+)/i) { |
if (/CREATE SEQUENCE "(\w+)_seq" start (\d+)/i) { |
89 |
|
|
90 |
# you will have to re-write functions manually! |
# you will have to re-write functions manually! |
91 |
if (/^CREATE FUNCTION/i) { |
if (/^CREATE FUNCTION/i) { |
92 |
print STDERR "functions not supported: $_\n\n"; |
warn "functions not supported: $_\n\n"; |
93 |
next; |
next; |
94 |
} |
} |
95 |
|
|
96 |
# rule is usually a defined view |
# rule is usually a defined view |
97 |
if (/^CREATE RULE/i) { |
if (/^CREATE RULE/i) { |
98 |
print STDERR "rules (views...) not supported: $_\n\n"; |
warn "rules (views...) not supported: $_\n\n"; |
99 |
next; |
next; |
100 |
} |
} |
101 |
if (/COPY "([^"]+)" FROM stdin/i) { |
if (/COPY "([^"]+)" FROM stdin/i) { |
125 |
if (/(CREATE \w*\s*INDEX "[^"]+" on "[^"]+")[^(]*\(([^\)]+)\)/i) { |
if (/(CREATE \w*\s*INDEX "[^"]+" on "[^"]+")[^(]*\(([^\)]+)\)/i) { |
126 |
my ($ind,$col) = ($1,$2); |
my ($ind,$col) = ($1,$2); |
127 |
$col=~s/" "[^"]+"/"/g; # nuke ops_name |
$col=~s/" "[^"]+"/"/g; # nuke ops_name |
128 |
$sql.="$ind ( $col );\n"; |
$sql.=lc($ind)." ( $col );\n"; |
|
# $sql.=s/"([^"]+)"/$1/g; |
|
129 |
next; |
next; |
130 |
} |
} |
131 |
|
|
132 |
|
if (/GRANT (.+) on "([^"]+)" to ([^;]+);/i) { |
133 |
|
($what,$table,$user) = ($1,$2,$3); |
134 |
|
$user=~s/"//g; |
135 |
|
if ($user =~ /group\s+(\S+)/i) { |
136 |
|
$sql.="grant $what on $table to group $1 ;\n"; |
137 |
|
$groups{$1}++; |
138 |
|
} else { |
139 |
|
$sql.="grant $what on $table to $user ;\n"; |
140 |
|
$users{$user}++; |
141 |
|
} |
142 |
|
next ; |
143 |
|
} |
144 |
|
|
145 |
} |
} |
146 |
|
|
147 |
if ($create && /\);/) { $create-- } |
if ($create && /\);/) { $create-- } |
148 |
|
|
|
$sql=~s/"([^"]+)"/$1/g; |
|
149 |
$sql.="$_\n"; |
$sql.="$_\n"; |
150 |
|
|
151 |
|
|
153 |
($dosql,$sql)=split(/;/,$sql,2); |
($dosql,$sql)=split(/;/,$sql,2); |
154 |
$dosql.=";"; # nuked by split, put it back! |
$dosql.=";"; # nuked by split, put it back! |
155 |
if ("$dosql" ne "") { |
if ("$dosql" ne "") { |
156 |
|
$dosql=~s/"([^"]+)"/$1/g; # nuke quotes |
157 |
print "$dosql\n"; |
print "$dosql\n"; |
158 |
} else { |
} else { |
159 |
print STDERR "empty sql!\n"; |
warn "empty sql!\n"; |
160 |
} |
} |
161 |
} |
} |
162 |
|
|
163 |
} |
} |
164 |
|
|
165 |
|
$sql=~s/"([^"]+)"/$1/g; # nuke quotes |
166 |
print "$sql\n$triggers\n"; |
print "$sql\n$triggers\n"; |
167 |
|
|
|
print "\n"; |
|
|
|
|
168 |
foreach $gen (keys %generator) { |
foreach $gen (keys %generator) { |
169 |
warn "created, but overused/unused generator: $gen (ref.count: $generator{$gen})\n" if ($generator{$gen} != 0); |
warn "created, but overused/unused generator: $gen (ref.count: $generator{$gen})\n" if ($generator{$gen} != 0); |
170 |
} |
} |
171 |
|
|
172 |
|
warn "Users used: ",join(", ",keys(%users)),"\n"; |
173 |
|
warn "Groups used: ",join(", ",keys(%groups)),"\n"; |
174 |
|
|