perl.dbi.dev
[Top] [All Lists]

Re: [patch] (final) DBD::Oracle - Support for standard array binds.

Subject: Re: [patch] (final) DBD::Oracle - Support for standard array binds.
From: Tim Bunce
Date: Mon, 10 Sep 2007 22:03:03 +0100
Newsgroups: perl.dbi.dev

On Mon, Sep 10, 2007 at 02:27:31PM +0400, Alexander V Alekseev wrote:
> >>    Forgot to attach DBI patch, though I already sent it to the
> >>list. Patch is attached just to keep everything needed in a single list
> >>thread.
> >
> >And, for the same reason, I'll restate that the DBI patch is neither
> >needed nor appropriate. bind_param_inout() takes a reference to the
> >value. In this case that value is also a reference. All is well.
> 
>       From my example:
>       $sth->bind_param_inout(":mytable", \@arr1, 10, {
>                       TYPE => DBD::Oracle::ORA_VARCHAR2,
>                       ora_maxarray_numentries => 100 } );

[TYPE is for specifying ISO-CLI/ODBC standard TYPE values, i.e. those
SQL_* constants like SQL_VARCHAR, SQL_INTEGER etc. So either use
TYPE => SQL_VARCHAR, or ora_type => TYPE => DBD::Oracle::ORA_VARCHAR2.]

> Here, "\@arr1" is a reference, but standard DBI declines it
> as a reference to array. It accepts only reference to scalar.
> Without change, user would have to:
> 
>       my @arr1;
>       my $ref1=\@arr1;
>       my $ref2=\$ref1;
> 
>       $sth->bind_param_inout(":mytable", $ref2 , 10 , ... )

There's no need for all that. You could just do this:

        $sth->bind_param_inout(":mytable", \\@arr1 , 10 , ... )

> Don't you think, it's better to use the first format ?

It's not really a question of one backslash vs two. It's more a question
of the principle behind the design of the API. Consistency trumps beauty
in the long run.

Annoyingly for me I can argue it both ways in this case.
Here's a question for you: what happens when the returnd value is NULL?
How can you distinguish that from an empty array?

With the current API you could do this:

        $sth->bind_param_inout(":mytable", \my $ary = \@arr1 , 10 , ... )
        die "got null" if !$ary;

(I'll admit I've made that rather terse, but that's not the point here.)

Tim.

<Prev in Thread] Current Thread [Next in Thread>