php - Postgresql Update a unique column and validate before Update -


scenario: admin user insert new client on db, has 3 uniques columns, postgres id, driver license, , email, later on i'm trying allow admin user update fields when run validation of course returns false, cause exist, read question , same issue ain't running symfony or other php framework, figured try send id within query , check against id , email instance since live validation send input value.

solution 1: don't allow admin user update fields , have him delete client , create new 1 (this easy getaway).

solution 2? can't think on logic, how can build query validate on issue?

something like:

select email users.users email=$email , id != $id ??? 

the problem can't figured out how send id within input field... validation code:

email: {             trigger: 'blur',             message: 'el email no es vĂ¡lido',             validators: {                 remote: {                     message: 'ya existe un usuario con ese email',                     url: 'actions/chk_available.php',                     data: {                         type: 'email'                     },                     type: 'post'                 }             }         }, 

this code runs on server side when admin user leave field.

update

let's got 2 rows:

  1. email: aaa@host.com
  2. email: bbb@host.com

    select count (1) users.users_web email=$email

if admin user updating second row , doesn't touch email, good, if update email same value row 1(aaa@host.com) query validate valid because still being count 1 , update end filling 2 identical emails, postgresql not gonna allow because unique field, that's gets messy.

don't bother trying "pre-validate" unique constraints. write db , catch violations. it's faster , more correct. trying "pre-validate" race condition anyway.

example: http://sqlfiddle.com/#!15/5f4a0/1


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -