diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 7de497e28b..bfde7ff41e 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,12 @@ +19990831-19:09 GMT+1 Bruno Cantero + * include/rddapi.h + source/rdd/dbcmd.c + source/rdd/dbf1.c + * Added more RDD functions. + + * tests/working/Makefile + * Added testdbf.prg + 19990831-17:40 GMT+1 Victor Szel * source/rtl/arrays.c diff --git a/harbour/include/rddapi.h b/harbour/include/rddapi.h index c4cf5815a8..99e8f912f8 100644 --- a/harbour/include/rddapi.h +++ b/harbour/include/rddapi.h @@ -551,20 +551,21 @@ typedef USHORT ( * DBENTRYP_VF )( AREAP area, LPDBFIELDINFO param ); typedef USHORT ( * DBENTRYP_VL )( AREAP area, LPDBLOCKINFO param ); typedef USHORT ( * DBENTRYP_SP )( AREAP area, USHORT * param ); typedef USHORT ( * DBENTRYP_P )( AREAP area, BYTE * param ); +typedef USHORT ( * DBENTRYP_PP )( AREAP area, BYTE ** param ); typedef USHORT ( * DBENTRYP_S )( AREAP area, USHORT param ); typedef USHORT ( * DBENTRYP_LP )( AREAP area, LONG * param ); typedef USHORT ( * DBENTRYP_ULP )( AREAP area, ULONG * param ); typedef USHORT ( * DBENTRYP_SVP )( AREAP area, USHORT index, void * param ); typedef USHORT ( * DBENTRYP_VSP )( AREAP area, USHORT action, ULONG lRecord ); +typedef USHORT ( * DBENTRYP_SVL )( AREAP area, USHORT index, ULONG * param ); typedef USHORT ( * DBENTRYP_SSI )( AREAP area, USHORT p1, USHORT p2, PHB_ITEM p3 ); +typedef USHORT ( * DBENTRYP_ISI )( AREAP area, PHB_ITEM p1, USHORT p2, PHB_ITEM p3 ); #if 0 -typedef USHORT ( * DBENTRYP_PP )( AREAP area, void ** param); typedef USHORT ( * DBENTRYP_SVPB )( AREAP area, USHORT index, void * param, USHORT mode); typedef USHORT ( * DBENTRYP_VPL )( AREAP area, void * p1, LONG p2); typedef USHORT ( * DBENTRYP_VPLP )( AREAP area, void * p1, LONGP p2); typedef USHORT ( * DBENTRYP_LSP )( AREAP area, LONG p1, USHORTP p2); -typedef USHORT ( * DBENTRYP_ISI )( AREAP area, PHB_ITEM p1, USHORT p2, PHB_ITEM p3); #endif @@ -598,30 +599,20 @@ typedef struct _RDDFUNCS DBENTRYP_V deleterec; DBENTRYP_BP deleted; DBENTRYP_SP fieldCount; -#if 0 - DBENTRYP_VP fieldDisplay; -#endif + DBENTRYP_VF fieldDisplay; DBENTRYP_SSI fieldInfo; DBENTRYP_SVP fieldName; DBENTRYP_V flush; -#if 0 DBENTRYP_PP getRec; -#endif DBENTRYP_SI getValue; -#if 0 - DBENTRYP_SVP getVarLen; -#endif + DBENTRYP_SVL getVarLen; DBENTRYP_V goCold; DBENTRYP_V goHot; -#if 0 - DBENTRYP_VP putRec; -#endif + DBENTRYP_P putRec; DBENTRYP_SI putValue; DBENTRYP_V recall; DBENTRYP_ULP reccount; -#if 0 DBENTRYP_ISI recInfo; -#endif DBENTRYP_I recno; DBENTRYP_S setFieldExtent; @@ -708,9 +699,7 @@ typedef struct _RDDFUNCS /* Memofile functions */ -#if 0 DBENTRYP_V closeMemFile; -#endif DBENTRYP_VP createMemFile; #if 0 DBENTRYP_SVPB getValueFile; @@ -729,9 +718,7 @@ typedef struct _RDDFUNCS /* Special and reserved methods */ -#if 0 DBENTRYP_SVP whoCares; -#endif } RDDFUNCS; diff --git a/harbour/source/rdd/dbcmd.c b/harbour/source/rdd/dbcmd.c index 71cde1b480..3c28c48d51 100644 --- a/harbour/source/rdd/dbcmd.c +++ b/harbour/source/rdd/dbcmd.c @@ -271,6 +271,12 @@ static ERRCODE Found( AREAP pArea, BOOL * pFound ) return SUCCESS; } +static ERRCODE GetRec( AREAP pArea, BYTE ** pBuffer ) +{ + * pBuffer = pArea->lpExtendInfo->bRecord; + return SUCCESS; +} + static ERRCODE GoCold( AREAP pArea ) { PHB_ITEM pError; @@ -412,15 +418,20 @@ static RDDFUNCS defTable = { Bof, UnSupported, ( DBENTRYP_BP ) UnSupported, FieldCount, + ( DBENTRYP_VF ) UnSupported, FieldInfo, FieldName, UnSupported, + GetRec, ( DBENTRYP_SI ) UnSupported, + ( DBENTRYP_SVL ) UnSupported, GoCold, GoHot, + ( DBENTRYP_P ) UnSupported, ( DBENTRYP_SI ) UnSupported, UnSupported, ( DBENTRYP_ULP ) UnSupported, + ( DBENTRYP_ISI ) UnSupported, ( DBENTRYP_I ) UnSupported, SetFieldExtent, Alias, @@ -436,10 +447,12 @@ static RDDFUNCS defTable = { Bof, ( DBENTRYP_VSP ) UnSupported, ( DBENTRYP_VL ) UnSupported, ( DBENTRYP_UL ) UnSupported, + UnSupported, ( DBENTRYP_VP ) UnSupported, ( DBENTRYP_VP ) UnSupported, UnSupported, - UnSupported + UnSupported, + ( DBENTRYP_SVP ) UnSupported }; diff --git a/harbour/source/rdd/dbf1.c b/harbour/source/rdd/dbf1.c index 2b3783cd8b..43e5aeb99e 100644 --- a/harbour/source/rdd/dbf1.c +++ b/harbour/source/rdd/dbf1.c @@ -229,11 +229,9 @@ static BOOL hb_dbfWriteMemo( AREAP pArea, LPDBFMEMO pMemo, ULONG * lNewRecNo ) if( * lNewRecNo == 0 ) /* Add an entry at eof */ { - hb_fsSeek( pArea->lpFileInfo->pNext->hFile, 0, FS_SET ); - if( hb_fsRead( pArea->lpFileInfo->pNext->hFile, ( BYTE * ) &pMemoHeader, - sizeof( MEMOHEADER ) ) != sizeof( MEMOHEADER ) ) - return FALSE; - + hb_fsSeek( pArea->lpFileInfo->pNext->hFile, 1, FS_SET ); + hb_fsRead( pArea->lpFileInfo->pNext->hFile, ( BYTE * ) &pMemoHeader, + sizeof( MEMOHEADER ) ); * lNewRecNo = pMemoHeader.lNextBlock; pMemoHeader.lNextBlock = * lNewRecNo + uiNumBlocks; hb_fsSeek( pArea->lpFileInfo->pNext->hFile, 0, FS_SET ); @@ -643,9 +641,7 @@ static ERRCODE Append( AREAP pArea, BOOL bUnLockAll ) return FAILURE; } - lRecNo = pArea->lpExtendInfo->lRecNo; SELF_GOTO( pArea, lRecCount + 1 ); - lRecCount++; lRecNo = lRecCount; pArea->fEof = FALSE; @@ -673,9 +669,13 @@ static ERRCODE Append( AREAP pArea, BOOL bUnLockAll ) static ERRCODE Close( AREAP pArea ) { + SELF_FLUSH( pArea ); + + if( pArea->lpExtendInfo->fHasMemo ) + SELF_CLOSEMEMFILE( pArea ); + if( pArea->lpFileInfo->hFile != FS_ERROR ) { - SELF_FLUSH( pArea ); SELF_RAWLOCK( pArea, FILE_UNLOCK, 0 ); hb_fsClose( pArea->lpFileInfo->hFile ); pArea->lpFileInfo->hFile = FS_ERROR; @@ -684,6 +684,18 @@ static ERRCODE Close( AREAP pArea ) return SUPER_CLOSE( pArea ); } +static ERRCODE CloseMemFile( AREAP pArea ) +{ + if( pArea->lpFileInfo->pNext->hFile != FS_ERROR ) + { + SELF_FLUSH( pArea ); + hb_fsClose( pArea->lpFileInfo->pNext->hFile ); + pArea->lpFileInfo->pNext->hFile = FS_ERROR; + } + + return SUCCESS; +} + static ERRCODE Create( AREAP pArea, LPDBOPENINFO pCreateInfo ) { pArea->lpFileInfo->hFile = hb_fsCreate( pCreateInfo->abName, FC_NORMAL ); @@ -706,7 +718,7 @@ static ERRCODE CreateMemFile( AREAP pArea, LPDBOPENINFO pCreateInfo ) { LPFILEINFO lpMemInfo; LPMEMOHEADER pMemoHeader; - BOOL bError = FALSE; + BOOL bError; lpMemInfo = ( LPFILEINFO ) hb_xgrab( sizeof( FILEINFO ) ); memset( lpMemInfo, 0, sizeof( FILEINFO ) ); @@ -767,12 +779,10 @@ static ERRCODE DeleteRec( AREAP pArea ) static ERRCODE Flush( AREAP pArea ) { if( pArea->lpFileInfo->hFile != FS_ERROR ) - { hb_fsCommit( pArea->lpFileInfo->hFile ); - return SUCCESS; - } - else - return FAILURE; + if( pArea->lpExtendInfo->fHasMemo && pArea->lpFileInfo->pNext->hFile != FS_ERROR ) + hb_fsCommit( pArea->lpFileInfo->pNext->hFile ); + return FAILURE; } static ERRCODE GetValue( AREAP pArea, USHORT uiIndex, PHB_ITEM pItem ) @@ -839,6 +849,27 @@ static ERRCODE GetValue( AREAP pArea, USHORT uiIndex, PHB_ITEM pItem ) return SUCCESS; } +static ERRCODE GetVarLen( AREAP pArea, USHORT uiIndex, ULONG * ulLen ) +{ + LPFIELD pField; + + pField = pArea->lpFields; + while( pField && uiIndex > 1 ) + { + pField = pField->lpfNext; + uiIndex--; + } + if( pField ) + { + if( pField->uiType == 'M' ) + * ulLen = ( ( LPDBFMEMO ) pField->memo )->uiLen; + else + * ulLen = pField->uiLen; + return SUCCESS; + } + return FAILURE; +} + static ERRCODE GoBottom( AREAP pArea ) { ULONG lRecCount; @@ -1026,6 +1057,30 @@ static ERRCODE OpenMemFile( AREAP pArea, LPDBOPENINFO pOpenInfo ) return SELF_GOTOP( pArea ); } +static ERRCODE PutRec( AREAP pArea, BYTE * pBuffer ) +{ + PHB_ITEM pError; + + if( SELF_GOCOLD( pArea ) == FAILURE ) + return FAILURE; + + if( !pArea->lpExtendInfo->fExclusive && !pArea->lpFileInfo->fFileLocked && + !hb_dbfIsLocked( pArea, pArea->lpExtendInfo->lRecNo ) ) + { + pError = hb_errNew(); + hb_errPutGenCode( pError, EG_UNLOCKED ); + hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_UNLOCKED ) ); + hb_errPutSubCode( pError, 1022 ); + SELF_ERROR( pArea, pError ); + hb_errRelease( pError ); + return FAILURE; + } + + memcpy( pArea->lpExtendInfo->bRecord, pBuffer, pArea->lpExtendInfo->uiRecordLen ); + pArea->lpExtendInfo->fRecordChanged = TRUE; + return SUCCESS; +} + static ERRCODE PutValue( AREAP pArea, USHORT uiIndex, PHB_ITEM pItem ) { LPFIELD pField; @@ -1315,6 +1370,40 @@ static ERRCODE RecCount( AREAP pArea, ULONG * pRecCount ) return SUCCESS; } +static ERRCODE RecInfo( AREAP pArea, PHB_ITEM pRecNo, USHORT uiType, PHB_ITEM pItem ) +{ + ULONG lRecNo; + + lRecNo = pArea->lpExtendInfo->lRecNo; + if( SELF_GOTOID( pArea, pRecNo ) == SUCCESS ) + { + switch( uiType ) + { + case DBRI_DELETED: + hb_itemPutL( pItem, ( pArea->lpExtendInfo->bRecord[ 0 ] == '*' ) ); + break; + + case DBRI_LOCKED: + hb_itemPutL( pItem, hb_dbfIsLocked( pArea, pArea->lpExtendInfo->lRecNo ) ); + break; + + case DBRI_RECNO: + SELF_RECNO( pArea, pItem ); + break; + + case DBRI_RECSIZE: + hb_itemPutNL( pItem, pArea->lpExtendInfo->uiRecordLen ); + break; + + case DBRI_UPDATED: + hb_itemPutL( pItem, pArea->lpExtendInfo->fRecordChanged ); + break; + } + } + SELF_GOTO( pArea, lRecNo ); + return SUCCESS; +} + static ERRCODE RecNo( AREAP pArea, PHB_ITEM pRecNo ) { hb_itemPutNL( pRecNo, pArea->lpExtendInfo->lRecNo ); @@ -1467,15 +1556,20 @@ static RDDFUNCS dbfTable = { 0, /* Super Bof */ DeleteRec, Deleted, 0, /* Super FieldCount */ + 0, /* Super FieldDisplay */ 0, /* Super FieldInfo */ 0, /* Super FieldName */ - Flush, /* Super Flush */ + Flush, + 0, /* Super GetRec */ GetValue, + GetVarLen, 0, /* Super GoCold */ 0, /* Super GoHot */ + PutRec, PutValue, RecAll, RecCount, + RecInfo, RecNo, 0, /* Super SetFieldsExtent */ 0, /* Super Alias */ @@ -1491,10 +1585,12 @@ static RDDFUNCS dbfTable = { 0, /* Super Bof */ RawLock, Lock, UnLock, + CloseMemFile, CreateMemFile, OpenMemFile, ReadDBHeader, - WriteDBHeader + WriteDBHeader, + 0 /* Super WhoCares */ }; HARBOUR HB__DBF( void ) diff --git a/harbour/tests/working/Makefile b/harbour/tests/working/Makefile index dc0af6af2d..1bd61d0626 100644 --- a/harbour/tests/working/Makefile +++ b/harbour/tests/working/Makefile @@ -128,6 +128,7 @@ PRG_SOURCES=\ testbrw.prg \ testcgi.prg \ testcopy.prg \ + testdbf.prg \ testerro.prg \ testfor.prg \ testgt.prg \