|Problems? Is your data what you think it is?|
How to get a placeholder to keep the current column value?by liz (Monsignor)
|on Oct 26, 2003 at 09:23 UTC||Need Help??|
liz has asked for the
wisdom of the Perl Monks concerning the following question:
While I'm (finally) getting to grips with using DBI placeholders, I realise that there may be one situation where placeholders are not the solution.
The situation: I'm writing an XML to RDBMS Perl layer that should allow my customer to use XML to update records in a database. For each type of information (e.g. address information), there are a number of expected nodes in the XML that correspond to columns in a table in the database. For example, a complete description of a record would be:
Now, when the customer supplies the following XML:
I want it to update just the "phone" column for that record in the database.
Now, at least in MySQL you can put the following in the SQL to indicate you don't want to change the value of a column. For example: the "street", "zip" and "city" fields.:
so in principle this should allow you to do a prepare once because the query would always be the same. Only those fields that you don't want changed, get their field name replaced rather than an actual value.
However, it seems to me that it is not possible to do this using placeholders, as you can only specify values with placeholders, rather than a name of the column.
Of course, I could always fetch the old values from the record in the database first, but I feel that sort of defeats the purpose. Or would it?
Anyway, my question: can I use placeholders in case I don't want to change the value of a column, without obtaining the old value from the record first?