Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Twice a key in a table
Message
From
16/02/2007 09:35:29
 
 
To
16/02/2007 03:12:35
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
01118041
Message ID:
01196499
Views:
11
>>>>In my prev. job I had some code to check for uniqueness at the class level using Indexseek as Cetin suggested (actually, I had the code twice in valid of textbox and in save time). If you want, I'll search for that old code...
>>>
>>>Hi N,
>>>
>>>An indexseek is not that reliable in a multiuser environment. I'd say you need a candidate index on the base table. - not on the view since it's a local copy which may/will be out of date
>>
>>Interestingly, I'm currently in need of this functionality. I'm thinking, what would be the best way to handle the situation? I'd like to be able to notify the user right away in the textbox Valid and on the Save as well. On the Save I can probably trap for the error, but how exactly would I know, if I'm not changing an existing field to an exisiting entry (but different record)?
>>
>>What are your thoughts here?
>>
>>Thanks in advance.
>>
>>This seems logical enough:
>>
>>thisform.addmode and oldval(lcfield,lcAlias)<>lcvalue)
>>* Note - the select only sees the values already on disk (not buffered)
>>		      lcSavDel=SET('DELETED')
>>		      SET DELETED OFF
>>
>>		select * from (lcAlias) ;
>>		where &lcfield == lcvalue to screen noconsole
>>	         SET DELETED &lcSavDel.
>>
>>		*!*	*--- Test results of SELECT-SQL duplicate record check.
>>
>>				if _tally > 0
>>					llunique = .f.
>>				endif
>>
>________
>That's an old one ...
>
>If you want a kind of warning during the edit, I would
>
>(1) Not check on addmode, ie one can change a field as well
>
>(2)
>If ( FieldChanged(... ) )
>    lcSavDel=SET('DELETED')  && only if indexexpr is not filtered on deleted()
>    SET DELETED OFF
>    AlreadyThere = indexseek(IndexExprWithThisValue, FALSE, BaseTableNameInCaseOfView, IndexTag)
>    SET DELETED &lcSavDel
>endif
>
>
>You have a candidate index on the base table
>
>Personally, I find this too much coding and would only trap the error on the Save()
>If the error message is meaningful and for the few times it would occur, I don't see any problem with that
>
>Also, if the index is based on more than one field you would have this kind of checking in more than one textbox
>I'd go for a subclassed textbox if I had to do it

I think I would implement an additional check in the valid using Indexseek. Thanks.
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform