in reply to How to get a placeholder to keep the current column value?
What about
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.UPDATE address SET phone = COALESCE(?, phone), street = COALESCE(?, street), zip = COALESCE(?, zip), city = COALESCE(?, city) WHERE ID=?
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: How to get a placeholder to keep the current column value?
by Anonymous Monk on Oct 26, 2003 at 22:54 UTC | |
by Jenda (Abbot) on Oct 27, 2003 at 13:25 UTC | |
Re: Re: How to get a placeholder to keep the current column value?
by giulienk (Curate) on Oct 27, 2003 at 08:07 UTC | |
Re: Re: How to get a placeholder to keep the current column value?
by liz (Monsignor) on Oct 26, 2003 at 21:55 UTC |