DBD::Mock and Class::DBI

[prev] [thread] [next] [Date index for 2005/03/05]

From: Greg Matheson
Subject: DBD::Mock and Class::DBI
Date: 11:05 on 05 Mar 2005
I'm trying to test my Class::DBI modules with DBD::Mock. I think
they have similar philosophies of abstracting the databases.

This is my test code:

	my $dbh = Rp::DBI->db_Main;
	
	my @players = (
	        [ 'indexn', 'classid', 'name', 'score' ],
	        [ 1, 9230103, 'Jeff', 0 ]
	);
	$dbh->{mock_add_resultset} = \@players;    # add players resultset
	
	my $player = Rp::Players->retrieve(1);
	
I define db_Main earlier on to use dbd::Mock 

        return DBI->connect('dbi:Mock:', '', '',
                        {
                                # defaults of Class::DBI
                                RaiseError                  => 1,
                                AutoCommit                 => 0,
                                PrintError                 => 0,
                                Taint                       => 1,
                                RootClass                   => "DBIx::
+ContextualFetch",
                                ChopBlanks                   => 1
				                        }

I am getting this error:

  DB<8>
Rp::Players can't SELECT indexn
FROM   players
WHERE  indexn = ?
: Assertion i == (((((SV *) (name_av))->sv_flags & 0x00008000)) ? Perl_mg_size((
(PerlInterpreter *)pthread_getspecific((*Perl_Gthr_key_ptr(((void *)0))))), (SV
*) name_av) : ((XPVAV*) (name_av)->sv_any)->xav_fill)+1 failed: file "DBI.xs", l
ine 1642 at /usr/lib/perl5/site_perl/5.8.5/DBD/Mock.pm line 487.
 at t/addrpscore.t line 45
 at /usr/lib/perl5/site_perl/5.8.5/Class/DBI.pm line 233
        Class::DBI::_croak('Rp::Players', 'Rp::Players can\'t SELECT indexn\x{a}
FROM   players\x{a}WHERE  indexn...', 'err', '') called at /usr/lib/perl5/site_p
erl/5.8.5/Class/DBI.pm line 1128
        Class::DBI::sth_to_objects('Rp::Players', 'DBIx::ContextualFetch::st=HAS
H(0xa1c9554)', 'ARRAY(0xa1c71d4)') called at /usr/lib/perl5/site_perl/5.8.5/Clas
s/DBI.pm line 1093
        Class::DBI::_do_search('Rp::Players', '=', 'indexn', 1) called at /usr/l
ib/perl5/site_perl/5.8.5/Class/DBI.pm line 1071
        Class::DBI::search('Rp::Players', 'indexn', 1) called at /usr/lib/perl5/
site_perl/5.8.5/Class/DBI.pm line 681
        Class::DBI::retrieve('Rp::Players', 1) called at t/addrpscore.t line 45
Debugged program terminated.  Use q to quit or R to restart,
  use O inhibit_exit to avoid stopping after program termination,
  h q, h R or h O to get additional info.
  DB<8>

The relevant method of DBD/Mock.pm, FETCH is testing lots of attributes
passed to the method:

NAME, NUM_OF_FIELDS, NUM_OF_PARAMS, TYPE, Active, and then
those  where $attrib !~ /^mock/, 
before testing those which do start with mock.

The error at line 487 is occuring with the test of $attrib !~ /^mock/, 

My guess that DBD::Mock would need to special case the attributes
Class::DBI is feeding to it. Do you think this is so?

        -- 
        Greg Matheson, Taiwan

DBD::Mock and Class::DBI
Greg Matheson 11:05 on 05 Mar 2005

Generated at 20:12 on 07 Mar 2005 by mariachi v0.52