On Fri, Apr 02, 2004 at 12:42:50AM -0500, Rudy Lippan wrote:
>
> I just revied the ParamValues docs, and it reminded me of a question I had
> WRT ParamValues and prepared statements.
>
> The docs say:
>
> It is possible that the values in the hash returned by "ParamVal-
> ues" are not exactly the same as those passed to bind_param() or
> execute(). The driver may have modified the values in some way
> based on the TYPE the value was bound with. For example a floating
> point value bound as an SQL_INTEGER type may be returned as an
> integer.
>
> Now, in DBD::mysql I change the behaviour of bind_param() depending on
> whether server-side prepared statements are enabled. If they are
> enabled there is no quoting of the string passed into bind_param() because
> it gets passed directly to mysql_bind_params() at execute time, but when
> server-side prepared statements are disabled I call quote() based on the
> bind type and tuck that away to be used at execute time. This obviously
> keeps the driver from having to requote bind params every time execute is
> called.
>
> But all of this means that strings in $sth->{ParamValues} vary depending
> on whether server-side prepare is enabled. If enabled you get the string
> you passed it, if disabled you get the quoted string back.
>
> Is this acceptable?
No! The values in ParamValues must not be modified in that way.
I've added this to the docs: "The values returned by C<ParamValues>
can be passed to another bind_param() method with the same TYPE and
will be seen by the database as the same value."
In other words this should return true:
$sth = $dbh->prepare("SELECT 1 WHERE ? = ?");
$sth->bind_param(1, "don't");
$sth->bind_param(2, $sth->{ParamValues}->{1});
$sth->execute;
$same = $sth->fetchrow_array;
Okay?
> Ps. I am reading the subversion book, and it looks pretty simple ;)
It is! Practically trivial. Highly recommended.
Tim.