Skip Menu |

This queue is for tickets about the DBD-Mock CPAN distribution.

Report information
The Basics
Id: 68101
Status: resolved
Priority: 0/
Queue: DBD-Mock

People
Owner: Nobody in particular
Requestors: RWSTAUNER [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.39
Fixed in: 1.48



Subject: table_info not defined (returns undef)
DBD::Mock::db::table_info is not defined. Code that calls it throws this error: qq[Can't call method "fetchall_arrayref" on an undefined value]. defining a simple sub that calls $_[0]->prepare seems to do the trick. I don't know a lot about DBI internals and what should be defined... There's likely a more appropriate way to make a fake statement handle but the attached patch works for me. For now I'm defining the method dynamically in my test code which also works: local *DBD::Mock::db::table_info = sub { $_[0]->prepare('SELECT table_info()'); };
Subject: table_info.patch
--- release/DBD/Mock.pm 2010-12-01 15:14:12.000000000 -0700 +++ table_info/DBD/Mock.pm 2011-05-10 14:57:39.000000000 -0700 @@ -398,6 +398,11 @@ return [ map { @$_[@cols] } @{$a_ref} ] } +sub table_info { + my ( $dbh, $cat, $sch, $tab, $typ ) = @_; + $dbh->prepare('SELECT * FROM "table_info"'); +} + sub FETCH { my ( $dbh, $attrib, $value ) = @_; $dbh->trace_msg( "Fetching DB attrib '$attrib'\n" );
On Tue May 10 18:13:46 2011, RWSTAUNER wrote: Show quoted text
> DBD::Mock::db::table_info is not defined. > Code that calls it throws this error: > > qq[Can't call method "fetchall_arrayref" on an undefined value]. > > defining a simple sub that calls $_[0]->prepare seems to do the trick. > I don't know a lot about DBI internals and what should be defined... > There's likely a more appropriate way to make a fake statement handle > but the attached patch works for me. > > For now I'm defining the method dynamically in my test code > which also works: > > local *DBD::Mock::db::table_info = sub { $_[0]->prepare('SELECT > table_info()'); };
Hi, I've recently picked up support for DBD::Mock and had a look at this table_info issue. It's a bit belated, but a new experimental feature for mocking DBI's table_info calls has been added to DBD::Mock's codebase and will be available when the next version is released (v1.48). In the meantime feel free to have a look at the current development version of the codebase at https://gitlab.com/scrapheap/DBD-Mock (any comments on the new functionality greatly appreciated). Regards, Jason.
On Tue Sep 10 11:09:27 2019, JLCOOPER wrote: Show quoted text
> Hi, > I've recently picked up support for DBD::Mock and had a look at this > table_info issue. It's a bit belated, but a new experimental feature > for mocking DBI's table_info calls has been added to DBD::Mock's > codebase and will be available when the next version is released > (v1.48). > > In the meantime feel free to have a look at the current development > version of the codebase at https://gitlab.com/scrapheap/DBD-Mock (any > comments on the new functionality greatly appreciated). > > Regards, > Jason.
Hi, DBD::Mock v1.48 was released at the end of last week (quickly followed by v1.49 that resolved some issues with old Perl versions). The new experimental table_info feature was included in the release so I'll close this case, but if you encounter any issues with it then open a new case and I'll take another look at it. Regards, Jason.