Upgrade to my2pg 1.9

This commit is contained in:
Bruce Momjian 2003-01-07 22:18:43 +00:00
parent a24104eb5e
commit 3e40ff58c5
1 changed files with 37 additions and 34 deletions

View File

@ -35,26 +35,27 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# $My2pg: my2pg.pl,v 1.24 2001/12/06 19:32:20 fonin Exp $
# $Id: my2pg.pl,v 1.9 2002/08/22 00:01:39 tgl Exp $
# TODO:
# + Handle SETs
# - LIKE implementation
# - memory use optimisation in SET_output function
# - raw integer values as input values must be OK
# - Use autoconf & automake to auto-build makefiles
# $My2pg: my2pg.pl,v 1.27 2001/12/06 19:32:20 fonin Exp $
# $Id: my2pg.pl,v 1.10 2003/01/07 22:18:43 momjian Exp $
#
# $Log: my2pg.pl,v $
# Revision 1.9 2002/08/22 00:01:39 tgl
# Add a bunch of pseudo-types to replace the behavior formerly associated
# with OPAQUE, as per recent pghackers discussion. I still want to do some
# more work on the 'cstring' pseudo-type, but I'm going to commit the bulk
# of the changes now before the tree starts shifting under me ...
# Revision 1.10 2003/01/07 22:18:43 momjian
# Upgrade to my2pg 1.9
#
# Revision 1.8 2002/04/24 01:42:29 momjian
# Update to my2pg 1.24.
# Revision 1.27 2002/07/16 14:54:07 fonin
# Bugfix - didn't quote the fields inside PRIMARY KEY with -d option.
# Fix by Milan P. Stanic <mps@rns-nis.co.yu>.
#
# Revision 1.26 2002/07/14 10:30:27 fonin
# Bugfix - MySQL keywords inside data (INSERT INTO sentence) were replaced
# with Postgres keywords and therefore messed up the data.
#
# Revision 1.25 2002/07/05 09:20:25 fonin
# - fixed data that contains two consecutive timestamps - thanks to
# Ben Darnell <bdarnell@google.com>
# - word 'default' was converted to upper case inside the data - fixed.
# Thanks to Madsen Wikholm <madsen@iki.fi>
#
# Revision 1.24 2002/04/20 14:15:43 fonin
# Patch by Felipe Nievinski <fnievinski@terra.com.br>.
@ -177,7 +178,7 @@ if($opts{d} ne '') {
$|=1;
print("------------------------------------------------------------------");
print("\n-- My2Pg 1.24 translated dump");
print("\n-- My2Pg 1.27 translated dump");
print("\n--");
print("\n------------------------------------------------------------------");
@ -199,7 +200,7 @@ $libtypename.='/libtypes.so';
# push header to libtypes.c
open(LIBTYPES,">$libtypesource");
print LIBTYPES "/******************************************************";
print LIBTYPES "\n * My2Pg \$Revision: 1.9 $ \translated dump";
print LIBTYPES "\n * My2Pg 1.27 \translated dump";
print LIBTYPES "\n * User types definitions";
print LIBTYPES "\n ******************************************************/";
print LIBTYPES "\n\n#include <postgres.h>\n";
@ -211,7 +212,7 @@ while (<>) {
if(!$tabledef && /^CREATE TABLE \S+/i){
$tabledef=1;
}elsif($tabledef && /^\);/i){ # /^\w/i
} elsif($tabledef && /^\) type=\w*;/i){ # /^\w/i
$tabledef=0;
}
@ -253,7 +254,9 @@ while (<>) {
# small hack - convert "default" to uppercase, because below we
# enclose all lowercase words in double quotes
s/default/DEFAULT/;
if(!/^INSERT/) {
s/default/DEFAULT/;
}
# Change all AUTO_INCREMENT fields to SERIAL ones with a pre-defined sequence
if(/([\w\d]+)\sint.*auto_increment/i) {
@ -314,11 +317,11 @@ int2* $typename"."_in (char *str) {
print LIBTYPES "\n * Types for table ".uc($table_name);
print LIBTYPES "\n */\n";
$types.="\nCREATE FUNCTION $typename"."_in (cstring)
$types.="\nCREATE FUNCTION $typename"."_in (opaque)
RETURNS $typename
AS '$libtypename'
LANGUAGE 'c'
WITH (ISSTRICT, ISCACHABLE);\n";
WITH (ISCACHABLE);\n";
# creating output function
my $func_out="
@ -368,11 +371,11 @@ bool $typename"."_ge(int2* a, int2* b) {
return (*a>=*b);
}\n";
$types.="\nCREATE FUNCTION $typename"."_out ($typename)
RETURNS cstring
$types.="\nCREATE FUNCTION $typename"."_out (opaque)
RETURNS opaque
AS '$libtypename'
LANGUAGE 'c'
WITH (ISSTRICT, ISCACHABLE);\n";
WITH (ISCACHABLE);\n";
$types.="\nCREATE TYPE $typename (
internallength = 2,
@ -515,7 +518,7 @@ $typesize* $typename"."_in (char *str) {
print LIBTYPES "\n * Types for table ".uc($table_name);
print LIBTYPES "\n */\n";
$types.="\nCREATE FUNCTION $typename"."_in (cstring)
$types.="\nCREATE FUNCTION $typename"."_in (opaque)
RETURNS $typename
AS '$libtypename'
LANGUAGE 'c';\n";
@ -567,8 +570,8 @@ $typesize find_in_set($typesize *a, $typesize *b) {
\n";
$types.="\nCREATE FUNCTION $typename"."_out ($typename)
RETURNS cstring
$types.="\nCREATE FUNCTION $typename"."_out (opaque)
RETURNS opaque
AS '$libtypename'
LANGUAGE 'c';\n";
@ -651,11 +654,11 @@ CREATE OPERATOR <> (
}
# output CHECK constraints instead UNSIGNED modifiers
if(/PRIMARY KEY \((.*)\)/i) {
if(/PRIMARY KEY\s+\((.*)\)/i) {
my $tmpfld=$1;
$tmpfld=~s/,/","/g if $dq;
$tmpfld=~s/ //g;
s/PRIMARY KEY (\(.*\))/PRIMARY KEY \($dq$tmpfld$dq\)/i;
s/PRIMARY KEY\s+(\(.*\))/PRIMARY KEY \($dq$tmpfld$dq\)/i;
s/(PRIMARY KEY \(.*\)).*/$1$check\n/i;
}
@ -685,9 +688,9 @@ CREATE OPERATOR <> (
# Fix timestamps
s/'0000-00-00/'0001-01-01/g;
# may work wrong !!!
s/([,(])00000000000000([,)])/$1'00010101 000000'$2/g;
s/([,(])(\d{8})(\d{6})([,)])/$1'$2 $3'$4/g;
s/([,(])(\d{4})(\d{2})(\d{2})([,)])/$1'$2-$3-$4 00:00:00'$5/g;
s/([,(])00000000000000(?=[,)])/$1'00010101 000000'/g;
s/([,(])(\d{8})(\d{6})(?=[,)])/$1'$2 $3'/g;
s/([,(])(\d{4})(\d{2})(\d{2})(?=[,)])/$1'$2-$3-$4 00:00:00'/g;
#<Hackzone> ---------------------------------------------------
#</Hackzone> --------------------------------------------------
$dump.=$_;
@ -731,7 +734,7 @@ close(LIBTYPES);
open(MAKE,">Makefile");
print MAKE "#
# My2Pg \$Revision: 1.9 $ \translated dump
# My2Pg \$Revision: 1.10 $ \translated dump
# Makefile
#