Skip Menu |

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

Report information
The Basics
Id: 125517
Status: open
Priority: 0/
Queue: DBD-mysql

People
Owner: Nobody in particular
Requestors: ruud.vantol [...] booking.com
Cc: pali [...] cpan.org
AdminCc:

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



Subject: missing error when a prepared statement with placeholders is executed with an empty bind
Date: Thu, 7 Jun 2018 17:39:18 +0200
To: bug-DBI [...] rt.cpan.org
From: "Ruud H.G. van Tol" <ruud.vantol [...] booking.com>
Missing error when a prepared statement with placeholders is executed with an empty bind. We now use this work-around: use DBI; use constant FAIL_ON_MYSQL_BUG_ABOUT_MISSING_ALL_PARAMETERS => 1; BEGIN { # countering a DBD::mysql bug if ( FAIL_ON_MYSQL_BUG_ABOUT_MISSING_ALL_PARAMETERS ) { no warnings "redefine"; require DBD::mysql; my $pa_key = "private_dbd_mysql_st_params"; my %orig; for my $m (qw/ prepare bind_param execute /) { $orig{ $m } = \&{"DBD::mysql::st::$m"} or die qq{can't hook DBD::mysql::st::$m}; } *DBD::mysql::st::prepare= sub { my $sth= $_[0]; $sth->{ $pa_key } = []; # initialize storage goto $orig{ prepare }; }; *DBD::mysql::st::bind_param= sub { my $sth= $_[0]; $sth->{ $pa_key }[ $_[1] - 1 ] = undef; # occupy slot goto $orig{ bind_param }; }; *DBD::mysql::st::execute= sub { my $sth= $_[0]; if ( @_ == 1 # no execute-params and my $want_num= $sth->FETCH("NUM_OF_PARAMS") ) { # must be a FETCH; may be undef # see also $sth->{ParamValues} my $have_num= @{ $sth->{ $pa_key } // [] }; if ( $have_num != $want_num ) { my $error= "called with $have_num bind variables when $want_num are needed (bug-fix)"; return $sth->set_err($DBI::stderr, $error); } } goto $orig{ execute }; }; } } -- Greetings, Ruud
On Thu Jun 07 11:41:55 2018, ruud.vantol@booking.com wrote: Show quoted text
> > Missing error when a prepared statement with placeholders is executed > with an empty bind. > > > We now use this work-around: > > use DBI; > use constant FAIL_ON_MYSQL_BUG_ABOUT_MISSING_ALL_PARAMETERS => 1; > > BEGIN { # countering a DBD::mysql bug > > if ( FAIL_ON_MYSQL_BUG_ABOUT_MISSING_ALL_PARAMETERS ) { > > no warnings "redefine"; > require DBD::mysql; > > my $pa_key = "private_dbd_mysql_st_params"; > > my %orig; > for my $m (qw/ prepare bind_param execute /) { > $orig{ $m } = \&{"DBD::mysql::st::$m"} > or die qq{can't hook DBD::mysql::st::$m}; > } > > *DBD::mysql::st::prepare= sub { > my $sth= $_[0]; > $sth->{ $pa_key } = []; # initialize storage > goto $orig{ prepare }; > }; > > *DBD::mysql::st::bind_param= sub { > my $sth= $_[0]; > $sth->{ $pa_key }[ $_[1] - 1 ] = undef; # occupy slot > goto $orig{ bind_param }; > }; > > *DBD::mysql::st::execute= sub { > my $sth= $_[0]; > if ( @_ == 1 # no execute-params > and my $want_num= $sth->FETCH("NUM_OF_PARAMS") > ) { # must be a FETCH; may be undef > # see also $sth->{ParamValues} > my $have_num= @{ $sth->{ $pa_key } // [] }; > > if ( $have_num != $want_num ) { > my $error= "called with $have_num bind variables > when $want_num are needed (bug-fix)"; > return $sth->set_err($DBI::stderr, $error); > } > } > goto $orig{ execute }; > }; > } > } > > -- Greetings, Ruud
Hi! I think that this problem should be fixed in DBD::MariaDB, fork of DBD::mysql by this pull request: https://github.com/gooddata/DBD-MariaDB/pull/22
On Tue Jun 19 08:42:18 2018, PALI wrote: Show quoted text
> On Thu Jun 07 11:41:55 2018, ruud.vantol@booking.com wrote:
> > > > Missing error when a prepared statement with placeholders is executed > > with an empty bind. > > > > > > We now use this work-around: > > > > use DBI; > > use constant FAIL_ON_MYSQL_BUG_ABOUT_MISSING_ALL_PARAMETERS => 1; > > > > BEGIN { # countering a DBD::mysql bug > > > > if ( FAIL_ON_MYSQL_BUG_ABOUT_MISSING_ALL_PARAMETERS ) { > > > > no warnings "redefine"; > > require DBD::mysql; > > > > my $pa_key = "private_dbd_mysql_st_params"; > > > > my %orig; > > for my $m (qw/ prepare bind_param execute /) { > > $orig{ $m } = \&{"DBD::mysql::st::$m"} > > or die qq{can't hook DBD::mysql::st::$m}; > > } > > > > *DBD::mysql::st::prepare= sub { > > my $sth= $_[0]; > > $sth->{ $pa_key } = []; # initialize storage > > goto $orig{ prepare }; > > }; > > > > *DBD::mysql::st::bind_param= sub { > > my $sth= $_[0]; > > $sth->{ $pa_key }[ $_[1] - 1 ] = undef; # occupy slot > > goto $orig{ bind_param }; > > }; > > > > *DBD::mysql::st::execute= sub { > > my $sth= $_[0]; > > if ( @_ == 1 # no execute-params > > and my $want_num= $sth->FETCH("NUM_OF_PARAMS") > > ) { # must be a FETCH; may be undef > > # see also $sth->{ParamValues} > > my $have_num= @{ $sth->{ $pa_key } // [] }; > > > > if ( $have_num != $want_num ) { > > my $error= "called with $have_num bind variables > > when $want_num are needed (bug-fix)"; > > return $sth->set_err($DBI::stderr, $error); > > } > > } > > goto $orig{ execute }; > > }; > > } > > } > > > > -- Greetings, Ruud
> > Hi! I think that this problem should be fixed in DBD::MariaDB, fork of > DBD::mysql by this pull request: > https://github.com/gooddata/DBD-MariaDB/pull/22
That fix is part of DBD::MariaDB 1.00 which is now on cpan: https://metacpan.org/pod/DBD::MariaDB