NAME
DBIx::Compare - Compare database content
SYNOPSIS
use DBIx::Compare;
my $oDB_Comparison = db_comparison->new($dbh1,$dbh2);
$oDB_Comparison->compare;
$oDB_Comparison->deep_compare;
DESCRIPTION
DBIx::Compare takes two database handles and performs comparisons of their table content.
METHODS
- new($dbh1,$dbh2)
-
You must pass two database handles at initialisation, and each database must be the same type.
- deep_compare
-
Performs a row-by-row comparison of each table that is common to, and have the same row count in each database handle, using only those fields that are common to both. Returns true if the tables are identical, false/undef if a difference was found. The table name and row number of the difference are reported to STDOUT and can be returned using the "get_differences" method.
- compare
-
Performs a low level comparison. Calls the methods compare_table_lists, compare_table_fields and compare_row_counts. In scalar context, returns a hashref of the differences found. In void context this method outputs a report to STDOUT.
- compare_table_lists
-
Simple comparison of the table names. Returns true if no differences are found, otherwise returns undef. An array ref of tables unique to each database:host can be recovered with get_differences(), using the hash key
'Tables unique to [db name:host]' - compare_table_fields
-
Simple comparison of the table fields. Returns true if no differences are found, otherwise returns undef. An array ref of fields unique to each database:host can be recovered with get_differences(), using the hash key
'Fields unique to [db name:host.table]' - compare_row_counts
-
Comparison of the row counts from each table. Can pass a table name, or will compare all tables. Returns true if no differences are found, otherwise returns undef. An array ref of tables with different row counts can be recovered with get_differences(), using the hash key
'Row count'. - get_primary_keys($table,$dbh)
-
Returns the primary keys (in key order) for the given table/database, either as a list or as a comma separated string.
- get_differences
-
Returns a hashref of differences between the two databases, where keys are the source of the difference, and values are an array ref of the differences found (see comparison methods above for details).
- get_tables
-
Returns a table list. Returns a 2D list of tables in list context, or just a list of tables in database1 in scalar context;
my @aList = $oDB_Comparison->get_tables; # returns (['table1','table2',etc],['table1','table2',etc]) my $aList = $oDB_Comparison->get_tables; # returns ['table1','table2',etc] - common_tables
-
Returns a list of tables common to both databases. Recursively cals compare_table_lists() if not already called.
- similar_tables
-
Returns a list of tables common to both databases and with identical row counts. Recursively cals compare_table_lists() and compare_row_counts() if not already called.
- field_list($table)
-
Returns a list of fields for the particular table that are common in both databases.
AUTHOR
Christopher Jones, Gynaecological Cancer Research Laboratories, UCL EGA Institute for Women's Health, University College London.
c.jones@ucl.ac.uk
COPYRIGHT AND LICENSE
Copyright 2008 by Christopher Jones, University College London
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.