Re: [rt.cpan.org #36395]



On 2008-07-01 01:37:01 -0400, Ramesh Thangamani via RT wrote:
Queue: DBI
Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=36395 >

On Tue Jun 24 17:17:23 2008, TIMB wrote:
The DBI is acting as defined. It's not a bug.
You should avoid using an array to pass arguments to execute().

I could still see the following examples mentioned in the documentation
in CPAN where we are passing an array to execute method(). Please
comment on this.

$rv = $sth->execute or die $sth->errstr;
$rv = $sth->execute(@bind_values) or die $sth->errstr;

Which means that exeute takes a list of bind values. It doesn't
necessarily mean that it is good style to use an actual array.

But I disagree with Tim here. There are many situations where using an
array is the right thing to do - especially if you are constructing sql
statements with a variable number of placeholders on the fly it is IMHO
the only sane way.

I think it is unfortunate that execute with zero parameters means
something different from execute with non-zero parameters and that there
is no way to distinguish zero parameters from an array with with zero
elements, but that can't be helped: Changing the former would break lots
of existing code, and the latter is a fundamental property of Perl5.

In practice I've never run into this problem. While I have occassionally
constructed queries where the number of placeholders and the size of the
array were not equal, I don't remember ever ending up with an empty
array. I did forget the parameter list a few times (i.e., $sth->execute
instead of $sth->execute($x, $y)) ...

hp

--
_ | Peter J. Holzer | If I wanted to be "academically correct",
|_|_) | Sysadmin WSR | I'd be programming in Java.
| | | hjp@xxxxxxxxx | I don't, and I'm not.
__/ | http://www.hjp.at/ | -- Jesse Erlbaum on dbi-users

Attachment: pgpNHjqcsga30.pgp
Description: PGP signature



Relevant Pages

  • Re: dynamic memory allocation in subroutines
    ... it merely gives the array x zero size. ... And silly as it might seem at first glance (why ... code might need zero parameters. ...
    (comp.lang.fortran)
  • Re: I dont understand the definition of DOES>
    ... on stack on code entry). ... You can use DOES to make ARRAY and then use ARRAY ... CREATE CELLS ALLOT ... First you'd make the code that will execute on the child word. ...
    (comp.lang.forth)
  • Re: Special characters and superscripts in PostScript and EPS
    ... When does one use bind def and load def? ... what you actually are doing is creating an executable array on the stack ... When you execute the array, if it contains any names the interpreter ... The 'load' operator searches dictionaries looking for a named value. ...
    (comp.lang.postscript)
  • Re: Space leak in Haskell code
    ... prettiness, here's another solution. ... It's 2-3 times slower than C++, ... code the recursion in execute'. ... access the array, or using unsafeAt, but the first won't work in my ...
    (comp.lang.functional)
  • Re: Code wont execute Main Macro Calls - non breaking spaces
    ... I am going to attach my first array which is the same as you have ... So each macro will execute one after the other. ... separated each find string and each replace string for the sake of ...
    (microsoft.public.word.vba.general)