Jump to content
MakeWebGames

{REQUEST}Mccode Duping...


ShizzleNizzle

Recommended Posts

Re: {REQUEST}Mccode Duping...

As was pointed out, "SQL duping" is an inaccurate term. Try looking up "why use transactions". Quoting from the first hit I found:

 

You need to use transactions anytime you're modifying a set of data, which could end up in a weird state if the modifications don't run to completion.

For example, changing the value of a PIN needs to be transactioned: you wouldn't want to change only the first two bytes, would you?

Another example: when an account is credited, another is debited from the same amount. Crediting the first account and debiting the second account must be performed atomically.

You don't need to use transactions when you're modifying a single primitive value (primitive types, one cell of an array of primitive types). However, please note that a set of atomic writes is not itself atomic, hence the need for transactions!

The last part of this - I'm not 100% convinced is accurate. Atomic writes, by their very nature, must be atomic. I've certainly never come across a situation where they have not been (assuming a single server architecture).

Transactions are easy enough once you get your head around them, however taking the initial step can be confusing. A lot of basic mistakes are made by people initially when experimenting with them, indeed, I still do from time to time.

One nasty effect visible from scripting languages is what happens if you cannot control script termination. If you fail to let the script run fully over a transaction block, then you run the risk of having invalid data states - a situtation which is never good.

Saying that, using simple exception handlers and forcing scripts to run to completion - or better yet, stored procedures is far better in my opinion.

There are - as pointed out - alternatives, simple locking *can* be effective, but again script completion here is important as is using threaded timeouts for resource (lock) allocation.

MySQL Transactional and Locking Statements (MySQL documentation)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...