Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Keep It Simple, Stupid
 
PerlMonks  

Re: DBI execute is not failing when placeholder values are not supplied

by Arguile (Hermit)
on Oct 24, 2001 at 19:59 UTC ( #121155=note: print w/ replies, xml ) Need Help??


in reply to DBI execute is not failing when placeholder values are not supplied

Actually it shouldn't throw an error, here's why:

@ARGV == ()

Yep, that's the entire reason.

If you don't pass anything on the command line @ARGV is an empty list. Databases allow NULL values and DBI represents a NULL as undef. When DBI evaluates @ARGV it autovivifies as many parameters as it needs. So what you're actually doing is binding NULL (undef) to each parameter.

Update:

Oops.. or according to runrig I could be entirely wrong.... Hehe (or maybe not entirely).

Update 2:

Well it appears DBD::Pg, DBD::mysql, and DBD::ODBC must all be off then. I just went through and tested them. In each case NULL was being bound to the parameters. But passing a list with even just undef in it throws an error. I guess that means autoviv isn't taking place? (Heh, I should have stuck with just admining DBMSs)
#!/usr/bin/perl -w use strict; use DBI; my $dbh = DBI->connect('dbi:connect_sting', 'user', 'pass', {RaiseErro +r => 1}); my $sth = $dbh->prepare('insert into foo (bar, qux) values (?,?)'); $sth->execute( () ); $sth->finish; $dbh->disconnect;


Comment on Re: DBI execute is not failing when placeholder values are not supplied
Select or Download Code
Re: Re: DBI execute is not failing when placeholder values are not supplied
by runrig (Abbot) on Oct 24, 2001 at 20:08 UTC
    When DBI evaluates @ARGV it autovivifies as many parameters as it needs.

    Not true. (And since I'm posting this after your update, yes, you are wrong :-)
    When I do $sth->execute(@ARGV) with an empty @ARGV to a DBD::Oracle prepared statement with a placeholder, I get an Oracle error.

    Update:Well, I guess that's the way some of 'em do it. But that won't stop me from this:

    <rant>That's a silly-ass way of doing it! undefined != missing - they're all wrong IMNSHO! Whack'em all over the head w/a clue-by-four!</rant>
    :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://121155]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2014-04-20 22:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (488 votes), past polls