From ceb75ebe2740d7acf6c3173bfdbe66b3e2f74038 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Sun, 4 Jun 2006 16:41:02 +0000 Subject: [PATCH] 2006-06-04 18:30 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/include/hbdefs.h * use i64 suffix for BCC 3.0 and higher for long long int * harbour/source/rtl/dummy.prg * harbour/source/rdd/dbcmd.c * added undocumented Clipper function: __dbTrans() __dbOpenSDF() and __dbJoin() I'll commit soon. There is also __dbTransRec() in dummy.prg but I cannot find any information about this function and its parameters in GOOGLE. If someone knows what is this functions syntax and can Inform me then I'll implement it. I guess it's a wrapper to TRANSREC() RDD method. * harbour/source/rdd/dbf1.c * DBI_LOCKOFFSET now returns DBF record lock offset really used (f.e. updated in FP locking after open/close production index) * harbour/source/rdd/delim1.c * cleaned BCC warning * harbour/source/rdd/dbfcdx/dbfcdx1.c ! updated internal production index flag after manual opening production index --- harbour/ChangeLog | 25 ++++++ harbour/include/hbdefs.h | 6 +- harbour/source/rdd/dbcmd.c | 80 +++++++++++++++++- harbour/source/rdd/dbf1.c | 121 +++++++++++++++------------- harbour/source/rdd/dbfcdx/dbfcdx1.c | 87 ++++++++++++-------- harbour/source/rdd/delim1.c | 4 +- harbour/source/rtl/dummy.prg | 1 - 7 files changed, 232 insertions(+), 92 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 8c823fa0ef..4be6255230 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,31 @@ 2002-12-01 13:30 UTC+0100 Foo Bar */ + * harbour/source/rdd/dbf1.c + ! fixed setting [V]FP DBF table type + + * harbour/source/vm/arrays.c + ! fixed ADEL() to clear last element + % optimized a little bit AINS() - use hb_itemMove() instead of + hb_itemCopy() + +2006-06-05 20:30 UTC+0200 Jacek Kubica (kubica/at/wssk.wroc.pl) + * harbour/makefile.bc + * added references for USRRDD.LIB + +2006-06-04 18:30 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/include/hbdefs.h + * use i64 suffix for BCC 3.0 and higher for long long int + + * harbour/source/rtl/dummy.prg + * harbour/source/rdd/dbcmd.c + * added undocumented Clipper function: __dbTrans() + __dbOpenSDF() and __dbJoin() I'll commit soon. + There is also __dbTransRec() in dummy.prg but I cannot find any + information about this function and its parameters in GOOGLE. + If someone knows what is this functions syntax and can Inform + me then I'll implement it. I guess it's a wrapper to TRANSREC() + RDD method. * harbour/source/rdd/dbf1.c * DBI_LOCKOFFSET now returns DBF record lock offset really used diff --git a/harbour/include/hbdefs.h b/harbour/include/hbdefs.h index a5a8a842e9..70b9423439 100644 --- a/harbour/include/hbdefs.h +++ b/harbour/include/hbdefs.h @@ -392,11 +392,13 @@ #define HB_LIM_INT64(l) ( INT64_MIN <= (l) && (l) <= INT64_MAX ) /* - * It's a hack for MSC which doesn't support LL suffix for LONGLONG + * It's a hack for compilers which don't support LL suffix for LONGLONG * numeric constant. This suffix is necessary for some compilers - * without it they cut the number to LONG */ -#if ( defined( _MSC_VER ) || defined( __BORLANDC__ ) ) && !defined(__DMC__) +#if __BORLANDC__ -0 >= 1328 +# define HB_LL( num ) num##i64 +#elif defined( _MSC_VER ) || defined( __BORLANDC__ ) # define HB_LL( num ) num #else # define HB_LL( num ) num##LL diff --git a/harbour/source/rdd/dbcmd.c b/harbour/source/rdd/dbcmd.c index e225f0467f..5df5397fd4 100644 --- a/harbour/source/rdd/dbcmd.c +++ b/harbour/source/rdd/dbcmd.c @@ -4127,6 +4127,27 @@ HB_FUNC( RDDINFO ) } } +static char * hb_dbTransFieldPos( PHB_ITEM pFields, USHORT uiField ) +{ + char * szField = NULL; + PHB_ITEM pItem; + + pItem = hb_arrayGetItemPtr( pFields, uiField ); + if( pItem ) + { + HB_TYPE type = hb_itemType( pItem ); + + if( type & HB_IT_ARRAY ) + szField = hb_arrayGetCPtr( pItem, DBS_NAME ); + else if( type & HB_IT_STRING ) + szField = hb_itemGetCPtr( pItem ); + + if( * szField == '\0' ) + szField = NULL; + } + + return szField; +} static ERRCODE hb_dbTransStruct( AREAP lpaSource, AREAP lpaDest, LPDBTRANSINFO lpdbTransInfo, @@ -4214,7 +4235,7 @@ static ERRCODE hb_dbTransStruct( AREAP lpaSource, AREAP lpaDest, uiSize = 0; for( uiCount = 1; uiCount <= uiFields; ++uiCount ) { - szField = hb_arrayGetCPtr( pFields, uiCount ); + szField = hb_dbTransFieldPos( pFields, uiCount ); if( szField ) { uiPosSrc = hb_rddFieldExpIndex( lpaSource, szField ); @@ -4419,6 +4440,63 @@ static ERRCODE hb_rddTransRecords( AREAP pArea, return errCode; } +/* __dbTrans( nDstArea, aFieldsStru, bFor, bWhile, nNext, nRecord, lRest ) */ +HB_FUNC( __DBTRANS ) +{ + if( ISNUM( 1 ) ) + { + USHORT uiSrcArea, uiDstArea; + AREAP pSrcArea, pDstArea; + + uiSrcArea = hb_rddGetCurrentWorkAreaNumber(); + pSrcArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); + uiDstArea = hb_parni( 1 ); + hb_rddSelectWorkAreaNumber( uiDstArea ); + pDstArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); + + if( pSrcArea && pDstArea ) + { + DBTRANSINFO dbTransInfo; + ERRCODE errCode; + PHB_ITEM pFields = hb_param( 2, HB_IT_ARRAY ); + + memset( &dbTransInfo, 0, sizeof( DBTRANSINFO ) ); + errCode = hb_dbTransStruct( pSrcArea, pDstArea, &dbTransInfo, + NULL, pFields ); + + if( errCode == SUCCESS ) + { + hb_rddSelectWorkAreaNumber( dbTransInfo.lpaSource->uiArea ); + + dbTransInfo.dbsci.itmCobFor = hb_param( 3, HB_IT_BLOCK ); + dbTransInfo.dbsci.lpstrFor = NULL; + dbTransInfo.dbsci.itmCobWhile = hb_param( 4, HB_IT_BLOCK ); + dbTransInfo.dbsci.lpstrWhile = NULL; + dbTransInfo.dbsci.lNext = hb_param( 5, HB_IT_NUMERIC ); + dbTransInfo.dbsci.itmRecID = ISNIL( 6 ) ? NULL : hb_param( 6, HB_IT_ANY ); + dbTransInfo.dbsci.fRest = hb_param( 7, HB_IT_LOGICAL ); + + dbTransInfo.dbsci.fIgnoreFilter = TRUE; + dbTransInfo.dbsci.fIncludeDeleted = TRUE; + dbTransInfo.dbsci.fLast = FALSE; + dbTransInfo.dbsci.fIgnoreDuplicates = FALSE; + dbTransInfo.dbsci.fBackward = FALSE; + + errCode = SELF_TRANS( dbTransInfo.lpaSource, &dbTransInfo ); + } + + if( dbTransInfo.lpTransItems ) + hb_xfree( dbTransInfo.lpTransItems ); + } + else + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "__DBTRANS" ); + + hb_rddSelectWorkAreaNumber( uiSrcArea ); + } + else + hb_errRT_DBCMD( EG_ARG, EDBCMD_USE_BADPARAMETER, NULL, "__DBTRANS" ); +} + HB_FUNC( __DBAPP ) { if( ISCHAR( 1 ) ) diff --git a/harbour/source/rdd/dbf1.c b/harbour/source/rdd/dbf1.c index f2c423fa90..d2e896d796 100644 --- a/harbour/source/rdd/dbf1.c +++ b/harbour/source/rdd/dbf1.c @@ -861,6 +861,67 @@ HB_EXPORT BOOL hb_dbfLockIdxFile( FHANDLE hFile, BYTE bScheme, USHORT usMode, HB return fRet; } +/* + * Get DBF locking parameters + */ +static ERRCODE hb_dbfLockData( DBFAREAP pArea, + HB_FOFFSET * ulPos, HB_FOFFSET * ulFlSize, + HB_FOFFSET * ulRlSize, int * iDir ) +{ + switch( pArea->bLockType ) + { + case DB_DBFLOCK_CLIP: + *ulPos = DBF_LOCKPOS_CLIP; + *iDir = DBF_LOCKDIR_CLIP; + *ulFlSize = DBF_FLCKSIZE_CLIP; + *ulRlSize = DBF_RLCKSIZE_CLIP; + break; + + case DB_DBFLOCK_CL53: + *ulPos = DBF_LOCKPOS_CL53; + *iDir = DBF_LOCKDIR_CL53; + *ulFlSize = DBF_FLCKSIZE_CL53; + *ulRlSize = DBF_RLCKSIZE_CL53; + break; + + case DB_DBFLOCK_CL53EXT: + *ulPos = DBF_LOCKPOS_CL53EXT; + *iDir = DBF_LOCKDIR_CL53EXT; + *ulFlSize = DBF_FLCKSIZE_CL53EXT; + *ulRlSize = DBF_RLCKSIZE_CL53EXT; + break; + + case DB_DBFLOCK_VFP: + if( pArea->fHasTags ) + { + *ulPos = DBF_LOCKPOS_VFPX; + *iDir = DBF_LOCKDIR_VFPX; + *ulFlSize = DBF_FLCKSIZE_VFPX; + *ulRlSize = DBF_RLCKSIZE_VFPX; + } + else + { + *ulPos = DBF_LOCKPOS_VFP; + *iDir = DBF_LOCKDIR_VFP; + *ulFlSize = DBF_FLCKSIZE_VFP; + *ulRlSize = DBF_RLCKSIZE_VFP; + } + break; + +#ifndef HB_LONG_LONG_OFF + case DB_DBFLOCK_XHB64: + *ulPos = DBF_LOCKPOS_XHB64; + *iDir = DBF_LOCKDIR_XHB64; + *ulFlSize = DBF_FLCKSIZE_XHB64; + *ulRlSize = DBF_RLCKSIZE_XHB64; + break; +#endif + default: + return FAILURE; + } + return SUCCESS; +} + /* * -- DBF METHODS -- */ @@ -2472,9 +2533,11 @@ static ERRCODE hb_dbfInfo( DBFAREAP pArea, USHORT uiIndex, PHB_ITEM pItem ) case DBI_LOCKOFFSET: { - HB_FOFFSET ulPos, ulPool; + HB_FOFFSET ulPos, ulFlSize, ulRlSize; + int iDir; - hb_dbfLockIdxGetData( pArea->bLockType, &ulPos, &ulPool ); + if( hb_dbfLockData( pArea, &ulPos, &ulFlSize, &ulRlSize, &iDir ) == FAILURE ) + ulPos = 0; hb_itemPutNInt( pItem, ulPos ); break; } @@ -3595,58 +3658,8 @@ static ERRCODE hb_dbfRawLock( DBFAREAP pArea, USHORT uiAction, ULONG ulRecNo ) if( pArea->fShared ) { - switch( pArea->bLockType ) - { - case DB_DBFLOCK_CLIP: - ulPos = DBF_LOCKPOS_CLIP; - iDir = DBF_LOCKDIR_CLIP; - ulFlSize = DBF_FLCKSIZE_CLIP; - ulRlSize = DBF_RLCKSIZE_CLIP; - break; - - case DB_DBFLOCK_CL53: - ulPos = DBF_LOCKPOS_CL53; - iDir = DBF_LOCKDIR_CL53; - ulFlSize = DBF_FLCKSIZE_CL53; - ulRlSize = DBF_RLCKSIZE_CL53; - break; - - case DB_DBFLOCK_CL53EXT: - ulPos = DBF_LOCKPOS_CL53EXT; - iDir = DBF_LOCKDIR_CL53EXT; - ulFlSize = DBF_FLCKSIZE_CL53EXT; - ulRlSize = DBF_RLCKSIZE_CL53EXT; - break; - - case DB_DBFLOCK_VFP: - if( pArea->fHasTags ) - { - ulPos = DBF_LOCKPOS_VFPX; - iDir = DBF_LOCKDIR_VFPX; - ulFlSize = DBF_FLCKSIZE_VFPX; - ulRlSize = DBF_RLCKSIZE_VFPX; - } - else - { - ulPos = DBF_LOCKPOS_VFP; - iDir = DBF_LOCKDIR_VFP; - ulFlSize = DBF_FLCKSIZE_VFP; - ulRlSize = DBF_RLCKSIZE_VFP; - } - break; - -#ifndef HB_LONG_LONG_OFF - case DB_DBFLOCK_XHB64: - ulPos = DBF_LOCKPOS_XHB64; - iDir = DBF_LOCKDIR_XHB64; - ulFlSize = DBF_FLCKSIZE_XHB64; - ulRlSize = DBF_RLCKSIZE_XHB64; - break; -#endif - - default: - return FAILURE; - } + if( hb_dbfLockData( pArea, &ulPos, &ulFlSize, &ulRlSize, &iDir ) == FAILURE ) + return FAILURE; switch( uiAction ) { diff --git a/harbour/source/rdd/dbfcdx/dbfcdx1.c b/harbour/source/rdd/dbfcdx/dbfcdx1.c index 2a5e42537d..ff1bb9ed9d 100644 --- a/harbour/source/rdd/dbfcdx/dbfcdx1.c +++ b/harbour/source/rdd/dbfcdx/dbfcdx1.c @@ -4780,16 +4780,16 @@ static BOOL hb_cdxIndexLoad( LPCDXINDEX pIndex, char * szBaseName ) /* * create index file name */ -static void hb_cdxCreateFName( CDXAREAP pArea, char * szBagName, +static void hb_cdxCreateFName( CDXAREAP pArea, char * szBagName, BOOL * fProd, char * szFileName, char * szBaseName ) { PHB_FNAME pFileName; - BOOL fName = szBagName && *szBagName; PHB_ITEM pExt = NULL; + BOOL fName = szBagName && *szBagName; pFileName = hb_fsFNameSplit( fName ? szBagName : pArea->szDataFileName ); - if ( szBaseName ) + if( szBaseName ) { if( pFileName->szName ) hb_strncpyUpperTrim( szBaseName, pFileName->szName, CDX_MAXTAGNAMELEN ); @@ -4797,23 +4797,48 @@ static void hb_cdxCreateFName( CDXAREAP pArea, char * szBagName, szBaseName[ 0 ] = '\0'; } - if ( !pFileName->szExtension || !fName ) + if( !pFileName->szExtension || !fName ) { DBORDERINFO pExtInfo; memset( &pExtInfo, 0, sizeof( pExtInfo ) ); pExt = pExtInfo.itmResult = hb_itemPutC( NULL, "" ); - if ( SELF_ORDINFO( ( AREAP ) pArea, DBOI_BAGEXT, &pExtInfo ) == SUCCESS && - hb_itemGetCLen( pExtInfo.itmResult ) > 0 ) + if( SELF_ORDINFO( ( AREAP ) pArea, DBOI_BAGEXT, &pExtInfo ) == SUCCESS && + hb_itemGetCLen( pExt ) > 0 ) { - pFileName->szExtension = hb_itemGetCPtr( pExtInfo.itmResult ); + pFileName->szExtension = hb_itemGetCPtr( pExt ); } } - hb_fsFNameMerge( szFileName, pFileName ); - if ( pExt ) - hb_itemRelease( pExt ); + if( fProd ) + { + if( ! pFileName->szName ) + *fProd = FALSE; + else if( !fName ) + *fProd = TRUE; + else + { + PHB_FNAME pTableFileName = hb_fsFNameSplit( pArea->szDataFileName ); + + *fProd = pTableFileName->szName && + hb_stricmp( pTableFileName->szName, pFileName->szName ) == 0; + if( *fProd && pFileName->szExtension && ! pExt ) + { + DBORDERINFO pExtInfo; + memset( &pExtInfo, 0, sizeof( pExtInfo ) ); + pExt = pExtInfo.itmResult = hb_itemPutC( NULL, "" ); + if( SELF_ORDINFO( ( AREAP ) pArea, DBOI_BAGEXT, &pExtInfo ) == SUCCESS ) + { + *fProd = hb_stricmp( pFileName->szExtension, + hb_itemGetCPtr( pExt ) ) == 0; + } + } + hb_xfree( pTableFileName ); + } + } hb_xfree( pFileName ); + if( pExt ) + hb_itemRelease( pExt ); } /* @@ -6944,7 +6969,8 @@ static ERRCODE hb_cdxOpen( CDXAREAP pArea, LPDBOPENINFO pOpenInfo ) { char szFileName[ _POSIX_PATH_MAX + 1 ]; - hb_cdxCreateFName( pArea, NULL, szFileName, NULL ); + pArea->fHasTags = FALSE; + hb_cdxCreateFName( pArea, NULL, NULL, szFileName, NULL ); if ( hb_spFile( ( BYTE * ) szFileName, NULL ) ) { DBORDERINFO pOrderInfo; @@ -6965,10 +6991,6 @@ static ERRCODE hb_cdxOpen( CDXAREAP pArea, LPDBOPENINFO pOpenInfo ) hb_itemRelease( pOrderInfo.atomBagName ); hb_itemRelease( pOrderInfo.itmResult ); } - else - { - pArea->fHasTags = FALSE; - } } else { @@ -7068,7 +7090,7 @@ static ERRCODE hb_cdxOrderListAdd( CDXAREAP pArea, LPDBORDERINFO pOrderInfo ) char szBaseName[ CDX_MAXTAGNAMELEN + 1 ]; char szFileName[ _POSIX_PATH_MAX + 1 ]; LPCDXINDEX pIndex, * pIndexPtr; - BOOL bRetry; + BOOL fProd, bRetry; HB_TRACE(HB_TR_DEBUG, ("hb_cdxOrderListAdd(%p, %p)", pArea, pOrderInfo)); @@ -7079,7 +7101,7 @@ static ERRCODE hb_cdxOrderListAdd( CDXAREAP pArea, LPDBORDERINFO pOrderInfo ) return FAILURE; hb_cdxCreateFName( pArea, hb_itemGetCPtr( pOrderInfo->atomBagName ), - szFileName, szBaseName ); + &fProd, szFileName, szBaseName ); /* if ( ! szBaseName[0] ) @@ -7148,6 +7170,9 @@ static ERRCODE hb_cdxOrderListAdd( CDXAREAP pArea, LPDBORDERINFO pOrderInfo ) return FAILURE; } + if( fProd ) + pArea->fHasTags = TRUE; + /* dbfcdx specific: If there was no controlling order, set this one. * This is the behaviour of Clipper's dbfcdx, although * Clipper doc says a different rule @@ -7266,7 +7291,7 @@ static ERRCODE hb_cdxOrderListRebuild( CDXAREAP pArea ) static ERRCODE hb_cdxOrderCreate( CDXAREAP pArea, LPDBORDERCREATEINFO pOrderInfo ) { ULONG ulRecNo; - BOOL fNewFile, fOpenedIndex, fProd = FALSE, fAscend = TRUE, fCustom = FALSE, + BOOL fNewFile, fOpenedIndex, fProd, fAscend = TRUE, fCustom = FALSE, fTemporary = FALSE, fExclusive = FALSE; PHB_ITEM pKeyExp, pForExp = NULL, pResult; char szCpndTagName[ CDX_MAXTAGNAMELEN + 1 ], szTagName[ CDX_MAXTAGNAMELEN + 1 ]; @@ -7396,7 +7421,7 @@ static ERRCODE hb_cdxOrderCreate( CDXAREAP pArea, LPDBORDERCREATEINFO pOrderInfo */ hb_cdxCreateFName( pArea, ( char * ) pOrderInfo->abBagName, - szFileName, szCpndTagName ); + &fProd, szFileName, szCpndTagName ); if ( pOrderInfo->atomBagName && pOrderInfo->atomBagName[0] ) { @@ -7542,25 +7567,23 @@ static ERRCODE hb_cdxOrderCreate( CDXAREAP pArea, LPDBORDERCREATEINFO pOrderInfo } hb_cdxIndexUnLockWrite( pIndex ); /* Update DBF header */ - if( !pArea->fHasTags && !fOpenedIndex && !pIndex->fDelete ) + if( !pArea->fHasTags && !fOpenedIndex && !pIndex->fDelete && fProd ) { - PHB_FNAME pFileName; - pFileName = hb_fsFNameSplit( pArea->szDataFileName ); - hb_strncpyUpperTrim( szFileName, pFileName->szName ? pFileName->szName : "", CDX_MAXTAGNAMELEN ); - hb_xfree( pFileName ); - if ( hb_stricmp( szFileName, szCpndTagName ) == 0 ) + pArea->fHasTags = TRUE; + if ( !pArea->fReadonly && ( pArea->dbfHeader.bHasTags & 0x01 ) == 0 ) { - pArea->fHasTags = fProd = TRUE; - if ( !pArea->fReadonly && ( pArea->dbfHeader.bHasTags & 0x01 ) == 0 ) - { #ifdef HB_CDX_CLIP_AUTOPEN - if ( hb_set.HB_SET_AUTOPEN ) + if ( hb_set.HB_SET_AUTOPEN ) #endif - SELF_WRITEDBHEADER( ( AREAP ) pArea ); - } + SELF_WRITEDBHEADER( ( AREAP ) pArea ); } } - if ( !fOpenedIndex ) + else + { + fProd = FALSE; + } + + if( !fOpenedIndex ) { if ( fProd || pArea->lpIndexes == NULL ) { diff --git a/harbour/source/rdd/delim1.c b/harbour/source/rdd/delim1.c index e1e1db7c84..4bf737baba 100644 --- a/harbour/source/rdd/delim1.c +++ b/harbour/source/rdd/delim1.c @@ -1149,9 +1149,9 @@ static ERRCODE hb_delimClose( DELIMAREAP pArea ) */ static ERRCODE hb_delimCreate( DELIMAREAP pArea, LPDBOPENINFO pCreateInfo ) { - ERRCODE errCode = SUCCESS; - PHB_FNAME pFileName; PHB_ITEM pError = NULL; + PHB_FNAME pFileName; + ERRCODE errCode; BOOL fRetry; BYTE szFileName[ _POSIX_PATH_MAX + 1 ]; diff --git a/harbour/source/rtl/dummy.prg b/harbour/source/rtl/dummy.prg index 7548470a3e..2360fccc9c 100644 --- a/harbour/source/rtl/dummy.prg +++ b/harbour/source/rtl/dummy.prg @@ -63,5 +63,4 @@ FUNCTION __dbJoin() ; RETURN NIL /* NOTE: Internal functions */ FUNCTION __dbFList() ; RETURN {} FUNCTION __dbOpenSDF() ; RETURN NIL -FUNCTION __dbTrans() ; RETURN NIL FUNCTION __dbTransRec() ; RETURN NIL