The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

DBIx::Copy 0.02 - For copying database content from one db to another

SYNOPSIS

use DBIx::Copy; use DBI;

my $dbh_source=DBI->connect(...); my $dbh_target=DBI->connect(...);

my %options=();

my $copy_handler= DBIx::Copy->new($dbh_source, $dbh_target, \%options);

$copy_handler->copy (['tabletobecopied', 'anothertabletobecopied', ...]);

DESCRIPTION

This Module might help you copying a DB. Currently only the data itself can be copied, future versions will handle the DD (data definitons) as well. This module can also be used for "upgrading" a DB when severe changes has been done to the underlying tables. I have contributed DBIx::Copy::UpgradeRT as an example.

The next version will also provide a mirroring/merging feature - thus the old version and old DB might be rolling along, and the script might be executed from the crontab and update the new tables. However, there should be Better Ways for handling DB mirroring on a permanent basis.

OPTIONS

table_translation_table

If a table called FOO in the source database should be called Bar in the destination database, it's possible to specify it in the options:

    $options{'table_tanslation_table'}={'FOO' => 'Bar'};

column_translation_table

If the table FOO contains a column with the name "LASTUPDATEDTIMESTAMP", and we want to call it "LastUpdated" in the table Bar, it's possible to specify it:

    $options{'column_translation_table'}->{FOO}={
        'ID' => 'id',
        'TITLE' => 'Title',
        'LASTUPDATEDTIMESTAMP' => 'LastUpdated'
        # _All_ columns you want to copy must be mentionated here.  I
        # will eventually fix a sub for initializing such a hash
        # reference.
    }

INHERITATING METHODS

I've optimized for flexibility, not speed. The following methods are "separated" out just in case you'd like to overload them especially for table-specific tasks:

insert_row

It might be overloaded i.e. if some of the values needs extra calculation. See the code for details.

sub get_insert_row_sub

This one should return a reference to insert_row. I just think that if an inheritating class is made and is supposed to serve several tables, then I don't want the if statement for checking

ERROR HANDLING AND STABILITY

DBIx::Copy->new will die unless it's feeded with at least two arguments.

copy will just return undef if it fails somewhere.

The exception will probably be raised within the DBI. By adjusting settings within the DBI object, the error handling might be improved. Check the options AutoCommit, PrintError and RaiseError.

Currently the module is optimisticly lacking all kind of locking. This will have to be done outside the module.

Be aware that the testing script following this package is NOT GOOD ENOUGH, it should be tested by hand using the synopsis above.

TODO

data_definitions

The module should also be capable of copying data definitions

avoid_deletion

It should be possible to avoid deleting the old table before inserting a new. The module should (by first running a select call) avoid inserting duplicates. This option will only insert new rows, not update old ones.

replace

Do not delete old data in the destination table unless it is to be replaced by new data from the source table.

max_timestamp / mirror

Check the timestamps and only import rows that has been modified after max_timestamp (typically the timestamp for the last import).

mirror will try to fetch the last timestamp from the database, and store the new timestamp in the database.

merge

If the same row is edited in both databases, try to merge the result.

locking

Locking should be supported somehow.

KNOWN BUGS

Except for all the "buts" and "ifs" and missing features above - none yet - but this module is very poorly tested!

LICENSE

Copyright (c) 2000 Tobias Brox. All rights reserved. This program is released under the GNU Public License. It might also be released under The Artistic License if you send me a mail why GPL is insufficient.

AUTHOR

Tobias Brox <tobix@irctos.org>. Comments, bug reports, patches and flames are appreciated.