Kevman has asked for the wisdom of the Perl Monks concerning the following question:


Hi Monks,

A question.

I have some code where Im using Bind variables in an update.

Ive built the code with a bit of sql such as

UPDATE table

SET value = 'X'

WHERE field1 = ?

AND field2 = ?

AND field3 = ?

Now I fill this in with $sth->execute(@array).

This doesnt seem to update any rows.

Yet when I cut and past the array values into sql works???

Is this something to do with nulls or what?????

Sorry if a bit vague, but not sure where problem is???

Kevman

Replies are listed 'Best First'.
Re: DBI + Binds?
by tomhukins (Curate) on May 27, 2002 at 15:43 UTC
    You don't mention whether you're checking for errors. The DBI documentation suggests you use $rv = $sth->execute(@bind_values) or die $sth->errstr; to throw an error if your query fails.
Re: DBI + Binds?
by mephit (Scribe) on May 27, 2002 at 17:21 UTC
    Don't forget about the DBI->trace() method. If you set the trace to level 2 or higher, you can see the statement after the bind values are inserted. That might help to identify any problems. You figured this particular problem out, so keep the trace() method in mind the next time you run into problems.

    --

    There are 10 kinds of people -- those that understand binary, and those that don't.

Re: DBI + Binds?
by hakkr (Chaplain) on May 27, 2002 at 10:10 UTC
    $sth->prepare($query); $sth->execute();

      I know how to do it thanks - the problem is the code is not working with an update bind

      Kevman
        What values are in @array? If there is an undef, this won't work properly: undef is translated to an SQL null and comparisons must be made with the IS operator, eg field1 is null because field1 = null will always be false.

        rdfield