Thursday, 15 August 2013

Preventing duplicate INSERTS MySQL -



Preventing duplicate INSERTS MySQL -

i have table takes inserts store integers date. these integers summed each date sum(column) , total used. so, date cannot unique there many inserts per date. integer value cannot unique either.

i utilize scheme count entries (for instance @ restaurant, club, whatever).

a person holds ipad @ door , sends insert command how many people entered (like grouping of 5 row integer value of 5 , current date).

if there bad connection , ipad sends request doesn't receive answer, user effort perform insert again, causing duplicates.

would sensible add together column such "identifier" random string/number/hash etc. unique, if user retries insert , server has row, give same reply if insert succeeded.

i'm having problem navigating logic in handling errors such these. if update command on unique column wouldn't issue, way built that's not possible.

what next approach?

client side:

create guid insert-request send insert-request (value + date + guid) wait response response received --> show confirmation user ("completed successfully") no response received --> request insert-response (incl. guid) insert-response received --> show confirmation user ("completed successfully") no insert-response received --> repeat 5. response == "not inserted" --> show error message user ("error, seek again")

server side:

receive insert-request --> insert info (value, date) table send confirmation --> guid, ok or: receive request (guid inserted?) --> send response guid inserted yes/no

mysql

No comments:

Post a Comment