[CDBI] Class::DBI::MockDBD (was C::DBI and DBD::Mock problem)
"Aaron Trevena" <[email protected]> Thu, 29 Mar 2007 04:22:56 +0100
| Newsgroups | gmane.comp.lang.perl.modules.class-dbi |
|---|---|
| Message-ID | <[email protected]> |
Hi All,
I now have DBD::Mock and Class::DBI working together :)
You need to over-ride sth_to_objects to use fetchrow_hashref instead
of bind_columns/fetch.
Also remember to populate the results first otherwise you get odd and
misleading errors.
To make it all much easier I'm bundling up the package I've built as
Class::DBI::MockDBD and putting it on CPAN.. the interface looks like
this :
In your ::DBI superclass :
"use base qw(Class::DBI::MockDBD);"
Your classes won't need a single line of code changed (with any luck)
In your test :
###############################
use ClassName;
# set up result
ClassName->next_result([ [qw/foo_id foo_name foo_bar/],[1,'aaaa','bbbb',]...]);
# run query
my $iterator = ClassName->search(...);
# get sql and params for query
my $sql = ClassName->last_query_info('statement');
my $params = ClassName->last_query_info('params');
#############################
I'll be uploading it to CPAN tomorrow once it's packaged up and meets
basic Koala Tea standards.
A.
--
http://www.aarontrevena.co.uk
LAMP System Integration, Development and Hosting