Skip Menu |

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

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

People
Owner: Nobody in particular
Requestors: rob.kinyon [...] progressive-medical.com
Cc:
AdminCc: stevan.little [...] gmail.com

Bug Information
Severity: Important
Broken in: 0.11
Fixed in: (no value)



Subject: prepare_cached doesn't affect mock_all_history when retrieving cached query
prepare_cached() doesn't work like prepare() does in affecting history. I suspect that you will need to trap calls to prepare_cached() and do similar work as you do in prepare(). This is important because prepare_cached() looks at the statement, not the parameters. So, I might run the same SQL with different parameters, but the StatementTracker will track all parameters bound to that statement for all executions of that statement. (In the tests below, the last test fails because the StatementTracker has both 1 and 2 as bound parameters.) I'm not quite sure what the fix is. The inuitive thing, in my eyes, would be to essentially disable caching and have prepare_cached() be an alias for prepare(). Adding the following to line 187 passes the tests below: *prepare_cached = \&prepare; ------------ use Test::More no_plan => 1; use DBI; my $dbh = DBI->connect( 'dbi:Mock:', '', '' ); foreach my $i ( 1 .. 2 ) { my $sth = $dbh->prepare( 'SELECT foo FROM bar WHERE x = ?' ); $sth->execute( $i ); my $history = $dbh->{mock_all_history}; ok( @$history == $i, "Have $i statement executions" ); } $dbh->{mock_clear_history} = 1; my $history = $dbh->{mock_all_history}; ok( @$history == 0, "History is cleared" ); foreach my $i ( 1 .. 2 ) { my $sth = $dbh->prepare_cached( 'SELECT foo FROM bar WHERE x = ?' ); $sth->execute( $i ); my $history = $dbh->{mock_all_history}; ok( @$history == $i, "Have $i statement executions" ); } my $sth = $dbh->{mock_all_history}->[0]; ok( $sth->statement eq 'SELECT foo FROM bar WHERE x = ?' ); my $params = $sth->bound_params; ok( @$params == 1 );
Fixed by Stevan as recommended in the report.