head	1.6;
access;
symbols
	REL7_4_29:1.5
	REL8_0_25:1.5
	REL8_1_21:1.5
	REL7_4_28:1.5
	REL8_0_24:1.5
	REL8_1_20:1.5
	REL7_4_27:1.5
	REL8_0_23:1.5
	REL8_1_19:1.5
	REL7_4_26:1.5
	REL8_0_22:1.5
	REL8_1_18:1.5
	REL7_4_25:1.5
	REL8_0_21:1.5
	REL8_1_17:1.5
	REL7_4_24:1.5
	REL8_0_20:1.5
	REL8_1_16:1.5
	REL7_4_23:1.5
	REL8_0_19:1.5
	REL8_1_15:1.5
	REL7_4_22:1.5
	REL8_0_18:1.5
	REL8_1_14:1.5
	REL7_4_21:1.5
	REL8_0_17:1.5
	REL8_1_13:1.5
	REL7_4_20:1.5
	REL8_0_16:1.5
	REL8_1_12:1.5
	REL7_3_21:1.4.2.1
	REL7_4_19:1.5
	REL8_0_15:1.5
	REL8_1_11:1.5
	REL7_3_20:1.4.2.1
	REL7_4_18:1.5
	REL8_0_14:1.5
	REL8_1_10:1.5
	REL7_3_19:1.4.2.1
	REL7_4_17:1.5
	REL8_0_13:1.5
	REL8_1_9:1.5
	REL8_0_12:1.5
	REL8_1_8:1.5
	REL7_3_18:1.4.2.1
	REL7_4_16:1.5
	REL8_0_11:1.5
	REL8_1_7:1.5
	REL8_0_10:1.5
	REL8_1_6:1.5
	REL7_4_15:1.5
	REL7_3_17:1.4.2.1
	REL8_1_5:1.5
	REL8_0_9:1.5
	REL7_4_14:1.5
	REL7_3_16:1.4.2.1
	REL7_3_15:1.4.2.1
	REL7_4_13:1.5
	REL8_0_8:1.5
	REL8_1_4:1.5
	REL7_3_14:1.4.2.1
	REL7_4_12:1.5
	REL8_0_7:1.5
	REL8_1_3:1.5
	REL7_3_13:1.4.2.1
	REL7_4_11:1.5
	REL8_0_6:1.5
	REL8_1_2:1.5
	REL7_3_12:1.4.2.1
	REL7_4_10:1.5
	REL8_0_5:1.5
	REL8_1_1:1.5
	REL8_1_STABLE:1.5.0.10
	REL8_1_0:1.5
	REL8_1_0RC1:1.5
	REL8_1_0BETA4:1.5
	REL8_1_0BETA3:1.5
	REL7_3_11:1.4.2.1
	REL7_4_9:1.5
	REL8_0_4:1.5
	REL8_1_0BETA2:1.5
	REL8_1_0BETA1:1.5
	REL7_2_8:1.3
	REL7_3_10:1.4.2.1
	REL7_4_8:1.5
	REL8_0_3:1.5
	REL8_0_2:1.5
	REL7_2_7:1.3
	REL7_3_9:1.4.2.1
	REL7_4_7:1.5
	REL8_0_1:1.5
	REL8_0_STABLE:1.5.0.8
	REL8_0_0:1.5.0.6
	REL8_0_0RC5:1.5
	REL8_0_0RC4:1.5
	REL8_0_0RC3:1.5
	REL8_0_0RC2:1.5
	REL8_0_0RC1:1.5
	REL8_0_0BETA5:1.5
	REL8_0_0BETA4:1.5
	REL7_4_6:1.5
	REL7_3_8:1.4.2.1
	REL7_2_6:1.3
	REL8_0_0BETA3:1.5
	REL8_0_0BETA2:1.5
	REL7_2_5:1.3
	REL7_4_5:1.5
	REL7_3_7:1.4.2.1
	REL7_4_4:1.5
	REL8_0_0BETA1:1.5
	REL7_4_3:1.5
	REL7_4_2:1.5
	REL7_3_6:1.4.2.1
	REL7_4_1:1.5
	REL7_3_5:1.4.2.1
	REL7_4:1.5
	REL7_4_RC2:1.5
	REL7_4_STABLE:1.5.0.4
	REL7_4_RC1:1.5
	REL7_4_BETA5:1.5
	REL7_4_BETA4:1.5
	REL7_4_BETA3:1.5
	REL7_4_BETA2:1.5
	WIN32_DEV:1.5.0.2
	REL7_4_BETA1:1.5
	REL7_3_4:1.4.2.1
	REL7_3_2:1.4.2.1
	REL7_2_4:1.3
	REL7_3_STABLE:1.4.0.2
	REL7_2_3:1.3
	REL7_2_STABLE:1.3.0.2
	REL7_2:1.3
	REL7_2_RC2:1.3
	REL7_2_RC1:1.3
	REL7_2_BETA5:1.3
	REL7_2_BETA4:1.3
	REL7_2_BETA3:1.3
	REL7_2_BETA2:1.3
	REL7_2_BETA1:1.3;
locks; strict;
comment	@# @;


1.6
date	2006.02.25.19.18.58;	author petere;	state dead;
branches;
next	1.5;

1.5
date	2003.01.07.22.17.14;	author momjian;	state Exp;
branches;
next	1.4;

1.4
date	2002.04.04.05.55.57;	author momjian;	state Exp;
branches
	1.4.2.1;
next	1.3;

1.3
date	2001.06.23.02.56.23;	author momjian;	state Exp;
branches;
next	1.2;

1.2
date	2001.05.13.02.10.00;	author momjian;	state Exp;
branches;
next	1.1;

1.1
date	2001.05.10.15.51.05;	author momjian;	state Exp;
branches;
next	;

1.4.2.1
date	2003.01.07.22.17.23;	author momjian;	state Exp;
branches;
next	;


desc
@@


1.6
log
@Remove ora2pg; now available at <http://www.samse.fr/GPL/ora2pg/>.
@
text
@NAME
    Ora2Pg - Oracle to PostgreSQL database schema converter

SYNOPSIS
            BEGIN {
                    $ENV{ORACLE_HOME} = '/usr/local/oracle/oracle816';
            }

            use strict;

            use Ora2Pg;

            # Init the database connection
            my $dbsrc = 'dbi:Oracle:host=testdb.samse.fr;sid=TEST;port=1521';
            my $dbuser = 'system';
            my $dbpwd = 'manager';

            # Create an instance of the Ora2Pg perl module
            my $schema = new Ora2Pg (
                    datasource => $dbsrc,           # Database DBD datasource
                    user => $dbuser,                # Database user
                    password => $dbpwd,             # Database password
                    {
                            PrintError => 0,
                            RaiseError => 1,
                            AutoCommit => 0
                    }
            );

            # Create the POSTGRESQL representation of all objects in the database
            $schema->export_schema("output.sql");

            exit(0);

    or if you only want to extract some tables:

            # Create an instance of the Ora2Pg perl module
            my @@tables = ('tab1', 'tab2', 'tab3');
            my $schema = new Ora2Pg (
                    datasource => $dbsrc,           # Database DBD datasource
                    user => $dbuser,                # Database user
                    password => $dbpwd,             # Database password
                    tables => \@@tables,
            or                                      # Tables to extract
                    tables => [('tab1','tab2')],
                    debug => 1                      # To show somethings when running
            );

    or if you only want to extract the 10 first tables:

            # Create an instance of the Ora2Pg perl module
            my $schema = new Ora2Pg (
                    datasource => $dbsrc,           # Database DBD datasource
                    user => $dbuser,                # Database user
                    password => $dbpwd,             # Database password
                    max => 10                       # 10 first tables to extract
            );

    or if you only want to extract tables 10 to 20:

            # Create an instance of the Ora2Pg perl module
            my $schema = new Ora2Pg (
                    datasource => $dbsrc,           # Database DBD datasource
                    user => $dbuser,                # Database user
                    password => $dbpwd,             # Database password
                    min => 10,                      # Begin extraction at indice 10
                    max => 20                       # End extraction at indice 20
            );

    To choose a particular Oracle schema to export just set the following
    option to your schema name:

            schema => 'APPS'

    This schema definition can also be needed when you want to export data.
    If export failed and complain that the table doesn't exists use this to
    prefix the table name by the schema name.

    If you want to use PostgreSQL 7.3 schema support activate the init
    option 'export_schema' set to 1. Default is no schema export

    To know at which indices tables can be found during extraction use the
    option:

            showtableid => 1

    To extract all views set the type option as follow:

            type => 'VIEW'

    To extract all grants set the type option as follow:

            type => 'GRANT'

    To extract all sequences set the type option as follow:

            type => 'SEQUENCE'

    To extract all triggers set the type option as follow:

            type => 'TRIGGER'

    To extract all functions set the type option as follow:

            type => 'FUNCTION'

    To extract all procedures set the type option as follow:

            type => 'PROCEDURE'

    To extract all packages and body set the type option as follow:

            type => 'PACKAGE'

    Default is table extraction

            type => 'TABLE'

    To extract all data from table extraction as INSERT statement use:

            type => 'DATA'

    To extract all data from table extraction as COPY statement use:

            type => 'COPY'

    and data_limit => n to specify the max tuples to return. If you set this
    options to 0 or nothing, no limitation are used. Additional option
    'table', 'min' and 'max' can also be used.

    When use of COPY or DATA you can export data by calling method:

    $schema->export_data("output.sql");

    Data are dumped to the given filename or to STDOUT with no argument. You
    can also send these data directly to a PostgreSQL backend using the
    following method:

    $schema->send_to_pgdb($destdatasrc,$destuser,$destpasswd);

    In this case you must call export_data() without argument after the call
    to method send_to_pgdb().

    If you set type to COPY and you want to dump data directly to a PG
    database, you must call method send_to_pgdb but data will not be sent
    via DBD::Pg but they will be load to the database using the psql
    command. Calling this method is istill required to be able to extract
    database name, hostname and port information. Edit the $PSQL variable to
    match the path of your psql command (nothing to edit if psql is in your
    path).

DESCRIPTION
    Ora2Pg is a perl OO module used to export an Oracle database schema to a
    PostgreSQL compatible schema.

    It simply connect to your Oracle database, extract its structure and
    generate a SQL script that you can load into your PostgreSQL database.

    I'm not a Oracle DBA so I don't really know something about its internal
    structure so you may find some incorrect things. Please tell me what is
    wrong and what can be better.

    It currently dump the database schema (tables, views, sequences,
    indexes, grants), with primary, unique and foreign keys into PostgreSQL
    syntax without editing the SQL code generated.

    It now can dump Oracle data into PostgreSQL DB as online process. You
    can choose what columns can be exported for each table.

    Functions, procedures and triggers PL/SQL code generated must be
    reviewed to match the PostgreSQL syntax. Some usefull recommandation on
    porting Oracle to PostgreSQL can be found at
    http://techdocs.postgresql.org/ under the "Converting from other
    Databases to PostgreSQL" Oracle part. I just notice one thing more is
    that the trunc() function in Oracle is the same for number or date so be
    carefull when porting to PostgreSQL to use trunc() for number and
    date_trunc() for date.

ABSTRACT
    The goal of the Ora2Pg perl module is to cover all part needed to export
    an Oracle database to a PostgreSQL database without other thing that
    provide the connection parameters to the Oracle database.

    Features must include:

            - Database schema export (tables, views, sequences, indexes),
              with unique, primary and foreign key.
            - Grants/privileges export by user and group.
            - Table selection (by name and max table) export.
            - Export Oracle schema to PostgreSQL 7.3 schema.
            - Predefined functions/triggers/procedures/packages export.
            - Data export.
            - Sql query converter (todo)

    My knowledge regarding database is really poor especially for Oracle so
    contribution is welcome.

REQUIREMENT
    You just need the DBI, DBD::Pg and DBD::Oracle perl module to be
    installed

PUBLIC METHODS
  new HASH_OPTIONS

    Creates a new Ora2Pg object.

    Supported options are:

            - datasource    : DBD datasource (required)
            - user          : DBD user (optional with public access)
            - password      : DBD password (optional with public access)
            - schema        : Oracle internal schema to extract
            - type          : Type of data to extract, can be TABLE,VIEW,GRANT,SEQUENCE,
                              TRIGGER,FUNCTION,PROCEDURE,DATA,COPY,PACKAGE
            - debug         : Print the current state of the parsing
            - export_schema : Export Oracle schema to PostgreSQL 7.3 schema
            - tables        : Extract only the given tables (arrayref)
            - showtableid   : Display only the table indice during extraction
            - min           : Indice to begin extraction. Default to 0
            - max           : Indice to end extraction. Default to 0 mean no limits
            - data_limit    : Number max of tuples to return during data extraction (default 0 no limit)

    Attempt that this list should grow a little more because all
    initialization is done by this way.

  export_data FILENAME

    Print SQL data output to a filename or to STDOUT if no file is given.

    Must be used only if type option is set to DATA or COPY =cut

    sub export_data { my ($self, $outfile) = @@_;

            $self->_get_sql_data($outfile);
    }

  export_sql FILENAME

    Print SQL conversion output to a filename or simply return these data if
    no file is given.

  send_to_pgdb DEST_DATASRC DEST_USER DEST_PASSWD

    Open a DB handle to a PostgreSQL database

  modify_struct TABLE_NAME ARRAYOF_FIELDNAME

    Modify a table structure during export. Only given fieldname will be
    exported.

PRIVATE METHODS
  _init HASH_OPTIONS

    Initialize a Ora2Pg object instance with a connexion to the Oracle
    database.

  _grants

    This function is used to retrieve all privilege information.

    It extract all Oracle's ROLES to convert them as Postgres groups and
    search all users associated to these roles.

    Set the main hash $self->{groups}. Set the main hash $self->{grantss}.

  _sequences

    This function is used to retrieve all sequences information.

    Set the main hash $self->{sequences}.

  _triggers

    This function is used to retrieve all triggers information.

    Set the main hash $self->{triggers}.

  _functions

    This function is used to retrieve all functions information.

    Set the main hash $self->{functions}.

  _packages

    This function is used to retrieve all packages information.

    Set the main hash $self->{packages}.

  _tables

    This function is used to retrieve all table information.

    Set the main hash of the database structure $self->{tables}. Keys are
    the names of all tables retrieved from the current database. Each table
    information compose an array associated to the table_info key as array
    reference. In other way:

        $self->{tables}{$class_name}{table_info} = [(OWNER,TYPE)];

    DBI TYPE can be TABLE, VIEW, SYSTEM TABLE, GLOBAL TEMPORARY, LOCAL
    TEMPORARY, ALIAS, SYNONYM or a data source specific type identifier.
    This only extract TABLE type.

    It also get the following informations in the DBI object to affect the
    main hash of the database structure :

        $self->{tables}{$class_name}{field_name} = $sth->{NAME};
        $self->{tables}{$class_name}{field_type} = $sth->{TYPE};

    It also call these other private subroutine to affect the main hash of
    the database structure :

        @@{$self->{tables}{$class_name}{column_info}} = $self->_column_info($class_name, $owner);
        @@{$self->{tables}{$class_name}{primary_key}} = $self->_primary_key($class_name, $owner);
        @@{$self->{tables}{$class_name}{unique_key}}  = $self->_unique_key($class_name, $owner);
        @@{$self->{tables}{$class_name}{foreign_key}} = $self->_foreign_key($class_name, $owner);

  _views

    This function is used to retrieve all views information.

    Set the main hash of the views definition $self->{views}. Keys are the
    names of all views retrieved from the current database values are the
    text definition of the views.

    It then set the main hash as follow:

        # Definition of the view
        $self->{views}{$table}{text} = $view_infos{$table};

  _get_sql_data

    Returns a string containing the entire SQL Schema definition compatible
    with PostgreSQL

  _get_data TABLE

    This function implements a Oracle-native data extraction.

    Return a list of array reference containing the data

  _sql_type INTERNAL_TYPE LENGTH PRECISION SCALE

    This function return the PostgreSQL datatype corresponding to the Oracle
    internal type.

  _column_info TABLE OWNER

    This function implements a Oracle-native column information.

    Return a list of array reference containing the following informations
    for each column the given a table

    [( column name, column type, column length, nullable column, default
    value )]

  _primary_key TABLE OWNER

    This function implements a Oracle-native primary key column information.

    Return a list of all column name defined as primary key for the given
    table.

  _unique_key TABLE OWNER

    This function implements a Oracle-native unique key column information.

    Return a list of all column name defined as unique key for the given
    table.

  _foreign_key TABLE OWNER

    This function implements a Oracle-native foreign key reference
    information.

    Return a list of hash of hash of array reference. Ouuf! Nothing very
    difficult. The first hash is composed of all foreign key name. The
    second hash just have two key known as 'local' and remote' corresponding
    to the local table where the foreign key is defined and the remote table
    where the key refer.

    The foreign key name is composed as follow:

        'local_table_name->remote_table_name'

    Foreign key data consist in two array representing at the same indice
    the local field and the remote field where the first one refer to the
    second. Just like this:

        @@{$link{$fkey_name}{local}} = @@local_columns;
        @@{$link{$fkey_name}{remote}} = @@remote_columns;

  _get_users

    This function implements a Oracle-native users information.

    Return a hash of all users as an array.

  _get_roles

    This function implements a Oracle-native roles information.

    Return a hash of all groups (roles) as an array of associated users.

  _get_all_grants

    This function implements a Oracle-native user privilege information.

    Return a hash of all tables grants as an array of associated users.

  _get_indexes TABLE OWNER

    This function implements a Oracle-native indexes information.

    Return hash of array containing all unique index and a hash of array of
    all indexes name which are not primary keys for the given table.

  _get_sequences

    This function implements a Oracle-native sequences information.

    Return a hash of array of sequence name with MIN_VALUE, MAX_VALUE,
    INCREMENT and LAST_NUMBER for the given table.

  _get_views

    This function implements a Oracle-native views information.

    Return a hash of view name with the SQL query it is based on.

  _alias_info

    This function implements a Oracle-native column information.

    Return a list of array reference containing the following informations
    for each alias of the given view

    [( column name, column id )]

  _get_triggers

    This function implements a Oracle-native triggers information.

    Return an array of refarray of all triggers informations

  _get_functions

    This function implements a Oracle-native functions information.

    Return a hash of all function name with their PLSQL code

  _get_packages

    This function implements a Oracle-native packages information.

    Return a hash of all function name with their PLSQL code

  _table_info

    This function retrieve all Oracle-native tables information.

    Return a handle to a DB query statement

AUTHOR
    Gilles Darold <gilles@@darold.net>

COPYRIGHT
    Copyright (c) 2001 Gilles Darold - All rights reserved.

    This program is free software; you can redistribute it and/or modify it
    under the same terms as Perl itself.

BUGS
    This perl module is in the same state as my knowledge regarding
    database, it can move and not be compatible with older version so I will
    do my best to give you official support for Ora2Pg. Your volontee to
    help construct it and your contribution are welcome.

SEE ALSO
    the DBI manpage, the DBD::Oracle manpage, the DBD::Pg manpage

ACKNOWLEDGEMENTS
    Thanks to Jason Servetar who decided me to implement data extraction.

@


1.5
log
@Upgrade to even newer ora2pg 2.0.
@
text
@@


1.4
log
@Update to new version of Oracle conversion utility, version 1.8.

Gilles DAROLD
@
text
@d79 3
d190 1
d216 1
d221 1
a221 1
            - data_limit    : Number max of tuples to return during data extraction (default 10)
d314 4
a317 4
        @@{$self->{tables}{$class_name}{column_info}} = $self->_column_info($class_name);
        @@{$self->{tables}{$class_name}{primary_key}} = $self->_primary_key($class_name);
        @@{$self->{tables}{$class_name}{unique_key}}  = $self->_unique_key($class_name);
        @@{$self->{tables}{$class_name}{foreign_key}} = $self->_foreign_key($class_name);
d348 1
a348 1
  _column_info TABLE
d358 1
a358 1
  _primary_key TABLE
d365 1
a365 1
  _unique_key TABLE
d372 1
a372 1
  _foreign_key TABLE
d412 1
a412 1
  _get_indexes TABLE
@


1.4.2.1
log
@Upgrade to even newer ora2pg 2.0.
@
text
@a78 3
    If you want to use PostgreSQL 7.3 schema support activate the init
    option 'export_schema' set to 1. Default is no schema export

a186 1
            - Export Oracle schema to PostgreSQL 7.3 schema.
a211 1
            - export_schema : Export Oracle schema to PostgreSQL 7.3 schema
d216 1
a216 1
            - data_limit    : Number max of tuples to return during data extraction (default 0 no limit)
d309 4
a312 4
        @@{$self->{tables}{$class_name}{column_info}} = $self->_column_info($class_name, $owner);
        @@{$self->{tables}{$class_name}{primary_key}} = $self->_primary_key($class_name, $owner);
        @@{$self->{tables}{$class_name}{unique_key}}  = $self->_unique_key($class_name, $owner);
        @@{$self->{tables}{$class_name}{foreign_key}} = $self->_foreign_key($class_name, $owner);
d343 1
a343 1
  _column_info TABLE OWNER
d353 1
a353 1
  _primary_key TABLE OWNER
d360 1
a360 1
  _unique_key TABLE OWNER
d367 1
a367 1
  _foreign_key TABLE OWNER
d407 1
a407 1
  _get_indexes TABLE OWNER
@


1.3
log
@Here the latest version and first working release of Ora2Pg a tool to export
Oracle database to PostgreSQL.

    It currently dump the database schema (tables, views, sequences,
    indexes, grants), with primary, unique and foreign keys into PostgreSQL
    syntax without editing the SQL code generated. You can dump only a
    particular schema from the Oracle database.

    Functions, procedures and triggers with SQL or PLSQL code generated must
    be reviewed to match the PostgreSQL syntax. Some usefull recommandation
    on porting Oracle to PostgreSQL can be found at
http://techdocs.postgresql.org/
    under the "Converting from other Databases to PostgreSQL" Oracle part. I
just
    notice one thing more is that the trunc() function in Oracle is the same for
number
    or date so be carefull when porting to PostgreSQL to use trunc() for number
and
    date_trunc() for date.

I will add more precision in type NUMBER conversion based on length to match
as closest as possible all rich PostgreSQL numerics type. But it seems not to be

urgent as it seems that Oracle DBAs only create number with length 22 (default)
Space seems not to be their problem...

Gilles DAROLD
@
text
@d23 5
d70 2
a71 2
    To choose a particular schema just set the following option to
    your schema name :
d75 6
a80 2
    To know at which indices table can be found during extraction
    use the option:
d84 1
a84 1
    To extract all views set the option type as follow:
d88 1
a88 1
    To extract all grants set the option type as follow:
d92 1
a92 1
    To extract all sequences set the option type as follow:
d96 1
a96 1
    To extract all triggers set the option type as follow:
d100 1
a100 1
    To extract all functions set the option type as follow:
d104 1
a104 1
    To extract all procedures set the option type as follow:
d108 5
a112 1
    Default is table schema extraction
d116 33
d150 2
a151 2
    Ora2Pg is a perl OO module used to export an Oracle database
    schema to a PostgreSQL compatible schema.
d153 2
a154 3
    It simply connect to your Oracle database, extract its structure
    and generate a SQL script that you can load into your PostgreSQL
    database.
d156 3
a158 3
    I'm not a Oracle DBA so I don't really know something about its
    internal structure so you may find some incorrect things. Please
    tell me what is wrong and what can be better.
d161 5
a165 2
    indexes, grants), with primary, unique and foreign keys into
    PostgreSQL syntax without editing the SQL code generated.
d168 2
a169 2
    reviewed to match the PostgreSQL syntax. Some usefull
    recommandation on porting Oracle to PostgreSQL can be found at
d171 4
a174 4
    Databases to PostgreSQL" Oracle part. I just notice one thing
    more is that the trunc() function in Oracle is the same for
    number or date so be carefull when porting to PostgreSQL to use
    trunc() for number and date_trunc() for date.
d177 3
a179 4
    The goal of the Ora2Pg perl module is to cover all part needed
    to export an Oracle database to a PostgreSQL database without
    other thing that provide the connection parameters to the Oracle
    database.
d187 2
a188 1
            - Predefined functions/triggers/procedures export.
a189 1
            - Data export (todo)
d191 2
a192 2
    My knowledge regarding database is really poor especially for
    Oracle so contribution is welcome.
d195 1
a195 1
    You just need the DBI and DBD::Oracle perl module to be
d209 2
a210 1
            - type          : Type of data to extract, can be TABLE,VIEW,GRANT,SEQUENCE,TRIGGER,FUNCTION,PROCEDURE
d216 1
d221 11
d234 11
a244 2
    Print SQL conversion output to a filename or to STDOUT if no
    file is given.
d249 2
a250 2
    Initialize a Ora2Pg object instance with a connexion to the
    Oracle database.
d256 2
a257 2
    It extract all Oracle's ROLES to convert them as Postgres groups
    and search all users associated to these roles.
d259 1
a259 2
    Set the main hash $self->{groups}. Set the main hash $self-
    >{grantss}.
d279 6
d289 4
a292 4
    Set the main hash of the database structure $self->{tables}.
    Keys are the names of all tables retrieved from the current
    database. Each table information compose an array associated to
    the table_info key as array reference. In other way:
d296 3
a298 3
    DBI TYPE can be TABLE, VIEW, SYSTEM TABLE, GLOBAL TEMPORARY,
    LOCAL TEMPORARY, ALIAS, SYNONYM or a data source specific type
    identifier. This only extract TABLE type.
d300 2
a301 2
    It also get the following informations in the DBI object to
    affect the main hash of the database structure :
d306 2
a307 2
    It also call these other private subroutine to affect the main
    hash of the database structure :
d318 3
a320 3
    Set the main hash of the views definition $self->{views}. Keys
    are the names of all views retrieved from the current database
    values are the text definition of the views.
d329 6
a334 2
    Returns a string containing the entire SQL Schema definition
    compatible with PostgreSQL
d336 1
a336 1
  _sql_type INTERNAL_TYPE LENGTH
d338 4
a341 2
    This function return the PostgreSQL datatype corresponding to
    the Oracle internal type.
d347 2
a348 2
    Return a list of array reference containing the following
    informations for each column the given a table
d350 2
a351 2
    [( column name, column type, column length, nullable column,
    default value )]
d355 1
a355 2
    This function implements a Oracle-native primary key column
    information.
d357 2
a358 2
    Return a list of all column name defined as primary key for the
    given table.
d362 1
a362 2
    This function implements a Oracle-native unique key column
    information.
d364 2
a365 2
    Return a list of all column name defined as unique key for the
    given table.
d372 5
a376 5
    Return a list of hash of hash of array reference. Ouuf! Nothing
    very difficult. The first hash is composed of all foreign key
    name. The second hash just have two key known as 'local' and
    remote' corresponding to the local table where the foreign key
    is defined and the remote table where the key refer.
d382 3
a384 3
    Foreign key data consist in two array representing at the same
    indice the local field and the remote field where the first one
    refer to the second. Just like this:
d399 1
a399 2
    Return a hash of all groups (roles) as an array of associated
    users.
d403 1
a403 2
    This function implements a Oracle-native user privilege
    information.
d405 1
a405 2
    Return a hash of all tables grants as an array of associated
    users.
d411 2
a412 3
    Return hash of array containing all unique index and a hash of
    array of all indexes name which are not primary keys for the
    given table.
d418 2
a419 2
    Return a hash of array of sequence name with MIN_VALUE,
    MAX_VALUE, INCREMENT and LAST_NUMBER for the given table.
d427 9
d448 6
d466 2
a467 2
    This program is free software; you can redistribute it and/or
    modify it under the same terms as Perl itself.
d471 3
a473 4
    database, it can move and not be compatible with older version
    so I will do my best to give you official support for Ora2Pg.
    Your volontee to help construct it and your contribution are
    welcome.
d476 4
a479 1
    the DBI manpage, the DBD::Oracle manpage
@


1.2
log
@Update to ora2pg 1.2.
@
text
@d38 3
a40 1
                    tables => \@@tables,             # Tables to extract
d61 1
a61 1
                    min => 10                       # Begin extraction at indice 10
d65 7
a71 2
    To know at which indices table can be found during extraction use the
    option:
d79 20
d101 2
d104 2
a105 2
    Ora2Pg is a perl OO module used to export an Oracle database schema to a
    PostgreSQL compatible schema.
d107 3
a109 2
    It simply connect to your Oracle database, extract its structure and
    generate a SQL script that you can load into your PostgreSQL database.
d111 16
a126 7
    I'm not a Oracle DBA so I don't really know something about its internal
    structure so you may find some incorrect things. Please tell me what is
    wrong and what can be better.

    It currently only dump the database schema, with primary, unique and
    foreign keys. I've tried to excluded internal system tables but perhaps
    not enougt, please let me know.
d129 4
a132 3
    The goal of the Ora2Pg perl module is to cover all part needed to export
    an Oracle database to a PostgreSQL database without other thing that
    provide the connection parameters to the Oracle database.
d136 2
a137 1
            - Database schema export, with unique, primary and foreign key.
d139 3
a141 3
            - Indexes and unique indexes export.
            - Table or view selection (by name and max table) export.
            - Predefined function/trigger export (todo)
a142 1
            - Sql query converter (todo)
d144 2
a145 2
    My knowledge regarding database is really poor especially for Oracle so
    contribution is welcome.
d148 2
a149 1
    You just need the DBI and DBD::Oracle perl module to be installed
d161 2
a162 1
            - type          : Type of data to extract, can be TABLE (default) or VIEW
d174 2
a175 2
    Print SQL conversion output to a filename or to STDOUT if no file is
    given.
d177 1
a177 1
PUBLIC METHODS
d180 30
a209 2
    Initialize a Ora2Pg object instance with a connexion to the Oracle
    database.
d215 4
a218 4
    Set the main hash of the database structure $self->{tables}. Keys are
    the names of all tables retrieved from the current database. Each table
    information compose an array associated to the table_info key as array
    reference. In other way:
d222 3
a224 3
    DBI TYPE can be TABLE, VIEW, SYSTEM TABLE, GLOBAL TEMPORARY, LOCAL
    TEMPORARY, ALIAS, SYNONYM or a data source specific type identifier.
    This only extract TABLE type.
d226 2
a227 2
    It also get the following informations in the DBI object to affect the
    main hash of the database structure :
d232 2
a233 2
    It also call these other private subroutine to affect the main hash of
    the database structure :
d235 4
a238 4
        @@{$self->{tables}{$class_name}{column_info}} = &_column_info($self, $class_name);
        @@{$self->{tables}{$class_name}{primary_key}} = &_primary_key($self, $class_name);
        @@{$self->{tables}{$class_name}{unique_key}}  = &_unique_key($self, $class_name);
        @@{$self->{tables}{$class_name}{foreign_key}} = &_foreign_key($self, $class_name);
d244 3
a246 3
    Set the main hash of the views definition $self->{views}. Keys are the
    names of all views retrieved from the current database values are the
    text definition of the views.
a251 2
        # Grants defined on the views 
        $self->{views}{$table}{grants} = when I find how...
d255 2
a256 2
    Returns a string containing the entire SQL Schema definition compatible
    with PostgreSQL
d260 2
a261 2
    This function return the PostgreSQL datatype corresponding to the Oracle
    internal type.
d267 2
a268 2
    Return a list of array reference containing the following informations
    for each column the given a table
d270 2
a271 2
    [( column name, column type, column length, nullable column, default
    value )]
d275 2
a276 1
    This function implements a Oracle-native primary key column information.
d278 2
a279 2
    Return a list of all column name defined as primary key for the given
    table.
d283 2
a284 1
    This function implements a Oracle-native unique key column information.
d286 2
a287 2
    Return a list of all column name defined as unique key for the given
    table.
d294 5
a298 5
    Return a list of hash of hash of array reference. Ouuf! Nothing very
    difficult. The first hash is composed of all foreign key name. The
    second hash just have two key known as 'local' and remote' corresponding
    to the local table where the foreign key is defined and the remote table
    where the key refer.
d304 3
a306 3
    Foreign key data consist in two array representing at the same indice
    the local field and the remote field where the first one refer to the
    second. Just like this:
d311 1
a311 1
  _get_table_privilege TABLE
d313 1
a313 1
    This function implements a Oracle-native table grants information.
d315 1
a315 1
    Return a hash of array of all users and their grants on the given table.
d319 1
a319 1
    This function implements a Oracle-native roles/users information.
d321 10
a330 1
    Return a hash of all groups (roles) as an array of associated users.
d336 2
a337 1
    Return an array of all indexes name which are not primary keys for the
d340 14
a353 3
    Note: Indexes name must be created like this tablename_fieldname else
    they will not be retrieved or if tablename false in the output
    fieldname.
d355 1
a355 1
  _get_sequences TABLE
d357 1
a357 1
    This function implements a Oracle-native sequence information.
d359 1
a359 2
    Return a hash of array of sequence name with MIN_VALUE, MAX_VALUE,
    INCREMENT and LAST_NUMBER for the given table.
d361 1
a361 1
    Not working yet.
d363 3
a365 1
  _get_views
d367 1
a367 1
    This function implements a Oracle-native views information.
d369 1
a369 2
    Return a hash of array of sequence name with MIN_VALUE, MAX_VALUE,
    INCREMENT and LAST_NUMBER for the given table.
d377 2
a378 2
    This program is free software; you can redistribute it and/or modify it
    under the same terms as Perl itself.
d382 4
a385 3
    database, it can move and not be compatible with older version so I will
    do my best to give you official support for Ora2Pg. Your volontee to
    help construct it and your contribution are welcome.
@


1.1
log
@Add oracle conversion utility ora2pg in /contrib/oracle.
@
text
@d1 296
a296 1
   Ora2Pg - Oracle to PostgreSQL database schema converter
a297 231
     _________________________________________________________________
   
                                   SYNOPSIS
                                       
        BEGIN {
                $ENV{ORACLE_HOME} = '/usr/local/oracle/oracle816';
        }

        use strict;

        use Ora2Pg;

        # Init the database connection
        my $dbsrc = 'dbi:Oracle:host=testdb.samse.fr;sid=TEST;port=1521';
        my $dbuser = 'system';
        my $dbpwd = 'manager';

        # Create an instance of the Ora2Pg perl module
        my $schema = new Ora2Pg (
                datasource => $dbsrc,           # Database DBD datasource
                user => $dbuser,                # Database user
                password => $dbpwd,             # Database password
        );

        # Create the POSTGRESQL representation of all objects in the database
        $schema->export_schema("output.sql");

        exit(0);
     _________________________________________________________________
   
                                  DESCRIPTION
                                       
   Ora2Pg is a perl OO module used to export an Oracle database schema to
   a PostgreSQL compatible schema.
   
   It simply connect to your Oracle database, extract its structure and
   generate a SQL script that you can load into your PostgreSQL database.
   
   I'm not a Oracle DBA so I don't really know something about its
   internal structure so you may find some incorrect things. Please tell
   me what is wrong and what can be better.
   
   It currently only dump the database schema, with primary, unique and
   foreign keys. I've tried to excluded internal system tables but
   perhaps not enougt, please let me know.
     _________________________________________________________________
   
                                   ABSTRACT
                                       
   The goal of the Ora2Pg perl module is to cover all part needed to
   export an Oracle database to a PostgreSQL database without other thing
   that provide the connection parameters to the Oracle database.
   
   Features must include:
   
        - database schema export (done)
        - grant export (done)
        - predefined function/trigger export (todo)
        - data export (todo)
        - sql query converter (todo)

   My knowledge regarding database is really poor especially for Oracle
   so contribution is welcome.
     _________________________________________________________________
   
                                  REQUIREMENT
                                       
   You just need the DBI and DBD::Oracle perl module to be installed
     _________________________________________________________________
   
                                PUBLIC METHODS
     _________________________________________________________________
   
new HASH_OPTIONS

   Creates a new Ora2Pg object.
   
   Supported options are:
   
        - datasource    : DBD datasource (required)
        - user          : DBD user (optional with public access)
        - password      : DBD password (optional with public access)

   Attempt that this list should grow a little more because all
   initialization is done by this way.
     _________________________________________________________________
   
export_sql FILENAME

   Print SQL conversion output to a filename or to STDOUT if no file is
   given.
     _________________________________________________________________
   
                                PUBLIC METHODS
     _________________________________________________________________
   
_init HASH_OPTIONS

   Initialize a Ora2Pg object instance with a connexion to the Oracle
   database.
     _________________________________________________________________
   
_tables

   This function is used to retrieve all table information.
   
   Set the main hash of the database structure $self->{tables}. Keys are
   the names of all tables retrieved from the current database. Each
   table information compose an array associated to the table_info key as
   array reference. In other way:
   
    $self->{tables}{$class_name}{table_info} = [(OWNER,TYPE)];

   TYPE Can be TABLE, VIEW, SYSTEM TABLE, GLOBAL TEMPORARY, LOCAL
   TEMPORARY, ALIAS, SYNONYM or a data source specific type identifier.
   
   It also get the following informations in the DBI object to affect the
   main hash of the database structure :
   
    $self->{tables}{$class_name}{field_name} = $sth->{NAME};
    $self->{tables}{$class_name}{field_type} = $sth->{TYPE};

   It also call these other private subroutine to affect the main hash of
   the database structure :
   
    @@{$self->{tables}{$class_name}{column_info}} = &_column_info($self, $class_
name);
    @@{$self->{tables}{$class_name}{primary_key}} = &_primary_key($self, $class_
name);
    @@{$self->{tables}{$class_name}{unique_key}}  = &_unique_key($self, $class_n
ame);
    @@{$self->{tables}{$class_name}{foreign_key}} = &_foreign_key($self, $class_
name);
     _________________________________________________________________
   
_get_sql_data

   Returns a string containing the entire SQL Schema definition
   compatible with PostgreSQL
     _________________________________________________________________
   
_sql_type INTERNAL_TYPE LENGTH

   This function return the PostgreSQL datatype corresponding to the
   Oracle internal type.
     _________________________________________________________________
   
_column_info TABLE

   This function implements a Oracle-native column information.
   
   Return a list of array reference containing the following informations
   for each column the given a table
   
   [( column name, column type, column length, nullable column, default
   value )]
     _________________________________________________________________
   
_primary_key TABLE

   This function implements a Oracle-native primary key column
   information.
   
   Return a list of all column name defined as primary key for the given
   table.
     _________________________________________________________________
   
_unique_key TABLE

   This function implements a Oracle-native unique key column
   information.
   
   Return a list of all column name defined as unique key for the given
   table.
     _________________________________________________________________
   
_foreign_key TABLE

   This function implements a Oracle-native foreign key reference
   information.
   
   Return a list of hash of hash of array reference. Ouuf! Nothing very
   difficult. The first hash is composed of all foreign key name. The
   second hash just have two key known as 'local' and remote'
   corresponding to the local table where the foreign key is defined and
   the remote table where the key refer.
   
   The foreign key name is composed as follow:
   
    'local_table_name->remote_table_name'

   Foreign key data consist in two array representing at the same indice
   the local field and the remote field where the first one refer to the
   second. Just like this:
   
    @@{$link{$fkey_name}{local}} = @@local_columns;
    @@{$link{$fkey_name}{remote}} = @@remote_columns;
     _________________________________________________________________
   
_get_privilege

   This function implements a Oracle-native tables grants information.
   
   Return a hash of all groups (roles) with associated users and a hash
   of arrays of all grants on related tables.
     _________________________________________________________________
   
                                    AUTHOR
                                       
   Gilles Darold <gilles@@darold.net>
     _________________________________________________________________
   
                                   COPYRIGHT
                                       
   Copyright (c) 2001 Gilles Darold - All rights reserved.
   
   This program is free software; you can redistribute it and/or modify
   it under the same terms as Perl itself.
     _________________________________________________________________
   
                                     BUGS
                                       
   This perl module is in the same state as my knowledge regarding
   database, it can move and not be compatible with older version so I
   will do my best to give you official support for Ora2Pg. Your volontee
   to help construct it and your contribution are welcome.
     _________________________________________________________________
   
                                   SEE ALSO
                                       
   DBI, DBD::Oracle
@
