On Mon, Nov 11, 2002 at 03:24:10PM -0800, Pete Leonard wrote:
> 
> I'm installing DBD::Pg 1.13 on a new box, and it's not passing 3 tests in
> 04execute.t, which tests bind behavior.  Tests # 5 & 6 are simply
> broken tests (expected results are backwards, fixes are in the patch file
> at the bottom of this email).
> 
> #7 brings up bigger questions- 
> 
> The test, as it reads:
> 
>     eval {
>       local $dbh->{PrintError} = 0;
>         $sth = $dbh->prepare(q{
>             SELECT id
>                  , name
>               FROM test
>              WHERE id = ?
>                AND name = ?
>         });
>         $sth->execute();
>     };
>     if ($@) {
>         print "ok $n\n"; $n++;
>     } else {
>         print "not ok $n\n"; $n++;
>     }

I'd recommend that t/*.t scripts use the Test module to implement tests.

> This should throw a big wonking error, as no values have been attached to
> the placeholders.  It doesn't.  Re-running this test with DBI->trace(2)
> shows that instead of crapping out, it re-assigns values of NULL, and runs
> the query:

> So here's the question - is this standard operating procedure for DBI/DBD,
> to rewrite missing bind vars as undef, and therefore NULL in the SQL?

No. If _no_ parameters are passed to execute() then the previously
bound values (eg from bind_param or an earlier execute(...) with params)
should be used.

> If not, what is expected behavior?

Fail with a placeholder value not bound error.

> Should undef be getting rewritten as NULL?

Yes.

> should execute(undef,undef) be legal, but crap out on execute()?

No. $sth->execute(undef,undef) is fine if the statement has two placeholders.
But $sth->execute() for the same statement is only valid if $sth->bind_param()
has been called at least once for each placeholder.

Also, I see that DBD::Pg is not using the Driver.xst template provided
by the DBI. That's not good. In fact these days that's actually bad.
I'd go so far as to say that any compiled driver not using Driver.xst
is unlikely to be behaving correctly. It's also missing out on the new
high-performance implementations of fetchall_arrayref etc.

I would urge DBD::Pg maintainers (and any other compiled driver authors
not using Driver.xst) to switch to using it ASAP.

Tim.

Reply via email to