in reply to Perl Beginners problem with DBI

The primary cause of your problem is that all the other values you are setting are numbers, so the SQL parser takes them without quotes. Only $updy is a character string - and you're passing it in without the quotes.

If you changed the code to say:

$dbh->do("UPDATE INV SET SOLD=\"$updy\" WHERE CODE==$CODE");
it would work.

But don't do that.

Instead, learn to use placeholders. It is true that they make you type more, but they take care of quoting problems like the one above:

$sth=$dbh->prepare("UPDATE INV SET SOLD=? WHERE CODE==?"); $sth->execute($updy,$CODE); # Why is that var all UPcase, BTW?
If you are performing this stuff in a loop, you can move the prepare stage out of the loop, and speed it up.

Finaly, I don't know if your SQL database doesn't allow multiple updates in a single statement (most do), but if you're having that much trouble with writing SQL, you really should take a look at an abstraction layer like Class::DBI, which lets you treat database tables and rows as objects, and manipulate them more easily.

Replies are listed 'Best First'.
Re: Re: Perl Beginners problem with DBI
by Anonymous Monk on Mar 17, 2004 at 14:57 UTC
    Thanks for the advice, its not really that I am having that much trouble with DBI, its just that I have never even looked at a database before in my life. And I don't have a good resource for learning about using DBI, I just kind of did a quick google search and started to try figuring out what I was doing. Oh yea, $CODE is uppercase because I am updating an old DBase III program at the request of a friend, so I just opened it up and started modifying it and the variables in it happened to be uppercase. I am an amature programmer with no formal training, so i don't pretend for a moment I have a clue what I'm doing. Thanks a lot for your help though.
Re: Re: Perl Beginners problem with DBI
by iburrell (Chaplain) on Mar 17, 2004 at 19:19 UTC
    BTW, what database allows double quotes around literal strings:
    $dbh->do("UPDATE INV SET SOLD=\"$updy\" WHERE CODE==$CODE");
    The SQL standard is single quotes around strings. Double quotes are used around identifiers.
      > BTW, what database allows double quotes around literal strings

      MySQL allows both. But you're right, I should be more carefull about that.