[CC'd to dbi-dev]
On Sun, Feb 29, 2004 at 09:56:00PM +0100, Kristian Nielsen wrote:
> Hi Tim,
>
> Tim Bunce <[EMAIL PROTECTED]> writes:
>
> > Where did we get to with this?
>
> > > Ok, I will merge it into the new DBD::Oracle when that is out. It really
> > > needs to be made to fit better into the execute_for_fetch() and stuff in
> > > the new DBI, and I will be happy to modify it to whatever preferences
>
> What I have is a patch for DBD::Oracle 1.14. This patch contains its own
> implementation of execute_array(), based on the one in DBI 1.30.
>
> The problem with this is of course that DBD::Oracle should not implement
> execute_array itself. The way I understand it is that currently drivers
> are supposed to implement execute_for_fetch(), and DBI will use that to
> implement the higher-level execute_array() functionality.
At the end of the day it doesn't really matter so long as both work.
(Though the more that's left to the DBI the less the driver has to
keep up with as the DBI evolves.)
> I see three possibilities:
>
> 1. As you may remember, the count of bind values must be known up-front
> before calling into OCI because of OCI limitations. So to switch to the
> execute_for_fetch() approach DBD::Oracle must buffer bind tuples in
> chunks that are passed to OCI individually. This introduces the annoying
> requirement to think about the chunk size. It also introduces some
> inefficiencies in the array->tuple_fetch_sub->array conversion. However
> if this is what you prefer it would be simple for me to adapt the patch.
>
> 2. A better way might be to add an optional third parameter to
> execute_for_fetch(): the number of bind tuples. If this parameter is
> supplied, DBD::Oracle should be able to implement execute_for_fetch()
> without buffering in chunks; this would be utilised by DBI in
> execute_array() by passing the third parameter in the cases where an
> array is supplied by the programmer. If the count parameter is not
> supplied, DBD::Oracle would fall-back to buffering in chunks. The
> disadvantage of this is that I would probably have to do some work to
> adapt the patch to implement this, but I would be willing to take a shot
> if you feel this is the best solution (I think it probably is).
>
> 3. The final option would be for DBI to be extended so that it could
> somehow detect both native array execute and native execute_for_fetch()
> in the driver. It would thus detect that DBD::Oracle supports array
> execute directly, but not execute_for_fetch(). DBI would then implement
> the bind_param_array() version of execute_array() using the DBD::Oracle
> array exec functionality, but would emulate execute_for_fetch() by
> buffering tuples. Another driver might implement only execute_for_fetch(),
> and DBI would emulate bind_param_array() using that (as it currently
> does).
>
> So I would like to hear your opinion on which approach to settle on. If
> you have no strong opinions I guess we should go for method 1 since it
> needs no changes to DBI and requires the least amount of work for me...
How about this... Don't implement execute_array, just use the DBI default.
Add an execute_for_fetch() in perl that looks something like this:
sub execute_for_fetch {
my ($sth, $fetch_tuple_sub, $tuple_status) = @_;
# start with empty status array
($tuple_status) ? @$tuple_status = () : $tuple_status = [];
my ($err_count, %errstr_cache);
do { # gather into chunks calling _execute_array_chunk() on each
my $chunk = $sth->{ora_array_chunk_size} ||= 1000;
my ($tuple, @tuples);
push @tuples, $tuple while ($chunk-- && $tuple = &$fetch_tuple_sub());
$sth->_execute_array_chunk([EMAIL PROTECTED], $tuple_status, \$err_count,
\%errstr_cache);
} while ($tuple);
return ($err_count) ? undef : scalar @$tuple_status;
}
> A couple of other issues:
>
> I think there should be added to DBI an easy way to supply a row-wise
> array of bind tuples to execute_array(). In my patch I implemented this
> with an ArrayTuple attribute for execute_array().
Doesn't this count as easy?:
$ins->execute_for_fetch(sub { shift @array_of_arrays }, \my @tuple_status);
We can discuss the relative cost of the sub-call overhead once it's all
working and we can benchmark.
> There is also the issue that this will only work for Oracle >= 8.1.5.
> Any thoughts on the need to fall back to default DBI behaviour for early
> Oracle 8.x.y (this would require detecting server version)?
I think so few people would need to use it < 8.1.5 that I wouldn't
worry about that. Most users of v8 should be >= 8.1.7 by now.
> And what about OCI 7, is support for that going out?
It's gone in my current copy.
> Currently this doesn't work for returning results. I will want to add
> that later; while SELECT is maybe not so useful, it will be needed for
> stuff like
>
> INSERT INTO mytable(a,b) VALUES(mysequence.nextval, ?) RETURNING a
>
> Maybe there will be some issues here for the interface to DBI similar to
> the issues with drivers permitting multiple result sets?
No, I think it just needs some extra code in the bind_param_inout logic:
"... RETURNING foo,bar INTO :foo,:bar" # use placeholders
$sth->bind_param_inout(':foo', [EMAIL PROTECTED]);
I've put most of it's in place already, probably simple to finish off,
I just never got round to it.
Tim.
p.s. It would be great if you cuould use subversion to keep upto
date with the current DBI and DBD::Oracle source. The latest version
has this in the docs:
=head2 How to create a patch using Subversion
The DBD::Oracle source code is maintained using Subversion (a replacement
for CVS, see L<http://subversion.tigris.org/>). To access the source
you'll need to install a Subversion client. Then, to get the source
code, do:
svn checkout http://svn.perl.org/modules/dbd-oracle/trunk
If it prompts for a username and password use your perl.org account
if you have one, else just 'guest' and 'guest'. The source code will
be in a new subdirectory called C<trunk>.
To keep informed about changes to the source you can send an empty email
to [EMAIL PROTECTED] after which you'll get an email with a diff
of any changes made to the source.
After making your changes you can generate a patch file, but before
you do, make sure your source is still upto date using:
svn update http://svn.perl.org/modules/dbd-oracle/trunk
If you get any conflicts reported you'll need to fix them first.
Then generate the patch file from within the C<trunk> directory using:
svn diff > foo.patch
Read the patch file, as a sanity check, and then email it to [EMAIL PROTECTED]
=cut
The same applies to the DBI only it's http://svn.perl.org/modules/dbi
and [EMAIL PROTECTED]