Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: DBI Prepared Update and NULLs

by lhoward (Vicar)
on Jul 28, 2004 at 20:09 UTC ( #378191=note: print w/replies, xml ) Need Help??


in reply to DBI Prepared Update and NULLs

You could build your update statment dynamically, and prepare it using prepare_cached. That way its only prepared once (for each variation), and you can still take good advantage of placeholders. This is not the tightest example, and is untested, but should serve its purpose:
my %col; $col{foo}=1; $col{bar}=undef; my %vbph; my @vbval; foreach(sort keys %arg){ if(defined $arg{$_}){ $vbph{$_}='?'; push @vbval,$arg{$_}; }else{ $vbph{$_}='NULL'; } } my $sql='update baz set '. join ', ',(map{$_.'='.$vb{$_}} sort keys %arg)); my $sth=$dbh->prepare_cached($sql); $sth->execute(@vbval);

Replies are listed 'Best First'.
Re^2: DBI Prepared Update and NULLs
by paulbort (Hermit) on Jul 28, 2004 at 20:58 UTC
    Thanks for the suggestion, I'll read up on prepare_cached. I know I can build the statement dynamically, that is what I've done on at least one previous occasion, but I thought that it really should work this way, so I'm trying to figure out what I'm doing wrong.

    --
    Spring: Forces, Coiled Again!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://378191]
help
Chatterbox?
[LanX]: unusual that "Pimp my Bride" never made it into TV (?)
LanX sighs ... no idea stupid enough
[choroba]: "Smack My Bitch Up" did, though
[Eily]: that's the internet for you LanX
[Eily]: and I'm pretty sure there's a rule somewhere that states that the stupider the idea, the more likely it is to already have been done
zentara is thinking of moving to Mars to esacpe it all

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (14)
As of 2017-03-27 15:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (320 votes). Check out past polls.