[ic] Detecting duplicate values in a database

Mike Heins interchange-users@icdevgroup.org
Tue Sep 10 11:02:01 2002


Quoting Michael (mslack@g1.slackford.com):
> Hi folks...
> 
> I have run into a bit of a problem using a form to update a database.
> 
> I have one column in userdb that really needs to be a unique value on 
> a record by record basis.  However it will not really be used as a key - it
> simply cannot have duplicates.

> The gear is:  IC ver 4.8.2 (a bit old), MySQL ver 3.23.36, Apache 1.3.22 on
> RedHat 7.1.  (not production gear)
> 
> Here is the mv code:  (bare bones)
> ----------------------------------------------------
> [set mv_data_enable]1[/set]
> 
> [set valid_form]
> &success=main1
> &fail=@@MV_PAGE@@
> ref_num=unique userdb "Value in use - Select another"
> &fatal=1
> [/set]

It would be easy to gen this up yourself.

  [set valid_form]
     [tmp ref_num_used][strip]
	[query sql="select ref_num from userdb where ref_num = '[cgi ref_num]'"]
		[sql-code]
	[/query]
     [/strip][/tmp]
     [if scratch ref_num_used]
	[calc]
		delete $CGI->{ref_num}; 
	[/calc]
	ref_num=mandatory Value in use - Select another
     [/if]
  [/set]

Not tested, but you should get the idea.

I should probably add the primitive ref_num=unique userdb:ref_num ....

-- 
Mike Heins
Perusion -- Expert Interchange Consulting    http://www.perusion.com/
phone +1.513.523.7621      <mike@perusion.com>

"Laughter is inner jogging." -- Norman Cousins