Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: checking to do a inser or update

by MrCromeDome (Deacon)
on Jun 07, 2002 at 04:05 UTC ( [id://172417]=note: print w/replies, xml ) Need Help??


in reply to checking to do a insert or update

Well, as they always say, TIMTOWTDI ;) Personally, if you don't want to keep old scores lying around, I would always do a delete statement, then an insert to add in the new stores. IMHO, it's a bit less work (for you and the database). I mean, you could check to see if the update processed successfully, and if not, do an insert, but this requires a lot less thought ;)

You might also wish to explicitly issue a commit at the end of your script. While I haven't brushed up on the DBI documentation lately, assuming that the disconnect will do a commit for you just strikes me as a bad idea (that next rollback could be brutal. . . ). For safety sake, you might wish to add a $dbh->commit() before the disconnect.

And (just a writeup tip) I hope the connection information for MySQL is bogus. If not, I hope you change the username and password for database access before exposing your database to the world ;) Kinda related to that though, you might wish to check out How (Not) To Ask A Question by jeffa for that (not giving us your real username and password) and other good writeup tips.

Hope this was of some help :) Good luck!
MrCromeDome

Replies are listed 'Best First'.
Re: Re: checking to do a inser or update
by zakb (Pilgrim) on Jun 07, 2002 at 09:56 UTC

    With regards to commit, by default DBI defaults to AutoCommit on, which means that DBI will commit after each statement.

    See the DBI docs, in particular here.

    If you've turned AutoCommit off, it is a bad idea to rely on disconnect to commit for you, the docs say the transaction behaviour of disconnect is undefined...

Re: checking to do a inser or update
by Abigail-II (Bishop) on Jun 07, 2002 at 11:22 UTC
    Well, he isn't checking the return value of the execute, nor does he have RaiseError to be true (and by default, AutoCommit is set to true *shiver*). So I guess he doesn't really care about his data and what happens if something fails.

    Abigail

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://172417]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-20 15:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found