Forums

Custom error code with DB save?

brononius 18 Feb, 2014
Hey,

In my table, I've set one colomn to unique.
I was wondering if I could show a custom code with 'DB save' if a same value is been used.

Now i'm getting:
Error: 0 - SQL=INSERT INTO `TB_data_family` (`cf_created`,`family`) VALUES ('2014-02-18 09:20:57','3test')


And I would like to have something like:

Sorry, This name is already been used. Try again with another name...

GreyHead 18 Feb, 2014
Hi brononius,

You could put a MySQL query into a Custom Serverside Validation action to check if the name is already in use.

Bob
adrian99 14 Mar, 2014
I have exactly the same challenge. The suggestion of checking if the value is already present before the save is not bulletproof. There is the (tiny) chance that the check would reveal no duplicate but that a new row is added (by some other process) in the moment of time between the check and the DB Save attempt. If the newly added row has the same indexed column value as the form that is about to be saved, then the form will fail to save.

It is a shame that one cannot check whether a DB Save has been successful and then programmatically examine the reason.
GreyHead 14 Mar, 2014
Hi adrian99,

Very few things are that bulletproof, I guess that you'd need to have some kind of a table-locking system to make certain. You can custom code any MySQL query that you like.

Bob
This topic is locked and no more replies can be posted.