Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
The stupid question is the question not asked
 
PerlMonks  

Re: Seeking a non-quoted DBI placeholder

by runrig (Abbot)
on Jan 29, 2001 at 22:12 UTC ( [id://55123]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Seeking a non-quoted DBI placeholder

No, you cannot, in general (nor anywhere that I know of) use placeholders for column names in a sql statement. It is a good idea to use placeholders everywhere that you can, though. Here's one idea for a variable number of columns:
my %columns = (field1=>"value1", field2=>"value2"); my $sql_stmt = "update my_table ".column_list(\%columns). " where id_field = ?"; my $sth = $dbh->prepare($sql_stmt); $sth->execute(values %columns, $id_field); sub column_list { join(" ", map {"$_=?"} keys %{$_[0]}); }
Of course, arturo's answer below is perfectly good also for substituting one or any constant number of column names :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://55123]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.