Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Even though there are two separate database handles error shows need two separate database handles to compare

by Anonymous Monk
on Mar 09, 2011 at 10:23 UTC ( [id://892167]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

#!/usr/bin/perl use strict; use warnings; use DBD::SQLite; use DBI ; use DBIx::Compare; use DBIx::Compare::SQLite; my $db1="xyz1.dat"; my $dbh1=DBI->connect("DBI:SQLite:[dbname]=$db1","",""); my $db2="xyz2.dat"; my $dbh2=DBI->connect("DBI:SQLite:[dbname]=$db2","",""); my $oDB_Comparison=db_comparison->new($dbh1,$dbh2); $oDB_Comparison->compare; $oDB_Comparison->deep_compare;
In the above code i get the error message "need two database handles to compare"
  • Comment on Even though there are two separate database handles error shows need two separate database handles to compare
  • Download Code

Replies are listed 'Best First'.
Re: Even though there are two separate database handles error shows need two separate database handles to compare
by mje (Curate) on Mar 09, 2011 at 10:40 UTC

    Are you sure $dbh1 and $dbh2 are defined i.e., you connected successfully?

      I like to look at database issues but I've never used this module. It looks pretty awesome. So as curious as I was I decided to try it. In order to replicate the issue I made a little sample script. When I tried to use:

      $oDB_Comparison->deep_compare(@aTable_Names);

      I get several errors that are very familiar to me from some work with DBIx::Class. You need to have tables defined a certain way in DBIx::Class for the deep->compare to work (or so it seems to me). But you can use the basic compare without seeing the errors:

      $oDB_Comparison->compare(@tables);

      Also, unless I have this line in my code:

      $oDB_Comparison->verbose;

      no results print, so you want to add that in I think. You need to check your definition of $dbh1 and $dbh2 like mje said.

      my $dbh1 = DBI->connect('DBI:DATABASE_TYPE:DATABASE_NAME:DATABASE_SERV +ER','USERNAME','PASSWORD') || die "Error Connecting to \$dbh1: ".$DBI +::errstr."\n";

      Also see DBIx::Class

      #!/usr/bin/perl use strict; use warnings; use DBI; use DBIx::Compare; my $dbh1 = #SEE sample connect line above my $dbh2 = #SEE sample connect line above my $oDB_Comparison = db_comparison->new($dbh1, $dbh2); my @tables = ('Table1', 'Table2); $oDB_Comparison->verbose; $oDB_Comparison->compare(@tables);

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://892167]
Approved by mje
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-04-24 20:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found