Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Single Pass Reindexing
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00505581
Message ID:
00505851
Views:
39
>>
>>Thanks, I wasn't aware of the bloat issue. When corruption occurs, I replace the CDX with an empty one (stored in my DBC's User field) then issue reindex. This has corrected every corruption that I've run into.
>
>I'm not sure if I follow...
>What are you storing in the DBC's User Field? The name to an empty CDX file?

No, a copy of an empty CDX. I do the following:
use the Dbc as table
Copy (Backup) the Dbf, Fpt, and Cdx files.
use the Dbf exclusive
zap the dbf
close the dbf
select the Dbc
append memo User from the cdx file

Here is the code:
lparameters tcDbc, tcTbl
local lcChr, lcDbf, lcOldSafety, lcOldTalk, lcPath, lnHdlIn, x, y
#DEFINE MB_OK 0
#DEFINE MB_YESNO 4
#DEFINE MB_ICONEXCLAMATION 48
#DEFINE IDNO 7

* Update the User (memo) field in the Dbc to contain an empty Cdx file.

if empty(tcDbc)
	tcDbc = GetFile("Dbc")
else
	if !file(tcDbc)
		if at(".", tcDbc) = 0
			tcDbc = rtrim(tcDbc) + ".Dbc"
		endif
		if !file(tcDbc)
			tcDbc = GetFile("Dbc")
		endif
	endif
endif	
if !file(tcDbc)
	MessageBox("No valid Dbc supplied.", MB_OK, "Cannot update")
	return .F.
endif

if MessageBox("Are you sure you want to create the empty Cdx entries" + chr(13) ;
					+ "in the User field of '" + tcDbc + "'" ;
					+ iif(empty(tcTbl), "", chr(13) + "for Table '" + tcTbl + "'") + "?", ;
					MB_YESNO + MB_ICONEXCLAMATION, "Confirm") == IDNO
	return .F.
endif

x = rat("\", tcDbc)
if x = 0
	lcPath = ".\"
else
	lcPath = left(tcDbc, x)
endif

lcOldSafety = set("Safety")
lcOldTalk = set("Talk")
set Safety off
set talk off
Set Exclusive Off
use (tcDbc) alias DbcAsDbf shared
if type("tcTbl") = "C"
	set filter to ObjectName = lower(tcTbl)
endif
count for ObjectType = "Table" to y
x = 0
scan for ObjectType = "Table"
	x = x + 1
	lcDbf = lcPath + rtrim(ObjectName)
	wait window "Saving " + lcDbf + chr(13) + str(x) + " of" + str(y) nowait
	if  file(lcDbf + ".Cdx") 			&& If no index, skip
		* Backup data
		copy file (lcDbf + ".Dbf") to (lcDbf + ".Dbf.Save")
		copy file (lcDbf + ".Cdx") to (lcDbf + ".Cdx.Save")
		if  file(lcDbf + ".Fpt") 
			copy file (lcDbf + ".Fpt") to (lcDbf + ".Fpt.Save")
		endif
		select 0
		use (lcDbf + ".Dbf") exclusive
		zap
		use
		select DbcAsDbf
		append memo User from (lcDbf + ".Cdx") overwrite
		* Restore Data
		erase (lcDbf + ".Dbf")
		rename (lcDbf + ".Dbf.Save") to (lcDbf + ".Dbf")
		erase (lcDbf + ".Cdx")
		rename (lcDbf + ".Cdx.Save") to (lcDbf + ".Cdx")
		if file(lcDbf + ".Fpt") 
			erase (lcDbf + ".Fpt")
			rename (lcDbf + ".Fpt.Save") to (lcDbf + ".Fpt")
		endif
	else
		replace User with "" in DbcAsDbf
	endif
endscan
wait clear
close all
open database (tcDbc) exclusive
pack database
Close Database
if lcOldSafety = "ON"
	set safety on
endif
if lcOldTalk = "ON"
	set talk on
endif
HTH,
Bill Armbrecht
VFP MCP
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform