Gabriel S. Oliveira wrote:
> Hello I'm having a trouble with a dbi statement if anyone could help me...
> 
> I have to do an update in a table like:
> 
> $dbh->do(qq{UPDATE foos SET $new_foo = $old_foo});
> 
> when i use this statement all works fine but when i use placeholders like:
> 
> $dbh->do(qq{UPDATE foos SET $new_foo = ?}, undef, $old_foo);
> 
> i get zeros in the entire column.
> 
> any clue about this?

The statements should have identical results. Assuming $old_foo == zero,
both statements will set the column named by $old_foo to zero for
*all* rows in table 'foos'.

However, your choice of variable names suggests you may be confused
between column names and column values, since you use $new_foo to
refer to a column *name*, and $old_foo to refer to a column *value*.

You may be really trying to do this:

  UPDATE foos SET <column> = <new-value>
  WHERE <column> = <old-value>;

In any event, without a WHERE clause, an UPDATE statement will always
update every row in the table, which is what your statements are doing.
The use, or non-use, of bind variables has no effect on that.

Mark

Reply via email to