11 |
# 1999-12-26 DbP don't make serial from auto_increment, create all manually |
# 1999-12-26 DbP don't make serial from auto_increment, create all manually |
12 |
# (to set start value right) |
# (to set start value right) |
13 |
# 2000-01-11 DbP now creates sequences with correct value |
# 2000-01-11 DbP now creates sequences with correct value |
14 |
|
# 2000-04-25 DbP import into CVS (at cvs.linux.hr) |
15 |
|
|
16 |
use DBI; |
use DBI; |
17 |
|
|
62 |
if (/^\s*(\w+)\s+/) { |
if (/^\s*(\w+)\s+/) { |
63 |
$seq="${table}_${1}_seq"; |
$seq="${table}_${1}_seq"; |
64 |
push @sequences,"$table.$1"; |
push @sequences,"$table.$1"; |
65 |
s/\w*int.*auto_increment/int4 default nextval('$seq') not null/ig; |
s/(\w+) \w*int.*auto_increment/$1 int4 default nextval('$seq') not null/ig; |
66 |
} else { |
} else { |
67 |
die "can't get name of field!"; |
die "can't get name of field!"; |
68 |
} |
} |
94 |
|
|
95 |
# nuke date representation (not supported in PostgreSQL) |
# nuke date representation (not supported in PostgreSQL) |
96 |
s/datetime default '[^']+'/datetime/i; |
s/datetime default '[^']+'/datetime/i; |
97 |
|
s/date default '[^']+'/datetime/i; |
98 |
|
s/time default '[^']+'/datetime/i; |
99 |
|
|
100 |
# change not null datetime filend to null valid ones |
# change not null datetime filend to null valid ones |
101 |
# (to support remapping of "zaro time" to null |
# (to support remapping of "zaro time" to null |
102 |
s/datetime not null/datetime/i; |
s/datetime not null/datetime/i; |
103 |
|
|
104 |
|
# add unique to definition of type (MySQL separates this) |
105 |
|
if (/unique \w+ \((\w+)\)/i) { |
106 |
|
$sql=~s/($1)([^,]+)/$1$2 unique/gi; |
107 |
|
next; |
108 |
|
} |
109 |
|
|
110 |
|
} else { # not inside create table |
111 |
|
|
112 |
#---- fix data in inserted data: (from MS world) |
#---- fix data in inserted data: (from MS world) |
113 |
# FIX: disabled for now |
# FIX: disabled for now |
114 |
if (00 && /insert into/i) { |
if (00 && /insert into/i) { |
119 |
s!\x92!`!g; |
s!\x92!`!g; |
120 |
} |
} |
121 |
|
|
|
} else { # not inside create table |
|
|
|
|
122 |
# fix dates '0000-00-00 00:00:00' (should be null) |
# fix dates '0000-00-00 00:00:00' (should be null) |
123 |
s/'0000-00-00 00:00:00'/null/gi; |
s/'0000-00-00 00:00:00'/null/gi; |
124 |
|
s/'0000-00-00'/null/gi; |
125 |
|
s/'00:00:00'/null/gi; |
126 |
} |
} |
127 |
|
|
128 |
$sql.="$_"; |
$sql.="$_"; |
157 |
print STDERR "$sql\n"; |
print STDERR "$sql\n"; |
158 |
$sth = $dbh->prepare($sql) || die $dbh->errstr(); |
$sth = $dbh->prepare($sql) || die $dbh->errstr(); |
159 |
$sth->execute() || die $sth->errstr(); |
$sth->execute() || die $sth->errstr(); |
160 |
($start) = $sth->fetchrow_array(); |
($start) = $sth->fetchrow_array() || 1; |
161 |
|
|
162 |
$seq="${table}_${field}_seq"; |
$seq="${table}_${field}_seq"; |
163 |
|
|