Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
UNIQUE Index Type takes into consideration of deleted re
Message
From
09/11/2005 02:25:54
 
 
To
09/11/2005 00:27:02
Felix Serra
Campus Management Corp.
Miami, Florida, United States
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01066679
Message ID:
01066686
Views:
14
>Unique Index Type takes into consideration of deleted records.
>Below is a program that will duplcate this problem. What happens is if you have duplcated records that are deleted, as in this example, when you order the table by the index, you will not see any records pertaining to these records. This is due to FoxPro, even with SET STEP ON, takes these deleted records as if they were not deleted.
>
>
>
>
>** Test program for UNIQUE Index problem
>CLOSE TABLES ALL
>CLEAR ALL
>SET DELETED ON
>
>
>IF FILE('UNQTBL.DBF')
>	DELETE FILE UNQTBL.DBF
>ENDIF
>
>
>CREATE TABLE UNQTBL (TRMCODE C(4), COURSE C(7), SECTION C(2))
>
>INSERT INTO UNQTBL VALUES ('1234', 'ACC101', '01')
>INSERT INTO UNQTBL VALUES ('1234', 'ACC101', '01')
>INSERT INTO UNQTBL VALUES ('1234', 'ACC101', '01')
>
>&& This will delete the first two identical records and leave
>&& the last record visible.
>GO TOP
>DELETE
>SKIP
>DELETE
>
>INDEX ON TRMCODE + COURSE + SECTION TAG UNIQREC UNIQUE
>&& Actual results show no records due to the prior deleted duplicate data
>BROWSE
>
>
UNIQUE index ignores deleted() flag
and respect the UNIQUE clause only when are created or is reindexed

To fix the DELETE() issue is simple:
** Test program for UNIQUE Index problem
CLOSE TABLES ALL
CLEAR ALL
SET DELETED ON 

IF FILE('UNQTBL.DBF')
	DELETE FILE UNQTBL.DBF
ENDIF


CREATE TABLE UNQTBL (TRMCODE C(4), COURSE C(7), SECTION C(2))

INSERT INTO UNQTBL VALUES ('1234', 'ACC101', '01') 
INSERT INTO UNQTBL VALUES ('1234', 'ACC101', '01')
INSERT INTO UNQTBL VALUES ('1234', 'ACC101', '01')

&& This will delete the first two identical records and leave 
&& the last record visible.
GO TOP
DELETE next 2

INDEX ON TRMCODE + COURSE + SECTION FOR NOT DELETED() TAG UNIQREC UNIQUE
&& Actual results show no records due to the prior deleted duplicate data
BROWSE 
But after every write operation ( DELETE/RECALL/REPLACE/UPDATE/APPEND/INSERT...)
the index become invalid, and you have to do a REINDEX.
** Test program for UNIQUE Index problem
CLOSE TABLES ALL

SET DELETED ON 


CREATE CURSOR  UNQTBL (recno i, TRMCODE C(4))

INSERT INTO UNQTBL VALUES (1,'1234')
INSERT INTO UNQTBL VALUES (2,'1234')
INSERT INTO UNQTBL VALUES (3,'1234')

&& This will delete the first two identical records and leave 
&& the last record visible.

DELETE RECORD 1

INDEX ON TRMCODE  FOR NOT DELETED() TAG UNIQREC UNIQUE

BROWSE TITLE "record 2"

RECALL RECORD 1

SET ORDER TO UNIQREC

BROWSE TITLE "2 records: expected Record 1 only"

REINDEX

BROWSE TITLE "record 1"

replace RECORD 1 TRMCODE WITH '6789'

BROWSE TITLE "record 1, expected 2"
Previous
Reply
Map
View

Click here to load this message in the networking platform