From f23d8bb71ba13b83167a73bd5429f8d9543eb3d6 Mon Sep 17 00:00:00 2001 From: Bruno Cantero Date: Tue, 26 Oct 1999 11:01:17 +0000 Subject: [PATCH] ChangeLogTag:19991026-12:49 GMT+1 Bruno Cantero --- harbour/ChangeLog | 5 +++++ harbour/source/rdd/dbf1.c | 22 +++++++++++++++++--- harbour/tests/testdbf.prg | 42 +++++++++++++++++++++++++++++++++++---- 3 files changed, 62 insertions(+), 7 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 053a10b393..b52aaed8cb 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,8 @@ +19991026-12:49 GMT+1 Bruno Cantero + * source/rdd/dbf1.c + tests/testdbf.prg + * __dbZap() function finished. Test added for this function. + 19991026-11:35 GMT+1 Victor Szel * source/tget.prg % New() will evaluate the setget only once instead of three times. diff --git a/harbour/source/rdd/dbf1.c b/harbour/source/rdd/dbf1.c index 66cbcf6947..428569c6b7 100644 --- a/harbour/source/rdd/dbf1.c +++ b/harbour/source/rdd/dbf1.c @@ -1714,6 +1714,7 @@ static ERRCODE dbfZap( AREAP pArea ) { PHB_ITEM pError; DBOPENINFO pInfo; + ULONG ulRecCount; if( !pArea->lpExtendInfo->fExclusive ) { @@ -1729,10 +1730,25 @@ static ERRCODE dbfZap( AREAP pArea ) if( SELF_GOCOLD( pArea ) == FAILURE || pArea->lpExtendInfo->fReadOnly ) return FAILURE; - /* - TODO: truncate dbf and memo files. - */ + /* Test if can write into file */ + SELF_RECCOUNT( pArea, &ulRecCount ); + if( !hb_dbfUpdateHeader( pArea, ulRecCount ) ) + return FAILURE; + hb_dbfUnLockAllRecords( pArea ); + hb_fsClose( pArea->lpFileInfo->hFile ); + pInfo.abName = ( BYTE * ) pArea->lpFileInfo->szFileName; + SELF_CREATE( pArea, &pInfo ); + hb_fsClose( pArea->lpFileInfo->hFile ); + pArea->lpFileInfo->hFile = hb_fsOpen( pInfo.abName, FO_READWRITE | FO_EXCLUSIVE ); + if( pArea->lpExtendInfo->fHasMemo ) + { + hb_fsClose( pArea->lpFileInfo->pNext->hFile ); + pInfo.abName = ( BYTE * ) pArea->lpFileInfo->pNext->szFileName; + SELF_CREATEMEMFILE( pArea, &pInfo ); + hb_fsClose( pArea->lpFileInfo->pNext->hFile ); + pArea->lpFileInfo->pNext->hFile = hb_fsOpen( pInfo.abName, FO_READWRITE | FO_EXCLUSIVE ); + } return SELF_GOTOP( pArea ); } diff --git a/harbour/tests/testdbf.prg b/harbour/tests/testdbf.prg index 161c094add..06a12b242b 100644 --- a/harbour/tests/testdbf.prg +++ b/harbour/tests/testdbf.prg @@ -25,8 +25,8 @@ function main() ? "[" + MYALIAS->MEMO1 + "]" ? "[" + MYALIAS->MEMO2 + "]" MYALIAS->( dbAppend() ) - MYALIAS->MEMO1 := "111" - MYALIAS->MEMO2 := "222" + MYALIAS->MEMO1 := "This is a test for field MEMO1." + MYALIAS->MEMO2 := "This is a test for field MEMO2." ? "[" + MYALIAS->MEMO1 + "]" ? "[" + MYALIAS->MEMO2 + "]" MYALIAS->NUMERIC := 90 @@ -34,12 +34,46 @@ function main() ? "[" + Str( MYALIAS->DOUBLE ) + "]" ? "[" + Str( MYALIAS->NUMERIC ) + "]" - dbCloseAll() - ? "" ? "Press any key..." InKey( 0 ) + ? "" + ? "Append 50 records with memos..." + for nI := 1 to 50 + MYALIAS->( dbAppend() ) + MYALIAS->MEMO1 := "This is a very long string. " + ; + "This may seem silly however strings like this are still " + ; + "used. Not by good programmers though, but I've seen " + ; + "stuff like this used for Copyright messages and other " + ; + "long text. What is the point to all of this you'd say. " + ; + "Well I am coming to the point right now, the constant " + ; + "string is limited to 256 characters and this string is " + ; + "a lot bigger. Do you get my drift ? If there is somebody " + ; + "who has read this line upto the very end: Esto es un " + ; + "sombrero grande rid¡culo." + Chr( 13 ) + Chr( 10 ) + ; + "/" + Chr( 13 ) + Chr( 10 ) + "[;-)" + Chr( 13 ) + Chr( 10 )+ ; + "\" + next + dbCommit() + + ? "Records before ZAP:", MYALIAS->( LastRec() ) + ? "Size of files (data and memo):", Directory( "testdbf.dbf" )[1][2], ; + Directory( "testdbf.fpt" )[1][2] + MYALIAS->( __dbZap() ) + dbCommit() + ? "Records after ZAP:", MYALIAS->( LastRec() ) + ? "Size of files (data and memo):", Directory( "testdbf.dbf" )[1][2], ; + Directory( "testdbf.fpt" )[1][2] + ? "Value of fields MEMO1, MEMO2, DOUBLE and NUMERIC:" + ? "[" + MYALIAS->MEMO1 + "]" + ? "[" + MYALIAS->MEMO2 + "]" + ? "[" + Str( MYALIAS->DOUBLE ) + "]" + ? "[" + Str( MYALIAS->NUMERIC ) + "]" + ? "Press any key..." + InKey( 0 ) + dbCloseAll() + dbCreate( "testdbf", aStruct, "DBFCDX", .t., "MYALIAS" ) for nI := 1 to 10