On Thu, Sep 06, 2007 at 07:28:23PM +0400, Alexander V Alekseev wrote:
> Hello!
>
> It would be great if I could do:
>
> $sth->bind_param_inout(":mytable1", [EMAIL PROTECTED], 100, { TYPE =>
> DBD::Oracle::ORA_VARCHAR2 } );
>
> But autogenerated code from DBD prohibits array reference binds.
>
> void
> bind_param_inout(sth, param, value_ref, maxlen, attribs=Nullsv)
> SV * sth
> SV * param
> SV * value_ref
> IV maxlen
> SV * attribs
> CODE:
> {
> IV sql_type = 0;
> D_imp_sth(sth);
> SV *value;
> if (!SvROK(value_ref) || SvTYPE(SvRV(value_ref)) > SVt_PVMG)
> croak("bind_param_inout needs a reference to a scalar value");
> value = SvRV(value_ref);
> if (SvREADONLY(value))
> croak("Modification of a read-only value attempted");
> But it would be great to bind arrays inout. What is the proper way
> to allow array bind?
My first thought was to allow a reference to an array to be passed in,
as you're trying to do. After some more thought I've decided it's not
needed.
Consider this example of how a script might use bind_param and bind_param_inout:
$foo = 42;
$sth->bind_param(":foo", $foo);
$sth->bind_param_inout(":foo", \$foo);
note that bind_param_inout is passed a reference because it will
overwrite the referenced value with a new one. Hence the check that
it's not a read-only value.
Now consider this example:
$foo = [ 42 ];
$sth->bind_param(":foo", $foo);
$sth->bind_param_inout(":foo", \$foo);
The kind of value has changed but bind_param_inout() is still passed a
reference to that value for the same reason: it may modify it.
Tim.