What's the correct way to protect against multiple sessions getting the same data?

Yevgeny Simkin

Let's say I have a table called tickets which has 4 rows, each representing a ticket to a show (in this scenario these are the last 4 tickets available to this show).

3 users are attempting a purchase simultaneously and each want to buy 2 tickets and all press their "purchase" button at the same time.

Is it enough to handle the assignment of each set of 2 via a TRANSACTION or do I need to explicitly call LOCK TABLE on each assignment to protect against the possibility that 2 of the tickets will be assigned to two users.

The desire is for one of them to get nothing and be told that the system was mistaken in thinking there were available tickets.

I'm confused by the documentation which says that the LOCK will be implicitly released when I start a TRANSACTION, and was hoping to get some clarity on the correct way to handle this.

Barmar

If you use a transaction, MySQL takes care of locking automatically. That's the whole point of transactions -- they totally prevent any kind of interference due to overlapping requests.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

What's the best way to protect against 'unrecognized selector' for objects returned from NSDictionary

From Dev

What's the correct way to store data in elasticsearch?

From Dev

CoreBluetooth : What's the correct way of retrieving multiple disconnected peripherals?

From Dev

What's the correct way to use multiple COUNT clauses in a single query?

From Dev

CoreBluetooth : What's the correct way of retrieving multiple disconnected peripherals?

From Dev

How to protect against data leak?

From Dev

What's the correct way to store a time interval in Core Data?

From Dev

What's the correct way to run a monthly simulation from a table data?

From Dev

What's an elegant way to catch the same exception multiple times?

From Dev

Best way to protect against SQL injection in SqlDataAdapter

From Dev

What does the NTFS encryption protect against?

From Dev

Pythonic way to process multiple for loops with different filters against the same list?

From Dev

How does SSL protect the data against sniffing?

From Dev

What's the proper way to link against an executable on Windows?

From Dev

What's the recommended way to get the latest sakai code to test against?

From Dev

What's the correct way to run multiple parallel tasks in an asp.net process?

From Dev

What's the correct way to build up a file path from multiple strings?

From Dev

What is the correct way to insert data into database with AsyncTask

From Dev

What is the correct way to structure this kind of data in Firestore?

From Dev

What's the correct way to use Fragments?

From Dev

What's the correct way to authorize Stormpath apps?

From Dev

What's the correct way of converting values?

From Dev

What's the correct way to declare a __block variable?

From Dev

What's the correct way to observe on the UI thread

From Dev

What's the correct way to read ISomething : ISomethingElse

From Dev

What's the correct way to share a Juju environment?

From Dev

What's the correct way to use XslCompiledTransform?

From Dev

What's the correct way to share a Juju environment?

From Dev

What's the correct way to store a list in MySQL?

Related Related

  1. 1

    What's the best way to protect against 'unrecognized selector' for objects returned from NSDictionary

  2. 2

    What's the correct way to store data in elasticsearch?

  3. 3

    CoreBluetooth : What's the correct way of retrieving multiple disconnected peripherals?

  4. 4

    What's the correct way to use multiple COUNT clauses in a single query?

  5. 5

    CoreBluetooth : What's the correct way of retrieving multiple disconnected peripherals?

  6. 6

    How to protect against data leak?

  7. 7

    What's the correct way to store a time interval in Core Data?

  8. 8

    What's the correct way to run a monthly simulation from a table data?

  9. 9

    What's an elegant way to catch the same exception multiple times?

  10. 10

    Best way to protect against SQL injection in SqlDataAdapter

  11. 11

    What does the NTFS encryption protect against?

  12. 12

    Pythonic way to process multiple for loops with different filters against the same list?

  13. 13

    How does SSL protect the data against sniffing?

  14. 14

    What's the proper way to link against an executable on Windows?

  15. 15

    What's the recommended way to get the latest sakai code to test against?

  16. 16

    What's the correct way to run multiple parallel tasks in an asp.net process?

  17. 17

    What's the correct way to build up a file path from multiple strings?

  18. 18

    What is the correct way to insert data into database with AsyncTask

  19. 19

    What is the correct way to structure this kind of data in Firestore?

  20. 20

    What's the correct way to use Fragments?

  21. 21

    What's the correct way to authorize Stormpath apps?

  22. 22

    What's the correct way of converting values?

  23. 23

    What's the correct way to declare a __block variable?

  24. 24

    What's the correct way to observe on the UI thread

  25. 25

    What's the correct way to read ISomething : ISomethingElse

  26. 26

    What's the correct way to share a Juju environment?

  27. 27

    What's the correct way to use XslCompiledTransform?

  28. 28

    What's the correct way to share a Juju environment?

  29. 29

    What's the correct way to store a list in MySQL?

HotTag

Archive