From: Bruce Momjian Date: Tue, 7 Jan 2003 22:15:56 +0000 (+0000) Subject: Upgrade to ora2pg 1.10. Backpatch to 7.3.X. X-Git-Tag: REL7_4_BETA1~1274 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ffab4fdf248ab41312d28d5c5bb9b5046d1c30eb;p=postgresql Upgrade to ora2pg 1.10. Backpatch to 7.3.X. --- diff --git a/contrib/oracle/CHANGES b/contrib/oracle/CHANGES index 34851ecb65..b1d27ad250 100644 --- a/contrib/oracle/CHANGES +++ b/contrib/oracle/CHANGES @@ -38,6 +38,7 @@ by the schema name. - Fix output of Oracle data extraction. It now require a call to the function export_data(). + 2002 01 07 - Version 1.6 - Fix problem exporting NULL value. Thanks to Stephane Schildknecht. @@ -49,3 +50,17 @@ - Add column alias extraction on view. Thanks to Jean-Francois RIPOUTEAU - Add PACKAGE extraction (type => DATA). +2002 06 04 - Version 1.9 + - Fix a problem export data which fill NULL instead of 0 or empty string. + Thanks to Jan Kester. + - Add time with date when export data [ tochar('YYYY-MM-DD HH24:MI:SS') ]. + Thanks to Paolo Mattioli. + +2002 07 29 - Version 1.10 + - Fix a problem with local settings regarding decimal separator (all , + are changed to .) Thank to Jan Kester. + +Thanks for all congratulation message and bug report I received. + +Gilles DAROLD + diff --git a/contrib/oracle/Ora2Pg.pm b/contrib/oracle/Ora2Pg.pm index a11d836550..b93423cc5c 100644 --- a/contrib/oracle/Ora2Pg.pm +++ b/contrib/oracle/Ora2Pg.pm @@ -17,8 +17,13 @@ package Ora2Pg; use vars qw($VERSION $PSQL); use Carp qw(confess); use DBI; +use POSIX qw(locale_h); -$VERSION = "1.8"; +#set locale to LC_NUMERIC C +setlocale(LC_NUMERIC,"C"); + + +$VERSION = "1.9"; $PSQL = "psql"; =head1 NAME @@ -854,7 +859,7 @@ print STDERR "Add triggers definition...\n" if ($self->{debug}); # Escaping Single Quotes #$trig->[4] =~ s/'/''/sg; - $sql_output .= "CREATE FUNCTION pg_fct_\L$trig->[0]\E () RETURNS TRIGGER AS '\n$trig->[4]\n' LANGUAGE 'plpgsql'\n\n"; + $sql_output .= "CREATE FUNCTION pg_fct_\L$trig->[0]\E () RETURNS OPAQUE AS '\n$trig->[4]\n' LANGUAGE 'plpgsql'\n\n"; $sql_output .= "CREATE TRIGGER \L$trig->[0]\E\n\t$trig->[1] $trig->[2] ON \L$trig->[3]\E FOR EACH ROW\n\tEXECUTE PROCEDURE pg_fct_\L$trig->[0]\E();\n\n"; } } @@ -1002,7 +1007,7 @@ print STDERR "Dumping table $table...\n" if ($self->{debug}); if ($self->{type} ne 'COPY') { if ($tt[$i] =~ /(char|date|time|text)/) { $row->[$i] =~ s/'/''/gs; - if ($row->[$i]) { + if ($row->[$i] ne '') { $row->[$i] = "'$row->[$i]'"; } else { $row->[$i] = 'NULL'; @@ -1017,7 +1022,8 @@ print STDERR "Dumping table $table...\n" if ($self->{debug}); } } } else { - if (!$row->[$i]) { + $row->[$i] =~ s/,/./; + if ($row->[$i] eq '') { $row->[$i] = 'NULL'; } if ($self->{dbhdest}) { @@ -1042,7 +1048,10 @@ print STDERR "Dumping table $table...\n" if ($self->{debug}); } } } else { - if (!$row->[$i]) { + if ($tt[$i] !~ /(char|date|time|text)/) { + $row->[$i] =~ s/,/./; + } + if ($row->[$i] eq '') { $row->[$i] = '\N'; } if ($self->{dbhdest}) { @@ -1228,7 +1237,7 @@ sub _get_data my $tmp = "SELECT "; for my $k (0 .. $#{$name}) { if ( $type->[$k] =~ /(date|time)/) { - $str .= "to_char($name->[$k], 'YYYY-MM-DD'),"; + $str .= "to_char($name->[$k], 'YYYY-MM-DD HH24:MI:SS'),"; } else { $str .= "$name->[$k],"; } @@ -1290,8 +1299,8 @@ sub _sql_type 'VARCHAR2' => 'varchar', 'NVARCHAR2' => 'varchar', # The DATE data type is used to store the date and time information. - # Pg type timestamp should match all needs - 'DATE' => 'timestamp', + # Pg type datetime should match all needs + 'DATE' => 'datetime', # Type LONG is like VARCHAR2 but with up to 2Gb. # PG type text should match all needs or if you want you could use blob 'LONG' => 'text', # Character data of variable length diff --git a/contrib/oracle/TODO b/contrib/oracle/TODO index c9f4392170..da0179e471 100644 --- a/contrib/oracle/TODO +++ b/contrib/oracle/TODO @@ -1,10 +1,6 @@ -Add possible call to perl function for each field value exported -(data conversion on the fly before dump) +The following need your contribution : - Fix problem regarding table/constraint output order. - -The following need your help : - - SQL queries converter. - PL/SQL code converter. diff --git a/contrib/oracle/ora2pg.pl b/contrib/oracle/ora2pg.pl index 3a15fb7bed..80c97c38cc 100755 --- a/contrib/oracle/ora2pg.pl +++ b/contrib/oracle/ora2pg.pl @@ -30,7 +30,7 @@ my $schema = new Ora2Pg ( user => $dbuser, # Database user password => $dbpwd, # Database password debug => 1, # Verbose mode - schema => 'APPS', # Extract only APPS schema + schema => 'ALICIA7', # Extract only APPS schema type => 'TABLE', # Extract table # type => 'PACKAGE', # Extract PACKAGE information # type => 'DATA', # Extract data with output as INSERT statement @@ -46,6 +46,7 @@ my $schema = new Ora2Pg ( # tables => [('TX_DATA')], # simple indexes # tables => [('NDW_BROWSER_ATTRIBUTES')], # view # tables => [('TRIP_DATA')], # Foreign key +# tables => [('JO_TMP')], # Foreign key # showtableid => 1, # Display only table indice during extraction # min => 1, # Extract begin at indice 3 # max => 10, # Extract ended at indice 5 @@ -56,7 +57,8 @@ my $schema = new Ora2Pg ( # Just export data of the following fields from table 's_txcot' #$schema->modify_struct('s_txcot','dossier', 'rub', 'datapp'); -# Function to use for extraction when type option is set to DATA or COPY +#### Function to use for extraction when type option is set to DATA or COPY + # Send exported data to a PostgreSQL database #$schema->send_to_pgdb('dbi:Pg:dbname=template1;host=localhost;port=5432','test','test'); @@ -64,7 +66,8 @@ my $schema = new Ora2Pg ( # If you set the send_to_pgdb() method the output is given to PG database. See above #$schema->export_data("output.sql"); -# Function to use ifor extraction with other type +#### Function to use for extraction of other type + # Create the POSTGRESQL representation of all objects in the database $schema->export_schema("output.sql");