My postgres database tables are setup to have unique index therefore no duplicates are not allow. If duplicate occur the db will return an error. Problem is when i try to submit duplicate data to the db i get an ugly error message. Is there anyway i can output my own error message for example "this data exist on the db already, please do not submit again" ? I don't want that error message because user's won't understand what is talking about. thanks.
My postgres database tables are setup to have unique index therefore no duplicates are not allow. If duplicate occur the db will return an error. Problem is when i try to submit duplicate data to the db i get an ugly error message. Is there anyway i can output my own error message for example "this data exist on the db already, please do not submit again" ? I don't want that error message because user's won't understand what is talking about.
I would solve this in the submit action by doing a select for the data before doing an insert. Example: (form_html) <form action="submit_html" method=post> .... </form> (submit_html) <dtml-in select_data> <dtml-if sequence-start> <dtml-var error_message> </dtml-if> <dtml-else> <dtml-call insert_data> </dtml-in> -jfarr ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Hi! I'm a signature virus. Copy me into your .sig to join the fun! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Jonothan Farr wrote:
I would solve this in the submit action by doing a select for the data before doing an insert. [snip]
<dtml-in select_data> <dtml-if sequence-start> <dtml-var error_message> </dtml-if> <dtml-else> <dtml-call insert_data> </dtml-in>
I see a couple of issues with this: 1) This may not scale well; if select_data becomes large you may be spending a while in the dtml-in loop. 2) There could still be a race condition here, between the check for data and the insertion (especially coupled with the above point - the probability would increase proportionally with the load of the machine and the size of the table). I say "could" here (guardedly :-), because I don't know how Zope's transaction semantics are implemented, and how they affect the DA that you're using (does anyone have any pointers to documents? I've just started reading "How to Write a DA", and this mentions the distributed commit protocol). I'm not sure if a solution to the original problem is to surround the insert with a <dtml-try> tag; I'm going to try this myself sometime today (if I get some spare time :-).
-jfarr
Regards, Daryl Tester
I see a couple of issues with this:
1) This may not scale well; if select_data becomes large you may be spending a while in the dtml-in loop.
I would write the select_data query to only select a single record, i.e. the one I'm worried about duplicating.
2) There could still be a race condition here, between the check for data and the insertion (especially coupled with the above point - the probability would increase proportionally with the load of the machine and the size of the table). I say "could" here (guardedly :-), because I don't know how Zope's transaction semantics are implemented, and how they affect the DA that you're using (does anyone have any pointers to documents? I've just started reading "How to Write a DA", and this mentions the distributed commit protocol).
I'm not sure if a solution to the original problem is to surround the insert with a <dtml-try> tag; I'm going to try this myself sometime today (if I get some spare time :-).
Good point. Yours is probably a better solution. <dtml-try> <dtml-call insert_data> <dtml-except specific_exception> <dtml-var error_message> </dtml-try> --jfarr
participants (3)
-
Daryl Tester -
Jonothan Farr -
Oai Luong