On Tue, Apr 02, 2002 at 11:01:41AM -0600, NIPP, SCOTT V (SBCSI) wrote:
>       New problem now.  I appear have resolved my earlier problems.  The
> final issue appears to have been that the SQL statement was interpreting the
> WHERE clause as having multiple arguments.  Quoting the where clause seems
> to have resolved the error, but the data still is not making it into the
> database?!?!  Below is the "working" UPDATE line:
> 
>          $dbh->do(qq{UPDATE systems SET $set WHERE 'Name = $name'});
> 
>       Not sure what is wrong now though.  :(

The chief thing that is wrong is that you are making random changes to your
code without understanding what you are doing.


An SQL UPDATE statement might look something like this:

UPDATE mytable
SET    gender = 'M',
       weight = 150
WHERE  name = 'Bob'

Note that the where clause is *not* in quotes; it just won't work the way
you have it above.  String values, such as 'Bob', must be in single quotes;
numeric values, such as 150, do not need to be quoted.  Single quotes
inside a string are escape with another single quote, as in 'O''Neill'.


The quick way to fix your code is, immediately after constructing your
update statement, print it out and make sure it's correct:

my $sql = "UPDATE systems SET $set WHERE name = $name";
print "$sql\n";

If it's not correct, figure out the error, and fix it.  If you're not sure,
send us the code *and* the SQL statement that it produces.


The long-term, but ultimately more effective, way to fix your code, is to
take the time to understand Perl, SQL, and DBI.  Some questions you might
want to ask yourself: What are symbolic references, and why should I avoid
using them?  How can I write Perl code that will run with use strict and
-w?  What are placeholders, and how do I use them with DBI?


Ronald

Reply via email to