http://www.perlmonks.org?node_id=302267


in reply to How to get a placeholder to keep the current column value?

What about

UPDATE address SET phone = COALESCE(?, phone), street = COALESCE(?, street), zip = COALESCE(?, zip), city = COALESCE(?, city) WHERE ID=?
This way the SQL is static, can be prepared and if you pass an undef for some field it'll keep the old value. Of course this would not work if you did want to be able to set some fields to NULL, but otherwise this seems to be a nice solution.

P.S.: I have never worked with MySQL so I'm not sure there is a COALESCE() function there. It's supposed to return the first non-NULL parameter.

Jenda
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
   -- Rick Osborne

Edit by castaway: Closed small tag in signature