Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to know about proper index
Message
From
26/05/2011 12:49:35
Mk Sharma
Shrishti Solutions
Mumbai, India
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
How to know about proper index
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Network:
Windows XP
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01511880
Message ID:
01511880
Views:
93
i am using CDX index files

some times i am facing index problem

when i use the dbf file, it is not showing any error.

but not showing any record

after reindex, it is showing all the records
use acmast index acmast excl
reind
how to know that the index is not proper after opening the dbf.

i have found this code
SET DELETED ON
CREATE DATA data1
CREATE TABLE "MyTable.dbf" (PK I)
ALTER TABLE MyTable ALTER COLUMN PK I PRIMARY KEY
INSERT INTO MyTable (PK) VALUES (1)
INSERT INTO MyTable (PK) VALUES (2)
INSERT INTO MyTable (PK) VALUES (3)
FLUSH
CLOSE DATABASES ALL
COPY FILE "mytable.cdx" TO "mytable.cdx.sav"
USE MyTable
INSERT INTO MyTable (PK) VALUES (4)
INSERT INTO MyTable (PK) VALUES (5)
FLUSH
CLOSE DATABASES ALL
DELETE FILE "mytable.cdx"
RENAME "mytable.cdx.sav" TO "mytable.cdx"
USE MyTable
SET ORDER TO PK
COUNT TO nIndexCount
nNumberOfRecords=0
SCAN ALL NOOPTIMIZE
	nNumberOfRecords=nNumberOfRecords+1
ENDSCAN

IF nIndexCount#nNumberOfRecords
	MESSAGEBOX("INDEX IS CORRUPT!")
ELSE
	MESSAGEBOX("Everything's fine")
ENDIF
MESSAGEBOX("nIndexCount "+ltrim(str(nIndexCount))+chr(13)+"nNumberOfRecords "+ltrim(str(nNumberOfRecords)))
CLOSE DATA ALL
RETURN
and this code
LPARAMETERS l_cDataDir

ON ERROR errproc()

#DEFINE CR 	CHR(13)+CHR(10)
#DEFINE  LOGFILE	"C:\tablelog.txt"
STRTOFILE(CR+CR+TRANSFORM(DATETIME())+CR+CR,LOGFILE,1)
CLOSE DATABASES all
CLEAR
SET EXCLUSIVE OFF
SET DELETED OFF
l_cCurrDir = SYS(5) + SYS(2003)

IF !EMPTY(l_cDataDir)
	CD (l_cDataDir)
ELSE
	CD ?
ENDIF

ntables=ADIR(latables,'*.DBF')
l_nStartSeconds = SECONDS()

STRTOFILE("Data folder scanned - " + SYS(5) + SYS(2003) + CR + CR,LOGFILE,1)

FOR ii=1 TO ntables
	nstart=SECONDS()
	USE latables[ii,1] SHARED IN 1
	STRTOFILE(latables[ii,1]+": ",LOGFILE,1)
	ntag=ATAGINFO(latags)
	FOR xx=1 TO ntag
		lok=.T.
		SET ORDER TO (latags[xx,1]) ASCENDING
		WAIT WINDOW "Scanning tag - " + ;
					latags[xx,1] + ;
					" in " + ;
					latables[ii,1] NOWAIT NOCLEAR
					
		nreccount=RECCOUNT()
		nrecs=0
		SCAN  && do the fastest check first
			nrecs=nrecs+1
		ENDSCAN

		IF nrecs#nreccount AND EMPTY(latags[xx,4])
			STRTOFILE("Record count failed for tag "+ latags[xx,1]+ ;
						" in table "+latables[ii,1]+CR,LOGFILE,1)
			lok=.F.
			EXIT
		ENDIF
	ENDFOR
	IF lok
		FOR xx=1 TO ntag
			lok=.T.
			SET ORDER TO (latags[xx,1]) ASCENDING
			coldindexexp=NULL
			SCAN

				IF EVALUATE(latags[xx,3]) < coldindexexp
					STRTOFILE("ascending failed for tag "+ latags[xx,1]+;
						" in table "+latables[ii,1]+CR,LOGFILE,1)
					lok=.F.
					EXIT
				ENDIF
				coldindexexp=EVALUATE(latags[xx,3])
			ENDSCAN
		IF lok=.f.
			EXIT
		ENDIF
		ENDFOR
	ENDIF
	nend=SECONDS()
	tot=nend-nstart
	STRTOFILE([Total time for this table: ]+TRANSFORM(tot)+CR,LOGFILE,1)
ENDFOR
l_nEndSeconds = SECONDS()

=STRTOFILE(CR + CR + "Total Scan time - " + ;
			TRANSFORM(l_nEndSeconds - l_nStartSeconds) +;
			" seconds" + CR,LOGFILE,1)
			
CLOSE DATABASES all
WAIT CLEAR

CD (l_cCurrDir)

MODIFY FILE (LOGFILE)

FUNCTION errproc
#DEFINE CR 	CHR(13)+CHR(10)
=STRTOFILE(CR + "ERROR: "+MESSAGE() + CR,LOGFILE,1)
please suggest

warm regards,
mk.
Next
Reply
Map
View

Click here to load this message in the networking platform