Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Flexible Update SQL

by PeterPeiGuo (Hermit)
on Dec 02, 2010 at 00:58 UTC ( [id://874790]=note: print w/replies, xml ) Need Help??

in reply to Flexible Update SQL

Look up "sql place holder". The query should really be written with placeholders similar to the following:

my $sql = "UPDATE table SET phone = ?, city = ?"

Peter (Guo) Pei

Replies are listed 'Best First'.
Re^2: Flexible Update SQL
by bichonfrise74 (Vicar) on Dec 02, 2010 at 01:14 UTC
    But this does not solve the problems:
  • passing null parameters...
  • placement of the comma...


      Actually, placeholders *do* handle the null parameter. Constructing the update statement can do the rest...

      my @fields = qw(name phone city country); my $SQL = "update table set " . join(", ", map { "$_=?" } @fields) . "where ...."; my $ST=$DB->prepare($SQL); while (...) { my @values = (.....); $ST->execute(@values); }


      When your only tool is a hammer, all problems look like your thumb.

Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-04-18 21:00 GMT
Find Nodes?
    Voting Booth?

    No recent polls found