Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Tablevalidate flaw?
Message
De
18/03/2003 11:15:43
 
 
À
18/03/2003 08:14:27
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00764400
Message ID:
00767088
Vues:
21
Hi Jim,

You are missing an error check for TABLEUPDATE.
As I thought, corrupted record count 4 doesn't report an error, but corrupted record count 3 reports error 2091.
In both cases last append is saved to disk. I am not happy with the fact that the first scenario doesn't report an error and that the record is saved, but this is how it currently works.

Changed code:
CLOSE DATABASES all
Clear
LOCAL nRecCount, nLogicalSize, nPhysicalSize, nHandler, i

CLOSE TABLES all
CLOSE DATABASES ALL 
DELETE FILE c:\VFP8new\test_tbl.dbf
DELETE FILE c:\VFP8new\test_db.dbc
DELETE FILE c:\VFP8new\test_db.dct
DELETE FILE c:\VFP8new\test_db.dcx

SET TABLEVALIDATE TO 2  &&  <-------- or 0
SET MULTILOCKS ON

CREATE DATABASE c:\VFP8new\test_db
CREATE TABLE    c:\VFP8new\test_tbl (one_field N(1,0))

? 'FileSize after create: ', HEADER() + 1


=CURSORSETPROP("Buffering",5)

FOR i = 1 TO 5
    INSERT INTO c:\VFP8new\test_tbl (one_field) VALUES (i)
ENDfor
=TABLEUPDATE(.T.)

* Check size before corruption.
*SELECT test_tbl

nRecCount = RECCOUNT()
nLogicalSize = HEADER() + (nRecCount * RECSIZE()) + 1
USE IN test_tbl

nHandler = FOPEN('c:\VFP8new\test_tbl.dbf', 2)
nPhysicalSize = FSEEK(nHandler, 0, 2)
FCLOSE(nHandler)

? 'BEFORE CORRUPTION'
? 'Record count: ', nRecCount
? 'Logical size: ', nLogicalSize
? 'Physical size:', nPhysicalSize

* Manually decrease the record count in the table header.
* Normally it would happen accidentally after some power 
* or network failures.


? 'Simulating table corruption...'

* Open table for R/W, buffered

nHandler = FOPEN('c:\VFP8new\test_tbl.dbf', 2) 
FSEEK(nHandler, 4)
FWRITE(nHandler, CHR(3))  &&  <------- or 3
FCLOSE(nHandler)

* Check size after corruption
USE c:\VFP8new\test_tbl
nRecCount = RECCOUNT()
nLogicalSize = HEADER() + (nRecCount * RECSIZE()) + 1
USE IN test_tbl

nHandler = FOPEN('c:\VFP8new\test_tbl.dbf', 2)
nPhysicalSize = FSEEK(nHandler, 0, 2)
FCLOSE(nHandler)


? 'AFTER CORRUPTION'
? 'Record count: ', nRecCount
? 'Logical size: ', nLogicalSize
? 'Physical size:', nPhysicalSize

* I will try inserting a record - NO transaction.
?
? 'Inserting new record...'

USE c:\VFP8new\test_tbl SHARED 
=CURSORSETPROP("Buffering",5)
*BEGIN TRANSACTION
    INSERT INTO c:\VFP8new\test_tbl VALUES (6)
    if(!TABLEUPDATE(.T.))
    	AERROR(aerrors)
    	DISPLAY MEMORY LIKE aerrors
    	TABLEREVERT(.T.)
    ENDIF
    FLUSH 
*    WAIT TIMEOUT 5 "Waiting 5 seconds"
*END TRANSACTION
*? 'No error:', ERROR()

* Check size after insert
nRecCount = RECCOUNT()
nLogicalSize = HEADER() + (nRecCount * RECSIZE()) + 1

USE IN test_tbl

nHandler = FOPEN('c:\VFP8new\test_tbl.dbf', 2)
nPhysicalSize = FSEEK(nHandler, 0, 2)
FCLOSE(nHandler)

?
? 'AFTER INSERTION'
? 'Record count: ', nRecCount
? 'Logical size: ', nLogicalSize
? 'Physical size:', nPhysicalSize

*? 'VFP discarded insert operation.'

USE c:\VFP8new\test_tbl SHARED 
LIST
CLOSE DATA ALL


return
Thanks,
Aleksey.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform