unique login id enforcement?

26 views
Skip to first unread message

tom wible

unread,
May 30, 2014, 11:29:25 PM5/30/14
to xata...@googlegroups.com
my user table id field is specified as unique, natch, but entering an existing value results in the unhelpful message

Duplicate entry in table 'users'

as there is more than 1 field and the user has no idea where the error is...any way to fix this?

Steve Hannah

unread,
May 31, 2014, 12:11:20 AM5/31/14
to tom wible, xata...@googlegroups.com

You can add your own custom validator and supply your own error message if it fails.

http://xataface.com/wiki/fieldname__validate

tom wible

unread,
May 31, 2014, 7:34:35 AM5/31/14
to xata...@googlegroups.com, tew...@verizon.net
thanx, where do get the database unique error status? i assume
function myfield__validate(&$record, $value, &$params)
is called before the insert is attempted...

Steve Hannah

unread,
Jun 4, 2014, 4:21:46 PM6/4/14
to tom wible, xata...@googlegroups.com
You'll need to check the uniqueness using an SQL query inside your validate method.  The database error is thrown by MySQL and it doesn't provide specifics as to which constraint was violated, just that it was a uniqueness constraint.

Steve
--
Steve Hannah
Web Lite Solutions Corp.

tom wible

unread,
Jun 6, 2014, 7:51:53 AM6/6/14
to Steve Hannah, xata...@googlegroups.com
Steve Hannah wrote:
> You'll need to check the uniqueness using an SQL query inside your validate
> method. The database error is thrown by MySQL and it doesn't provide specifics
> as to which constraint was violated, just that it was a uniqueness constraint.


thanx, steve, i'll go that way...just wondering: where is the sql error caught?

Steve Hannah

unread,
Jun 6, 2014, 12:25:19 PM6/6/14
to tom wible, xata...@googlegroups.com
The SQL error is caught when the SQL is executed in MySQL.  Xataface attempts to run the INSERT statement, and when it receives the "DUPLICATE" error code, it propagates the error up.  It actually occurs here

Steve
Reply all
Reply to author
Forward
0 new messages