Skip Menu |

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

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

People
Owner: Nobody in particular
Requestors: sav [...] nevoobrazimo.ru
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 1.48



Subject: Bug with Regex in DBD::Mock::Session
Date: Tue, 25 Dec 2012 16:11:22 +0200
To: bug-DBD-Mock [...] rt.cpan.org
From: Vitaliy Salnik <sav [...] nevoobrazimo.ru>
Hi, I has found the bug in the method _verify_bound_param of DBD::Mock::Session When I have regexp param in my bound_params I got error. for example: $mock_session = DBD::Mock::Session->new('my_session' => ( { statement => qr/^INSERT INTO bill/, bound_params => [10.00, 'RUB', qr/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/, 0, 'notpayed', 'bank', 12.00, qr/[a-f0-9]{32}/i], results => [['rows'], []], }, )); I got error: DBI Exception: DBD::Mock::st execute failed: Session Error: Bound param 2 do not match in current state in DBD::Mock::Session (my_session) because in the method _verify_bound_param you always check param as scalar after check it as regex
On Tue Dec 25 09:11:35 2012, sav@nevoobrazimo.ru wrote: Show quoted text
> I has found the bug in the method _verify_bound_param of > DBD::Mock::Session > When I have regexp param in my bound_params I got error.
This bug was introduced in 1.45 by commit 84beb7e, in the long journey to finally resolve ticket #71438. I guess the saga is not over yet. :) Here's a simple patch for this bug. (I lazily hijacked an existing test instead of creating one from scratch.)
Subject: 0001-Properly-handle-Regexp-bound_params.patch
From 3878958ea641bf0ade6a32eb7971fb29315be10b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Bri=C3=A8re?= <fbriere@fbriere.net> Date: Wed, 13 Mar 2013 13:59:33 -0400 Subject: [PATCH] Properly handle Regexp bound_params (This fixes a bug introduced by commit 84beb7e.) --- lib/DBD/Mock/Session.pm | 26 ++++++++++++++------------ t/022_DBD_Mock_Session_bound_params.t | 2 +- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/DBD/Mock/Session.pm b/lib/DBD/Mock/Session.pm index 912f36b..c1aff16 100644 --- a/lib/DBD/Mock/Session.pm +++ b/lib/DBD/Mock/Session.pm @@ -171,18 +171,20 @@ sub _verify_bound_param { my $ref = ref $expected; - if ( $ref eq 'Regexp' and $got !~ /$expected/ ) { - die "Bound param $index do not match (using regexp) " - . "in current state in DBD::Mock::Session ($self->{name})" - . " got: $got\n" - . " expected: $expected"; - } - - if ( $got ne $expected ) { - die "Bound param $index do not match " - . "in current state in DBD::Mock::Session ($self->{name})\n" - . " got: $got\n" - . " expected: $expected"; + if ( $ref eq 'Regexp' ) { + if ( $got !~ /$expected/ ) { + die "Bound param $index do not match (using regexp) " + . "in current state in DBD::Mock::Session ($self->{name})" + . " got: $got\n" + . " expected: $expected"; + } + } else { + if ( $got ne $expected ) { + die "Bound param $index do not match " + . "in current state in DBD::Mock::Session ($self->{name})\n" + . " got: $got\n" + . " expected: $expected"; + } } } diff --git a/t/022_DBD_Mock_Session_bound_params.t b/t/022_DBD_Mock_Session_bound_params.t index 669f575..cba71fd 100644 --- a/t/022_DBD_Mock_Session_bound_params.t +++ b/t/022_DBD_Mock_Session_bound_params.t @@ -19,7 +19,7 @@ BEGIN { }, { statement => 'SELECT bar FROM foo WHERE baz = ?', - bound_params => [ 125 ], + bound_params => [ qr/^125$/ ], results => [[ 'bar' ], [ 15 ]] }, )); -- 1.7.10.4
On Wed Mar 13 14:10:00 2013, FBRIERE wrote: Show quoted text
> On Tue Dec 25 09:11:35 2012, sav@nevoobrazimo.ru wrote:
> > I has found the bug in the method _verify_bound_param of > > DBD::Mock::Session > > When I have regexp param in my bound_params I got error.
> > This bug was introduced in 1.45 by commit 84beb7e, in the long journey > to finally resolve ticket #71438. I guess the saga is not over yet. :) > > Here's a simple patch for this bug. (I lazily hijacked an existing test > instead of creating one from scratch.)
Hi, I've recently picked up support for DBD::Mock and I've pulled your fix into the DBD::Mock codebase - so it'll go live with the next release (1.48). It's a little belated, but thanks for the work on this. Regards, Jason.
On Fri Sep 06 10:47:00 2019, JLCOOPER wrote: Show quoted text
> On Wed Mar 13 14:10:00 2013, FBRIERE wrote:
> > On Tue Dec 25 09:11:35 2012, sav@nevoobrazimo.ru wrote:
> > > I has found the bug in the method _verify_bound_param of > > > DBD::Mock::Session > > > When I have regexp param in my bound_params I got error.
> > > > This bug was introduced in 1.45 by commit 84beb7e, in the long > > journey > > to finally resolve ticket #71438. I guess the saga is not over yet. > > :) > > > > Here's a simple patch for this bug. (I lazily hijacked an existing > > test > > instead of creating one from scratch.)
> > Hi, > I've recently picked up support for DBD::Mock and I've pulled your > fix into the DBD::Mock codebase - so it'll go live with the next > release (1.48). > > It's a little belated, but thanks for the work on this. > > 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 fix that resolves this issue was included in the release, so I'll close this case. If you find any problems with the fix then feel free to reopen this case and I'll take another look at it. Regards, Jason.