Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Fix a dbf over 2Gb?
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01488207
Message ID:
01488389
Views:
63
>>>Once a dbf goes over the 2Gb limit and you get errors trying to open it...is there anyway to get into it to delete some records or pack it or do you just have to restore a backup copy that is smaller?
>>>
>>>-Phil
>>
>>Are you talking about dbf file itself, or about memo file?
>
>It's the dbf file.

Here is an example:
*---do  yfix2G with fullpath(your_table)-------------------------------------------------------
* split one corrupted file into two dbfs
Parameter pTab

clear
close data all

gnHrecnum=0
gnFrecnum=0

* determine the file size
oFSO = CREATEOBJECT("Scripting.FileSystemObject")
ifp_size = oFSO.Getfile(pTab).Size

?"Size ",ifp_size 

lnHeaderSize = 0
lnRecordLength = 0
	
=icheckfile(pTab)

=iCreateNewTable(pTab)

RETURN
*--------------------
FUNCTION icheckfile
LPARAMETERS pFile

oFile = oFSO.OpenTextFile(pFile)

FOR i=0 TO 11
	li = "m.f"+ALLTR(STR(i))			&&m.f1, m.f2...
	&li = ASC(oFile.Read(1))
ENDFOR

oFile.Skip(18)

if m.f0=48		&&VFP dbf
	m.f28=ASC(oFile.Read(1))		&& cdx/memo
ENDIF
m.f29=ASC(oFile.Read(1))
m.f30=ASC(oFile.Read(1))
m.f31=ASC(oFile.Read(1))
gnhrecnum = m.f7*256^3+m.f6*256^2+m.f5*256+m.f4

oFile.close
gnhrecnum = m.f7*256^3+m.f6*256^2+m.f5*256+m.f4


?ALLTR(STR(m.f0)),", file type: ",iDbfType(m.f0) &&" Type of Data File, could be 3, 48, 245, 131"
*0x02FoxBASE, 								2
*0x03FoxBASE+/dBASE III PLUS, no memo, 		3
*0x30Visual FoxPro, 						48
*0x43dBASE IV SQL table files, no memo, 	67
*0x63dBASE IV SQL system files, no memo, 	99
*0x83FoxBASE+/dBASE III PLUS, with memo, 	131
*0x8BdBASE IV with memo,  					139
*0xCBdBASE IV SQL table files, with memo, 	203
*0xF5FoxPro 2.x (or earlier) with memo, 	245
*0xFBFoxBASE, 								251
if  m.f0=48 and type("f28")="N"
*0x01file has a structural .cdx
*0x02file has a Memo field
*0x04file is a database (.dbc)
*Note that this byte can contain the sum of any of the above values. 
*For example, 0x03 indicates the table has a structural .cdx and a Memo field. 
	?ALLTR(STR(m.f28)) 
	do case
	case m.f28=0
		??"                having no cdx and no memo files"
	case m.f28=1
		??"                 file has a structural .cdx"
	case m.f28=2
		??"                 file has a Memo field"
	case m.f28=3
		??"                 file has a structural .cdx and a Memo field"
	otherwise
		??" 				table flag"
	endcase
	? "has "+trans((m.f9*256+m.f8-264)/32 -1), " Fields"
endif
	
?padl(ALLTR(STR(m.f2)),2,"0")+"/"+padl(ALLTR(STR(m.f3)),2,"0")+"/"+;
	padl(ALLTR(STR(m.f1)),2,"0")+"                               Last Date"
?ALLTR(STR(m.f4))+" "+ALLTR(STR(m.f5))+" "+ALLTR(STR(m.f6))+" "+ALLTR(STR(m.f7))+;
	"                               "+ALLTR(STR(m.f7*256^3+m.f6*256^2+m.f5*256+m.f4))+" - Number of Records by HEADER"

?ALLTR(STR(m.f8))+" "+ALLTR(STR(m.f9))+;
	"                          "+ALLTR(STR(m.f9*256+m.f8+1))+" - First record Position"
	
lnHeaderSize = m.f9*256+m.f8

	
?ALLTR(STR(m.f10))+" "+ALLTR(STR(m.f11))+"                     Record Length"

lnRecordLength = m.f11*256+m.f10

RETURN

*---------------------------------------------
PROCEDURE iCreateNewTable
LPARAMETERS pTab
* copy header and records to two new tables c:\testout1.dbf, c:\testout2.dbf
*
ERASE c:\testout1.dbf
erase c:\testout2.dbf

*oFSO = CREATEOBJECT("Scripting.FileSystemObject")
oFile = oFSO.OpenTextFile(pTab)
lcHeader=oFile.Read(lnHeaderSize)

lnbulk = 1000  && number of records in the package to be written at once

* Set File Size limit
lnsize = ifp_size / 2
lnRecords = FLOOR((ifp_size - lnHeaderSize-1) / lnRecordLength)		&& ignore eof indicator if exists

lnRecords_1 = (lnsize - lnHeaderSize) / lnRecordLength
lnRecords_1 = ceil(lnRecords_1 / lnbulk) * lnbulk

lnRecords_2 = lnRecords - lnRecords_1

?lnRecords_1, lnRecords_2, lnRecords_1+lnRecords_2

oFile_1 = oFSO.CreateTextFile("c:\testout1.dbf",.t.)
oFile_1.Write(LEFT(lcHeader,4) + iDocument_records(lnRecords_1) + SUBSTR(lcheader,9))

lnRec=0
DO WHILE lnRec < lnRecords_1 AND NOT Ofile.AtEndOfStream
	oFile_1.Write(oFile.Read(lnRecordLength * lnbulk))
	lnRec = lnRec + lnbulk
	WAIT WINDOW NOWAIT "Adding records to table 1... added "+TRANSFORM(lnRec)
ENDDO
oFile_1.close

IF NOT Ofile.AtEndOfStream
	oFile_2 = oFSO.CreateTextFile("c:\testout2.dbf",.t.)
	oFile_2.Write(LEFT(lcHeader,4)+iDocument_records(lnRecords_2)+SUBSTR(lcheader,9))
	
	lnRec=0
	DO WHILE lnRec < lnRecords_2 AND NOT Ofile.AtEndOfStream
		WAIT WINDOW NOWAIT "Adding records to table 2... added "+TRANSFORM(lnRec+lnbulk)
		oFile_2.Write(oFile.Read(lnRecordLength * lnbulk))
		lnRec = lnRec + lnbulk
	ENDDO
	oFile_2.close
ENDIF
oFile.close
Return
*----------------------------------------
PROCEDURE iDocument_Records
LPARAMETERS lnumber
LOCAL lc1, lc2, lc3, lc4		
			lc4 = CHR(INT(lnumber/(256^3)))
			lc3 = chr(INT((lnumber%(256^3))/(256^2)))
			lc2 = chr(INT(((lnumber%(256^3))%(256^2))/256))
			lc1 = CHR(((lnumber%(256^3))%(256^2)) % 256)
RETURN lc1+lc2+lc3+lc4
*------------------------------------------
PROCEDURE iDbfType
LPARAMETERS pn
DO case
CASE pn=2
	RETURN "FOXBASE"
CASE pn=3
	RETURN "FoxBASE+/dBASE III PLUS, no memo"
CASE pn=48
	RETURN "Visual FoxPro"
CASE pn=67
	RETURN "dBASE IV SQL table files, no memo"
CASE pn=99
	RETURN "dBASE IV SQL system files, no memo"
CASE pn=131
	RETURN "FoxBASE+/dBASE III PLUS, with memo"
CASE pn=139
	RETURN "dBASE IV with memo"
CASE pn=203
	RETURN "dBASE IV SQL table files, with memo"
CASE pn=245
	RETURN "FoxPro 2.x (or earlier) with memo"
CASE pn=251
	RETURN "FoxBASE"
OTHERWISE
	RETURN "Unknown"
ENDCASE
*------------------------------------------
Previous
Reply
Map
View

Click here to load this message in the networking platform