From 271095b949e5aeeef6ffc03eb9452a579a71b7c9 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Thu, 3 May 2007 14:11:30 +0000 Subject: [PATCH] 2007-05-03 16:10 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/common.mak * harbour/include/hbapirdd.h - harbour/include/hbrddwrk.h * harbour/source/rdd/Makefile + harbour/source/rdd/wacore.c + harbour/source/rdd/wafunc.c * harbour/source/rdd/workarea.c * cleaned RDD code: * the default work area implementation from which each RDD inherits and RDD management is now in workarea.c file - this part will be common for all threads in future MT version * the code to mange workareas and aliases moved to wacore.c - this code uses some static variables which will be moved to HVM stack in MT version * helper RDD functions thread independent moved to wafunc.c * harbour/source/rdd/dbcmd.c * removed RDD/WorkArea management code - only independent HB_FUNCs left. IMHO it will be good to divide this file into few ones. * changed dbCreate() and dbUseArea() to return logical value * harbour/config/global.cf - removed nulsys from linked library list - it should not be here because it can confuse some linkers and wrong library will be created * harbour/contrib/rdd_ads/ads1.c * harbour/source/rdd/dbf1.c * harbour/source/rdd/delim1.c * harbour/source/rdd/sdf1.c * harbour/source/rdd/dbfcdx/dbfcdx1.c * harbour/source/rdd/dbfdbt/dbfdbt1.c * harbour/source/rdd/dbffpt/dbffpt1.c * harbour/source/rdd/dbfntx/dbfntx1.c * harbour/source/rdd/nulsys/nulsys.c * updated for recent modifications in RDD API * harbour/include/hbextern.ch - removed __RDDSETDEFAULT() - this function was necessary with old rdd register code and we not not need it for few years. It's not Clipper function so I do not see any reason to keep it but if you want we can add wrapper to standard RDDSETDEFAULT() * harbour/source/rdd/hbsix/sxcompr.c + added workaround for SIX3 bug which I intentionally replicated in [x]Harbour but it may cause data corruption so IMHO it will be better to fix it. * harbour/source/rtl/errorsys.prg * added default action for EG_LOCK - it's Clipper compatible behavior but done in differ way. Due to some differences in linker we are using we cannot exactly replicate Clipper behavior because it will not work on some platforms as expected so I decided to add it here. I think it's even more Clear then the trick with source/sys/ntxerr.prg done by Clipper. Many people do not even knows about it. * harbour/source/rtl/gtcrs/chrmap.c * changed environment variable name from HB_CHRMAP to HB_CHARMAP to be compatible with description in default map file --- harbour/ChangeLog | 61 + harbour/common.mak | 2 + harbour/config/global.cf | 1 - harbour/contrib/rdd_ads/ads1.c | 204 +-- harbour/include/hbapirdd.h | 97 +- harbour/include/hbextern.ch | 1 - harbour/include/hbrddwrk.h | 170 -- harbour/source/rdd/Makefile | 2 + harbour/source/rdd/dbcmd.c | 2554 +++------------------------ harbour/source/rdd/dbf1.c | 206 +-- harbour/source/rdd/dbfcdx/dbfcdx1.c | 14 +- harbour/source/rdd/dbfdbt/dbfdbt1.c | 4 +- harbour/source/rdd/dbffpt/dbffpt1.c | 4 +- harbour/source/rdd/dbfntx/dbfntx1.c | 9 +- harbour/source/rdd/delim1.c | 204 +-- harbour/source/rdd/hbsix/sxcompr.c | 46 +- harbour/source/rdd/nulsys/nulsys.c | 4 +- harbour/source/rdd/sdf1.c | 202 +-- harbour/source/rdd/wacore.c | 421 +++++ harbour/source/rdd/wafunc.c | 1108 ++++++++++++ harbour/source/rdd/workarea.c | 497 +++++- harbour/source/rtl/errorsys.prg | 14 +- harbour/source/rtl/gtcrs/chrmap.c | 2 +- 23 files changed, 2833 insertions(+), 2994 deletions(-) delete mode 100644 harbour/include/hbrddwrk.h create mode 100644 harbour/source/rdd/wacore.c create mode 100644 harbour/source/rdd/wafunc.c diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 5f662113f0..ce8dac6565 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,67 @@ 2002-12-01 13:30 UTC+0100 Foo Bar */ +2007-05-03 16:10 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/common.mak + * harbour/include/hbapirdd.h + - harbour/include/hbrddwrk.h + * harbour/source/rdd/Makefile + + harbour/source/rdd/wacore.c + + harbour/source/rdd/wafunc.c + * harbour/source/rdd/workarea.c + * cleaned RDD code: + * the default work area implementation from which each RDD inherits + and RDD management is now in workarea.c file - this part will be + common for all threads in future MT version + * the code to mange workareas and aliases moved to wacore.c - this + code uses some static variables which will be moved to HVM stack + in MT version + * helper RDD functions thread independent moved to wafunc.c + + * harbour/source/rdd/dbcmd.c + * removed RDD/WorkArea management code - only independent HB_FUNCs + left. IMHO it will be good to divide this file into few ones. + * changed dbCreate() and dbUseArea() to return logical value + + * harbour/config/global.cf + - removed nulsys from linked library list - it should not be here + because it can confuse some linkers and wrong library will be + created + + * harbour/contrib/rdd_ads/ads1.c + * harbour/source/rdd/dbf1.c + * harbour/source/rdd/delim1.c + * harbour/source/rdd/sdf1.c + * harbour/source/rdd/dbfcdx/dbfcdx1.c + * harbour/source/rdd/dbfdbt/dbfdbt1.c + * harbour/source/rdd/dbffpt/dbffpt1.c + * harbour/source/rdd/dbfntx/dbfntx1.c + * harbour/source/rdd/nulsys/nulsys.c + * updated for recent modifications in RDD API + + * harbour/include/hbextern.ch + - removed __RDDSETDEFAULT() - this function was necessary with old + rdd register code and we not not need it for few years. It's not + Clipper function so I do not see any reason to keep it but if you + want we can add wrapper to standard RDDSETDEFAULT() + + * harbour/source/rdd/hbsix/sxcompr.c + + added workaround for SIX3 bug which I intentionally replicated in + [x]Harbour but it may cause data corruption so IMHO it will be better + to fix it. + + * harbour/source/rtl/errorsys.prg + * added default action for EG_LOCK - it's Clipper compatible behavior + but done in differ way. Due to some differences in linker we are + using we cannot exactly replicate Clipper behavior because it will + not work on some platforms as expected so I decided to add it here. + I think it's even more Clear then the trick with source/sys/ntxerr.prg + done by Clipper. Many people do not even knows about it. + + * harbour/source/rtl/gtcrs/chrmap.c + * changed environment variable name from HB_CHRMAP to HB_CHARMAP to + be compatible with description in default map file + 2007-05-01 22:53 UTC+0100 Antonio Linares (alinares@fivetechsoft.com) * contrib/adordd/adordd.prg * DbCreate() implementation just for Microsoft Access diff --git a/harbour/common.mak b/harbour/common.mak index 88e70cb983..ac2836283b 100644 --- a/harbour/common.mak +++ b/harbour/common.mak @@ -681,6 +681,8 @@ CODEPAGE_LIB_OBJS = \ RDD_LIB_OBJS = \ $(OBJ_DIR)\dbcmd.obj \ $(OBJ_DIR)\workarea.obj \ + $(OBJ_DIR)\wacore.obj \ + $(OBJ_DIR)\wafunc.obj \ $(OBJ_DIR)\dbf1.obj \ $(OBJ_DIR)\dbnubs.obj \ $(OBJ_DIR)\delim1.obj \ diff --git a/harbour/config/global.cf b/harbour/config/global.cf index 9d926f4d5e..b34799b743 100644 --- a/harbour/config/global.cf +++ b/harbour/config/global.cf @@ -6,7 +6,6 @@ GRANDP = ../../ HB_ARCH := $(HB_ARCHITECTURE)/$(HB_COMPILER) HB_DB_DRIVERS=\ - nulsys \ dbfntx \ dbfcdx \ dbffpt \ diff --git a/harbour/contrib/rdd_ads/ads1.c b/harbour/contrib/rdd_ads/ads1.c index a4e28ef109..214abd7156 100644 --- a/harbour/contrib/rdd_ads/ads1.c +++ b/harbour/contrib/rdd_ads/ads1.c @@ -359,7 +359,7 @@ static ERRCODE hb_adsCheckLock( ADSAREAP pArea ) u32RetVal = AdsIsRecordLocked( pArea->hTable, 0, &u16Locked ); if( u32RetVal != AE_SUCCESS ) { - hb_errRT_DBCMD( EG_LOCK, u32RetVal, "Lock Required by TestRecLocks", "ADSISRECORDLOCKED" ); + hb_errRT_DBCMD( EG_UNLOCKED, u32RetVal, "Lock Required by TestRecLocks", "ADSISRECORDLOCKED" ); return FAILURE; } if( !u16Locked ) @@ -4496,106 +4496,106 @@ static ERRCODE adsRddInfo( LPRDDNODE pRDD, USHORT uiIndex, ULONG ulConnect, PHB_ #define adsWhoCares NULL -static RDDFUNCS adsTable = { ( DBENTRYP_BP ) adsBof, - ( DBENTRYP_BP ) adsEof, - ( DBENTRYP_BP ) adsFound, - ( DBENTRYP_V ) adsGoBottom, - ( DBENTRYP_UL ) adsGoTo, - ( DBENTRYP_I ) adsGoToId, - ( DBENTRYP_V ) adsGoTop, - ( DBENTRYP_BIB ) adsSeek, - ( DBENTRYP_L ) adsSkip, - ( DBENTRYP_L ) adsSkipFilter, - ( DBENTRYP_L ) adsSkipRaw, - ( DBENTRYP_VF ) adsAddField, - ( DBENTRYP_B ) adsAppend, - ( DBENTRYP_I ) adsCreateFields, - ( DBENTRYP_V ) adsDeleteRec, - ( DBENTRYP_BP ) adsDeleted, - ( DBENTRYP_SP ) adsFieldCount, - ( DBENTRYP_VF ) adsFieldDisplay, - ( DBENTRYP_SSI ) adsFieldInfo, - ( DBENTRYP_SVP ) adsFieldName, - ( DBENTRYP_V ) adsFlush, - ( DBENTRYP_PP ) adsGetRec, - ( DBENTRYP_SI ) adsGetValue, - ( DBENTRYP_SVL ) adsGetVarLen, - ( DBENTRYP_V ) adsGoCold, - ( DBENTRYP_V ) adsGoHot, - ( DBENTRYP_P ) adsPutRec, - ( DBENTRYP_SI ) adsPutValue, - ( DBENTRYP_V ) adsRecall, - ( DBENTRYP_ULP ) adsRecCount, - ( DBENTRYP_ISI ) adsRecInfo, - ( DBENTRYP_ULP ) adsRecNo, - ( DBENTRYP_I ) adsRecId, - ( DBENTRYP_S ) adsSetFieldExtent, - ( DBENTRYP_P ) adsAlias, - ( DBENTRYP_V ) adsClose, - ( DBENTRYP_VP ) adsCreate, - ( DBENTRYP_SI ) adsInfo, - ( DBENTRYP_V ) adsNewArea, - ( DBENTRYP_VP ) adsOpen, - ( DBENTRYP_V ) adsRelease, - ( DBENTRYP_SP ) adsStructSize, - ( DBENTRYP_P ) adsSysName, - ( DBENTRYP_VEI ) adsEval, - ( DBENTRYP_V ) adsPack, - ( DBENTRYP_LSP ) adsPackRec, - ( DBENTRYP_VS ) adsSort, - ( DBENTRYP_VT ) adsTrans, - ( DBENTRYP_VT ) adsTransRec, - ( DBENTRYP_V ) adsZap, - ( DBENTRYP_VR ) adsChildEnd, - ( DBENTRYP_VR ) adsChildStart, - ( DBENTRYP_VR ) adsChildSync, - ( DBENTRYP_V ) adsSyncChildren, - ( DBENTRYP_V ) adsClearRel, - ( DBENTRYP_V ) adsForceRel, - ( DBENTRYP_SVP ) adsRelArea, - ( DBENTRYP_VR ) adsRelEval, - ( DBENTRYP_SVP ) adsRelText, - ( DBENTRYP_VR ) adsSetRel, - ( DBENTRYP_OI ) adsOrderListAdd, - ( DBENTRYP_V ) adsOrderListClear, - ( DBENTRYP_OI ) adsOrderListDelete, - ( DBENTRYP_OI ) adsOrderListFocus, - ( DBENTRYP_V ) adsOrderListRebuild, - ( DBENTRYP_VOI ) adsOrderCondition, - ( DBENTRYP_VOC ) adsOrderCreate, - ( DBENTRYP_OI ) adsOrderDestroy, - ( DBENTRYP_OII ) adsOrderInfo, - ( DBENTRYP_V ) adsClearFilter, - ( DBENTRYP_V ) adsClearLocate, - ( DBENTRYP_V ) adsClearScope, - ( DBENTRYP_VPLP ) adsCountScope, - ( DBENTRYP_I ) adsFilterText, - ( DBENTRYP_SI ) adsScopeInfo, - ( DBENTRYP_VFI ) adsSetFilter, - ( DBENTRYP_VLO ) adsSetLocate, - ( DBENTRYP_VOS ) adsSetScope, - ( DBENTRYP_VPL ) adsSkipScope, - ( DBENTRYP_B ) adsLocate, - ( DBENTRYP_P ) adsCompile, - ( DBENTRYP_I ) adsError, - ( DBENTRYP_I ) adsEvalBlock, - ( DBENTRYP_VSP ) adsRawLock, - ( DBENTRYP_VL ) adsLock, - ( DBENTRYP_I ) adsUnLock, - ( DBENTRYP_V ) adsCloseMemFile, - ( DBENTRYP_VP ) adsCreateMemFile, - ( DBENTRYP_SVPB ) adsGetValueFile, - ( DBENTRYP_VP ) adsOpenMemFile, - ( DBENTRYP_SVPB ) adsPutValueFile, - ( DBENTRYP_V ) adsReadDBHeader, - ( DBENTRYP_V ) adsWriteDBHeader, - ( DBENTRYP_R ) adsInit, - ( DBENTRYP_R ) adsExit, - ( DBENTRYP_RVV ) adsDrop, - ( DBENTRYP_RVV ) adsExists, - ( DBENTRYP_RSLV ) adsRddInfo, - ( DBENTRYP_SVP ) adsWhoCares - }; +static const RDDFUNCS adsTable = { ( DBENTRYP_BP ) adsBof, + ( DBENTRYP_BP ) adsEof, + ( DBENTRYP_BP ) adsFound, + ( DBENTRYP_V ) adsGoBottom, + ( DBENTRYP_UL ) adsGoTo, + ( DBENTRYP_I ) adsGoToId, + ( DBENTRYP_V ) adsGoTop, + ( DBENTRYP_BIB ) adsSeek, + ( DBENTRYP_L ) adsSkip, + ( DBENTRYP_L ) adsSkipFilter, + ( DBENTRYP_L ) adsSkipRaw, + ( DBENTRYP_VF ) adsAddField, + ( DBENTRYP_B ) adsAppend, + ( DBENTRYP_I ) adsCreateFields, + ( DBENTRYP_V ) adsDeleteRec, + ( DBENTRYP_BP ) adsDeleted, + ( DBENTRYP_SP ) adsFieldCount, + ( DBENTRYP_VF ) adsFieldDisplay, + ( DBENTRYP_SSI ) adsFieldInfo, + ( DBENTRYP_SVP ) adsFieldName, + ( DBENTRYP_V ) adsFlush, + ( DBENTRYP_PP ) adsGetRec, + ( DBENTRYP_SI ) adsGetValue, + ( DBENTRYP_SVL ) adsGetVarLen, + ( DBENTRYP_V ) adsGoCold, + ( DBENTRYP_V ) adsGoHot, + ( DBENTRYP_P ) adsPutRec, + ( DBENTRYP_SI ) adsPutValue, + ( DBENTRYP_V ) adsRecall, + ( DBENTRYP_ULP ) adsRecCount, + ( DBENTRYP_ISI ) adsRecInfo, + ( DBENTRYP_ULP ) adsRecNo, + ( DBENTRYP_I ) adsRecId, + ( DBENTRYP_S ) adsSetFieldExtent, + ( DBENTRYP_P ) adsAlias, + ( DBENTRYP_V ) adsClose, + ( DBENTRYP_VP ) adsCreate, + ( DBENTRYP_SI ) adsInfo, + ( DBENTRYP_V ) adsNewArea, + ( DBENTRYP_VP ) adsOpen, + ( DBENTRYP_V ) adsRelease, + ( DBENTRYP_SP ) adsStructSize, + ( DBENTRYP_P ) adsSysName, + ( DBENTRYP_VEI ) adsEval, + ( DBENTRYP_V ) adsPack, + ( DBENTRYP_LSP ) adsPackRec, + ( DBENTRYP_VS ) adsSort, + ( DBENTRYP_VT ) adsTrans, + ( DBENTRYP_VT ) adsTransRec, + ( DBENTRYP_V ) adsZap, + ( DBENTRYP_VR ) adsChildEnd, + ( DBENTRYP_VR ) adsChildStart, + ( DBENTRYP_VR ) adsChildSync, + ( DBENTRYP_V ) adsSyncChildren, + ( DBENTRYP_V ) adsClearRel, + ( DBENTRYP_V ) adsForceRel, + ( DBENTRYP_SVP ) adsRelArea, + ( DBENTRYP_VR ) adsRelEval, + ( DBENTRYP_SVP ) adsRelText, + ( DBENTRYP_VR ) adsSetRel, + ( DBENTRYP_OI ) adsOrderListAdd, + ( DBENTRYP_V ) adsOrderListClear, + ( DBENTRYP_OI ) adsOrderListDelete, + ( DBENTRYP_OI ) adsOrderListFocus, + ( DBENTRYP_V ) adsOrderListRebuild, + ( DBENTRYP_VOI ) adsOrderCondition, + ( DBENTRYP_VOC ) adsOrderCreate, + ( DBENTRYP_OI ) adsOrderDestroy, + ( DBENTRYP_OII ) adsOrderInfo, + ( DBENTRYP_V ) adsClearFilter, + ( DBENTRYP_V ) adsClearLocate, + ( DBENTRYP_V ) adsClearScope, + ( DBENTRYP_VPLP ) adsCountScope, + ( DBENTRYP_I ) adsFilterText, + ( DBENTRYP_SI ) adsScopeInfo, + ( DBENTRYP_VFI ) adsSetFilter, + ( DBENTRYP_VLO ) adsSetLocate, + ( DBENTRYP_VOS ) adsSetScope, + ( DBENTRYP_VPL ) adsSkipScope, + ( DBENTRYP_B ) adsLocate, + ( DBENTRYP_P ) adsCompile, + ( DBENTRYP_I ) adsError, + ( DBENTRYP_I ) adsEvalBlock, + ( DBENTRYP_VSP ) adsRawLock, + ( DBENTRYP_VL ) adsLock, + ( DBENTRYP_I ) adsUnLock, + ( DBENTRYP_V ) adsCloseMemFile, + ( DBENTRYP_VP ) adsCreateMemFile, + ( DBENTRYP_SVPB ) adsGetValueFile, + ( DBENTRYP_VP ) adsOpenMemFile, + ( DBENTRYP_SVPB ) adsPutValueFile, + ( DBENTRYP_V ) adsReadDBHeader, + ( DBENTRYP_V ) adsWriteDBHeader, + ( DBENTRYP_R ) adsInit, + ( DBENTRYP_R ) adsExit, + ( DBENTRYP_RVV ) adsDrop, + ( DBENTRYP_RVV ) adsExists, + ( DBENTRYP_RSLV ) adsRddInfo, + ( DBENTRYP_SVP ) adsWhoCares + }; static void adsRegisterRDD( USHORT * pusRddId ) { @@ -4611,7 +4611,7 @@ static void adsRegisterRDD( USHORT * pusRddId ) { ERRCODE errCode; - errCode = hb_rddInherit( pTable, &adsTable, &adsSuper, 0 ); + errCode = hb_rddInherit( pTable, &adsTable, &adsSuper, NULL ); if ( errCode == SUCCESS ) { /* diff --git a/harbour/include/hbapirdd.h b/harbour/include/hbapirdd.h index 5307aa0662..6035ea47f7 100644 --- a/harbour/include/hbapirdd.h +++ b/harbour/include/hbapirdd.h @@ -77,25 +77,6 @@ HB_EXTERN_BEGIN #define HARBOUR_MAX_RDD_RELTEXT_LENGTH 256 -/* RDD virtual machine integration functions */ - -extern HB_EXPORT USHORT hb_rddInsertAreaNode( char *szDriver ); -extern HB_EXPORT USHORT hb_rddGetCurrentFieldPos( char * szName ); -extern HB_EXPORT void * hb_rddAllocWorkAreaAlias( char * szAlias, int iArea ); -extern HB_EXPORT int hb_rddGetCurrentWorkAreaNumber( void ); -extern HB_EXPORT void * hb_rddGetCurrentWorkAreaPointer( void ); -extern HB_EXPORT ERRCODE hb_rddGetAliasNumber( char * szAlias, int * iArea ); -extern HB_EXPORT ERRCODE hb_rddSelectWorkAreaAlias( char * szAlias ); -extern HB_EXPORT ERRCODE hb_rddSelectWorkAreaNumber( int iArea ); -extern HB_EXPORT ERRCODE hb_rddSelectWorkAreaSymbol( PHB_SYMB pSymAlias ); -extern HB_EXPORT ERRCODE hb_rddGetFieldValue( HB_ITEM_PTR pItem, PHB_SYMB pFieldSymbol ); -extern HB_EXPORT ERRCODE hb_rddPutFieldValue( HB_ITEM_PTR pItem, PHB_SYMB pFieldSymbol ); -extern HB_EXPORT ERRCODE hb_rddFieldGet( HB_ITEM_PTR pItem, PHB_SYMB pFieldSymbol ); -extern HB_EXPORT ERRCODE hb_rddFieldPut( HB_ITEM_PTR pItem, PHB_SYMB pFieldSymbol ); -extern HB_EXPORT void hb_rddShutDown( void ); -extern HB_EXPORT void hb_rddReleaseCurrentArea( void ); - - /* DBCMD errors */ @@ -104,6 +85,7 @@ extern HB_EXPORT void hb_rddReleaseCurrentArea( void ); #define EDBCMD_NOVAR 1003 #define EDBCMD_USE_BADPARAMETER 1005 #define EDBCMD_REL_BADPARAMETER 1006 +#define EDBCMD_ORDLSTADD_BADPARAMETER 1008 #define EDBCMD_FIELDNAME_BADPARAMETER 1009 #define EDBCMD_BADALIAS 1010 #define EDBCMD_DUPALIAS 1011 @@ -1129,19 +1111,80 @@ typedef RDDNODE * LPRDDNODE; * PROTOTYPES * ---------- */ -extern HB_EXPORT int hb_rddRegister( char * szDriver, USHORT uiType ); -extern HB_EXPORT ERRCODE hb_rddInherit( PRDDFUNCS pTable, PRDDFUNCS pSubTable, PRDDFUNCS pSuperTable, BYTE * szDrvName ); +/* RDD virtual machine integration functions */ + +extern HB_EXPORT void hb_rddShutDown( void ); +extern HB_EXPORT ERRCODE hb_rddGetFieldValue( HB_ITEM_PTR pItem, PHB_SYMB pFieldSymbol ); +extern HB_EXPORT ERRCODE hb_rddPutFieldValue( HB_ITEM_PTR pItem, PHB_SYMB pFieldSymbol ); +extern HB_EXPORT ERRCODE hb_rddFieldGet( HB_ITEM_PTR pItem, PHB_SYMB pFieldSymbol ); +extern HB_EXPORT ERRCODE hb_rddFieldPut( HB_ITEM_PTR pItem, PHB_SYMB pFieldSymbol ); +extern HB_EXPORT int hb_rddGetCurrentWorkAreaNumber( void ); +extern HB_EXPORT ERRCODE hb_rddSelectWorkAreaNumber( int iArea ); +extern HB_EXPORT ERRCODE hb_rddSelectWorkAreaAlias( const char * szAlias ); +extern HB_EXPORT ERRCODE hb_rddSelectWorkAreaSymbol( PHB_SYMB pSymAlias ); +extern HB_EXPORT ERRCODE hb_rddGetAliasNumber( const char * szAlias, int * iArea ); + +/* other functions */ +extern HB_EXPORT void * hb_rddAllocWorkAreaAlias( const char * szAlias, int iArea ); +extern HB_EXPORT void * hb_rddGetCurrentWorkAreaPointer( void ); +extern HB_EXPORT void * hb_rddGetWorkAreaPointer( int iArea ); +extern HB_EXPORT USHORT hb_rddInsertAreaNode( const char *szDriver ); +extern HB_EXPORT void hb_rddReleaseCurrentArea( void ); + +extern HB_EXPORT int hb_rddRegister( const char * szDriver, USHORT uiType ); +extern HB_EXPORT ERRCODE hb_rddInherit( RDDFUNCS * pTable, const RDDFUNCS * pSubTable, RDDFUNCS * pSuperTable, const char * szDrvName ); extern HB_EXPORT LPRDDNODE hb_rddGetNode( USHORT uiNode ); +extern HB_EXPORT LPRDDNODE hb_rddFindNode( const char * szDriver, USHORT * uiIndex ); +extern HB_EXPORT USHORT hb_rddFieldIndex( AREAP pArea, const char * szName ); +extern HB_EXPORT USHORT hb_rddFieldExpIndex( AREAP pArea, const char * szField ); +extern HB_EXPORT const char * hb_rddDefaultDrv( const char * szDriver ); +extern HB_EXPORT ERRCODE hb_rddSelectFirstAvailable( void ); +extern HB_EXPORT ERRCODE hb_rddVerifyAliasName( const char * szAlias ); +extern HB_EXPORT void * hb_rddNewAreaNode( LPRDDNODE pRddNode, USHORT uiRddID ); +extern HB_EXPORT PHB_ITEM hb_rddList( USHORT uiType ); +extern HB_EXPORT void hb_rddCloseAll( void ); +extern HB_EXPORT void hb_rddFlushAll( void ); +extern HB_EXPORT void hb_rddUnLockAll( void ); +extern HB_EXPORT BOOL hb_rddGetNetErr( void ); +extern HB_EXPORT void hb_rddSetNetErr( BOOL fNetErr ); + +extern HB_EXPORT ERRCODE hb_rddOpenTable( + const char * szFileName, const char * szDriver, + USHORT uiArea, const char *szAlias, + BOOL fShared, BOOL fReadonly, + const char * szCpId, ULONG ulConnection, + PHB_ITEM pStruct, PHB_ITEM pDelim ); +extern HB_EXPORT ERRCODE hb_rddCreateTable( + const char * szFileName, const char * szDriver, + USHORT uiArea, const char *szAlias, + BOOL fKeepOpen, + const char * szCpId, ULONG ulConnection, + PHB_ITEM pStruct, PHB_ITEM pDelim ); +extern HB_EXPORT ERRCODE hb_dbTransStruct( + AREAP lpaSource, AREAP lpaDest, + LPDBTRANSINFO lpdbTransInfo, + PHB_ITEM *pStruct, PHB_ITEM pFields ); +extern HB_EXPORT ERRCODE hb_rddTransRecords( + AREAP pArea, + const char *szFileName, const char *szDriver, + ULONG ulConnection, + PHB_ITEM pFields, BOOL fExport, + PHB_ITEM pCobFor, PHB_ITEM pStrFor, + PHB_ITEM pCobWhile, PHB_ITEM pStrWhile, + PHB_ITEM pNext, PHB_ITEM pRecID, + PHB_ITEM pRest, + const char *szCpId, + PHB_ITEM pDelim ); +extern HB_EXPORT void hb_tblStructure( AREAP pArea, PHB_ITEM pStruct ); + #if 0 -extern HB_EXPORT ERRCODE hb_rddDisinherit( BYTE * drvName ); +extern HB_EXPORT ERRCODE hb_rddDisinherit( char * drvName ); +extern HB_EXPORT USHORT hb_rddGetCurrentFieldPos( const char * szName ); extern HB_EXPORT USHORT hb_rddExtendType( HB_TYPE fieldType ); extern HB_EXPORT HB_TYPE hb_rddFieldType( USHORT extendType ); #endif - -typedef short (* WACALLBACK )( AREA *, int ); -extern HB_EXPORT ERRCODE hb_rddIterateWorkAreas ( WACALLBACK pCallBack, int data ); -extern HB_EXPORT USHORT hb_rddFieldIndex( AREAP pArea, char * szName ); -extern HB_EXPORT USHORT hb_rddFieldExpIndex( AREAP pArea, char * szField ); +typedef ERRCODE ( * WACALLBACK )( AREAP, void * ); +extern HB_EXPORT ERRCODE hb_rddIterateWorkAreas( WACALLBACK pCallBack, void * cargo ); extern HB_EXPORT ERRCODE hb_rddGetTempAlias( char * szAliasTmp ); HB_EXTERN_END diff --git a/harbour/include/hbextern.ch b/harbour/include/hbextern.ch index 14c172e898..24f0ff84cd 100644 --- a/harbour/include/hbextern.ch +++ b/harbour/include/hbextern.ch @@ -417,7 +417,6 @@ EXTERNAL __MRESTORE EXTERNAL __MSAVE EXTERNAL __MXRELEASE EXTERNAL __QUIT -EXTERNAL __RDDSETDEFAULT EXTERNAL __REPORTFORM EXTERNAL __RUN EXTERNAL __SETCENTURY diff --git a/harbour/include/hbrddwrk.h b/harbour/include/hbrddwrk.h deleted file mode 100644 index 00775ba323..0000000000 --- a/harbour/include/hbrddwrk.h +++ /dev/null @@ -1,170 +0,0 @@ -/* - * $Id$ - */ - -/* - * Harbour Project source code: - * Default RDD module - * - * Copyright 1999 Bruno Cantero - * www - http://www.harbour-project.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this software; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). - * - * As a special exception, the Harbour Project gives permission for - * additional uses of the text contained in its release of Harbour. - * - * The exception is that, if you link the Harbour libraries with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the Harbour library code into it. - * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. - * - * This exception applies only to the code released by the Harbour - * Project under the name Harbour. If you copy code from other - * Harbour Project or Free Software Foundation releases into a copy of - * Harbour, as the General Public License permits, the exception does - * not apply to the code that you add in this way. To avoid misleading - * anyone as to the status of such modified files, you must delete - * this exception notice from them. - * - * If you write modifications of your own for Harbour, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. - * - */ - -#ifndef HB_RDDWRK_H_ -#define HB_RDDWRK_H_ - -#include "hbapirdd.h" - -HB_EXTERN_BEGIN - -/* - * -- METHODS -- - */ - -extern ERRCODE hb_waBof( AREAP pArea, BOOL * pBof ); -extern ERRCODE hb_waEof( AREAP pArea, BOOL * pEof ); -extern ERRCODE hb_waFound( AREAP pArea, BOOL * pFound ); -#define hb_waGoBottom hb_waUnsupported -#define hb_waGoTo ( DBENTRYP_UL ) hb_waUnsupported -#define hb_waGoToId ( DBENTRYP_I ) hb_waUnsupported -#define hb_waGoTop hb_waUnsupported -#define hb_waSeek ( DBENTRYP_BIB ) hb_waUnsupported -extern ERRCODE hb_waSkip( AREAP pArea, LONG lToSkip ); -extern ERRCODE hb_waSkipFilter( AREAP pArea, LONG lUpDown ); -#define hb_waSkipRaw ( DBENTRYP_L ) hb_waUnsupported -extern ERRCODE hb_waAddField( AREAP pArea, LPDBFIELDINFO pFieldInfo ); -#define hb_waAppend ( DBENTRYP_B ) hb_waUnsupported -extern ERRCODE hb_waCreateFields( AREAP pArea, PHB_ITEM pStruct ); -#define hb_waDeleteRec hb_waUnsupported -#define hb_waDeleted ( DBENTRYP_BP ) hb_waUnsupported -extern ERRCODE hb_waFieldCount( AREAP pArea, USHORT * uiFields ); -#define hb_waFieldDisplay ( DBENTRYP_VF ) hb_waUnsupported -extern ERRCODE hb_waFieldInfo( AREAP pArea, USHORT uiIndex, USHORT uiType, PHB_ITEM pItem ); -extern ERRCODE hb_waFieldName( AREAP pArea, USHORT uiIndex, void * szName ); -#define hb_waFlush hb_waUnsupported -#define hb_waGetRec ( DBENTRYP_PP ) hb_waUnsupported -#define hb_waGetValue ( DBENTRYP_SI ) hb_waUnsupported -#define hb_waGetVarLen ( DBENTRYP_SVL ) hb_waUnsupported -#define hb_waGoCold hb_waUnsupported -#define hb_waGoHot hb_waUnsupported -#define hb_waPutRec ( DBENTRYP_P ) hb_waUnsupported -#define hb_waPutValue ( DBENTRYP_SI ) hb_waUnsupported -#define hb_waRecall hb_waUnsupported -#define hb_waRecCount ( DBENTRYP_ULP ) hb_waUnsupported -#define hb_waRecInfo ( DBENTRYP_ISI ) hb_waUnsupported -#define hb_waRecNo ( DBENTRYP_ULP ) hb_waUnsupported -#define hb_waRecId ( DBENTRYP_I ) hb_waUnsupported -extern ERRCODE hb_waSetFieldExtent( AREAP pArea, USHORT uiFieldExtent ); -extern ERRCODE hb_waAlias( AREAP pArea, BYTE * szAlias ); -extern ERRCODE hb_waClose( AREAP pArea ); -/* Like in Clipper map CREATE() method at work area level to OPEN() */ -#define hb_waCreate hb_waOpen -extern ERRCODE hb_waInfo( AREAP pArea, USHORT uiIndex, PHB_ITEM pItem ); -extern ERRCODE hb_waNewArea( AREAP pArea ); -extern ERRCODE hb_waOpen( AREAP pArea, LPDBOPENINFO pInfo ); -extern ERRCODE hb_waRelease( AREAP pArea ); -extern ERRCODE hb_waStructSize( AREAP pArea, USHORT * uiSize ); -extern ERRCODE hb_waSysName( AREAP pArea, BYTE * pBuffer ); -extern ERRCODE hb_waEval( AREAP pArea, LPDBEVALINFO pEvalInfo ); -#define hb_waPack hb_waUnsupported -#define hb_waPackRec ( DBENTRYP_LSP ) hb_waUnsupported -#define hb_waSort ( DBENTRYP_VS ) hb_waUnsupported -extern ERRCODE hb_waTrans( AREAP pArea, LPDBTRANSINFO pTransInfo ); -extern ERRCODE hb_waTransRec( AREAP pArea, LPDBTRANSINFO pTransInfo ); -#define hb_waZap hb_waUnsupported -extern ERRCODE hb_waChildEnd( AREAP pArea, LPDBRELINFO pRelInfo ); -extern ERRCODE hb_waChildStart( AREAP pArea, LPDBRELINFO pRelInfo ); -#define hb_waChildSync ( DBENTRYP_VR ) hb_waUnsupported -extern ERRCODE hb_waSyncChildren( AREAP pArea ); -extern ERRCODE hb_waClearRel( AREAP pArea ); -#define hb_waForceRel hb_waUnsupported -extern ERRCODE hb_waRelArea( AREAP pArea, USHORT uiRelNo, void * pRelArea ); -extern ERRCODE hb_waRelEval( AREAP pArea, LPDBRELINFO pRelInfo ); -extern ERRCODE hb_waRelText( AREAP pArea, USHORT uiRelNo, void * pExpr ); -extern ERRCODE hb_waSetRel( AREAP pArea, LPDBRELINFO pRelInfo ); -#define hb_waOrderListAdd ( DBENTRYP_OI ) hb_waUnsupported -#define hb_waOrderListClear hb_waUnsupported -#define hb_waOrderListDelete ( DBENTRYP_OI ) hb_waUnsupported -#define hb_waOrderListFocus ( DBENTRYP_OI ) hb_waUnsupported -#define hb_waOrderListRebuild hb_waUnsupported -extern ERRCODE hb_waOrderCondition( AREAP pArea, LPDBORDERCONDINFO param ); -#define hb_waOrderCreate ( DBENTRYP_VOC ) hb_waUnsupported -#define hb_waOrderDestroy ( DBENTRYP_OI ) hb_waUnsupported -/* #define hb_waOrderInfo ( DBENTRYP_OII ) hb_waNull */ -extern ERRCODE hb_waOrderInfo( AREAP pArea, USHORT index, LPDBORDERINFO param ); -extern ERRCODE hb_waClearFilter( AREAP pArea ); -extern ERRCODE hb_waClearLocate( AREAP pArea ); -#define hb_waClearScope hb_waUnsupported -#define hb_waCountScope ( DBENTRYP_VPLP ) hb_waUnsupported -extern ERRCODE hb_waFilterText( AREAP pArea, PHB_ITEM pFilter ); -#define hb_waScopeInfo ( DBENTRYP_SI ) hb_waUnsupported -extern ERRCODE hb_waSetFilter( AREAP pArea, LPDBFILTERINFO pFilterInfo ); -extern ERRCODE hb_waSetLocate( AREAP pArea, LPDBSCOPEINFO pScopeInfo ); -#define hb_waSetScope ( DBENTRYP_VOS ) hb_waUnsupported -#define hb_waSkipScope ( DBENTRYP_VPL ) hb_waUnsupported -ERRCODE hb_waLocate( AREAP pArea, BOOL fContinue ); -extern ERRCODE hb_waCompile( AREAP pArea, BYTE * pExpr ); -extern ERRCODE hb_waError( AREAP pArea, PHB_ITEM pError ); -extern ERRCODE hb_waEvalBlock( AREAP pArea, PHB_ITEM pBlock ); -#define hb_waRawLock ( DBENTRYP_VSP ) hb_waUnsupported -#define hb_waLock ( DBENTRYP_VL ) hb_waUnsupported -#define hb_waUnLock ( DBENTRYP_I ) hb_waUnsupported -#define hb_waCloseMemFile hb_waUnsupported -#define hb_waCreateMemFile ( DBENTRYP_VP ) hb_waUnsupported -#define hb_waGetValueFile ( DBENTRYP_SVPB ) hb_waUnsupported -#define hb_waOpenMemFile ( DBENTRYP_VP ) hb_waUnsupported -#define hb_waPutValueFile ( DBENTRYP_SVPB ) hb_waUnsupported -#define hb_waReadDBHeader hb_waUnsupported -#define hb_waWriteDBHeader hb_waUnsupported - -#define hb_rddInit (DBENTRYP_R) NULL -#define hb_rddExit (DBENTRYP_R) NULL -#define hb_rddDrop (DBENTRYP_RVV) hb_waRddUnsupported -#define hb_rddExists (DBENTRYP_RVV) hb_waRddUnsupported -extern ERRCODE hb_rddInfo( LPRDDNODE pRDD, USHORT uiIndex, ULONG ulConnection, PHB_ITEM pItem ); - -#define hb_waWhoCares ( DBENTRYP_SVP ) hb_waUnsupported - -HB_EXTERN_END - -#endif /* HB_RDDWRK_H_ */ diff --git a/harbour/source/rdd/Makefile b/harbour/source/rdd/Makefile index 4c12d18f7a..b2022c3284 100644 --- a/harbour/source/rdd/Makefile +++ b/harbour/source/rdd/Makefile @@ -7,6 +7,8 @@ ROOT = ../../ C_SOURCES=\ dbcmd.c \ workarea.c \ + wacore.c \ + wafunc.c \ dbf1.c \ dbnubs.c \ dbsql.c \ diff --git a/harbour/source/rdd/dbcmd.c b/harbour/source/rdd/dbcmd.c index 9591d8803d..e632d22560 100644 --- a/harbour/source/rdd/dbcmd.c +++ b/harbour/source/rdd/dbcmd.c @@ -7,6 +7,7 @@ * Base RDD module * * Copyright 1999 Bruno Cantero + * Copyright 2004-2007 Przemyslaw Czerpak * www - http://www.harbour-project.org * * This program is free software; you can redistribute it and/or modify @@ -62,1276 +63,18 @@ * */ -/* JC1: optimizing stack access under MT */ -#define HB_THREAD_OPTIMIZE_STACK - -#include #include "hbapi.h" -#include "hbstack.h" -#include "hbvm.h" -#include "hbapifs.h" -#include "hbset.h" +#include "hbapirdd.h" #include "hbapierr.h" -#include "hbapilng.h" #include "hbapiitm.h" -#include "hbrddwrk.h" -#include "rddsys.ch" -#if defined(__XHARBOUR__) -#include "hbfast.h" -#else -# define HB_THREAD_STUB -#endif -#ifndef HB_CDP_SUPPORT_OFF -# include "hbapicdp.h" -#endif - -HB_FUNC_EXTERN( RDDSYS ); - -static char s_szDefDriver[HARBOUR_MAX_RDD_DRIVERNAME_LENGTH + 1] = ""; /* Default RDD name */ -static LPRDDNODE * s_RddList = NULL; /* Registered RDDs */ -static USHORT s_uiRddMax = 0; /* Number of registered RDD */ - -static AREAP * s_WaList = NULL; /* Allocated WorkAreas */ -static USHORT s_uiWaMax = 0; /* Number of allocated WA */ -static USHORT s_uiWaSpace = 0; /* Number of allocated WA */ - -static USHORT * s_WaNums = NULL; /* Allocated WorkAreas */ -static USHORT s_uiWaNumMax = 0; /* Number of allocated WA */ - -static BOOL s_bNetError = FALSE; /* Error on Networked environments */ -#ifndef HB_THREAD_SUPPORT - static USHORT s_uiCurrArea = 1; /* Selected area */ - static AREAP s_pCurrArea = NULL; /* Selected area */ - #define LOCK_AREA - #define UNLOCK_AREA - #define LOCK_AREA_INIT - #define LOCK_AREA_DESTROY -#else - #define s_uiCurrArea HB_VM_STACK.uiCurrArea - #define s_pCurrArea HB_VM_STACK.pCurrArea - HB_CRITICAL_T s_mtxWorkArea; - #if defined (HB_OS_WIN_32) || defined(HB_OS_OS2) - static BOOL s_fMtLockInit = FALSE; - #define LOCK_AREA if ( s_fMtLockInit ) HB_CRITICAL_LOCK( s_mtxWorkArea ); - #define UNLOCK_AREA if ( s_fMtLockInit ) HB_CRITICAL_UNLOCK( s_mtxWorkArea ); - #define LOCK_AREA_INIT if ( !s_fMtLockInit ) { HB_CRITICAL_INIT( s_mtxWorkArea ); s_fMtLockInit = TRUE; } - #define LOCK_AREA_DESTROY if ( s_fMtLockInit ) { HB_CRITICAL_DESTROY( s_mtxWorkArea ); s_fMtLockInit = FALSE; } - #else - #define LOCK_AREA HB_CRITICAL_LOCK( s_mtxWorkArea ); - #define UNLOCK_AREA HB_CRITICAL_UNLOCK( s_mtxWorkArea ); - #define LOCK_AREA_INIT - #define LOCK_AREA_DESTROY - #endif -#endif - -#define HB_SET_WA( n ) do \ - { \ - s_uiCurrArea = n; \ - s_pCurrArea = ( ( s_uiCurrArea < s_uiWaNumMax ) ? \ - s_WaList[ s_WaNums[ s_uiCurrArea ] ] : \ - NULL ); \ - } while ( 0 ); - -#define HB_GET_WA( n ) ( ( (n) < s_uiWaNumMax ) ? s_WaList[ s_WaNums[ ( n ) ] ] : NULL ) -/* #define HB_CURRENT_WA HB_GET_WA( s_uiCurrArea ) */ -#define HB_CURRENT_WA s_pCurrArea - -/* - * -- DEFAULT METHODS -- - */ - -#if 0 -/* - * Empty method. - */ -static ERRCODE hb_waNull( AREAP pArea ) -{ - HB_TRACE(HB_TR_DEBUG, ("hb_waNull(%p)", pArea)); - HB_SYMBOL_UNUSED( pArea ); - - return SUCCESS; -} -#endif - -/* - * Raise a runtime error if an method is not defined. - */ -static ERRCODE hb_waUnsupported( AREAP pArea ) -{ - PHB_ITEM pError; - - HB_TRACE(HB_TR_DEBUG, ("hb_waUnsupported(%p)", pArea)); - - if( !pArea ) - { - HB_FUNC_EXEC( RDDSYS ); - } - - pError = hb_errNew(); - hb_errPutGenCode( pError, EG_UNSUPPORTED ); - hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_UNSUPPORTED ) ); - SELF_ERROR( pArea, pError ); - hb_itemRelease( pError ); - - return FAILURE; -} - -/* - * Raise a runtime error if an method is not defined. - */ -static ERRCODE hb_waRddUnsupported( LPRDDNODE pRDD ) -{ - PHB_ITEM pError; - - HB_TRACE(HB_TR_DEBUG, ("hb_waRDDUnsupported(%p)", pRDD)); - - pError = hb_errNew(); - hb_errPutGenCode( pError, EG_UNSUPPORTED ); - hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_UNSUPPORTED ) ); - - hb_errPutSeverity( pError, ES_ERROR ); - hb_errPutSubSystem( pError, pRDD->szName ); - hb_errLaunch( pError ); - hb_itemRelease( pError ); - - return FAILURE; -} - -/* - * The default virtual method table for all WorkAreas. - */ -static RDDFUNCS waTable = { hb_waBof, - hb_waEof, - hb_waFound, - hb_waGoBottom, - hb_waGoTo, - hb_waGoToId, - hb_waGoTop, - hb_waSeek, - hb_waSkip, - hb_waSkipFilter, - hb_waSkipRaw, - hb_waAddField, - hb_waAppend, - hb_waCreateFields, - hb_waDeleteRec, - hb_waDeleted, - hb_waFieldCount, - hb_waFieldDisplay, - hb_waFieldInfo, - hb_waFieldName, - hb_waFlush, - hb_waGetRec, - hb_waGetValue, - hb_waGetVarLen, - hb_waGoCold, - hb_waGoHot, - hb_waPutRec, - hb_waPutValue, - hb_waRecall, - hb_waRecCount, - hb_waRecInfo, - hb_waRecNo, - hb_waRecId, - hb_waSetFieldExtent, - hb_waAlias, - hb_waClose, - hb_waCreate, - hb_waInfo, - hb_waNewArea, - hb_waOpen, - hb_waRelease, - hb_waStructSize, - hb_waSysName, - hb_waEval, - hb_waPack, - hb_waPackRec, - hb_waSort, - hb_waTrans, - hb_waTransRec, - hb_waZap, - hb_waChildEnd, - hb_waChildStart, - hb_waChildSync, - hb_waSyncChildren, - hb_waClearRel, - hb_waForceRel, - hb_waRelArea, - hb_waRelEval, - hb_waRelText, - hb_waSetRel, - hb_waOrderListAdd, - hb_waOrderListClear, - hb_waOrderListDelete, - hb_waOrderListFocus, - hb_waOrderListRebuild, - hb_waOrderCondition, - hb_waOrderCreate, - hb_waOrderDestroy, - hb_waOrderInfo, - hb_waClearFilter, - hb_waClearLocate, - hb_waClearScope, - hb_waCountScope, - hb_waFilterText, - hb_waScopeInfo, - hb_waSetFilter, - hb_waSetLocate, - hb_waSetScope, - hb_waSkipScope, - hb_waLocate, - hb_waCompile, - hb_waError, - hb_waEvalBlock, - hb_waRawLock, - hb_waLock, - hb_waUnLock, - hb_waCloseMemFile, - hb_waCreateMemFile, - hb_waGetValueFile, - hb_waOpenMemFile, - hb_waPutValueFile, - hb_waReadDBHeader, - hb_waWriteDBHeader, - hb_rddInit, - hb_rddExit, - hb_rddDrop, - hb_rddExists, - hb_rddInfo, - hb_waWhoCares - }; - -/* - * Get RDD node poionter - */ -HB_EXPORT LPRDDNODE hb_rddGetNode( USHORT uiNode ) -{ - HB_TRACE(HB_TR_DEBUG, ("hb_rddGetNode(%hu)", uiNode)); - - return uiNode < s_uiRddMax ? s_RddList[ uiNode ] : NULL; -} - -/* - * Find a RDD node. - */ -static LPRDDNODE hb_rddFindNode( char * szDriver, USHORT * uiIndex ) -{ - USHORT uiCount; - - HB_TRACE(HB_TR_DEBUG, ("hb_rddFindNode(%s, %p)", szDriver, uiIndex)); - - for ( uiCount = 0; uiCount < s_uiRddMax; uiCount++ ) - { - if( strcmp( s_RddList[ uiCount ]->szName, szDriver ) == 0 ) /* Matched RDD */ - { - if( uiIndex ) - * uiIndex = uiCount; - return s_RddList[ uiCount ]; - } - } - if( uiIndex ) - * uiIndex = 0; - return NULL; -} - -/* - * Get (/set) default RDD driver - */ -static char * hb_rddDefaultDrv( char * szDriver ) -{ - static BOOL fInit = FALSE; - - if( szDriver && *szDriver ) - { - char szNewDriver[ HARBOUR_MAX_RDD_DRIVERNAME_LENGTH + 1 ]; - - hb_strncpyUpper( szNewDriver, szDriver, HARBOUR_MAX_RDD_DRIVERNAME_LENGTH ); - if( !hb_rddFindNode( szNewDriver, NULL ) ) - { - return NULL; - } - hb_strncpy( s_szDefDriver, szNewDriver, HARBOUR_MAX_RDD_DRIVERNAME_LENGTH ); - } - else if( !fInit && !s_szDefDriver[ 0 ] && s_uiRddMax ) - { - char *szDrvTable[] = { "DBFNTX", "DBFCDX", "DBFFPT", "DBF", NULL }; - int i; - - for( i = 0; szDrvTable[ i ]; ++i ) - { - if( hb_rddFindNode( szDrvTable[ i ], NULL ) ) - { - hb_strncpy( s_szDefDriver, szDrvTable[ i ], HARBOUR_MAX_RDD_DRIVERNAME_LENGTH ); - break; - } - } - fInit = TRUE; - } - - return s_szDefDriver; -} - -/* - * Register a RDD driver. - */ -HB_EXPORT int hb_rddRegister( char * szDriver, USHORT uiType ) -{ - LPRDDNODE pRddNewNode; - PHB_DYNS pGetFuncTable; - char szGetFuncTable[ HARBOUR_MAX_RDD_DRIVERNAME_LENGTH + 14 ]; - USHORT uiFunctions; - - HB_TRACE(HB_TR_DEBUG, ("hb_rddRegister(%s, %hu)", szDriver, uiType)); - - if( hb_rddFindNode( szDriver, NULL ) ) /* Duplicated RDD */ - { - return 1; - } - - snprintf( szGetFuncTable, sizeof( szGetFuncTable ), "%s_GETFUNCTABLE", - szDriver ); - pGetFuncTable = hb_dynsymFindName( szGetFuncTable ); - if( !pGetFuncTable ) - { - return 2; /* Not valid RDD */ - } - - /* Create a new RDD node */ - pRddNewNode = ( LPRDDNODE ) hb_xgrab( sizeof( RDDNODE ) ); - memset( pRddNewNode, 0, sizeof( RDDNODE ) ); - - /* Fill the new RDD node */ - hb_strncpy( pRddNewNode->szName, szDriver, HARBOUR_MAX_RDD_DRIVERNAME_LENGTH ); - pRddNewNode->uiType = uiType; - pRddNewNode->rddID = s_uiRddMax; - - /* Call _GETFUNCTABLE() */ - hb_vmPushSymbol( hb_dynsymSymbol( pGetFuncTable ) ); - hb_vmPushNil(); - hb_vmPushPointer( ( void * ) &uiFunctions ); - hb_vmPushPointer( ( void * ) &pRddNewNode->pTable ); - hb_vmPushPointer( ( void * ) &pRddNewNode->pSuperTable ); - hb_vmPushInteger( s_uiRddMax ); - hb_vmDo( 4 ); - if( hb_parni( -1 ) != SUCCESS ) - { - hb_xfree( pRddNewNode ); /* Delete de new RDD node */ - return 3; /* Invalid FUNCTABLE */ - } - - if( s_uiRddMax == 0 ) /* First RDD node */ - { - LOCK_AREA_INIT - s_RddList = (LPRDDNODE *) hb_xgrab( sizeof(LPRDDNODE) ); - } - else - s_RddList = (LPRDDNODE *) hb_xrealloc( s_RddList, sizeof(LPRDDNODE) * ( s_uiRddMax + 1 ) ); - - s_RddList[ s_uiRddMax++ ] = pRddNewNode; /* Add the new RDD node */ - - if( pRddNewNode->pTable.init != NULL ) - { - SELF_INIT( pRddNewNode ); - } - - return 0; /* Ok */ -} - -/* - * pTable - a table in new RDDNODE that will be filled - * pSubTable - a table with a list of supported functions - * pSuperTable - a current table in a RDDNODE - * szDrvName - a driver name that will be inherited - */ -HB_EXPORT ERRCODE hb_rddInherit( PRDDFUNCS pTable, PRDDFUNCS pSubTable, PRDDFUNCS pSuperTable, BYTE * szDrvName ) -{ - LPRDDNODE pRddNode; - USHORT uiCount; - DBENTRYP_V * pFunction, * pSubFunction; - - HB_TRACE(HB_TR_DEBUG, ("hb_rddInherit(%p, %p, %p, %s)", pTable, pSubTable, pSuperTable, szDrvName)); - - if( !pTable ) - { - return FAILURE; - } - - /* Copy the pSuperTable into pTable */ - if( !szDrvName || ! *szDrvName ) - { - /* no name for inherited driver - use the default one */ - memcpy( pTable, &waTable, sizeof( RDDFUNCS ) ); - memcpy( pSuperTable, &waTable, sizeof( RDDFUNCS ) ); - } - else - { - char szSuperName[ HARBOUR_MAX_RDD_DRIVERNAME_LENGTH + 1 ]; - hb_strncpyUpper( szSuperName, ( char * ) szDrvName, HARBOUR_MAX_RDD_DRIVERNAME_LENGTH ); - pRddNode = hb_rddFindNode( szSuperName, NULL ); - - if( !pRddNode ) - { - return FAILURE; - } - - memcpy( pTable, &pRddNode->pTable, sizeof( RDDFUNCS ) ); - memcpy( pSuperTable, &pRddNode->pTable, sizeof( RDDFUNCS ) ); - } - - /* Copy the non NULL entries from pSubTable into pTable */ - pFunction = ( DBENTRYP_V * ) pTable; - pSubFunction = ( DBENTRYP_V * ) pSubTable; - for( uiCount = 0; uiCount < RDDFUNCSCOUNT; uiCount++ ) - { - if( * pSubFunction ) - * pFunction = * pSubFunction; - pFunction ++; - pSubFunction ++; - } - return SUCCESS; -} - -/* - * check if a given name can be used as alias expression - */ -static ERRCODE hb_rddVerifyAliasName( char * szAlias ) -{ - char c; - - if( szAlias ) - { - while( *szAlias == ' ' ) - { - szAlias++; - } - c = *szAlias; - if( c >= 'a' && c <= 'z' ) - { - c -= 'a' - 'A'; - } - if( ( c >= 'A' && c <= 'Z' ) || c == '_' ) - { - c = *(++szAlias); - while( c != 0 && c != ' ' ) - { - if( c != '_' && ! ( c >= '0' && c <= '9' ) && - ! ( c >= 'A' && c <= 'Z' ) && ! ( c >= 'a' && c <= 'z' ) ) - { - return FAILURE; - } - c = *(++szAlias); - } - return SUCCESS; - } - } - return FAILURE; -} - -/* - * Find a WorkArea by the alias, return FAILURE if not found - */ -HB_EXPORT ERRCODE hb_rddGetAliasNumber( char * szAlias, int * iArea ) -{ - BOOL fOneLetter; - char c; - - HB_TRACE(HB_TR_DEBUG, ("hb_rddGetAliasNumber(%s, %p)", szAlias, iArea)); - - while ( *szAlias == ' ' ) - { - szAlias++; - } - c = szAlias[ 0 ]; - if ( c >= 'a' && c <= 'z' ) - { - c -= 'a' - 'A'; - } - - fOneLetter = c && ( szAlias[ 1 ] == 0 || szAlias[ 1 ] == ' ' ); - - if( c >= '0' && c <= '9' ) - { - *iArea = atoi( szAlias ); - } - else if ( fOneLetter && c >= 'A' && c <= 'K' ) - { - *iArea = c - 'A' + 1; - } - else if ( fOneLetter && c == 'M' ) - { - *iArea = HARBOUR_MAX_RDD_AREA_NUM; - } - else - { - PHB_DYNS pSymAlias = hb_dynsymFindName( szAlias ); - - *iArea = pSymAlias ? ( int ) hb_dynsymAreaHandle( pSymAlias ) : 0; - if( *iArea == 0 ) - { - return FAILURE; - } - } - - return SUCCESS; -} - -/* - * Return the next free WorkArea for later use. - */ -static ERRCODE hb_rddSelectFirstAvailable( void ) -{ - HB_THREAD_STUB - USHORT uiArea; - - HB_TRACE(HB_TR_DEBUG, ("hb_rddSelectFirstAvailable()")); - - LOCK_AREA - uiArea = 1; - while( uiArea < s_uiWaNumMax ) - { - if ( s_WaNums[ uiArea ] == 0 ) - break; - uiArea++; - } - HB_SET_WA( uiArea ); - UNLOCK_AREA - return SUCCESS; -} - -/* - * Prepares a new WorkArea node. - */ -static AREAP hb_rddNewAreaNode( LPRDDNODE pRddNode, USHORT uiRddID ) -{ - AREAP pArea; - - HB_TRACE(HB_TR_DEBUG, ("hb_rddNewAreaNode(%p,%hu)", pRddNode, uiRddID)); - - if( pRddNode->uiAreaSize == 0 ) /* Calculate the size of WorkArea */ - { - USHORT uiSize; - - pArea = ( AREAP ) hb_xgrab( sizeof( AREA ) ); - memset( pArea, 0, sizeof( AREA ) ); - pArea->lprfsHost = &pRddNode->pTable; - pArea->rddID = uiRddID; - - if( SELF_STRUCTSIZE( pArea, &uiSize ) != SUCCESS ) - return NULL; - - /* Need more space? */ - if( uiSize > sizeof( AREA ) ) /* Size of Area changed */ - { - pArea = ( AREAP ) hb_xrealloc( pArea, uiSize ); - memset( pArea, 0, uiSize ); - pArea->lprfsHost = &pRddNode->pTable; - pArea->rddID = uiRddID; - } - - pRddNode->uiAreaSize = uiSize; /* Update the size of WorkArea */ - } - else - { - pArea = ( AREAP ) hb_xgrab( pRddNode->uiAreaSize ); - memset( pArea, 0, pRddNode->uiAreaSize ); - pArea->lprfsHost = &pRddNode->pTable; - pArea->rddID = uiRddID; - } - - if( SELF_NEW( pArea ) != SUCCESS ) - { - SELF_RELEASE( pArea ); - return NULL; - } - - return pArea; -} - -/* - * Closes and releases the current WorkArea preparing it - * to be used with a new database. - */ -HB_EXPORT void hb_rddReleaseCurrentArea( void ) -{ - HB_THREAD_STUB - USHORT uiWaPos; - AREAP pArea = HB_CURRENT_WA; - - HB_TRACE(HB_TR_DEBUG, ("hb_rddReleaseCurrentArea()")); - - if( !pArea ) - { - return; - } - - if( SELF_CLOSE( pArea ) == FAILURE ) - { - return; - } - SELF_RELEASE( pArea ); - - LOCK_AREA - - uiWaPos = s_WaNums[ s_uiCurrArea ]; - s_WaNums[ s_uiCurrArea ] = 0; - s_uiWaMax--; - if ( s_uiWaMax <= 1 ) - { - s_uiWaSpace = s_uiWaMax = s_uiWaNumMax = 0; - hb_xfree( s_WaList ); - hb_xfree( s_WaNums ); - s_WaList = NULL; - s_WaNums = NULL; - } - else - { - while ( uiWaPos < s_uiWaMax ) - { - s_WaList[ uiWaPos ] = s_WaList[ uiWaPos + 1 ]; - s_WaNums[ s_WaList[ uiWaPos ]->uiArea ] = uiWaPos; - uiWaPos++; - } - s_WaList[ s_uiWaMax ] = NULL; - if ( s_uiWaSpace - s_uiWaMax >= 256 ) - { - s_uiWaSpace = ( ( s_uiWaMax + 256 ) >> 8 ) << 8; - s_WaList = (AREAP *) hb_xrealloc( s_WaList, s_uiWaSpace * sizeof(AREAP) ); - } - } - s_pCurrArea = NULL; - - UNLOCK_AREA -} - -/* - * Closes all WorkAreas. - */ -static void hb_rddCloseAll( void ) -{ - HB_THREAD_STUB - - HB_TRACE(HB_TR_DEBUG, ("hb_rddCloseAll()")); - - if ( s_uiWaMax > 0 ) - { - BOOL isParents = TRUE, isFinish = FALSE; - AREAP pArea; - USHORT uiIndex; - - LOCK_AREA - - while( isParents ) - { - isParents = FALSE; - for ( uiIndex = 1; uiIndex < s_uiWaMax; uiIndex++ ) - { - pArea = s_WaList[ uiIndex ]; - HB_SET_WA( pArea->uiArea ); - if ( isFinish ) - { - SELF_RELEASE( pArea ); - s_WaNums[ s_uiCurrArea ] = 0; - s_pCurrArea = NULL; - } - else if( pArea->uiParents ) - { - isParents = TRUE; - } - else - { - SELF_CLOSE( pArea ); - } - } - if( !isParents && !isFinish ) - { - isParents = isFinish = TRUE; - } - } - - s_uiWaSpace = s_uiWaMax = s_uiWaNumMax = 0; - hb_xfree( s_WaList ); - hb_xfree( s_WaNums ); - s_WaList = NULL; - s_WaNums = NULL; - HB_SET_WA( 1 ); - - UNLOCK_AREA - } -} - - -/* - * -- FUNCTIONS ACCESSED FROM VIRTUAL MACHINE -- - */ - -/* - * Shutdown the RDD system. - */ -HB_EXPORT void hb_rddShutDown( void ) -{ - USHORT uiCount; - - HB_TRACE(HB_TR_DEBUG, ("hb_rddShutDown()")); - - hb_rddCloseAll(); - - s_szDefDriver[ 0 ] = '\0'; - - if ( s_uiRddMax > 0 ) - { - for ( uiCount = 0; uiCount < s_uiRddMax; uiCount++ ) - { - if ( s_RddList[ uiCount ]->pTable.exit != NULL ) - { - SELF_EXIT( s_RddList[ uiCount ] ); - } - hb_xfree( s_RddList[ uiCount ] ); - } - hb_xfree( s_RddList ); - s_RddList = NULL; - - LOCK_AREA_DESTROY - } -} - -/* - * Insert the new WorkArea node - */ -HB_EXPORT USHORT hb_rddInsertAreaNode( char *szDriver ) -{ - HB_THREAD_STUB - - USHORT uiRddID, uiWaPos; - LPRDDNODE pRddNode; - AREAP pArea; - - HB_TRACE(HB_TR_DEBUG, ("hb_rddInsertAreaNode(%s)", szDriver)); - - if( s_uiCurrArea && s_pCurrArea ) - return 0; - - pRddNode = hb_rddFindNode( szDriver, &uiRddID ); - if( !pRddNode ) - return 0; - - pArea = hb_rddNewAreaNode( pRddNode, uiRddID ); - if( !pArea ) - return 0; - - LOCK_AREA - - if ( s_uiCurrArea == 0 ) - { - USHORT uiArea = 1; - while ( uiArea < s_uiWaNumMax ) - { - if ( s_WaNums[ uiArea ] == 0 ) - break; - uiArea++; - } - HB_SET_WA( uiArea ); - } - - if ( s_uiCurrArea >= s_uiWaNumMax ) - { - int iSize = ( ( s_uiCurrArea + 256 ) >> 8 ) << 8; - - if ( s_uiWaNumMax == 0 ) - { - s_WaNums = (USHORT *) hb_xgrab( iSize * sizeof(USHORT) ); - } - else - { - s_WaNums = (USHORT *) hb_xrealloc( s_WaNums, iSize * sizeof(USHORT) ); - } - memset( &s_WaNums[ s_uiWaNumMax ], 0, ( iSize - s_uiWaNumMax ) * sizeof(USHORT) ); - s_uiWaNumMax = iSize; - } - - if ( s_uiWaSpace == 0 ) - { - s_uiWaSpace = 256; - s_WaList = (AREAP *) hb_xgrab( s_uiWaSpace * sizeof(AREAP) ); - memset( &s_WaList[ 0 ], 0, s_uiWaSpace * sizeof(AREAP) ); - s_WaList[ 0 ] = NULL; - uiWaPos = 1; - s_uiWaMax = 2; - } - else - { - uiWaPos = s_uiWaMax++; - if ( s_uiWaMax > s_uiWaSpace ) - { - s_uiWaSpace = ( ( s_uiWaMax + 256 ) >> 8 ) << 8; - s_WaList = (AREAP *) hb_xrealloc( s_WaList, s_uiWaSpace * sizeof(AREAP) ); - memset( &s_WaList[ s_uiWaMax ], 0, ( s_uiWaSpace - s_uiWaMax ) * sizeof(AREAP) ); - } - while ( uiWaPos > 1 ) - { - if ( s_WaList[ uiWaPos - 1 ]->uiArea < s_uiCurrArea ) - break; - s_WaList[ uiWaPos ] = s_WaList[ uiWaPos - 1 ]; - s_WaNums[ s_WaList[ uiWaPos ]->uiArea ] = uiWaPos; - uiWaPos--; - } - } - s_WaList[ uiWaPos ] = pArea; - s_WaNums[ s_uiCurrArea ] = uiWaPos; - s_pCurrArea = s_WaList[ uiWaPos ]; - s_pCurrArea->uiArea = s_uiCurrArea; - - UNLOCK_AREA - - return s_uiCurrArea; -} - -/* - * allocate and return atomAlias for new workarea or NULL if alias already exist - */ -HB_EXPORT void * hb_rddAllocWorkAreaAlias( char * szAlias, int iArea ) -{ - PHB_DYNS pSymAlias; - int iDummyArea; - - HB_TRACE(HB_TR_DEBUG, ("hb_rddAllocWorkAreaAlias(%s, %d)", szAlias, iArea)); - - /* Verify if the alias name is valid symbol */ - if( hb_rddVerifyAliasName( szAlias ) != SUCCESS ) - { - hb_errRT_DBCMD_Ext( EG_BADALIAS, EDBCMD_BADALIAS, NULL, szAlias, EF_CANDEFAULT ); - return NULL; - } - /* Verify if the alias is already in use */ - if( hb_rddGetAliasNumber( szAlias, &iDummyArea ) == SUCCESS ) - { - hb_errRT_DBCMD_Ext( EG_DUPALIAS, EDBCMD_DUPALIAS, NULL, szAlias, EF_CANDEFAULT ); - return NULL; - } - - LOCK_AREA - pSymAlias = hb_dynsymGet( szAlias ); - if( hb_dynsymAreaHandle( pSymAlias ) != 0 ) - { - pSymAlias = NULL; - } - else - { - hb_dynsymSetAreaHandle( pSymAlias, iArea ); - } - UNLOCK_AREA - - if( ! pSymAlias ) - { - hb_errRT_DBCMD_Ext( EG_DUPALIAS, EDBCMD_DUPALIAS, NULL, szAlias, EF_CANDEFAULT ); - } - - return pSymAlias; -} - -/* - * Return the current WorkArea number. - */ -HB_EXPORT int hb_rddGetCurrentWorkAreaNumber( void ) -{ - HB_THREAD_STUB - - HB_TRACE(HB_TR_DEBUG, ("hb_rddGetCurrentWorkAreaNumber()")); - - return s_uiCurrArea; -} - -/* - * Select a WorkArea by the number. - */ -HB_EXPORT ERRCODE hb_rddSelectWorkAreaNumber( int iArea ) -{ - HB_THREAD_STUB - - HB_TRACE(HB_TR_DEBUG, ("hb_rddSelectWorkAreaNumber(%d)", iArea)); - - LOCK_AREA - if( iArea < 1 || iArea > HARBOUR_MAX_RDD_AREA_NUM ) - { - HB_SET_WA( 0 ); - } - else - { - HB_SET_WA( iArea ); - } - UNLOCK_AREA - - return ( HB_CURRENT_WA == NULL ) ? FAILURE : SUCCESS; -} - -/* - * Select a WorkArea by the symbol name. - */ -HB_EXPORT ERRCODE hb_rddSelectWorkAreaSymbol( PHB_SYMB pSymAlias ) -{ - ERRCODE bResult; - char * szName; - int iArea; - - HB_TRACE(HB_TR_DEBUG, ("hb_rddSelectWorkAreaSymbol(%p)", pSymAlias)); - - iArea = ( int ) hb_dynsymAreaHandle( pSymAlias->pDynSym ); - if( iArea ) - { - hb_rddSelectWorkAreaNumber( iArea ); - bResult = SUCCESS; - } - else - { - szName = hb_dynsymName( pSymAlias->pDynSym ); - - if( szName[ 0 ] && ! szName[ 1 ] && toupper( szName[ 0 ] ) >= 'A' && toupper( szName[ 0 ] ) <= 'K' ) - { - hb_rddSelectWorkAreaNumber( toupper( szName[ 0 ] ) - 'A' + 1 ); - bResult = SUCCESS; - } - else if( szName[ 0 ] && ! szName[ 1 ] && toupper( szName[ 0 ] ) == 'M' ) - { - hb_rddSelectWorkAreaNumber( HARBOUR_MAX_RDD_AREA_NUM ); - bResult = SUCCESS; - } - else - { - /* - * generate an error with retry possibility - * (user created error handler can open a missing database) - */ - HB_ITEM_PTR pError; - - pError = hb_errRT_New( ES_ERROR, NULL, EG_NOALIAS, EDBCMD_NOALIAS, NULL, pSymAlias->szName, 0, EF_CANRETRY ); - bResult = FAILURE; - - do - { - if( hb_errLaunch( pError ) != E_RETRY ) - break; - iArea = ( int ) hb_dynsymAreaHandle( pSymAlias->pDynSym ); - if( iArea ) - { - hb_rddSelectWorkAreaNumber( iArea ); - bResult = SUCCESS; - } - } - while( bResult == FAILURE ); - - hb_itemRelease( pError ); - } - } - - return bResult; -} - -/* - * Select a WorkArea by the name. - */ -HB_EXPORT ERRCODE hb_rddSelectWorkAreaAlias( char * szAlias ) -{ - ERRCODE bResult; - int iArea; - - HB_TRACE(HB_TR_DEBUG, ("hb_rddSelectWorkAreaAlias(%s)", szAlias)); - - bResult = hb_rddGetAliasNumber( szAlias, &iArea ); - - if ( bResult == FAILURE ) - { - /* - * generate an error with retry possibility - * (user created error handler can open a missing database) - */ - HB_ITEM_PTR pError = hb_errRT_New( ES_ERROR, NULL, EG_NOALIAS, EDBCMD_NOALIAS, NULL, szAlias, 0, EF_CANRETRY ); - - do - { - if( hb_errLaunch( pError ) != E_RETRY ) - break; - bResult = hb_rddGetAliasNumber( szAlias, &iArea ); - } - while( bResult == FAILURE ); - - hb_itemRelease( pError ); - } - - if ( bResult == SUCCESS ) - { - if( iArea < 1 || iArea > HARBOUR_MAX_RDD_AREA_NUM ) - hb_rddSelectFirstAvailable(); - else - hb_rddSelectWorkAreaNumber( iArea ); - } - - return bResult; -} - -/* - * Function for getting current workarea pointer - */ -HB_EXPORT void * hb_rddGetCurrentWorkAreaPointer( void ) -{ - HB_THREAD_STUB - - HB_TRACE(HB_TR_DEBUG, ("hb_rddGetCurrentWorkAreaPointer()")); - - return HB_CURRENT_WA; -} - -/* - * call a pCallBack function with all open workareas ### - */ -HB_EXPORT ERRCODE hb_rddIterateWorkAreas( WACALLBACK pCallBack, int data ) -{ - USHORT uiIndex; - - HB_TRACE(HB_TR_DEBUG, ("hb_rddIterateWorkAreas(%p)", pCallBack)); - - LOCK_AREA - for ( uiIndex = 1; uiIndex < s_uiWaMax; uiIndex++ ) - { - if ( ! (*pCallBack)( s_WaList[ uiIndex ], data ) ) - { - break; - } - } - UNLOCK_AREA - return SUCCESS; -} - -/* - * Find a field index by name - */ -HB_EXPORT USHORT hb_rddFieldIndex( AREAP pArea, char * szName ) -{ - USHORT uiCount = 0; - LPFIELD pField; - - HB_TRACE(HB_TR_DEBUG, ("hb_rddFieldIndex(%p, %s)", pArea, szName)); - - while( HB_ISSPACE( *szName ) ) - { - ++szName; - } - - if( *szName ) - { - char szSym[ HB_SYMBOL_NAME_LEN + 1 ]; - hb_strncpyUpperTrim( szSym, szName, HB_SYMBOL_NAME_LEN ); - - pField = pArea->lpFields; - while( pField ) - { - ++uiCount; - if( strcmp( szSym, hb_dynsymName( ( PHB_DYNS ) pField->sym ) ) == 0 ) - return uiCount; - pField = pField->lpfNext; - } - } - return 0; -} - -/* - * find a field expression index, this function strips _FIELD->, FIELD->, - * alias-> prefixes - */ -HB_EXPORT USHORT hb_rddFieldExpIndex( AREAP pArea, char * szField ) -{ - int n; - - while( HB_ISSPACE( *szField ) ) - { - ++szField; - } - - if( strchr( szField, '>' ) != NULL ) - { - char szAlias[ HARBOUR_MAX_RDD_ALIAS_LENGTH + 1 ]; - int i, j, l; - - n = 0; - if ( SELF_ALIAS( pArea, ( BYTE * ) szAlias ) == SUCCESS ) - l = strlen( szAlias ); - else - l = 0; - - /* - * strip the _FIELD-> and FIELD-> prefix, it could be nested - * so repeat this process until all prefixes will be removed - */ - do - { - j = n; - if( hb_strnicmp( &szField[ n ], "FIELD", 5 ) == 0 ) - i = 5; - else if( hb_strnicmp( &szField[ n ], "_FIELD", 6 ) == 0 ) - i = 6; - else if( l > 0 && hb_strnicmp( &szField[ n ], szAlias, l ) == 0 ) - i = l; - else - i = 0; - - if( i > 0 ) - { - i += n; - while( HB_ISSPACE( szField[ i ] ) ) - i++; - if( szField[ i ] == '-' && szField[ i + 1 ] == '>' ) - { - n = i + 2; - while( szField[ n ] == ' ' ) - n++; - } - } - } - while ( n != j ); - szField = &szField[ n ]; - } - return hb_rddFieldIndex( pArea, szField ); -} - -/* - * Obtain the current value of a field. - */ -HB_EXPORT ERRCODE hb_rddFieldGet( HB_ITEM_PTR pItem, PHB_SYMB pFieldSymbol ) -{ - HB_THREAD_STUB - AREAP pArea = HB_CURRENT_WA; - - HB_TRACE(HB_TR_DEBUG, ("hb_rddFieldGet(%p, %p)", pItem, pFieldSymbol)); - - if( pArea ) - { - USHORT uiField = 1; - LPFIELD pField = pArea->lpFields; - PHB_DYNS pDynSym = pFieldSymbol->pDynSym; - - while( pField ) - { - if( ( PHB_DYNS ) pField->sym == pDynSym ) - { - return SELF_GETVALUE( pArea, uiField, pItem ); - } - ++uiField; - pField = pField->lpfNext; - } - } - return FAILURE; -} - -/* - * Assign a value to a field. - */ -HB_EXPORT ERRCODE hb_rddFieldPut( HB_ITEM_PTR pItem, PHB_SYMB pFieldSymbol ) -{ - HB_THREAD_STUB - AREAP pArea = HB_CURRENT_WA; - - HB_TRACE(HB_TR_DEBUG, ("hb_rddFieldPut(%p, %p)", pItem, pFieldSymbol)); - - if( pArea ) - { - USHORT uiField = 1; - LPFIELD pField = pArea->lpFields; - PHB_DYNS pDynSym = pFieldSymbol->pDynSym; - - while( pField ) - { - if( ( PHB_DYNS ) pField->sym == pDynSym ) - { - return SELF_PUTVALUE( pArea, uiField, pItem ); - } - ++uiField; - pField = pField->lpfNext; - } - } - return FAILURE; -} - -/* - * Obtain the current value of a field. - */ -HB_EXPORT ERRCODE hb_rddGetFieldValue( HB_ITEM_PTR pItem, PHB_SYMB pFieldSymbol ) -{ - ERRCODE bSuccess; - - HB_TRACE(HB_TR_DEBUG, ("hb_rddGetFieldValue(%p, %p)", pItem, pFieldSymbol)); - - bSuccess = hb_rddFieldGet( pItem, pFieldSymbol ); - - if( bSuccess == FAILURE && hb_vmRequestQuery() == 0 ) - { - /* - * generate an error with retry possibility - * (user created error handler can make this field accessible) - */ - PHB_ITEM pError = hb_errRT_New( ES_ERROR, NULL, EG_NOVAR, EDBCMD_NOVAR, - NULL, pFieldSymbol->szName, 0, EF_CANRETRY ); - - while( hb_errLaunch( pError ) == E_RETRY ) - { - bSuccess = hb_rddFieldGet( pItem, pFieldSymbol ); - - if( bSuccess == SUCCESS || hb_vmRequestQuery() != 0 ) - break; - } - hb_itemRelease( pError ); - } - - return bSuccess; -} - -/* - * Assign a value to a field. - */ -HB_EXPORT ERRCODE hb_rddPutFieldValue( HB_ITEM_PTR pItem, PHB_SYMB pFieldSymbol ) -{ - ERRCODE bSuccess; - - HB_TRACE(HB_TR_DEBUG, ("hb_rddPutFieldValue(%p, %p)", pItem, pFieldSymbol)); - - bSuccess = hb_rddFieldPut( pItem, pFieldSymbol ); - - if( bSuccess == FAILURE && hb_vmRequestQuery() == 0 ) - { - /* - * generate an error with retry possibility - * (user created error handler can make this field accessible) - */ - PHB_ITEM pError = hb_errRT_New( ES_ERROR, NULL, EG_NOVAR, EDBCMD_NOVAR, - NULL, pFieldSymbol->szName, 0, EF_CANRETRY ); - - while( hb_errLaunch( pError ) == E_RETRY ) - { - bSuccess = hb_rddFieldPut( pItem, pFieldSymbol ); - - if( bSuccess == SUCCESS || hb_vmRequestQuery() != 0 ) - break; - } - hb_itemRelease( pError ); - } - return bSuccess; -} - -/* - * -- END OF FUNCTIONS ACCESSED FROM VIRTUAL MACHINE -- - */ - -/* - * -- BASIC RDD METHODS -- - */ - -/* - * -- HARBOUR FUNCTIONS -- - */ +#include "hbvm.h" +#include "hbset.h" HB_FUNC( AFIELDS ) { - HB_THREAD_STUB PHB_ITEM pName, pType, pLen, pDec; USHORT uiFields, uiCount; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( !pArea ) { @@ -1415,12 +158,11 @@ HB_FUNC( AFIELDS ) HB_FUNC( ALIAS ) { - HB_THREAD_STUB USHORT uiArea; AREAP pArea; uiArea = hb_parni( 1 ); - pArea = uiArea ? HB_GET_WA( uiArea ) : HB_CURRENT_WA; + pArea = ( AREAP ) hb_rddGetWorkAreaPointer( uiArea ); if( pArea ) { char szAlias[ HARBOUR_MAX_RDD_ALIAS_LENGTH + 1 ]; @@ -1436,10 +178,8 @@ HB_FUNC( ALIAS ) HB_FUNC( DBEVAL ) { - HB_THREAD_STUB - DBEVALINFO pEvalInfo; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { @@ -1494,14 +234,13 @@ HB_FUNC( DBEVAL ) HB_FUNC( DBF ) { - HB_THREAD_STUB - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { char szAlias[ HARBOUR_MAX_RDD_ALIAS_LENGTH + 1 ]; - if ( SELF_ALIAS( pArea, ( BYTE * ) szAlias ) == SUCCESS ) + if( SELF_ALIAS( pArea, ( BYTE * ) szAlias ) == SUCCESS ) { hb_retc( szAlias ); return; @@ -1512,9 +251,8 @@ HB_FUNC( DBF ) HB_FUNC( BOF ) { - HB_THREAD_STUB BOOL bBof = TRUE; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) SELF_BOF( pArea, &bBof ); @@ -1524,18 +262,24 @@ HB_FUNC( BOF ) HB_FUNC( DBAPPEND ) { - HB_THREAD_STUB - BOOL bUnLockAll; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { - bUnLockAll = ISLOG( 1 ) ? hb_parl( 1 ) : TRUE; - s_bNetError = FALSE; - if( SELF_APPEND( pArea, bUnLockAll ) != SUCCESS ) - { - s_bNetError = TRUE; /* Temp fix! What about other types of errors? */ - } + BOOL bUnLockAll = ISLOG( 1 ) ? hb_parl( 1 ) : TRUE; + ERRCODE errCode; + + /* Clipper clears NETERR flag when table is open */ + hb_rddSetNetErr( FALSE ); + errCode = SELF_APPEND( pArea, bUnLockAll ); + hb_retl( errCode == SUCCESS ); + + /* + * Warning: this is not Clipper compatible. NETERR() should be set by + * error handler not here + */ + if( errCode != SUCCESS ) + hb_rddSetNetErr( TRUE ); } else hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "DBAPPEND" ); @@ -1543,8 +287,7 @@ HB_FUNC( DBAPPEND ) HB_FUNC( DBCLEARFILTER ) { - HB_THREAD_STUB - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) SELF_CLEARFILTER( pArea ); @@ -1559,18 +302,12 @@ HB_FUNC( DBCLOSEALL ) HB_FUNC( DBCLOSEAREA ) { - HB_THREAD_STUB - - if( HB_CURRENT_WA ) - { - hb_rddReleaseCurrentArea(); - } + hb_rddReleaseCurrentArea(); } HB_FUNC( DBCOMMIT ) { - HB_THREAD_STUB - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) SELF_FLUSH( pArea ); else @@ -1579,192 +316,7 @@ HB_FUNC( DBCOMMIT ) HB_FUNC( DBCOMMITALL ) { - HB_THREAD_STUB - USHORT uiArea = hb_rddGetCurrentWorkAreaNumber(), uiIndex; - - LOCK_AREA - for ( uiIndex = 1; uiIndex < s_uiWaMax; ++uiIndex ) - { - hb_rddSelectWorkAreaNumber( s_WaList[ uiIndex ]->uiArea ); - SELF_FLUSH( HB_CURRENT_WA ); - } - UNLOCK_AREA - hb_rddSelectWorkAreaNumber( uiArea ); -} - -static ERRCODE hb_rddOpenTable( char * szFileName, char * szDriver, - USHORT uiArea, char *szAlias, - BOOL fShared, BOOL fReadonly, - char * szCpId, ULONG ulConnection, - PHB_ITEM pStruct, PHB_ITEM pDelim ) -{ - char szDriverBuffer[ HARBOUR_MAX_RDD_DRIVERNAME_LENGTH + 1 ]; - DBOPENINFO pInfo; - ERRCODE errCode; - USHORT uiPrevArea; - AREAP pArea; - - s_bNetError = FALSE; - - if( szDriver && szDriver[ 0 ] ) - { - hb_strncpyUpper( szDriverBuffer, szDriver, HARBOUR_MAX_RDD_DRIVERNAME_LENGTH ); - szDriver = szDriverBuffer; - } - else - { - szDriver = hb_rddDefaultDrv( NULL ); - } - - uiPrevArea = hb_rddGetCurrentWorkAreaNumber(); - - /* - * 0 means chose first available in hb_rddInsertAreaNode() - * This hack is necessary to avoid race condition in MT - * if we don't want to lock whole RDD subsystem, Druzus - */ - hb_rddSelectWorkAreaNumber( uiArea ); - if( uiArea ) - { - hb_rddReleaseCurrentArea(); - } - - s_bNetError = TRUE; - - /* Create a new WorkArea node */ - if( ! hb_rddInsertAreaNode( szDriver ) ) - { - hb_errRT_DBCMD( EG_ARG, EDBCMD_USE_BADPARAMETER, NULL, "DBUSEAREA" ); - return FAILURE; - } - pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); - - /* Fill pInfo structure */ - pInfo.uiArea = pArea->uiArea; - pInfo.abName = ( BYTE * ) szFileName; - pInfo.atomAlias = ( BYTE * ) szAlias; - pInfo.fShared = fShared; - pInfo.fReadonly = fReadonly; - pInfo.cdpId = ( BYTE * ) szCpId; - pInfo.ulConnection = ulConnection; - pInfo.lpdbHeader = NULL; - - if( pStruct ) - { - errCode = SELF_CREATEFIELDS( pArea, pStruct ); - } - else - { - errCode = SUCCESS; - } - - if( errCode == SUCCESS ) - { - if( pDelim && !HB_IS_NIL( pDelim ) ) - errCode = SELF_INFO( pArea, DBI_SETDELIMITER, pDelim ); - - if( errCode == SUCCESS ) - { - /* Open file */ - errCode = SELF_OPEN( pArea, &pInfo ); - - if( errCode != SUCCESS ) - { - hb_rddReleaseCurrentArea(); - hb_rddSelectWorkAreaNumber( uiPrevArea ); - } - } - } - - /* - * Warning: this is not Clipper compatible. NETERR() should be set by - * error handler not here - */ - s_bNetError = errCode != SUCCESS; - - return errCode; -} - -static ERRCODE hb_rddCreateTable( char * szFileName, PHB_ITEM pStruct, - char * szDriver, - BOOL fKeepOpen, USHORT uiArea, char *szAlias, - PHB_ITEM pDelim, - char * szCpId, ULONG ulConnection ) -{ - char szDriverBuffer[ HARBOUR_MAX_RDD_DRIVERNAME_LENGTH + 1 ]; - DBOPENINFO pInfo; - ERRCODE errCode; - USHORT uiPrevArea; - AREAP pArea; - - if( szDriver && szDriver[ 0 ] ) - { - hb_strncpyUpper( szDriverBuffer, szDriver, HARBOUR_MAX_RDD_DRIVERNAME_LENGTH ); - szDriver = szDriverBuffer; - } - else - { - szDriver = hb_rddDefaultDrv( NULL ); - } - - uiPrevArea = hb_rddGetCurrentWorkAreaNumber(); - - /* - * 0 means chose first available in hb_rddInsertAreaNode() - * This hack is necessary to avoid race condition in MT - * if we don't want to lock whole RDD subsystem, Druzus - */ - hb_rddSelectWorkAreaNumber( uiArea ); - if( uiArea ) - { - hb_rddReleaseCurrentArea(); - } - - s_bNetError = TRUE; - - /* Create a new WorkArea node */ - if( ! hb_rddInsertAreaNode( szDriver ) ) - { - hb_errRT_DBCMD( EG_CREATE, EDBCMD_BADPARAMETER, NULL, "DBCREATE" ); - return FAILURE; - } - pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); - - /* Fill pInfo structure */ - pInfo.uiArea = pArea->uiArea; - pInfo.abName = ( BYTE * ) szFileName; - pInfo.atomAlias = ( BYTE * ) szAlias; - pInfo.fShared = FALSE; - pInfo.fReadonly = FALSE; - pInfo.cdpId = ( BYTE * ) szCpId; - pInfo.ulConnection = ulConnection; - pInfo.lpdbHeader = NULL; - - if( pDelim && !HB_IS_NIL( pDelim ) ) - errCode = SELF_INFO( pArea, DBI_SETDELIMITER, pDelim ); - else - errCode = SUCCESS; - - if( errCode == SUCCESS ) - { - errCode = SELF_CREATEFIELDS( pArea, pStruct ); - if( errCode == SUCCESS ) - errCode = SELF_CREATE( pArea, &pInfo ); - } - - if( !fKeepOpen || errCode != SUCCESS ) - { - hb_rddReleaseCurrentArea(); - hb_rddSelectWorkAreaNumber( uiPrevArea ); - } - - /* - * Warning: this is not Clipper compatible. NETERR() should be set by - * error handler not here - */ - s_bNetError = errCode != SUCCESS; - - return errCode; + hb_rddFlushAll(); } /* @@ -1832,9 +384,11 @@ HB_FUNC( DBCREATE ) } } - hb_rddCreateTable( szFileName, pStruct, szDriver, fKeepOpen, - fCurrArea ? hb_rddGetCurrentWorkAreaNumber() : 0, - szAlias, pDelim, szCpId, ulConnection ); + hb_retl( hb_rddCreateTable( szFileName, szDriver, + fCurrArea ? hb_rddGetCurrentWorkAreaNumber() : 0, + szAlias, fKeepOpen, + szCpId, ulConnection, + pStruct, pDelim ) == SUCCESS ); } /* @@ -1908,23 +462,17 @@ HB_FUNC( __DBOPENSDF ) HB_FUNC( DBDELETE ) { - HB_THREAD_STUB - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) - { SELF_DELETE( pArea ); - } else - { hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "DBDELETE" ); - } } HB_FUNC( DBFILTER ) { - HB_THREAD_STUB - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { @@ -1940,8 +488,7 @@ HB_FUNC( DBFILTER ) HB_FUNC( DBGOBOTTOM ) { - HB_THREAD_STUB - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) SELF_GOBOTTOM( pArea ); @@ -1951,27 +498,23 @@ HB_FUNC( DBGOBOTTOM ) HB_FUNC( DBGOTO ) { - HB_THREAD_STUB - PHB_ITEM pItem; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); - if( !pArea ) + if( pArea ) { - hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "DBGOTO" ); - return; + PHB_ITEM pItem = hb_param( 1, HB_IT_ANY ); + if( !pItem ) + hb_errRT_DBCMD( EG_ARG, EDBCMD_NOVAR, NULL, "DBGOTO" ); + else + SELF_GOTOID( pArea, pItem ); } - - pItem = hb_param( 1, HB_IT_ANY ); - if( !pItem ) - hb_errRT_DBCMD( EG_ARG, EDBCMD_NOVAR, NULL, "DBGOTO" ); else - SELF_GOTOID( pArea, pItem ); + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "DBGOTO" ); } HB_FUNC( DBGOTOP ) { - HB_THREAD_STUB - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) SELF_GOTOP( pArea ); @@ -1981,42 +524,37 @@ HB_FUNC( DBGOTOP ) HB_FUNC( __DBLOCATE ) { - HB_THREAD_STUB DBSCOPEINFO dbScopeInfo; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); - if( !pArea ) + if( pArea ) { + dbScopeInfo.itmCobFor = hb_param( 1, HB_IT_BLOCK ); + dbScopeInfo.lpstrFor = NULL; + dbScopeInfo.itmCobWhile = hb_param( 2, HB_IT_BLOCK ); + dbScopeInfo.lpstrWhile = NULL; + dbScopeInfo.lNext = hb_param( 3, HB_IT_NUMERIC ); + dbScopeInfo.itmRecID = hb_param( 4, HB_IT_NUMERIC ); + dbScopeInfo.fRest = hb_param( 5, HB_IT_LOGICAL ); + + dbScopeInfo.fIgnoreFilter = TRUE; + dbScopeInfo.fIncludeDeleted = TRUE; + dbScopeInfo.fLast = FALSE; + dbScopeInfo.fIgnoreDuplicates = FALSE; + dbScopeInfo.fBackward = FALSE; + + if( SELF_SETLOCATE( pArea, &dbScopeInfo ) == SUCCESS ) + SELF_LOCATE( pArea, FALSE ); + } + else hb_errRT_DBCMD( EG_NOTABLE, EG_NOTABLE, NULL, "__DBLOCATE" ); - return; - } - - dbScopeInfo.itmCobFor = hb_param( 1, HB_IT_BLOCK ); - dbScopeInfo.lpstrFor = NULL; - dbScopeInfo.itmCobWhile = hb_param( 2, HB_IT_BLOCK ); - dbScopeInfo.lpstrWhile = NULL; - dbScopeInfo.lNext = hb_param( 3, HB_IT_NUMERIC ); - dbScopeInfo.itmRecID = hb_param( 4, HB_IT_NUMERIC ); - dbScopeInfo.fRest = hb_param( 5, HB_IT_LOGICAL ); - - dbScopeInfo.fIgnoreFilter = TRUE; - dbScopeInfo.fIncludeDeleted = TRUE; - dbScopeInfo.fLast = FALSE; - dbScopeInfo.fIgnoreDuplicates = FALSE; - dbScopeInfo.fBackward = FALSE; - - if( SELF_SETLOCATE( pArea, &dbScopeInfo ) == SUCCESS ) - { - SELF_LOCATE( pArea, FALSE ); - } } HB_FUNC( __DBSETLOCATE ) { - HB_THREAD_STUB PHB_ITEM pLocate; DBSCOPEINFO pScopeInfo; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { @@ -2032,25 +570,18 @@ HB_FUNC( __DBSETLOCATE ) HB_FUNC( __DBCONTINUE ) { - HB_THREAD_STUB - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) - { SELF_LOCATE( pArea, TRUE ); - } else - { - hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "DBCONTINUE" ); - return; - } + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "__DBCONTINUE" ); } HB_FUNC( __DBPACK ) { - HB_THREAD_STUB PHB_ITEM pBlock, pEvery; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { @@ -2070,7 +601,7 @@ HB_FUNC( __DBPACK ) } else { - if ( pArea->valResult ) + if( pArea->valResult ) hb_itemClear( pArea->valResult ); else pArea->valResult = hb_itemNew( NULL ); @@ -2085,8 +616,7 @@ HB_FUNC( __DBPACK ) HB_FUNC( DBRECALL ) { - HB_THREAD_STUB - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) SELF_RECALL( pArea ); else @@ -2095,47 +625,42 @@ HB_FUNC( DBRECALL ) HB_FUNC( DBRLOCK ) { - HB_THREAD_STUB - DBLOCKINFO dbLockInfo; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); - dbLockInfo.fResult = FALSE; if( pArea ) { + DBLOCKINFO dbLockInfo; + dbLockInfo.fResult = FALSE; dbLockInfo.itmRecID = hb_param( 1, HB_IT_ANY ); if( !dbLockInfo.itmRecID || ISNIL( 1 ) ) dbLockInfo.uiMethod = DBLM_EXCLUSIVE; else dbLockInfo.uiMethod = DBLM_MULTIPLE; SELF_LOCK( pArea, &dbLockInfo ); + hb_retl( dbLockInfo.fResult ); } else hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "DBRLOCK" ); - - hb_retl( dbLockInfo.fResult ); } HB_FUNC( DBRLOCKLIST ) { - HB_THREAD_STUB - PHB_ITEM pList; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); - pList = hb_itemNew( NULL ); - hb_arrayNew( pList, 0 ); if( pArea ) + { + PHB_ITEM pList = hb_itemArrayNew( 0 ); SELF_INFO( pArea, DBI_GETLOCKARRAY, pList ); + hb_itemRelease( hb_itemReturnForward( pList ) ); + } else hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "DBRLOCKLIST" ); - hb_itemReturn( pList ); - hb_itemRelease( pList ); } HB_FUNC( DBRUNLOCK ) { - HB_THREAD_STUB - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) SELF_UNLOCK( pArea, hb_param( 1, HB_IT_ANY ) ); @@ -2145,34 +670,27 @@ HB_FUNC( DBRUNLOCK ) HB_FUNC( DBSEEK ) { - HB_THREAD_STUB - PHB_ITEM pKey; - BOOL bSoftSeek, bFindLast, fFound; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { if( !ISNIL( 1 ) ) { - pKey = hb_param( 1, HB_IT_ANY ); - bSoftSeek = ISLOG( 2 ) ? ( BOOL ) hb_parl( 2 ) : hb_set.HB_SET_SOFTSEEK; - bFindLast = ISLOG( 3 ) ? hb_parl( 3 ) : FALSE; + PHB_ITEM pKey = hb_param( 1, HB_IT_ANY ); + BOOL bSoftSeek = ISLOG( 2 ) ? ( BOOL ) hb_parl( 2 ) : hb_set.HB_SET_SOFTSEEK; + BOOL bFindLast = ISLOG( 3 ) ? hb_parl( 3 ) : FALSE, fFound = FALSE; if( SELF_SEEK( pArea, bSoftSeek, pKey, bFindLast ) == SUCCESS ) { - if( SELF_FOUND( pArea, &fFound ) == SUCCESS ) - { - hb_retl( fFound ); - return; - } + if( SELF_FOUND( pArea, &fFound ) != SUCCESS ) + fFound = FALSE; } + hb_retl( fFound ); } else hb_errRT_DBCMD( EG_ARG, EDBCMD_SEEK_BADPARAMETER, NULL, "DBSEEK" ); } else hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "DBSEEK" ); - - hb_retl( FALSE ); } HB_FUNC( DBSELECTAREA ) @@ -2204,13 +722,11 @@ HB_FUNC( DBSELECTAREA ) HB_FUNC( __DBSETFOUND ) { - HB_THREAD_STUB - PHB_ITEM pFound; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { - pFound = hb_param( 1, HB_IT_LOGICAL ); + PHB_ITEM pFound = hb_param( 1, HB_IT_LOGICAL ); if( pFound ) pArea->fFound = hb_itemGetL( pFound ); } @@ -2218,13 +734,12 @@ HB_FUNC( __DBSETFOUND ) HB_FUNC( DBSETFILTER ) { - HB_THREAD_STUB - PHB_ITEM pBlock, pText; - DBFILTERINFO pFilterInfo; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { + PHB_ITEM pBlock, pText; + DBFILTERINFO pFilterInfo; pBlock = hb_param( 1, HB_IT_BLOCK ); if( pBlock ) { @@ -2252,60 +767,25 @@ HB_FUNC( DBSETFILTER ) HB_FUNC( DBSKIP ) { - HB_THREAD_STUB - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) SELF_SKIP( pArea, ISNUM( 1 ) ? hb_parnl( 1 ) : 1 ); else hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "DBSKIP" ); } -static void hb_fldStructure( AREAP pArea, USHORT uiField, PHB_ITEM pField ) -{ - hb_arrayNew( pField, 4 ); - - SELF_FIELDINFO( pArea, uiField, DBS_NAME, hb_arrayGetItemPtr( pField, 1 ) ); - SELF_FIELDINFO( pArea, uiField, DBS_TYPE, hb_arrayGetItemPtr( pField, 2 ) ); - SELF_FIELDINFO( pArea, uiField, DBS_LEN, hb_arrayGetItemPtr( pField, 3 ) ); - SELF_FIELDINFO( pArea, uiField, DBS_DEC, hb_arrayGetItemPtr( pField, 4 ) ); -} - -static void hb_tblStructure( AREAP pArea, PHB_ITEM pStruct ) -{ - USHORT uiFields, uiCount; - - if( SELF_FIELDCOUNT( pArea, &uiFields ) == SUCCESS ) - { - if( hb_arraySize( pStruct, uiFields ) ) - { - for( uiCount = 1; uiCount <= uiFields; ++uiCount ) - { - hb_fldStructure( pArea, uiCount, - hb_arrayGetItemPtr( pStruct, uiCount ) ); - } - } - } -} - HB_FUNC( DBSTRUCT ) { - PHB_ITEM pStruct; + PHB_ITEM pStruct = hb_itemArrayNew( 0 ); AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); - - pStruct = hb_itemNew( NULL ); - hb_arrayNew( pStruct, 0 ); if( pArea ) - { hb_tblStructure( pArea, pStruct ); - } - hb_itemReturn( pStruct ); - hb_itemRelease( pStruct ); + hb_itemRelease( hb_itemReturn( pStruct ) ); } HB_FUNC( DBTABLEEXT ) { - HB_THREAD_STUB - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); PHB_ITEM pItem = hb_itemPutC( NULL, "" ); if( !pArea ) @@ -2315,10 +795,10 @@ HB_FUNC( DBTABLEEXT ) pRddNode = hb_rddFindNode( hb_rddDefaultDrv( NULL ), &uiRddID ); if( pRddNode ) { - pArea = hb_rddNewAreaNode( pRddNode, uiRddID ); + pArea = ( AREAP ) hb_rddNewAreaNode( pRddNode, uiRddID ); if( pArea ) { - SELF_INFO( ( AREAP ) pArea, DBI_TABLEEXT, pItem ); + SELF_INFO( pArea, DBI_TABLEEXT, pItem ); SELF_RELEASE( pArea ); } } @@ -2333,8 +813,7 @@ HB_FUNC( DBTABLEEXT ) HB_FUNC( DBUNLOCK ) { - HB_THREAD_STUB - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) SELF_UNLOCK( pArea, NULL ); @@ -2344,42 +823,20 @@ HB_FUNC( DBUNLOCK ) HB_FUNC( DBUNLOCKALL ) { - HB_THREAD_STUB - USHORT uiArea = hb_rddGetCurrentWorkAreaNumber(), uiIndex; - - LOCK_AREA - for ( uiIndex = 1; uiIndex < s_uiWaMax; ++uiIndex ) - { - hb_rddSelectWorkAreaNumber( s_WaList[ uiIndex ]->uiArea ); - SELF_UNLOCK( HB_CURRENT_WA, NULL ); - } - UNLOCK_AREA - hb_rddSelectWorkAreaNumber( uiArea ); + hb_rddUnLockAll(); } HB_FUNC( DBUSEAREA ) { - char * szFileName; - - szFileName = hb_parc( 3 ); - - if( !szFileName || !szFileName[ 0 ] ) - { - hb_errRT_DBCMD( EG_ARG, EDBCMD_USE_BADPARAMETER, NULL, "DBUSEAREA" ); - return; - } - - hb_rddOpenTable( szFileName, hb_parc( 2 ), - hb_parl( 1 ) ? 0 : hb_rddGetCurrentWorkAreaNumber(), - hb_parc( 4 ), - ISLOG( 5 ) ? hb_parl( 5 ) : !hb_set.HB_SET_EXCLUSIVE, - hb_parl( 6 ), hb_parc( 7 ), hb_parnl( 8 ), NULL, NULL ); + hb_retl( hb_rddOpenTable( hb_parc( 3 ), hb_parc( 2 ), + hb_parl( 1 ) ? 0 : hb_rddGetCurrentWorkAreaNumber(), + hb_parc( 4 ), ISLOG( 5 ) ? hb_parl( 5 ) : !hb_set.HB_SET_EXCLUSIVE, + hb_parl( 6 ), hb_parc( 7 ), hb_parnl( 8 ), NULL, NULL ) == SUCCESS ); } HB_FUNC( __DBZAP ) { - HB_THREAD_STUB - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) SELF_ZAP( pArea ); @@ -2389,9 +846,8 @@ HB_FUNC( __DBZAP ) HB_FUNC( DELETED ) { - HB_THREAD_STUB BOOL bDeleted = FALSE; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) SELF_DELETED( pArea, &bDeleted ); @@ -2400,9 +856,8 @@ HB_FUNC( DELETED ) HB_FUNC( EOF ) { - HB_THREAD_STUB BOOL bEof = TRUE; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) SELF_EOF( pArea, &bEof ); @@ -2411,9 +866,8 @@ HB_FUNC( EOF ) HB_FUNC( FCOUNT ) { - HB_THREAD_STUB USHORT uiFields = 0; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) SELF_FIELDCOUNT( pArea, &uiFields ); @@ -2422,8 +876,7 @@ HB_FUNC( FCOUNT ) HB_FUNC( FIELDDEC ) { - HB_THREAD_STUB - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { @@ -2448,9 +901,8 @@ HB_FUNC( FIELDDEC ) HB_FUNC( FIELDGET ) { - HB_THREAD_STUB PHB_ITEM pItem = hb_itemNew( NULL ); - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); USHORT uiField = hb_parni( 1 ); if( pArea && uiField ) @@ -2464,8 +916,7 @@ HB_FUNC( FIELDGET ) HB_FUNC( FIELDLEN ) { - HB_THREAD_STUB - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { @@ -2489,9 +940,8 @@ HB_FUNC( FIELDLEN ) HB_FUNC( FIELDNAME ) { - HB_THREAD_STUB char * szName; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); USHORT uiFields, uiIndex = hb_parni( 1 ); if( pArea && uiIndex ) @@ -2515,23 +965,17 @@ HB_FUNC( FIELDNAME ) HB_FUNC( FIELDPOS ) { - HB_THREAD_STUB - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea && hb_parclen( 1 ) > 0 ) - { hb_retni( hb_rddFieldIndex( pArea, hb_parc( 1 ) ) ); - } else - { hb_retni( 0 ); - } } HB_FUNC( FIELDPUT ) { - HB_THREAD_STUB - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { @@ -2552,8 +996,7 @@ HB_FUNC( FIELDPUT ) HB_FUNC( FIELDTYPE ) { - HB_THREAD_STUB - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { @@ -2578,28 +1021,25 @@ HB_FUNC( FIELDTYPE ) HB_FUNC( FLOCK ) { - HB_THREAD_STUB - DBLOCKINFO dbLockInfo; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); - dbLockInfo.fResult = FALSE; if( pArea ) { + DBLOCKINFO dbLockInfo; + dbLockInfo.fResult = FALSE; dbLockInfo.itmRecID = NULL; dbLockInfo.uiMethod = DBLM_FILE; SELF_LOCK( pArea, &dbLockInfo ); + hb_retl( dbLockInfo.fResult ); } else hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "FLOCK" ); - - hb_retl( dbLockInfo.fResult ); } HB_FUNC( FOUND ) { - HB_THREAD_STUB BOOL bFound = FALSE; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) SELF_FOUND( pArea, &bFound ); @@ -2608,8 +1048,7 @@ HB_FUNC( FOUND ) HB_FUNC( HEADER ) { - HB_THREAD_STUB - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( !pArea ) hb_retni( 0 ); @@ -2624,8 +1063,7 @@ HB_FUNC( HEADER ) HB_FUNC( INDEXORD ) { - HB_THREAD_STUB - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { @@ -2643,9 +1081,8 @@ HB_FUNC( INDEXORD ) /* Same as RECCOUNT() */ HB_FUNC( LASTREC ) { - HB_THREAD_STUB ULONG ulRecCount = 0; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) SELF_RECCOUNT( pArea, &ulRecCount ); @@ -2655,27 +1092,24 @@ HB_FUNC( LASTREC ) HB_FUNC( LOCK ) { - HB_THREAD_STUB - DBLOCKINFO dbLockInfo; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); - dbLockInfo.fResult = FALSE; if( pArea ) { + DBLOCKINFO dbLockInfo; + dbLockInfo.fResult = FALSE; dbLockInfo.itmRecID = NULL; dbLockInfo.uiMethod = DBLM_EXCLUSIVE; SELF_LOCK( pArea, &dbLockInfo ); + hb_retl( dbLockInfo.fResult ); } else hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "LOCK" ); - - hb_retl( dbLockInfo.fResult ); } HB_FUNC( LUPDATE ) { - HB_THREAD_STUB - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { @@ -2691,19 +1125,16 @@ HB_FUNC( LUPDATE ) HB_FUNC( NETERR ) { - HB_THREAD_STUB - - hb_retl( s_bNetError ); + hb_retl( hb_rddGetNetErr() ); if( ISLOG( 1 ) ) - s_bNetError = hb_parl( 1 ); + hb_rddSetNetErr( hb_parl( 1 ) ); } HB_FUNC( ORDBAGEXT ) { - HB_THREAD_STUB DBORDERINFO pInfo; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); memset( &pInfo, 0, sizeof( DBORDERINFO ) ); pInfo.itmResult = hb_itemPutC( NULL, "" ); @@ -2714,7 +1145,7 @@ HB_FUNC( ORDBAGEXT ) pRddNode = hb_rddFindNode( hb_rddDefaultDrv( NULL ), &uiRddID ); if( pRddNode ) { - pArea = hb_rddNewAreaNode( pRddNode, uiRddID ); + pArea = ( AREAP ) hb_rddNewAreaNode( pRddNode, uiRddID ); if( pArea ) { SELF_ORDINFO( pArea, DBOI_BAGEXT, &pInfo ); @@ -2732,12 +1163,11 @@ HB_FUNC( ORDBAGEXT ) HB_FUNC( ORDBAGNAME ) { - HB_THREAD_STUB - DBORDERINFO pOrderInfo; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { + DBORDERINFO pOrderInfo; memset( &pOrderInfo, 0, sizeof( DBORDERINFO ) ); pOrderInfo.itmOrder = hb_param( 1, HB_IT_ANY ); @@ -2767,13 +1197,13 @@ HB_FUNC( ORDBAGNAME ) HB_FUNC( ORDCONDSET ) { - HB_THREAD_STUB - LPDBORDERCONDINFO lpdbOrdCondInfo; - PHB_ITEM pItem; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { + LPDBORDERCONDINFO lpdbOrdCondInfo; + PHB_ITEM pItem; + lpdbOrdCondInfo = ( LPDBORDERCONDINFO ) hb_xgrab( sizeof( DBORDERCONDINFO ) ); lpdbOrdCondInfo->abFor = hb_parclen( 1 ) > 0 ? ( BYTE * ) hb_strdup( hb_parc( 1 ) ) : NULL; @@ -2842,13 +1272,13 @@ HB_FUNC( ORDCONDSET ) HB_FUNC( ORDCREATE ) { - HB_THREAD_STUB - DBORDERCREATEINFO dbOrderInfo; - DBCONSTRAINTINFO dbConstrInfo; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { + DBORDERCREATEINFO dbOrderInfo; + DBCONSTRAINTINFO dbConstrInfo; + dbOrderInfo.lpdbOrdCondInfo = pArea->lpdbOrdCondInfo; dbOrderInfo.abBagName = ( BYTE * ) hb_parcx( 1 ); dbOrderInfo.atomBagName = ( BYTE * ) hb_parcx( 2 ); @@ -2885,12 +1315,11 @@ HB_FUNC( ORDCREATE ) HB_FUNC( ORDBAGCLEAR ) { - HB_THREAD_STUB - DBORDERINFO pOrderInfo; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { + DBORDERINFO pOrderInfo; memset( &pOrderInfo, 0, sizeof( DBORDERINFO ) ); pOrderInfo.atomBagName = hb_param( 1, HB_IT_STRING ); if( !pOrderInfo.atomBagName ) @@ -2903,12 +1332,11 @@ HB_FUNC( ORDBAGCLEAR ) HB_FUNC( ORDDESTROY ) { - HB_THREAD_STUB - DBORDERINFO pOrderInfo; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { + DBORDERINFO pOrderInfo; memset( &pOrderInfo, 0, sizeof( DBORDERINFO ) ); pOrderInfo.itmOrder = hb_param( 1, HB_IT_STRING ); if( !pOrderInfo.itmOrder ) @@ -2922,12 +1350,11 @@ HB_FUNC( ORDDESTROY ) HB_FUNC( ORDFOR ) { - HB_THREAD_STUB - DBORDERINFO pOrderInfo; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { + DBORDERINFO pOrderInfo; pOrderInfo.itmOrder = hb_param( 1, HB_IT_ANY ); if( pOrderInfo.itmOrder && !HB_IS_STRING( pOrderInfo.itmOrder ) ) { @@ -2959,12 +1386,11 @@ HB_FUNC( ORDFOR ) HB_FUNC( ORDKEY ) { - HB_THREAD_STUB - DBORDERINFO pOrderInfo; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { + DBORDERINFO pOrderInfo; memset( &pOrderInfo, 0, sizeof( DBORDERINFO ) ); pOrderInfo.itmOrder = hb_param( 1, HB_IT_ANY ); if( pOrderInfo.itmOrder && !HB_IS_STRING( pOrderInfo.itmOrder ) ) @@ -2995,12 +1421,11 @@ HB_FUNC( ORDKEY ) #ifdef HB_COMPAT_C53 HB_FUNC( ORDKEYCOUNT ) { - HB_THREAD_STUB - DBORDERINFO pOrderInfo; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { + DBORDERINFO pOrderInfo; memset( &pOrderInfo, 0, sizeof( DBORDERINFO ) ); pOrderInfo.itmOrder = hb_param( 1, HB_IT_STRING ); if( !pOrderInfo.itmOrder ) @@ -3020,12 +1445,11 @@ HB_FUNC( ORDKEYCOUNT ) HB_FUNC( ORDKEYNO ) { - HB_THREAD_STUB - DBORDERINFO pOrderInfo; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { + DBORDERINFO pOrderInfo; memset( &pOrderInfo, 0, sizeof( DBORDERINFO ) ); pOrderInfo.itmOrder = hb_param( 1, HB_IT_STRING ); if( !pOrderInfo.itmOrder ) @@ -3044,12 +1468,11 @@ HB_FUNC( ORDKEYNO ) HB_FUNC( ORDKEYGOTO ) { - HB_THREAD_STUB - DBORDERINFO pOrderInfo; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { + DBORDERINFO pOrderInfo; memset( &pOrderInfo, 0, sizeof( DBORDERINFO ) ); pOrderInfo.itmNewVal = hb_param( 1 , HB_IT_NUMERIC ); pOrderInfo.itmResult = hb_itemPutL( NULL, FALSE ); @@ -3063,12 +1486,11 @@ HB_FUNC( ORDKEYGOTO ) HB_FUNC( ORDKEYRELPOS ) { - HB_THREAD_STUB - DBORDERINFO pOrderInfo; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { + DBORDERINFO pOrderInfo; memset( &pOrderInfo, 0, sizeof( DBORDERINFO ) ); pOrderInfo.itmNewVal = hb_param( 1 , HB_IT_NUMERIC ); pOrderInfo.itmResult = hb_itemPutNI( NULL, 0 ); @@ -3082,12 +1504,11 @@ HB_FUNC( ORDKEYRELPOS ) HB_FUNC( ORDFINDREC ) { - HB_THREAD_STUB - DBORDERINFO pOrderInfo; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { + DBORDERINFO pOrderInfo; memset( &pOrderInfo, 0, sizeof( DBORDERINFO ) ); pOrderInfo.itmNewVal = hb_param( 1 , HB_IT_NUMERIC ); pOrderInfo.itmResult = hb_itemPutL( NULL, FALSE ); @@ -3102,8 +1523,7 @@ HB_FUNC( ORDFINDREC ) HB_FUNC( ORDSKIPRAW ) { - HB_THREAD_STUB - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) SELF_SKIPRAW( pArea, ISNUM( 1 ) ? hb_parnl( 1 ) : 1 ); else @@ -3113,12 +1533,11 @@ HB_FUNC( ORDSKIPRAW ) HB_FUNC( ORDSKIPUNIQUE ) { - HB_THREAD_STUB - DBORDERINFO pOrderInfo; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { + DBORDERINFO pOrderInfo; memset( &pOrderInfo, 0, sizeof( DBORDERINFO ) ); pOrderInfo.itmNewVal = hb_param( 1, HB_IT_ANY ); pOrderInfo.itmResult = hb_itemPutL( NULL, FALSE ); @@ -3132,12 +1551,11 @@ HB_FUNC( ORDSKIPUNIQUE ) HB_FUNC( ORDKEYVAL ) { - HB_THREAD_STUB - DBORDERINFO pOrderInfo; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { + DBORDERINFO pOrderInfo; memset( &pOrderInfo, 0, sizeof( DBORDERINFO ) ); pOrderInfo.itmResult = hb_itemNew( NULL ); SELF_ORDINFO( pArea, DBOI_KEYVAL, &pOrderInfo ); @@ -3150,12 +1568,11 @@ HB_FUNC( ORDKEYVAL ) HB_FUNC( ORDKEYADD ) { - HB_THREAD_STUB - DBORDERINFO pOrderInfo; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { + DBORDERINFO pOrderInfo; memset( &pOrderInfo, 0, sizeof( DBORDERINFO ) ); pOrderInfo.itmOrder = hb_param( 1, HB_IT_STRING ); if( !pOrderInfo.itmOrder ) @@ -3174,12 +1591,11 @@ HB_FUNC( ORDKEYADD ) HB_FUNC( ORDKEYDEL ) { - HB_THREAD_STUB - DBORDERINFO pOrderInfo; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { + DBORDERINFO pOrderInfo; memset( &pOrderInfo, 0, sizeof( DBORDERINFO ) ); pOrderInfo.itmOrder = hb_param( 1, HB_IT_STRING ); if( !pOrderInfo.itmOrder ) @@ -3198,12 +1614,11 @@ HB_FUNC( ORDKEYDEL ) HB_FUNC( ORDDESCEND ) { - HB_THREAD_STUB - DBORDERINFO pOrderInfo; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { + DBORDERINFO pOrderInfo; memset( &pOrderInfo, 0, sizeof( DBORDERINFO ) ); pOrderInfo.itmOrder = hb_param( 1, HB_IT_STRING ); if( !pOrderInfo.itmOrder ) @@ -3222,12 +1637,11 @@ HB_FUNC( ORDDESCEND ) HB_FUNC( ORDISUNIQUE ) { - HB_THREAD_STUB - DBORDERINFO pOrderInfo; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { + DBORDERINFO pOrderInfo; memset( &pOrderInfo, 0, sizeof( DBORDERINFO ) ); pOrderInfo.itmOrder = hb_param( 1, HB_IT_STRING ); if( !pOrderInfo.itmOrder ) @@ -3246,12 +1660,11 @@ HB_FUNC( ORDISUNIQUE ) HB_FUNC( ORDCUSTOM ) { - HB_THREAD_STUB - DBORDERINFO pOrderInfo; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { + DBORDERINFO pOrderInfo; memset( &pOrderInfo, 0, sizeof( DBORDERINFO ) ); pOrderInfo.itmOrder = hb_param( 1, HB_IT_STRING ); if( !pOrderInfo.itmOrder ) @@ -3270,12 +1683,11 @@ HB_FUNC( ORDCUSTOM ) HB_FUNC( ORDCOUNT ) { - HB_THREAD_STUB - DBORDERINFO pOrderInfo; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { + DBORDERINFO pOrderInfo; memset( &pOrderInfo, 0, sizeof( DBORDERINFO ) ); pOrderInfo.atomBagName = hb_param( 1, HB_IT_STRING ); pOrderInfo.itmResult = hb_itemPutNI( NULL, 0 ); @@ -3292,9 +1704,7 @@ HB_FUNC( ORDCOUNT ) #ifdef HB_COMPAT_XPP HB_FUNC( ORDWILDSEEK ) { - HB_THREAD_STUB AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); - BOOL fFound = FALSE; if( pArea ) { @@ -3302,7 +1712,7 @@ HB_FUNC( ORDWILDSEEK ) if( szPatern ) { - BOOL fCont = hb_parl( 2 ), fBack = hb_parl( 3 ); + BOOL fCont = hb_parl( 2 ), fBack = hb_parl( 3 ), fFound = FALSE; DBORDERINFO OrderInfo; ERRCODE errCode = SUCCESS; @@ -3336,42 +1746,51 @@ HB_FUNC( ORDWILDSEEK ) fFound = hb_itemGetL( OrderInfo.itmResult ); } hb_itemRelease( OrderInfo.itmResult ); + hb_retl( fFound ); } else - { hb_errRT_DBCMD( EG_ARG, EDBCMD_DBFILEPUTBADPARAMETER, NULL, "ORDWILDSEEK" ); - } } else - { hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "ORDWILDSEEK" ); - } - hb_retl( fFound ); } #endif HB_FUNC( ORDLISTADD ) { - HB_THREAD_STUB - DBORDERINFO pOrderInfo; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); - s_bNetError = FALSE; if( pArea ) { + DBORDERINFO pOrderInfo; + ERRCODE errCode; + + /* Clipper clears NETERR flag when table is open */ + hb_rddSetNetErr( FALSE ); + memset( &pOrderInfo, 0, sizeof( DBORDERINFO ) ); pOrderInfo.atomBagName = hb_param( 1, HB_IT_STRING ); pOrderInfo.itmOrder = hb_param( 2, HB_IT_STRING ); + if( !pOrderInfo.atomBagName ) { if( !ISNIL( 1 ) ) - hb_errRT_DBCMD( EG_ARG, EDBCMD_REL_BADPARAMETER, NULL, "ORDLISTADD" ); + hb_errRT_DBCMD( EG_ARG, EDBCMD_ORDLSTADD_BADPARAMETER, NULL, "ORDLISTADD" ); return; } + pOrderInfo.itmResult = hb_itemNew( NULL ); - s_bNetError = SELF_ORDLSTADD( pArea, &pOrderInfo ) != SUCCESS; - hb_itemReturn( pOrderInfo.itmResult ); - hb_itemRelease( pOrderInfo.itmResult ); + + errCode = SELF_ORDLSTADD( pArea, &pOrderInfo ); + + /* + * Warning: this is not Clipper compatible. NETERR() should be set by + * error handler not here + */ + if( errCode != SUCCESS ) + hb_rddSetNetErr( TRUE ); + + hb_itemRelease( hb_itemReturn( pOrderInfo.itmResult ) ); } else hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "ORDLISTADD" ); @@ -3379,8 +1798,7 @@ HB_FUNC( ORDLISTADD ) HB_FUNC( ORDLISTCLEAR ) { - HB_THREAD_STUB - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) SELF_ORDLSTCLEAR( pArea ); @@ -3390,8 +1808,7 @@ HB_FUNC( ORDLISTCLEAR ) HB_FUNC( ORDLISTREBUILD ) { - HB_THREAD_STUB - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) SELF_ORDLSTREBUILD( pArea ); @@ -3401,12 +1818,11 @@ HB_FUNC( ORDLISTREBUILD ) HB_FUNC( ORDNAME ) { - HB_THREAD_STUB - DBORDERINFO pOrderInfo; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { + DBORDERINFO pOrderInfo; memset( &pOrderInfo, 0, sizeof( DBORDERINFO ) ); pOrderInfo.itmOrder = hb_param( 1, HB_IT_ANY ); if( pOrderInfo.itmOrder ) @@ -3437,12 +1853,11 @@ HB_FUNC( ORDNAME ) HB_FUNC( ORDNUMBER ) { - HB_THREAD_STUB - DBORDERINFO pOrderInfo; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { + DBORDERINFO pOrderInfo; memset( &pOrderInfo, 0, sizeof( DBORDERINFO ) ); pOrderInfo.itmOrder = hb_param( 1, HB_IT_STRING ); pOrderInfo.atomBagName = hb_param( 2, HB_IT_STRING ); @@ -3462,12 +1877,11 @@ HB_FUNC( ORDNUMBER ) HB_FUNC( ORDSETFOCUS ) { - HB_THREAD_STUB - DBORDERINFO pInfo; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { + DBORDERINFO pInfo; memset( &pInfo, 0, sizeof( DBORDERINFO ) ); pInfo.itmOrder = hb_param( 1, HB_IT_STRING ); if( !pInfo.itmOrder ) @@ -3484,32 +1898,12 @@ HB_FUNC( ORDSETFOCUS ) HB_FUNC( RDDLIST ) { - USHORT uiType, uiCount, uiRdds = 0, uiIndex = 0; - PHB_ITEM pRddArray = hb_itemNew( NULL ); - - uiType = hb_parni( 1 ); /* 0 all types of RDD's */ - - for( uiCount = 0; uiCount < s_uiRddMax; ++uiCount ) - { - if( ( uiType == 0 ) || ( s_RddList[ uiCount ]->uiType == uiType ) ) - ++ uiRdds; - } - hb_arrayNew( pRddArray, uiRdds ); - for( uiCount = 0; uiRdds && uiCount < s_uiRddMax; ++uiCount ) - { - if( ( uiType == 0 ) || ( s_RddList[ uiCount ]->uiType == uiType ) ) - { - hb_itemPutC( hb_arrayGetItemPtr( pRddArray, ++uiIndex ), s_RddList[ uiCount ]->szName ); - } - } - hb_itemReturnForward( pRddArray ); - hb_itemRelease( pRddArray ); + hb_itemRelease( hb_itemReturnForward( hb_rddList( hb_parni( 1 ) ) ) ); } HB_FUNC( RDDNAME ) { - HB_THREAD_STUB - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { @@ -3556,8 +1950,7 @@ HB_FUNC( RECCOUNT ) HB_FUNC( RECNO ) { - HB_THREAD_STUB - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); PHB_ITEM pRecNo = hb_itemPutNL( NULL, 0 ); if( pArea ) @@ -3570,8 +1963,7 @@ HB_FUNC( RECNO ) HB_FUNC( RECSIZE ) { - HB_THREAD_STUB - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { @@ -3586,26 +1978,23 @@ HB_FUNC( RECSIZE ) HB_FUNC( RLOCK ) { - HB_THREAD_STUB - DBLOCKINFO dbLockInfo; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); - dbLockInfo.fResult = FALSE; if( pArea ) { + DBLOCKINFO dbLockInfo; + dbLockInfo.fResult = FALSE; dbLockInfo.itmRecID = NULL; dbLockInfo.uiMethod = DBLM_EXCLUSIVE; SELF_LOCK( pArea, &dbLockInfo ); + hb_retl( dbLockInfo.fResult ); } else hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "RLOCK" ); - - hb_retl( dbLockInfo.fResult ); } HB_FUNC( SELECT ) { - HB_THREAD_STUB if( hb_parinfo( 0 ) == 0 ) { hb_retni( hb_rddGetCurrentWorkAreaNumber() ); @@ -3632,72 +2021,36 @@ HB_FUNC( SELECT ) HB_FUNC( USED ) { - HB_THREAD_STUB - hb_retl( HB_CURRENT_WA != NULL ); -} - -/* NOTE: Same as dbSetDriver() and rddSetDefault(), but doesn't - throw any error if the driver doesn't exist, this is - required in the RDDSYS INIT function, since it's not guaranteed - that the RDD is already registered at that point. [vszakats] */ - -HB_FUNC( __RDDSETDEFAULT ) -{ - HB_THREAD_STUB - USHORT uiLen; - - hb_retc( s_szDefDriver ); - - uiLen = ( USHORT ) hb_parclen( 1 ); - - if( uiLen > 0 ) - { - if( uiLen > HARBOUR_MAX_RDD_DRIVERNAME_LENGTH ) - { - uiLen = HARBOUR_MAX_RDD_DRIVERNAME_LENGTH; - } - hb_strncpyUpper( s_szDefDriver, hb_parc( 1 ), uiLen ); - } + hb_retl( hb_rddGetCurrentWorkAreaPointer() != NULL ); } HB_FUNC( RDDSETDEFAULT ) { - HB_THREAD_STUB - hb_retc( hb_rddDefaultDrv( NULL ) ); if( hb_parclen( 1 ) > 0 ) { if( ! hb_rddDefaultDrv( hb_parc( 1 ) ) ) - { hb_errRT_DBCMD( EG_ARG, EDBCMD_BADPARAMETER, NULL, "RDDSETDEFAULT" ); - return; - } } } HB_FUNC( DBSETDRIVER ) { - HB_THREAD_STUB - hb_retc( hb_rddDefaultDrv( NULL ) ); if( hb_parclen( 1 ) > 0 ) { if( ! hb_rddDefaultDrv( hb_parc( 1 ) ) ) - { hb_errRT_DBCMD( EG_ARG, EDBCMD_BADPARAMETER, NULL, "DBSETDRIVER" ); - return; - } } } HB_FUNC( ORDSCOPE ) { - HB_THREAD_STUB - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); - if ( pArea ) + if( pArea ) { DBORDERINFO pInfo; USHORT uiAction; @@ -3705,9 +2058,9 @@ HB_FUNC( ORDSCOPE ) memset( &pInfo, 0, sizeof( DBORDERINFO ) ); pInfo.itmResult = hb_itemNew( NULL ); - if ( iScope == 2 ) + if( iScope == 2 ) { - if ( hb_pcount() > 1 && !ISNIL( 2 ) ) + if( hb_pcount() > 1 && !ISNIL( 2 ) ) { uiAction = DBOI_SCOPESET; pInfo.itmNewVal = hb_param( 2, HB_IT_ANY); @@ -3736,9 +2089,8 @@ HB_FUNC( ORDSCOPE ) HB_FUNC( DBRELATION ) /* () --> cLinkExp */ { - HB_THREAD_STUB char szExprBuff[ HARBOUR_MAX_RDD_RELTEXT_LENGTH + 1 ]; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); szExprBuff[ 0 ] = 0; if( pArea ) @@ -3749,9 +2101,8 @@ HB_FUNC( DBRELATION ) /* () --> cLinkExp */ HB_FUNC( DBRSELECT ) /* () --> nWorkArea */ { - HB_THREAD_STUB USHORT uiWorkArea = 0; - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) SELF_RELAREA( pArea, hb_parni(1), &uiWorkArea ); @@ -3761,8 +2112,7 @@ HB_FUNC( DBRSELECT ) /* () --> nWorkArea */ HB_FUNC( DBCLEARRELATION ) { - HB_THREAD_STUB - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) SELF_CLEARREL( pArea ); @@ -3770,8 +2120,7 @@ HB_FUNC( DBCLEARRELATION ) HB_FUNC( DBSETRELATION ) { - HB_THREAD_STUB - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { @@ -3796,14 +2145,12 @@ HB_FUNC( DBSETRELATION ) hb_rddSelectWorkAreaAlias( hb_parcx( 1 ) ); if( hb_vmRequestQuery() ) - { return; - } uiChildArea = hb_rddGetCurrentWorkAreaNumber(); hb_rddSelectWorkAreaNumber( uiArea ); } - pChildArea = HB_GET_WA( uiChildArea ); + pChildArea = uiChildArea ? ( AREAP ) hb_rddGetWorkAreaPointer( uiChildArea ) : NULL; if( !pChildArea ) { @@ -3821,15 +2168,12 @@ HB_FUNC( DBSETRELATION ) SELF_SETREL( pArea, &dbRelations ); } else - { hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "DBSETRELATION" ); - } } HB_FUNC( __DBARRANGE ) { - HB_THREAD_STUB - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { @@ -3939,7 +2283,8 @@ HB_FUNC( __DBARRANGE ) } dbSortInfo.dbtri.lpaSource = pArea; - dbSortInfo.dbtri.lpaDest = HB_GET_WA( uiNewArea ); + dbSortInfo.dbtri.lpaDest = ( AREAP ) hb_rddGetWorkAreaPointer( uiNewArea ); + /* TODO: check what Clipper does when lpaDest == NULL or lpaDest == lpaSource */ if( dbSortInfo.uiItemCount == 0 ) SELF_TRANS( pArea, &dbSortInfo.dbtri ); @@ -3958,8 +2303,7 @@ HB_FUNC( __DBARRANGE ) HB_FUNC( DBINFO ) { - HB_THREAD_STUB - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { @@ -3983,17 +2327,15 @@ HB_FUNC( DBINFO ) HB_FUNC( DBORDERINFO ) { - HB_THREAD_STUB - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { - PHB_ITEM pType; - DBORDERINFO pOrderInfo; - - pType = hb_param( 1 , HB_IT_NUMERIC ); + PHB_ITEM pType = hb_param( 1 , HB_IT_NUMERIC ); if( pType ) { + DBORDERINFO pOrderInfo; + /* atomBagName may be NIL */ pOrderInfo.atomBagName = hb_param( 2, HB_IT_STRING ); if( !pOrderInfo.atomBagName ) @@ -4020,8 +2362,7 @@ HB_FUNC( DBORDERINFO ) HB_FUNC( DBFIELDINFO ) { - HB_THREAD_STUB - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { @@ -4048,8 +2389,7 @@ HB_FUNC( DBFIELDINFO ) HB_FUNC( DBRECORDINFO ) { - HB_THREAD_STUB - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { @@ -4074,8 +2414,7 @@ HB_FUNC( DBRECORDINFO ) HB_FUNC( DBFILEGET ) { - HB_THREAD_STUB - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { @@ -4105,8 +2444,7 @@ HB_FUNC( DBFILEGET ) HB_FUNC( DBFILEPUT ) { - HB_THREAD_STUB - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { @@ -4136,10 +2474,9 @@ HB_FUNC( DBFILEPUT ) /* here we have the NEW RDD level functions DBDROP, DBEXISTS, RDDINFO */ HB_FUNC( DBDROP ) { - HB_THREAD_STUB LPRDDNODE pRDDNode; USHORT uiRddID; - char *szDriver; + const char * szDriver; szDriver = hb_parc( 3 ); if( !szDriver ) /* no VIA RDD parameter, use default */ @@ -4149,7 +2486,7 @@ HB_FUNC( DBDROP ) pRDDNode = hb_rddFindNode( szDriver, &uiRddID ); /* find the RDDNODE */ - if ( !pRDDNode ) + if( !pRDDNode ) { hb_errRT_DBCMD( EG_ARG, EDBCMD_EVAL_BADPARAMETER, NULL, "DBDROP" ); return; @@ -4161,10 +2498,9 @@ HB_FUNC( DBDROP ) HB_FUNC( DBEXISTS ) { - HB_THREAD_STUB LPRDDNODE pRDDNode; USHORT uiRddID; - char * szDriver; + const char * szDriver; szDriver = hb_parc( 3 ); if( !szDriver ) /* no VIA RDD parameter, use default */ @@ -4174,7 +2510,7 @@ HB_FUNC( DBEXISTS ) pRDDNode = hb_rddFindNode( szDriver, &uiRddID ); /* find the RDD */ - if ( !pRDDNode ) + if( !pRDDNode ) { hb_errRT_DBCMD( EG_ARG, EDBCMD_EVAL_BADPARAMETER, NULL, "DBEXISTS" ); return; @@ -4190,7 +2526,7 @@ HB_FUNC( RDDINFO ) USHORT uiRddID; ULONG ulConnection; PHB_ITEM pIndex, pParam; - char *szDriver; + const char * szDriver; szDriver = hb_parc( 3 ); if( !szDriver ) /* no VIA RDD parameter, use default */ @@ -4216,340 +2552,6 @@ 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, - PHB_ITEM *pStruct, PHB_ITEM pFields ) -{ - USHORT uiFields, uiSize, uiCount, uiPosSrc, uiPosDst, uiSizeSrc, uiSizeDst; - ERRCODE errCode; - char * szField; - BOOL fAll; - - errCode = SELF_FIELDCOUNT( lpaSource, &uiSizeSrc ); - if( errCode != SUCCESS ) - return errCode; - - if( lpaDest ) - { - errCode = SELF_FIELDCOUNT( lpaDest, &uiSizeDst ); - if( errCode != SUCCESS ) - return errCode; - uiSize = HB_MIN( uiSizeDst, uiSizeSrc ); - } - else - { - uiSize = uiSizeDst = uiSizeSrc; - } - - if( !uiSize ) - return FAILURE; - if( hb_itemType( pFields ) & HB_IT_ARRAY ) - { - uiFields = ( USHORT ) hb_arrayLen( pFields ); - if( uiFields ) - uiSize = uiFields; - } - else - uiFields = 0; - - fAll = ( uiSizeDst == uiSizeSrc ); - - lpdbTransInfo->lpaSource = lpaSource; - lpdbTransInfo->lpaDest = lpaDest; - lpdbTransInfo->lpTransItems = ( LPDBTRANSITEM ) - hb_xgrab( uiSize * sizeof( DBTRANSITEM ) ); - - if( !lpaDest ) - { - *pStruct = hb_itemNew( NULL ); - hb_arrayNew( *pStruct, 0 ); - } - - if( uiFields == 0 ) - { - if( lpaDest ) - { - PHB_ITEM pItem = hb_itemNew( NULL ); - uiSize = 0; - for( uiCount = 1; uiCount <= uiSizeSrc; ++uiCount ) - { - if( SELF_FIELDINFO( lpaSource, uiCount, DBS_NAME, pItem ) != SUCCESS ) - { - uiSize = 0; - break; - } - szField = hb_itemGetCPtr( pItem ); - uiPosDst = hb_rddFieldExpIndex( lpaDest, szField ); - if( uiPosDst != uiCount ) - fAll = FALSE; - if( uiPosDst ) - { - USHORT ui; - - /* check for replicated field names in source area */ - for( ui = 0; ui < uiSize; ++ui ) - { - if( lpdbTransInfo->lpTransItems[ ui ].uiDest == uiPosDst ) - break; - } - if( ui == uiSize ) - { - lpdbTransInfo->lpTransItems[ uiSize ].uiSource = uiCount; - lpdbTransInfo->lpTransItems[ uiSize++ ].uiDest = uiPosDst; - } - } - } - hb_itemRelease( pItem ); - } - else - { - hb_tblStructure( lpaSource, *pStruct ); - uiSize = ( USHORT ) hb_arrayLen( *pStruct ); - for( uiCount = 0; uiCount < uiSize; ++uiCount ) - { - lpdbTransInfo->lpTransItems[ uiCount ].uiSource = - lpdbTransInfo->lpTransItems[ uiCount ].uiDest = uiCount + 1; - } - } - } - else - { - uiSize = 0; - for( uiCount = 1; uiCount <= uiFields; ++uiCount ) - { - szField = hb_dbTransFieldPos( pFields, uiCount ); - if( szField ) - { - uiPosSrc = hb_rddFieldExpIndex( lpaSource, szField ); - if( !uiPosSrc ) - continue; - if( lpaDest ) - uiPosDst = hb_rddFieldExpIndex( lpaDest, szField ); - else - uiPosDst = uiSize + 1; - if( uiPosDst ) - { - if( uiPosSrc != uiPosDst ) - fAll = FALSE; - lpdbTransInfo->lpTransItems[ uiSize ].uiSource = uiPosSrc; - lpdbTransInfo->lpTransItems[ uiSize++ ].uiDest = uiPosDst; - if( !lpaDest ) - { - hb_arraySize( *pStruct, uiSize ); - hb_fldStructure( lpaSource, uiPosSrc, - hb_arrayGetItemPtr( *pStruct, uiSize ) ); - } - } - } - } - } - - if( uiSize != uiSizeSrc ) - fAll = FALSE; - - if( fAll && lpaDest ) - { - PHB_ITEM pSrcItm = hb_itemNew( NULL ), - pDstItm = hb_itemNew( NULL ); - /* - * if fAll is TRUE here then it means that all fields are included - * and they are on the same positions in both tables, so now check - * if their types and sizes are also equal - */ - for( uiCount = 1; uiCount <= uiSize; ++uiCount ) - { - if( SELF_FIELDINFO( lpaSource, uiCount, DBS_TYPE, pSrcItm ) != SUCCESS || - SELF_FIELDINFO( lpaDest, uiCount, DBS_TYPE, pDstItm ) != SUCCESS ) - { - uiSize = 0; - break; - } - if( hb_stricmp( hb_itemGetCPtr( pSrcItm ), - hb_itemGetCPtr( pDstItm ) ) != 0 ) - { - fAll = FALSE; - break; - } - if( SELF_FIELDINFO( lpaSource, uiCount, DBS_LEN, pSrcItm ) != SUCCESS || - SELF_FIELDINFO( lpaDest, uiCount, DBS_LEN, pDstItm ) != SUCCESS ) - { - uiSize = 0; - break; - } - if( hb_itemGetNL( pSrcItm ) != hb_itemGetNL( pDstItm ) ) - { - fAll = FALSE; - break; - } - if( SELF_FIELDINFO( lpaSource, uiCount, DBS_DEC, pSrcItm ) != SUCCESS || - SELF_FIELDINFO( lpaDest, uiCount, DBS_DEC, pDstItm ) != SUCCESS ) - { - uiSize = 0; - break; - } - if( hb_itemGetNL( pSrcItm ) != hb_itemGetNL( pDstItm ) ) - { - fAll = FALSE; - break; - } - } - hb_itemRelease( pSrcItm ); - hb_itemRelease( pDstItm ); - } - - lpdbTransInfo->uiFlags = fAll ? DBTF_MATCH : 0; - lpdbTransInfo->uiItemCount = uiSize; - - return uiSize ? SUCCESS : FAILURE; -} - -static ERRCODE hb_rddTransRecords( AREAP pArea, - char *szFileName, char *szDriver, - ULONG ulConnection, - PHB_ITEM pFields, BOOL fExport, - PHB_ITEM pCobFor, PHB_ITEM pStrFor, - PHB_ITEM pCobWhile, PHB_ITEM pStrWhile, - PHB_ITEM pNext, PHB_ITEM pRecID, - PHB_ITEM pRest, - char *szCpId, - PHB_ITEM pDelim ) -{ - AREAP lpaClose = NULL; - PHB_ITEM pStruct = NULL; - DBTRANSINFO dbTransInfo; - USHORT uiPrevArea, uiCount, uiSwap; - ERRCODE errCode; - - memset( &dbTransInfo, 0, sizeof( DBTRANSINFO ) ); - uiPrevArea = hb_rddGetCurrentWorkAreaNumber(); - - if( szDriver == NULL ) - /* szDriver = SELF_RDDNODE( pArea )->szName; */ - szDriver = hb_rddDefaultDrv( NULL ); - - if( fExport ) - { - errCode = hb_dbTransStruct( pArea, NULL, &dbTransInfo, - &pStruct, pFields ); - if( errCode == SUCCESS ) - { - errCode = hb_rddCreateTable( szFileName, pStruct, szDriver, - TRUE, 0, "", pDelim, szCpId, - ulConnection ); - if( errCode == SUCCESS ) - { - dbTransInfo.lpaDest = lpaClose = - ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); - } - } - } - else - { - LPRDDNODE pRddNode = hb_rddFindNode( szDriver, NULL ); - - if( !pRddNode ) - { - hb_errRT_DBCMD( EG_ARG, EDBCMD_USE_BADPARAMETER, NULL, "DBUSEAREA" ); - return FAILURE; - } - - if( pRddNode->uiType == RDT_TRANSFER ) - { - errCode = hb_dbTransStruct( pArea, NULL, &dbTransInfo, - &pStruct, pFields ); - - /* revert area and items */ - dbTransInfo.lpaDest = dbTransInfo.lpaSource; - for( uiCount = 0; uiCount < dbTransInfo.uiItemCount; ++uiCount ) - { - uiSwap = dbTransInfo.lpTransItems[uiCount].uiSource; - dbTransInfo.lpTransItems[uiCount].uiSource = - dbTransInfo.lpTransItems[uiCount].uiDest; - dbTransInfo.lpTransItems[uiCount].uiDest = uiSwap; - } - - if( errCode == SUCCESS ) - { - errCode = hb_rddOpenTable( szFileName, szDriver, 0, "", TRUE, TRUE, - szCpId, ulConnection, pStruct, pDelim ); - if( errCode == SUCCESS ) - { - lpaClose = dbTransInfo.lpaSource = - ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); - } - } - } - else - { - errCode = hb_rddOpenTable( szFileName, szDriver, 0, "", TRUE, TRUE, - szCpId, ulConnection, NULL, pDelim ); - if( errCode == SUCCESS ) - { - lpaClose = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); - errCode = hb_dbTransStruct( lpaClose, pArea, &dbTransInfo, - NULL, pFields ); - } - } - } - - if( pStruct ) - hb_itemRelease( pStruct ); - - if( errCode == SUCCESS ) - { - hb_rddSelectWorkAreaNumber( dbTransInfo.lpaSource->uiArea ); - - dbTransInfo.dbsci.itmCobFor = pCobFor; - dbTransInfo.dbsci.lpstrFor = pStrFor; - dbTransInfo.dbsci.itmCobWhile = pCobWhile; - dbTransInfo.dbsci.lpstrWhile = pStrWhile; - dbTransInfo.dbsci.lNext = pNext; - dbTransInfo.dbsci.itmRecID = pRecID; - dbTransInfo.dbsci.fRest = pRest; - - 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 ); - if( lpaClose ) - { - hb_rddSelectWorkAreaNumber( lpaClose->uiArea ); - hb_rddReleaseCurrentArea(); - } - hb_rddSelectWorkAreaNumber( uiPrevArea ); - - return errCode; -} - /* __dbTrans( nDstArea, aFieldsStru, bFor, bWhile, nNext, nRecord, lRest ) */ HB_FUNC( __DBTRANS ) { @@ -4610,14 +2612,9 @@ HB_FUNC( __DBTRANS ) HB_FUNC( __DBAPP ) { - BOOL bRetVal = FALSE; - - if( ISCHAR( 1 ) ) - { - AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); - if( pArea ) - { - bRetVal = ( SUCCESS == hb_rddTransRecords( pArea, + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); + if( pArea ) + hb_retl( SUCCESS == hb_rddTransRecords( pArea, hb_parc( 1 ), /* file name */ hb_parc( 8 ), /* RDD */ hb_parnl( 9 ), /* connection */ @@ -4632,26 +2629,15 @@ HB_FUNC( __DBAPP ) hb_param( 7, HB_IT_LOGICAL ), /* Rest */ hb_parc( 10 ), /* Codepage */ hb_param( 11, HB_IT_ANY ) ) ); /* Delimiter */ - } - else - { - hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "APPEND FROM" ); - } - } - - hb_retl( bRetVal ); + else + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "APPEND FROM" ); } HB_FUNC( __DBCOPY ) { - BOOL bRetVal = FALSE; - - if( ISCHAR( 1 ) ) - { - AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); - if( pArea ) - { - bRetVal = ( SUCCESS == hb_rddTransRecords( pArea, + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); + if( pArea ) + hb_retl( SUCCESS == hb_rddTransRecords( pArea, hb_parc( 1 ), /* file name */ hb_parc( 8 ), /* RDD */ hb_parnl( 9 ), /* connection */ @@ -4666,40 +2652,15 @@ HB_FUNC( __DBCOPY ) hb_param( 7, HB_IT_LOGICAL ), /* Rest */ hb_parc( 10 ), /* Codepage */ hb_param( 11, HB_IT_ANY ) ) ); /* Delimiter */ - } - else - { - hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "COPY TO" ); - } - } - - hb_retl( bRetVal ); -} - -HB_EXPORT ERRCODE hb_rddGetTempAlias( char * szAliasTmp ) -{ - int i, iArea; - - for( i = 1 ; i < 1000 ; i++ ) - { - snprintf( szAliasTmp, 11, "__HBTMP%03i", i); - - if( hb_rddGetAliasNumber( szAliasTmp, &iArea ) != SUCCESS ) - { - return SUCCESS; - } - } - - szAliasTmp[0] = '\0'; - return FAILURE; + else + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "COPY TO" ); } HB_FUNC( __RDDGETTEMPALIAS ) { - HB_THREAD_STUB char szAliasTmp[ HARBOUR_MAX_RDD_ALIAS_LENGTH + 1 ]; - if ( hb_rddGetTempAlias( szAliasTmp ) == SUCCESS ) + if( hb_rddGetTempAlias( szAliasTmp ) == SUCCESS ) hb_retc( szAliasTmp ); else hb_ret(); @@ -4708,8 +2669,7 @@ HB_FUNC( __RDDGETTEMPALIAS ) #ifdef HB_COMPAT_XPP HB_FUNC( DBSKIPPER ) { - HB_THREAD_STUB - AREAP pArea = HB_CURRENT_WA; + AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); if( pArea ) { diff --git a/harbour/source/rdd/dbf1.c b/harbour/source/rdd/dbf1.c index 80d97eae6e..0f01e9aec3 100644 --- a/harbour/source/rdd/dbf1.c +++ b/harbour/source/rdd/dbf1.c @@ -72,106 +72,106 @@ static USHORT s_uiRddId = ( USHORT ) -1; static RDDFUNCS dbfSuper; -static RDDFUNCS dbfTable = { ( DBENTRYP_BP ) hb_dbfBof, - ( DBENTRYP_BP ) hb_dbfEof, - ( DBENTRYP_BP ) hb_dbfFound, - ( DBENTRYP_V ) hb_dbfGoBottom, - ( DBENTRYP_UL ) hb_dbfGoTo, - ( DBENTRYP_I ) hb_dbfGoToId, - ( DBENTRYP_V ) hb_dbfGoTop, - ( DBENTRYP_BIB ) hb_dbfSeek, - ( DBENTRYP_L ) hb_dbfSkip, - ( DBENTRYP_L ) hb_dbfSkipFilter, - ( DBENTRYP_L ) hb_dbfSkipRaw, - ( DBENTRYP_VF ) hb_dbfAddField, - ( DBENTRYP_B ) hb_dbfAppend, - ( DBENTRYP_I ) hb_dbfCreateFields, - ( DBENTRYP_V ) hb_dbfDeleteRec, - ( DBENTRYP_BP ) hb_dbfDeleted, - ( DBENTRYP_SP ) hb_dbfFieldCount, - ( DBENTRYP_VF ) hb_dbfFieldDisplay, - ( DBENTRYP_SSI ) hb_dbfFieldInfo, - ( DBENTRYP_SVP ) hb_dbfFieldName, - ( DBENTRYP_V ) hb_dbfFlush, - ( DBENTRYP_PP ) hb_dbfGetRec, - ( DBENTRYP_SI ) hb_dbfGetValue, - ( DBENTRYP_SVL ) hb_dbfGetVarLen, - ( DBENTRYP_V ) hb_dbfGoCold, - ( DBENTRYP_V ) hb_dbfGoHot, - ( DBENTRYP_P ) hb_dbfPutRec, - ( DBENTRYP_SI ) hb_dbfPutValue, - ( DBENTRYP_V ) hb_dbfRecall, - ( DBENTRYP_ULP ) hb_dbfRecCount, - ( DBENTRYP_ISI ) hb_dbfRecInfo, - ( DBENTRYP_ULP ) hb_dbfRecNo, - ( DBENTRYP_I ) hb_dbfRecId, - ( DBENTRYP_S ) hb_dbfSetFieldExtent, - ( DBENTRYP_P ) hb_dbfAlias, - ( DBENTRYP_V ) hb_dbfClose, - ( DBENTRYP_VP ) hb_dbfCreate, - ( DBENTRYP_SI ) hb_dbfInfo, - ( DBENTRYP_V ) hb_dbfNewArea, - ( DBENTRYP_VP ) hb_dbfOpen, - ( DBENTRYP_V ) hb_dbfRelease, - ( DBENTRYP_SP ) hb_dbfStructSize, - ( DBENTRYP_P ) hb_dbfSysName, - ( DBENTRYP_VEI ) hb_dbfEval, - ( DBENTRYP_V ) hb_dbfPack, - ( DBENTRYP_LSP ) hb_dbfPackRec, - ( DBENTRYP_VS ) hb_dbfSort, - ( DBENTRYP_VT ) hb_dbfTrans, - ( DBENTRYP_VT ) hb_dbfTransRec, - ( DBENTRYP_V ) hb_dbfZap, - ( DBENTRYP_VR ) hb_dbfChildEnd, - ( DBENTRYP_VR ) hb_dbfChildStart, - ( DBENTRYP_VR ) hb_dbfChildSync, - ( DBENTRYP_V ) hb_dbfSyncChildren, - ( DBENTRYP_V ) hb_dbfClearRel, - ( DBENTRYP_V ) hb_dbfForceRel, - ( DBENTRYP_SVP ) hb_dbfRelArea, - ( DBENTRYP_VR ) hb_dbfRelEval, - ( DBENTRYP_SVP ) hb_dbfRelText, - ( DBENTRYP_VR ) hb_dbfSetRel, - ( DBENTRYP_OI ) hb_dbfOrderListAdd, - ( DBENTRYP_V ) hb_dbfOrderListClear, - ( DBENTRYP_OI ) hb_dbfOrderListDelete, - ( DBENTRYP_OI ) hb_dbfOrderListFocus, - ( DBENTRYP_V ) hb_dbfOrderListRebuild, - ( DBENTRYP_VOI ) hb_dbfOrderCondition, - ( DBENTRYP_VOC ) hb_dbfOrderCreate, - ( DBENTRYP_OI ) hb_dbfOrderDestroy, - ( DBENTRYP_OII ) hb_dbfOrderInfo, - ( DBENTRYP_V ) hb_dbfClearFilter, - ( DBENTRYP_V ) hb_dbfClearLocate, - ( DBENTRYP_V ) hb_dbfClearScope, - ( DBENTRYP_VPLP ) hb_dbfCountScope, - ( DBENTRYP_I ) hb_dbfFilterText, - ( DBENTRYP_SI ) hb_dbfScopeInfo, - ( DBENTRYP_VFI ) hb_dbfSetFilter, - ( DBENTRYP_VLO ) hb_dbfSetLocate, - ( DBENTRYP_VOS ) hb_dbfSetScope, - ( DBENTRYP_VPL ) hb_dbfSkipScope, - ( DBENTRYP_B ) hb_dbfLocate, - ( DBENTRYP_P ) hb_dbfCompile, - ( DBENTRYP_I ) hb_dbfError, - ( DBENTRYP_I ) hb_dbfEvalBlock, - ( DBENTRYP_VSP ) hb_dbfRawLock, - ( DBENTRYP_VL ) hb_dbfLock, - ( DBENTRYP_I ) hb_dbfUnLock, - ( DBENTRYP_V ) hb_dbfCloseMemFile, - ( DBENTRYP_VP ) hb_dbfCreateMemFile, - ( DBENTRYP_SVPB ) hb_dbfGetValueFile, - ( DBENTRYP_VP ) hb_dbfOpenMemFile, - ( DBENTRYP_SVPB ) hb_dbfPutValueFile, - ( DBENTRYP_V ) hb_dbfReadDBHeader, - ( DBENTRYP_V ) hb_dbfWriteDBHeader, - ( DBENTRYP_R ) hb_dbfInit, - ( DBENTRYP_R ) hb_dbfExit, - ( DBENTRYP_RVV ) hb_dbfDrop, - ( DBENTRYP_RVV ) hb_dbfExists, - ( DBENTRYP_RSLV ) hb_dbfRddInfo, - ( DBENTRYP_SVP ) hb_dbfWhoCares - }; +static const RDDFUNCS dbfTable = { ( DBENTRYP_BP ) hb_dbfBof, + ( DBENTRYP_BP ) hb_dbfEof, + ( DBENTRYP_BP ) hb_dbfFound, + ( DBENTRYP_V ) hb_dbfGoBottom, + ( DBENTRYP_UL ) hb_dbfGoTo, + ( DBENTRYP_I ) hb_dbfGoToId, + ( DBENTRYP_V ) hb_dbfGoTop, + ( DBENTRYP_BIB ) hb_dbfSeek, + ( DBENTRYP_L ) hb_dbfSkip, + ( DBENTRYP_L ) hb_dbfSkipFilter, + ( DBENTRYP_L ) hb_dbfSkipRaw, + ( DBENTRYP_VF ) hb_dbfAddField, + ( DBENTRYP_B ) hb_dbfAppend, + ( DBENTRYP_I ) hb_dbfCreateFields, + ( DBENTRYP_V ) hb_dbfDeleteRec, + ( DBENTRYP_BP ) hb_dbfDeleted, + ( DBENTRYP_SP ) hb_dbfFieldCount, + ( DBENTRYP_VF ) hb_dbfFieldDisplay, + ( DBENTRYP_SSI ) hb_dbfFieldInfo, + ( DBENTRYP_SVP ) hb_dbfFieldName, + ( DBENTRYP_V ) hb_dbfFlush, + ( DBENTRYP_PP ) hb_dbfGetRec, + ( DBENTRYP_SI ) hb_dbfGetValue, + ( DBENTRYP_SVL ) hb_dbfGetVarLen, + ( DBENTRYP_V ) hb_dbfGoCold, + ( DBENTRYP_V ) hb_dbfGoHot, + ( DBENTRYP_P ) hb_dbfPutRec, + ( DBENTRYP_SI ) hb_dbfPutValue, + ( DBENTRYP_V ) hb_dbfRecall, + ( DBENTRYP_ULP ) hb_dbfRecCount, + ( DBENTRYP_ISI ) hb_dbfRecInfo, + ( DBENTRYP_ULP ) hb_dbfRecNo, + ( DBENTRYP_I ) hb_dbfRecId, + ( DBENTRYP_S ) hb_dbfSetFieldExtent, + ( DBENTRYP_P ) hb_dbfAlias, + ( DBENTRYP_V ) hb_dbfClose, + ( DBENTRYP_VP ) hb_dbfCreate, + ( DBENTRYP_SI ) hb_dbfInfo, + ( DBENTRYP_V ) hb_dbfNewArea, + ( DBENTRYP_VP ) hb_dbfOpen, + ( DBENTRYP_V ) hb_dbfRelease, + ( DBENTRYP_SP ) hb_dbfStructSize, + ( DBENTRYP_P ) hb_dbfSysName, + ( DBENTRYP_VEI ) hb_dbfEval, + ( DBENTRYP_V ) hb_dbfPack, + ( DBENTRYP_LSP ) hb_dbfPackRec, + ( DBENTRYP_VS ) hb_dbfSort, + ( DBENTRYP_VT ) hb_dbfTrans, + ( DBENTRYP_VT ) hb_dbfTransRec, + ( DBENTRYP_V ) hb_dbfZap, + ( DBENTRYP_VR ) hb_dbfChildEnd, + ( DBENTRYP_VR ) hb_dbfChildStart, + ( DBENTRYP_VR ) hb_dbfChildSync, + ( DBENTRYP_V ) hb_dbfSyncChildren, + ( DBENTRYP_V ) hb_dbfClearRel, + ( DBENTRYP_V ) hb_dbfForceRel, + ( DBENTRYP_SVP ) hb_dbfRelArea, + ( DBENTRYP_VR ) hb_dbfRelEval, + ( DBENTRYP_SVP ) hb_dbfRelText, + ( DBENTRYP_VR ) hb_dbfSetRel, + ( DBENTRYP_OI ) hb_dbfOrderListAdd, + ( DBENTRYP_V ) hb_dbfOrderListClear, + ( DBENTRYP_OI ) hb_dbfOrderListDelete, + ( DBENTRYP_OI ) hb_dbfOrderListFocus, + ( DBENTRYP_V ) hb_dbfOrderListRebuild, + ( DBENTRYP_VOI ) hb_dbfOrderCondition, + ( DBENTRYP_VOC ) hb_dbfOrderCreate, + ( DBENTRYP_OI ) hb_dbfOrderDestroy, + ( DBENTRYP_OII ) hb_dbfOrderInfo, + ( DBENTRYP_V ) hb_dbfClearFilter, + ( DBENTRYP_V ) hb_dbfClearLocate, + ( DBENTRYP_V ) hb_dbfClearScope, + ( DBENTRYP_VPLP ) hb_dbfCountScope, + ( DBENTRYP_I ) hb_dbfFilterText, + ( DBENTRYP_SI ) hb_dbfScopeInfo, + ( DBENTRYP_VFI ) hb_dbfSetFilter, + ( DBENTRYP_VLO ) hb_dbfSetLocate, + ( DBENTRYP_VOS ) hb_dbfSetScope, + ( DBENTRYP_VPL ) hb_dbfSkipScope, + ( DBENTRYP_B ) hb_dbfLocate, + ( DBENTRYP_P ) hb_dbfCompile, + ( DBENTRYP_I ) hb_dbfError, + ( DBENTRYP_I ) hb_dbfEvalBlock, + ( DBENTRYP_VSP ) hb_dbfRawLock, + ( DBENTRYP_VL ) hb_dbfLock, + ( DBENTRYP_I ) hb_dbfUnLock, + ( DBENTRYP_V ) hb_dbfCloseMemFile, + ( DBENTRYP_VP ) hb_dbfCreateMemFile, + ( DBENTRYP_SVPB ) hb_dbfGetValueFile, + ( DBENTRYP_VP ) hb_dbfOpenMemFile, + ( DBENTRYP_SVPB ) hb_dbfPutValueFile, + ( DBENTRYP_V ) hb_dbfReadDBHeader, + ( DBENTRYP_V ) hb_dbfWriteDBHeader, + ( DBENTRYP_R ) hb_dbfInit, + ( DBENTRYP_R ) hb_dbfExit, + ( DBENTRYP_RVV ) hb_dbfDrop, + ( DBENTRYP_RVV ) hb_dbfExists, + ( DBENTRYP_RSLV ) hb_dbfRddInfo, + ( DBENTRYP_SVP ) hb_dbfWhoCares + }; /* * Common functions. @@ -4610,11 +4610,11 @@ HB_FUNC( DBF_GETFUNCTABLE ) { ERRCODE errCode; - if ( uiCount ) + if( uiCount ) * uiCount = RDDFUNCSCOUNT; - errCode = hb_rddInherit( pTable, &dbfTable, &dbfSuper, 0 ); + errCode = hb_rddInherit( pTable, &dbfTable, &dbfSuper, NULL ); hb_retni( errCode ); - if ( errCode == SUCCESS ) + if( errCode == SUCCESS ) { /* * we successfully register our RDD so now we can initialize it diff --git a/harbour/source/rdd/dbfcdx/dbfcdx1.c b/harbour/source/rdd/dbfcdx/dbfcdx1.c index 35f2bd3b23..16cbc5588a 100644 --- a/harbour/source/rdd/dbfcdx/dbfcdx1.c +++ b/harbour/source/rdd/dbfcdx/dbfcdx1.c @@ -133,7 +133,7 @@ static void hb_cdxSortFree( LPCDXSORTINFO pSort ); static USHORT s_uiRddId = ( USHORT ) -1; static RDDFUNCS cdxSuper; -static RDDFUNCS cdxTable = +static const RDDFUNCS cdxTable = { /* Movement and positioning methods */ @@ -9443,11 +9443,11 @@ HB_FUNC( SIXCDX_GETFUNCTABLE ) if ( uiCount ) * uiCount = RDDFUNCSCOUNT; - errCode = hb_rddInherit( pTable, &cdxTable, &cdxSuper, ( BYTE * ) "DBFFPT" ); + errCode = hb_rddInherit( pTable, &cdxTable, &cdxSuper, "DBFFPT" ); if ( errCode != SUCCESS ) - errCode = hb_rddInherit( pTable, &cdxTable, &cdxSuper, ( BYTE * ) "DBFDBT" ); + errCode = hb_rddInherit( pTable, &cdxTable, &cdxSuper, "DBFDBT" ); if ( errCode != SUCCESS ) - errCode = hb_rddInherit( pTable, &cdxTable, &cdxSuper, ( BYTE * ) "DBF" ); + errCode = hb_rddInherit( pTable, &cdxTable, &cdxSuper, "DBF" ); hb_retni( errCode ); if ( errCode == SUCCESS ) { @@ -9507,11 +9507,11 @@ HB_FUNC( DBFCDX_GETFUNCTABLE ) if ( uiCount ) * uiCount = RDDFUNCSCOUNT; - errCode = hb_rddInherit( pTable, &cdxTable, &cdxSuper, ( BYTE * ) "DBFFPT" ); + errCode = hb_rddInherit( pTable, &cdxTable, &cdxSuper, "DBFFPT" ); if ( errCode != SUCCESS ) - errCode = hb_rddInherit( pTable, &cdxTable, &cdxSuper, ( BYTE * ) "DBFDBT" ); + errCode = hb_rddInherit( pTable, &cdxTable, &cdxSuper, "DBFDBT" ); if ( errCode != SUCCESS ) - errCode = hb_rddInherit( pTable, &cdxTable, &cdxSuper, ( BYTE * ) "DBF" ); + errCode = hb_rddInherit( pTable, &cdxTable, &cdxSuper, "DBF" ); if ( errCode == SUCCESS ) { /* diff --git a/harbour/source/rdd/dbfdbt/dbfdbt1.c b/harbour/source/rdd/dbfdbt/dbfdbt1.c index 8cf1f41690..4547788e52 100644 --- a/harbour/source/rdd/dbfdbt/dbfdbt1.c +++ b/harbour/source/rdd/dbfdbt/dbfdbt1.c @@ -69,7 +69,7 @@ #endif static RDDFUNCS dbtSuper; -static RDDFUNCS dbtTable = +static const RDDFUNCS dbtTable = { /* Movement and positioning methods */ @@ -805,7 +805,7 @@ HB_FUNC( DBFDBT_GETFUNCTABLE ) { if ( uiCount ) * uiCount = RDDFUNCSCOUNT; - hb_retni( hb_rddInherit( pTable, &dbtTable, &dbtSuper, ( BYTE * ) "DBF" ) ); + hb_retni( hb_rddInherit( pTable, &dbtTable, &dbtSuper, "DBF" ) ); } else hb_retni( FAILURE ); diff --git a/harbour/source/rdd/dbffpt/dbffpt1.c b/harbour/source/rdd/dbffpt/dbffpt1.c index 2e338a92fc..4187d63884 100644 --- a/harbour/source/rdd/dbffpt/dbffpt1.c +++ b/harbour/source/rdd/dbffpt/dbffpt1.c @@ -81,7 +81,7 @@ static USHORT s_uiRddIdBLOB = ( USHORT ) -1; static USHORT s_uiRddIdFPT = ( USHORT ) -1; static RDDFUNCS fptSuper; -static RDDFUNCS fptTable = +static const RDDFUNCS fptTable = { /* Movement and positioning methods */ @@ -4689,7 +4689,7 @@ static void hb_dbffptRegisterRDD( USHORT * pusRddId ) if ( uiCount ) * uiCount = RDDFUNCSCOUNT; - errCode = hb_rddInherit( pTable, &fptTable, &fptSuper, ( BYTE * ) "DBF" ); + errCode = hb_rddInherit( pTable, &fptTable, &fptSuper, "DBF" ); if ( errCode == SUCCESS ) *pusRddId = uiRddId; hb_retni( errCode ); diff --git a/harbour/source/rdd/dbfntx/dbfntx1.c b/harbour/source/rdd/dbfntx/dbfntx1.c index bef53a8f8b..851daf6e10 100644 --- a/harbour/source/rdd/dbfntx/dbfntx1.c +++ b/harbour/source/rdd/dbfntx/dbfntx1.c @@ -7504,7 +7504,8 @@ static ERRCODE ntxRddInfo( LPRDDNODE pRDD, USHORT uiIndex, ULONG ulConnect, PHB_ return SUCCESS; } -static RDDFUNCS ntxTable = { ntxBof, +static const RDDFUNCS ntxTable = { + ntxBof, ntxEof, ntxFound, ( DBENTRYP_V ) ntxGoBottom, @@ -7622,11 +7623,11 @@ HB_FUNC( DBFNTX_GETFUNCTABLE ) if( uiCount ) * uiCount = RDDFUNCSCOUNT; - errCode = hb_rddInherit( pTable, &ntxTable, &ntxSuper, ( BYTE * ) "DBFFPT" ); + errCode = hb_rddInherit( pTable, &ntxTable, &ntxSuper, "DBFFPT" ); if( errCode != SUCCESS ) - errCode = hb_rddInherit( pTable, &ntxTable, &ntxSuper, ( BYTE * ) "DBFDBT" ); + errCode = hb_rddInherit( pTable, &ntxTable, &ntxSuper, "DBFDBT" ); if( errCode != SUCCESS ) - errCode = hb_rddInherit( pTable, &ntxTable, &ntxSuper, ( BYTE * ) "DBF" ); + errCode = hb_rddInherit( pTable, &ntxTable, &ntxSuper, "DBF" ); if( errCode == SUCCESS ) { /* diff --git a/harbour/source/rdd/delim1.c b/harbour/source/rdd/delim1.c index 875530973b..3422eec976 100644 --- a/harbour/source/rdd/delim1.c +++ b/harbour/source/rdd/delim1.c @@ -66,7 +66,7 @@ #define SUPERTABLE (&delimSuper) static RDDFUNCS delimSuper; -static USHORT s_uiNumLength[ 9 ] = { 0, 4, 6, 8, 11, 13, 16, 18, 20 }; +static const USHORT s_uiNumLength[ 9 ] = { 0, 4, 6, 8, 11, 13, 16, 18, 20 }; static void hb_delimInitArea( DELIMAREAP pArea, char * szFileName ) { @@ -1402,106 +1402,106 @@ static ERRCODE hb_delimRddInfo( LPRDDNODE pRDD, USHORT uiIndex, ULONG ulConnect, } -static RDDFUNCS delimTable = { NULL /* hb_delimBof */, - NULL /* hb_delimEof */, - NULL /* hb_delimFound */, - NULL /* hb_delimGoBottom */, - NULL /* hb_delimGoTo */, - NULL /* hb_delimGoToId */, - ( DBENTRYP_V ) hb_delimGoTop, - NULL /* hb_delimSeek */, - NULL /* hb_delimSkip */, - NULL /* hb_delimSkipFilter */, - ( DBENTRYP_L ) hb_delimSkipRaw, - ( DBENTRYP_VF ) hb_delimAddField, - ( DBENTRYP_B ) hb_delimAppend, - NULL /* hb_delimCreateFields */, - ( DBENTRYP_V ) hb_delimDeleteRec, - ( DBENTRYP_BP ) hb_delimDeleted, - NULL /* hb_delimFieldCount */, - NULL /* hb_delimFieldDisplay */, - NULL /* hb_delimFieldInfo */, - NULL /* hb_delimFieldName */, - ( DBENTRYP_V ) hb_delimFlush, - ( DBENTRYP_PP ) hb_delimGetRec, - ( DBENTRYP_SI ) hb_delimGetValue, - NULL /* hb_delimGetVarLen */, - ( DBENTRYP_V ) hb_delimGoCold, - ( DBENTRYP_V ) hb_delimGoHot, - ( DBENTRYP_P ) hb_delimPutRec, - ( DBENTRYP_SI ) hb_delimPutValue, - NULL /* hb_delimRecall */, - ( DBENTRYP_ULP ) hb_delimRecCount, - NULL /* hb_delimRecInfo */, - ( DBENTRYP_ULP ) hb_delimRecNo, - ( DBENTRYP_I ) hb_delimRecId, - ( DBENTRYP_S ) hb_delimSetFieldExtent, - NULL /* hb_delimAlias */, - ( DBENTRYP_V ) hb_delimClose, - ( DBENTRYP_VP ) hb_delimCreate, - ( DBENTRYP_SI ) hb_delimInfo, - ( DBENTRYP_V ) hb_delimNewArea, - ( DBENTRYP_VP ) hb_delimOpen, - NULL /* hb_delimRelease */, - ( DBENTRYP_SP ) hb_delimStructSize, - NULL /* hb_delimSysName */, - NULL /* hb_delimEval */, - NULL /* hb_delimPack */, - NULL /* hb_delimPackRec */, - NULL /* hb_delimSort */, - ( DBENTRYP_VT ) hb_delimTrans, - NULL /* hb_delimTransRec */, - NULL /* hb_delimZap */, - NULL /* hb_delimChildEnd */, - NULL /* hb_delimChildStart */, - NULL /* hb_delimChildSync */, - NULL /* hb_delimSyncChildren */, - NULL /* hb_delimClearRel */, - NULL /* hb_delimForceRel */, - NULL /* hb_delimRelArea */, - NULL /* hb_delimRelEval */, - NULL /* hb_delimRelText */, - NULL /* hb_delimSetRel */, - NULL /* hb_delimOrderListAdd */, - NULL /* hb_delimOrderListClear */, - NULL /* hb_delimOrderListDelete */, - NULL /* hb_delimOrderListFocus */, - NULL /* hb_delimOrderListRebuild */, - NULL /* hb_delimOrderCondition */, - NULL /* hb_delimOrderCreate */, - NULL /* hb_delimOrderDestroy */, - NULL /* hb_delimOrderInfo */, - NULL /* hb_delimClearFilter */, - NULL /* hb_delimClearLocate */, - NULL /* hb_delimClearScope */, - NULL /* hb_delimCountScope */, - NULL /* hb_delimFilterText */, - NULL /* hb_delimScopeInfo */, - NULL /* hb_delimSetFilter */, - NULL /* hb_delimSetLocate */, - NULL /* hb_delimSetScope */, - NULL /* hb_delimSkipScope */, - NULL /* hb_delimLocate */, - NULL /* hb_delimCompile */, - NULL /* hb_delimError */, - NULL /* hb_delimEvalBlock */, - NULL /* hb_delimRawLock */, - NULL /* hb_delimLock */, - NULL /* hb_delimUnLock */, - NULL /* hb_delimCloseMemFile */, - NULL /* hb_delimCreateMemFile */, - NULL /* hb_delimGetValueFile */, - NULL /* hb_delimOpenMemFile */, - NULL /* hb_delimPutValueFile */, - NULL /* hb_delimReadDBHeader */, - NULL /* hb_delimWriteDBHeader */, - NULL /* hb_delimInit */, - NULL /* hb_delimExit */, - NULL /* hb_delimDrop */, - NULL /* hb_delimExists */, - ( DBENTRYP_RSLV ) hb_delimRddInfo, - NULL /* hb_delimWhoCares */ - }; +static const RDDFUNCS delimTable = { NULL /* hb_delimBof */, + NULL /* hb_delimEof */, + NULL /* hb_delimFound */, + NULL /* hb_delimGoBottom */, + NULL /* hb_delimGoTo */, + NULL /* hb_delimGoToId */, + ( DBENTRYP_V ) hb_delimGoTop, + NULL /* hb_delimSeek */, + NULL /* hb_delimSkip */, + NULL /* hb_delimSkipFilter */, + ( DBENTRYP_L ) hb_delimSkipRaw, + ( DBENTRYP_VF ) hb_delimAddField, + ( DBENTRYP_B ) hb_delimAppend, + NULL /* hb_delimCreateFields */, + ( DBENTRYP_V ) hb_delimDeleteRec, + ( DBENTRYP_BP ) hb_delimDeleted, + NULL /* hb_delimFieldCount */, + NULL /* hb_delimFieldDisplay */, + NULL /* hb_delimFieldInfo */, + NULL /* hb_delimFieldName */, + ( DBENTRYP_V ) hb_delimFlush, + ( DBENTRYP_PP ) hb_delimGetRec, + ( DBENTRYP_SI ) hb_delimGetValue, + NULL /* hb_delimGetVarLen */, + ( DBENTRYP_V ) hb_delimGoCold, + ( DBENTRYP_V ) hb_delimGoHot, + ( DBENTRYP_P ) hb_delimPutRec, + ( DBENTRYP_SI ) hb_delimPutValue, + NULL /* hb_delimRecall */, + ( DBENTRYP_ULP ) hb_delimRecCount, + NULL /* hb_delimRecInfo */, + ( DBENTRYP_ULP ) hb_delimRecNo, + ( DBENTRYP_I ) hb_delimRecId, + ( DBENTRYP_S ) hb_delimSetFieldExtent, + NULL /* hb_delimAlias */, + ( DBENTRYP_V ) hb_delimClose, + ( DBENTRYP_VP ) hb_delimCreate, + ( DBENTRYP_SI ) hb_delimInfo, + ( DBENTRYP_V ) hb_delimNewArea, + ( DBENTRYP_VP ) hb_delimOpen, + NULL /* hb_delimRelease */, + ( DBENTRYP_SP ) hb_delimStructSize, + NULL /* hb_delimSysName */, + NULL /* hb_delimEval */, + NULL /* hb_delimPack */, + NULL /* hb_delimPackRec */, + NULL /* hb_delimSort */, + ( DBENTRYP_VT ) hb_delimTrans, + NULL /* hb_delimTransRec */, + NULL /* hb_delimZap */, + NULL /* hb_delimChildEnd */, + NULL /* hb_delimChildStart */, + NULL /* hb_delimChildSync */, + NULL /* hb_delimSyncChildren */, + NULL /* hb_delimClearRel */, + NULL /* hb_delimForceRel */, + NULL /* hb_delimRelArea */, + NULL /* hb_delimRelEval */, + NULL /* hb_delimRelText */, + NULL /* hb_delimSetRel */, + NULL /* hb_delimOrderListAdd */, + NULL /* hb_delimOrderListClear */, + NULL /* hb_delimOrderListDelete */, + NULL /* hb_delimOrderListFocus */, + NULL /* hb_delimOrderListRebuild */, + NULL /* hb_delimOrderCondition */, + NULL /* hb_delimOrderCreate */, + NULL /* hb_delimOrderDestroy */, + NULL /* hb_delimOrderInfo */, + NULL /* hb_delimClearFilter */, + NULL /* hb_delimClearLocate */, + NULL /* hb_delimClearScope */, + NULL /* hb_delimCountScope */, + NULL /* hb_delimFilterText */, + NULL /* hb_delimScopeInfo */, + NULL /* hb_delimSetFilter */, + NULL /* hb_delimSetLocate */, + NULL /* hb_delimSetScope */, + NULL /* hb_delimSkipScope */, + NULL /* hb_delimLocate */, + NULL /* hb_delimCompile */, + NULL /* hb_delimError */, + NULL /* hb_delimEvalBlock */, + NULL /* hb_delimRawLock */, + NULL /* hb_delimLock */, + NULL /* hb_delimUnLock */, + NULL /* hb_delimCloseMemFile */, + NULL /* hb_delimCreateMemFile */, + NULL /* hb_delimGetValueFile */, + NULL /* hb_delimOpenMemFile */, + NULL /* hb_delimPutValueFile */, + NULL /* hb_delimReadDBHeader */, + NULL /* hb_delimWriteDBHeader */, + NULL /* hb_delimInit */, + NULL /* hb_delimExit */, + NULL /* hb_delimDrop */, + NULL /* hb_delimExists */, + ( DBENTRYP_RSLV ) hb_delimRddInfo, + NULL /* hb_delimWhoCares */ + }; /* @@ -1523,7 +1523,7 @@ HB_FUNC( DELIM_GETFUNCTABLE ) HB_TRACE(HB_TR_DEBUG, ("DELIM_GETFUNCTABLE(%i, %p)", uiCount, pTable)); if( pTable ) - hb_retni( hb_rddInherit( pTable, &delimTable, &delimSuper, 0 ) ); + hb_retni( hb_rddInherit( pTable, &delimTable, &delimSuper, NULL ) ); else hb_retni( FAILURE ); } diff --git a/harbour/source/rdd/hbsix/sxcompr.c b/harbour/source/rdd/hbsix/sxcompr.c index 3aca77b7ec..6c1c713807 100644 --- a/harbour/source/rdd/hbsix/sxcompr.c +++ b/harbour/source/rdd/hbsix/sxcompr.c @@ -123,6 +123,9 @@ #include "hbsxfunc.h" +#define HB_SX_UNCOMPRESED 0xFFFFFFFFUL + + /* number of bits for encoded item (position,length) */ #define ITEMBITS 16 /* unused DUMMY bits - who does know why SIX has it? */ @@ -677,7 +680,6 @@ HB_FUNC( SX_FDECOMPRESS ) HB_FUNC( _SX_STRCOMPRESS ) { - BOOL fOK = FALSE; BYTE * pStr = ( BYTE * ) hb_parc( 1 ), * pBuf; if( pStr ) @@ -688,13 +690,16 @@ HB_FUNC( _SX_STRCOMPRESS ) ulBuf = ulLen + 257; pBuf = ( BYTE * ) hb_xgrab( ulBuf ); HB_PUT_LE_UINT32( pBuf, ulLen ); - fOK = hb_LZSSxCompressMem( pStr, ulLen, pBuf + 4, ulBuf - 4, &ulDst ); - if( fOK ) - hb_retclen( ( char * ) pBuf, ulDst + 4 ); + if( ! hb_LZSSxCompressMem( pStr, ulLen, pBuf + 4, ulBuf - 4, &ulDst ) ) + { + /* It's not six compatible - it's a workaround for wrongly defined SIX behavior */ + HB_PUT_LE_UINT32( pBuf, HB_SX_UNCOMPRESED ); + memcpy( pBuf + 4, pStr, ulLen ); + } + hb_retclen( ( char * ) pBuf, ulDst + 4 ); hb_xfree( pBuf ); } - - if( !fOK ) + else hb_itemReturn( hb_param( 1, HB_IT_ANY ) ); } @@ -710,20 +715,29 @@ HB_FUNC( _SX_STRDECOMPRESS ) if( ulLen >= 4 ) { ulBuf = HB_GET_LE_UINT32( pStr ); - pBuf = ( BYTE * ) hb_xalloc( ulBuf ); - if( pBuf ) + if( ulBuf == HB_SX_UNCOMPRESED ) { - fOK = hb_LZSSxDecompressMem( pStr + 4, ulLen - 4, pBuf, ulBuf ); - if( fOK ) - hb_retclen( ( char * ) pBuf, ulBuf ); - hb_xfree( pBuf ); + hb_retclen( ( char * ) pStr + 4, ulLen - 4 ); + fOK = TRUE; } else { - PHB_ITEM pItem = hb_errRT_SubstParams( "SIXCOMPRESS", EG_MEM, 0, "possible compressed string corruption", "_SX_STRDECOMPRESS" ); - hb_itemReturn( pItem ); - hb_itemRelease( pItem ); - return; + pBuf = ( BYTE * ) hb_xalloc( ulBuf + 1 ); + if( pBuf ) + { + fOK = hb_LZSSxDecompressMem( pStr + 4, ulLen - 4, pBuf, ulBuf ); + if( fOK ) + hb_retclen_buffer( ( char * ) pBuf, ulBuf ); + else + hb_xfree( pBuf ); + } + else + { + PHB_ITEM pItem = hb_errRT_SubstParams( "SIXCOMPRESS", EG_MEM, 0, "possible compressed string corruption", "_SX_STRDECOMPRESS" ); + if( pItem ) + hb_itemRelease( hb_itemReturn( pItem ) ); + return; + } } } } diff --git a/harbour/source/rdd/nulsys/nulsys.c b/harbour/source/rdd/nulsys/nulsys.c index e9e893172f..426ffe8fc6 100644 --- a/harbour/source/rdd/nulsys/nulsys.c +++ b/harbour/source/rdd/nulsys/nulsys.c @@ -54,7 +54,7 @@ #include "hbapi.h" #include "hbapirdd.h" -HB_EXPORT ERRCODE hb_rddSelectWorkAreaAlias( char * szName ) +HB_EXPORT ERRCODE hb_rddSelectWorkAreaAlias( const char * szName ) { HB_SYMBOL_UNUSED( szName ); @@ -112,7 +112,7 @@ HB_EXPORT ERRCODE hb_rddPutFieldValue( HB_ITEM_PTR pItem, PHB_SYMB pFieldSymbol return FAILURE; } -HB_EXPORT ERRCODE hb_rddGetAliasNumber( char * szAlias, int * iArea ) +HB_EXPORT ERRCODE hb_rddGetAliasNumber( const char * szAlias, int * iArea ) { HB_SYMBOL_UNUSED( szAlias ); HB_SYMBOL_UNUSED( iArea ); diff --git a/harbour/source/rdd/sdf1.c b/harbour/source/rdd/sdf1.c index c030764f60..3d57d97c9e 100644 --- a/harbour/source/rdd/sdf1.c +++ b/harbour/source/rdd/sdf1.c @@ -65,7 +65,7 @@ #define SUPERTABLE (&sdfSuper) static RDDFUNCS sdfSuper; -static USHORT s_uiNumLength[ 9 ] = { 0, 4, 6, 8, 11, 13, 16, 18, 20 }; +static const USHORT s_uiNumLength[ 9 ] = { 0, 4, 6, 8, 11, 13, 16, 18, 20 }; static void hb_sdfInitArea( SDFAREAP pArea, char * szFileName ) { @@ -1134,105 +1134,105 @@ static ERRCODE hb_sdfRddInfo( LPRDDNODE pRDD, USHORT uiIndex, ULONG ulConnect, P } -static RDDFUNCS sdfTable = { NULL /* hb_sdfBof */, - NULL /* hb_sdfEof */, - NULL /* hb_sdfFound */, - NULL /* hb_sdfGoBottom */, - NULL /* hb_sdfGoTo */, - NULL /* hb_sdfGoToId */, - ( DBENTRYP_V ) hb_sdfGoTop, - NULL /* hb_sdfSeek */, - NULL /* hb_sdfSkip */, - NULL /* hb_sdfSkipFilter */, - ( DBENTRYP_L ) hb_sdfSkipRaw, - ( DBENTRYP_VF ) hb_sdfAddField, - ( DBENTRYP_B ) hb_sdfAppend, - NULL /* hb_sdfCreateFields */, - ( DBENTRYP_V ) hb_sdfDeleteRec, - ( DBENTRYP_BP ) hb_sdfDeleted, - NULL /* hb_sdfFieldCount */, - NULL /* hb_sdfFieldDisplay */, - NULL /* hb_sdfFieldInfo */, - NULL /* hb_sdfFieldName */, - ( DBENTRYP_V ) hb_sdfFlush, - ( DBENTRYP_PP ) hb_sdfGetRec, - ( DBENTRYP_SI ) hb_sdfGetValue, - NULL /* hb_sdfGetVarLen */, - ( DBENTRYP_V ) hb_sdfGoCold, - ( DBENTRYP_V ) hb_sdfGoHot, - ( DBENTRYP_P ) hb_sdfPutRec, - ( DBENTRYP_SI ) hb_sdfPutValue, - NULL /* hb_sdfRecall */, - ( DBENTRYP_ULP ) hb_sdfRecCount, - NULL /* hb_sdfRecInfo */, - ( DBENTRYP_ULP ) hb_sdfRecNo, - ( DBENTRYP_I ) hb_sdfRecId, - ( DBENTRYP_S ) hb_sdfSetFieldExtent, - NULL /* hb_sdfAlias */, - ( DBENTRYP_V ) hb_sdfClose, - ( DBENTRYP_VP ) hb_sdfCreate, - ( DBENTRYP_SI ) hb_sdfInfo, - ( DBENTRYP_V ) hb_sdfNewArea, - ( DBENTRYP_VP ) hb_sdfOpen, - NULL /* hb_sdfRelease */, - ( DBENTRYP_SP ) hb_sdfStructSize, - NULL /* hb_sdfSysName */, - NULL /* hb_sdfEval */, - NULL /* hb_sdfPack */, - NULL /* hb_sdfPackRec */, - NULL /* hb_sdfSort */, - ( DBENTRYP_VT ) hb_sdfTrans, - NULL /* hb_sdfTransRec */, - NULL /* hb_sdfZap */, - NULL /* hb_sdfChildEnd */, - NULL /* hb_sdfChildStart */, - NULL /* hb_sdfChildSync */, - NULL /* hb_sdfSyncChildren */, - NULL /* hb_sdfClearRel */, - NULL /* hb_sdfForceRel */, - NULL /* hb_sdfRelArea */, - NULL /* hb_sdfRelEval */, - NULL /* hb_sdfRelText */, - NULL /* hb_sdfSetRel */, - NULL /* hb_sdfOrderListAdd */, - NULL /* hb_sdfOrderListClear */, - NULL /* hb_sdfOrderListDelete */, - NULL /* hb_sdfOrderListFocus */, - NULL /* hb_sdfOrderListRebuild */, - NULL /* hb_sdfOrderCondition */, - NULL /* hb_sdfOrderCreate */, - NULL /* hb_sdfOrderDestroy */, - NULL /* hb_sdfOrderInfo */, - NULL /* hb_sdfClearFilter */, - NULL /* hb_sdfClearLocate */, - NULL /* hb_sdfClearScope */, - NULL /* hb_sdfCountScope */, - NULL /* hb_sdfFilterText */, - NULL /* hb_sdfScopeInfo */, - NULL /* hb_sdfSetFilter */, - NULL /* hb_sdfSetLocate */, - NULL /* hb_sdfSetScope */, - NULL /* hb_sdfSkipScope */, - NULL /* hb_sdfLocate */, - NULL /* hb_sdfCompile */, - NULL /* hb_sdfError */, - NULL /* hb_sdfEvalBlock */, - NULL /* hb_sdfRawLock */, - NULL /* hb_sdfLock */, - NULL /* hb_sdfUnLock */, - NULL /* hb_sdfCloseMemFile */, - NULL /* hb_sdfCreateMemFile */, - NULL /* hb_sdfGetValueFile */, - NULL /* hb_sdfOpenMemFile */, - NULL /* hb_sdfPutValueFile */, - NULL /* hb_sdfReadDBHeader */, - NULL /* hb_sdfWriteDBHeader */, - NULL /* hb_sdfInit */, - NULL /* hb_sdfExit */, - NULL /* hb_sdfDrop */, - NULL /* hb_sdfExists */, - ( DBENTRYP_RSLV ) hb_sdfRddInfo, - NULL /* hb_sdfWhoCares */ +static const RDDFUNCS sdfTable = { NULL /* hb_sdfBof */, + NULL /* hb_sdfEof */, + NULL /* hb_sdfFound */, + NULL /* hb_sdfGoBottom */, + NULL /* hb_sdfGoTo */, + NULL /* hb_sdfGoToId */, + ( DBENTRYP_V ) hb_sdfGoTop, + NULL /* hb_sdfSeek */, + NULL /* hb_sdfSkip */, + NULL /* hb_sdfSkipFilter */, + ( DBENTRYP_L ) hb_sdfSkipRaw, + ( DBENTRYP_VF ) hb_sdfAddField, + ( DBENTRYP_B ) hb_sdfAppend, + NULL /* hb_sdfCreateFields */, + ( DBENTRYP_V ) hb_sdfDeleteRec, + ( DBENTRYP_BP ) hb_sdfDeleted, + NULL /* hb_sdfFieldCount */, + NULL /* hb_sdfFieldDisplay */, + NULL /* hb_sdfFieldInfo */, + NULL /* hb_sdfFieldName */, + ( DBENTRYP_V ) hb_sdfFlush, + ( DBENTRYP_PP ) hb_sdfGetRec, + ( DBENTRYP_SI ) hb_sdfGetValue, + NULL /* hb_sdfGetVarLen */, + ( DBENTRYP_V ) hb_sdfGoCold, + ( DBENTRYP_V ) hb_sdfGoHot, + ( DBENTRYP_P ) hb_sdfPutRec, + ( DBENTRYP_SI ) hb_sdfPutValue, + NULL /* hb_sdfRecall */, + ( DBENTRYP_ULP ) hb_sdfRecCount, + NULL /* hb_sdfRecInfo */, + ( DBENTRYP_ULP ) hb_sdfRecNo, + ( DBENTRYP_I ) hb_sdfRecId, + ( DBENTRYP_S ) hb_sdfSetFieldExtent, + NULL /* hb_sdfAlias */, + ( DBENTRYP_V ) hb_sdfClose, + ( DBENTRYP_VP ) hb_sdfCreate, + ( DBENTRYP_SI ) hb_sdfInfo, + ( DBENTRYP_V ) hb_sdfNewArea, + ( DBENTRYP_VP ) hb_sdfOpen, + NULL /* hb_sdfRelease */, + ( DBENTRYP_SP ) hb_sdfStructSize, + NULL /* hb_sdfSysName */, + NULL /* hb_sdfEval */, + NULL /* hb_sdfPack */, + NULL /* hb_sdfPackRec */, + NULL /* hb_sdfSort */, + ( DBENTRYP_VT ) hb_sdfTrans, + NULL /* hb_sdfTransRec */, + NULL /* hb_sdfZap */, + NULL /* hb_sdfChildEnd */, + NULL /* hb_sdfChildStart */, + NULL /* hb_sdfChildSync */, + NULL /* hb_sdfSyncChildren */, + NULL /* hb_sdfClearRel */, + NULL /* hb_sdfForceRel */, + NULL /* hb_sdfRelArea */, + NULL /* hb_sdfRelEval */, + NULL /* hb_sdfRelText */, + NULL /* hb_sdfSetRel */, + NULL /* hb_sdfOrderListAdd */, + NULL /* hb_sdfOrderListClear */, + NULL /* hb_sdfOrderListDelete */, + NULL /* hb_sdfOrderListFocus */, + NULL /* hb_sdfOrderListRebuild */, + NULL /* hb_sdfOrderCondition */, + NULL /* hb_sdfOrderCreate */, + NULL /* hb_sdfOrderDestroy */, + NULL /* hb_sdfOrderInfo */, + NULL /* hb_sdfClearFilter */, + NULL /* hb_sdfClearLocate */, + NULL /* hb_sdfClearScope */, + NULL /* hb_sdfCountScope */, + NULL /* hb_sdfFilterText */, + NULL /* hb_sdfScopeInfo */, + NULL /* hb_sdfSetFilter */, + NULL /* hb_sdfSetLocate */, + NULL /* hb_sdfSetScope */, + NULL /* hb_sdfSkipScope */, + NULL /* hb_sdfLocate */, + NULL /* hb_sdfCompile */, + NULL /* hb_sdfError */, + NULL /* hb_sdfEvalBlock */, + NULL /* hb_sdfRawLock */, + NULL /* hb_sdfLock */, + NULL /* hb_sdfUnLock */, + NULL /* hb_sdfCloseMemFile */, + NULL /* hb_sdfCreateMemFile */, + NULL /* hb_sdfGetValueFile */, + NULL /* hb_sdfOpenMemFile */, + NULL /* hb_sdfPutValueFile */, + NULL /* hb_sdfReadDBHeader */, + NULL /* hb_sdfWriteDBHeader */, + NULL /* hb_sdfInit */, + NULL /* hb_sdfExit */, + NULL /* hb_sdfDrop */, + NULL /* hb_sdfExists */, + ( DBENTRYP_RSLV ) hb_sdfRddInfo, + NULL /* hb_sdfWhoCares */ }; HB_FUNC( SDF ) { ; } @@ -1249,7 +1249,7 @@ HB_FUNC( SDF_GETFUNCTABLE ) HB_TRACE(HB_TR_DEBUG, ("SDF_GETFUNCTABLE(%i, %p)", uiCount, pTable)); if( pTable ) - hb_retni( hb_rddInherit( pTable, &sdfTable, &sdfSuper, 0 ) ); + hb_retni( hb_rddInherit( pTable, &sdfTable, &sdfSuper, NULL ) ); else hb_retni( FAILURE ); } diff --git a/harbour/source/rdd/wacore.c b/harbour/source/rdd/wacore.c new file mode 100644 index 0000000000..0bacfe7da0 --- /dev/null +++ b/harbour/source/rdd/wacore.c @@ -0,0 +1,421 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * Default RDD module + * + * Copyright 1999 Bruno Cantero + * Copyright 2007 Przemyslaw Czerpak + * www - http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +#include "hbapi.h" +#include "hbapirdd.h" +#include "hbapiitm.h" +#include "hbapierr.h" +#include "hbvm.h" + +/* Default RDD name */ + +static AREAP * s_WaList = NULL; /* Allocated WorkAreas */ +static USHORT s_uiWaMax = 0; /* Number of allocated WA */ +static USHORT s_uiWaSpace = 0; /* Number of allocated WA */ + +static USHORT * s_WaNums = NULL; /* Allocated WorkAreas */ +static USHORT s_uiWaNumMax = 0; /* Number of allocated WA */ + +static USHORT s_uiCurrArea = 1; /* Current WokrArea number */ +static AREAP s_pCurrArea = NULL; /* Current WorkArea pointer */ + +static BOOL s_fNetError = FALSE; /* Error on Networked environments */ + + +#define HB_SET_WA( n ) do \ + { \ + s_uiCurrArea = n; \ + s_pCurrArea = ( ( s_uiCurrArea < s_uiWaNumMax ) ? \ + s_WaList[ s_WaNums[ s_uiCurrArea ] ] : \ + NULL ); \ + } while( 0 ) + + +/* + * Return the next free WorkArea for later use. + */ +HB_EXPORT ERRCODE hb_rddSelectFirstAvailable( void ) +{ + USHORT uiArea; + + HB_TRACE(HB_TR_DEBUG, ("hb_rddSelectFirstAvailable()")); + + uiArea = 1; + while( uiArea < s_uiWaNumMax ) + { + if( s_WaNums[ uiArea ] == 0 ) + break; + uiArea++; + } + if( uiArea >= HARBOUR_MAX_RDD_AREA_NUM ) + return FAILURE; + HB_SET_WA( uiArea ); + return SUCCESS; +} + +/* + * Insert the new WorkArea node + */ +HB_EXPORT USHORT hb_rddInsertAreaNode( const char *szDriver ) +{ + USHORT uiRddID, uiWaPos; + LPRDDNODE pRddNode; + AREAP pArea; + + HB_TRACE(HB_TR_DEBUG, ("hb_rddInsertAreaNode(%s)", szDriver)); + + if( s_uiCurrArea && s_pCurrArea ) + return 0; + + pRddNode = hb_rddFindNode( szDriver, &uiRddID ); + if( !pRddNode ) + return 0; + + pArea = ( AREAP ) hb_rddNewAreaNode( pRddNode, uiRddID ); + if( !pArea ) + return 0; + + if( s_uiCurrArea == 0 ) + { + if( hb_rddSelectFirstAvailable() != SUCCESS ) + return 0; + } + + if( s_uiCurrArea >= s_uiWaNumMax ) + { + int iSize = ( ( s_uiCurrArea + 256 ) >> 8 ) << 8; + + if( s_uiWaNumMax == 0 ) + { + s_WaNums = (USHORT *) hb_xgrab( iSize * sizeof(USHORT) ); + } + else + { + s_WaNums = (USHORT *) hb_xrealloc( s_WaNums, iSize * sizeof(USHORT) ); + } + memset( &s_WaNums[ s_uiWaNumMax ], 0, ( iSize - s_uiWaNumMax ) * sizeof(USHORT) ); + s_uiWaNumMax = iSize; + } + + if( s_uiWaSpace == 0 ) + { + s_uiWaSpace = 256; + s_WaList = (AREAP *) hb_xgrab( s_uiWaSpace * sizeof(AREAP) ); + memset( &s_WaList[ 0 ], 0, s_uiWaSpace * sizeof(AREAP) ); + s_WaList[ 0 ] = NULL; + uiWaPos = 1; + s_uiWaMax = 2; + } + else + { + uiWaPos = s_uiWaMax++; + if( s_uiWaMax > s_uiWaSpace ) + { + s_uiWaSpace = ( ( s_uiWaMax + 256 ) >> 8 ) << 8; + s_WaList = (AREAP *) hb_xrealloc( s_WaList, s_uiWaSpace * sizeof(AREAP) ); + memset( &s_WaList[ s_uiWaMax ], 0, ( s_uiWaSpace - s_uiWaMax ) * sizeof(AREAP) ); + } + while( uiWaPos > 1 ) + { + if( s_WaList[ uiWaPos - 1 ]->uiArea < s_uiCurrArea ) + break; + s_WaList[ uiWaPos ] = s_WaList[ uiWaPos - 1 ]; + s_WaNums[ s_WaList[ uiWaPos ]->uiArea ] = uiWaPos; + uiWaPos--; + } + } + s_WaList[ uiWaPos ] = pArea; + s_WaNums[ s_uiCurrArea ] = uiWaPos; + s_pCurrArea = s_WaList[ uiWaPos ]; + s_pCurrArea->uiArea = s_uiCurrArea; + + return s_uiCurrArea; +} + +/* + * Closes and releases the current WorkArea preparing it + * to be used with a new database. + */ +HB_EXPORT void hb_rddReleaseCurrentArea( void ) +{ + USHORT uiWaPos; + AREAP pArea = s_pCurrArea; + + HB_TRACE(HB_TR_DEBUG, ("hb_rddReleaseCurrentArea()")); + + if( !pArea ) + return; + + if( SELF_CLOSE( pArea ) == FAILURE ) + return; + + SELF_RELEASE( pArea ); + + uiWaPos = s_WaNums[ s_uiCurrArea ]; + s_WaNums[ s_uiCurrArea ] = 0; + s_uiWaMax--; + if( s_uiWaMax <= 1 ) + { + s_uiWaSpace = s_uiWaMax = s_uiWaNumMax = 0; + hb_xfree( s_WaList ); + hb_xfree( s_WaNums ); + s_WaList = NULL; + s_WaNums = NULL; + } + else + { + while( uiWaPos < s_uiWaMax ) + { + s_WaList[ uiWaPos ] = s_WaList[ uiWaPos + 1 ]; + s_WaNums[ s_WaList[ uiWaPos ]->uiArea ] = uiWaPos; + uiWaPos++; + } + s_WaList[ s_uiWaMax ] = NULL; + if( s_uiWaSpace - s_uiWaMax >= 256 ) + { + s_uiWaSpace = ( ( s_uiWaMax + 256 ) >> 8 ) << 8; + s_WaList = ( AREAP * ) hb_xrealloc( s_WaList, s_uiWaSpace * sizeof( AREAP ) ); + } + } + s_pCurrArea = NULL; +} + +/* + * Closes all WorkAreas. + */ +HB_EXPORT void hb_rddCloseAll( void ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_rddCloseAll()")); + + if( s_uiWaMax > 0 ) + { + BOOL isParents, isFinish = FALSE; + AREAP pArea; + USHORT uiIndex; + + do + { + isParents = FALSE; + for( uiIndex = 1; uiIndex < s_uiWaMax; uiIndex++ ) + { + pArea = s_WaList[ uiIndex ]; + HB_SET_WA( pArea->uiArea ); + if( isFinish ) + { + SELF_RELEASE( pArea ); + s_WaNums[ s_uiCurrArea ] = 0; + s_pCurrArea = NULL; + } + else if( pArea->uiParents ) + { + isParents = TRUE; + } + else + { + SELF_CLOSE( pArea ); + } + } + if( !isParents && !isFinish ) + { + isParents = isFinish = TRUE; + } + } + while( isParents ); + + s_uiWaSpace = s_uiWaMax = s_uiWaNumMax = 0; + hb_xfree( s_WaList ); + hb_xfree( s_WaNums ); + s_WaList = NULL; + s_WaNums = NULL; + HB_SET_WA( 1 ); + } +} + +HB_EXPORT void hb_rddFlushAll( void ) +{ + USHORT uiArea = hb_rddGetCurrentWorkAreaNumber(), uiIndex; + + for( uiIndex = 1; uiIndex < s_uiWaMax; ++uiIndex ) + { + hb_rddSelectWorkAreaNumber( s_WaList[ uiIndex ]->uiArea ); + SELF_FLUSH( s_pCurrArea ); + } + hb_rddSelectWorkAreaNumber( uiArea ); +} + +HB_EXPORT void hb_rddUnLockAll( void ) +{ + USHORT uiArea = hb_rddGetCurrentWorkAreaNumber(), uiIndex; + + for( uiIndex = 1; uiIndex < s_uiWaMax; ++uiIndex ) + { + hb_rddSelectWorkAreaNumber( s_WaList[ uiIndex ]->uiArea ); + SELF_UNLOCK( s_pCurrArea, NULL ); + } + hb_rddSelectWorkAreaNumber( uiArea ); +} + +/* + * call a pCallBack function with all open workareas ### + */ +HB_EXPORT ERRCODE hb_rddIterateWorkAreas( WACALLBACK pCallBack, void * cargo ) +{ + ERRCODE errCode = SUCCESS; + USHORT uiIndex; + + HB_TRACE(HB_TR_DEBUG, ("hb_rddIterateWorkAreas(%p)", pCallBack)); + + for( uiIndex = 1; uiIndex < s_uiWaMax; uiIndex++ ) + { + errCode = pCallBack( s_WaList[ uiIndex ], cargo ); + if( errCode != SUCCESS ) + break; + } + return errCode; +} + +HB_EXPORT BOOL hb_rddGetNetErr( void ) +{ + return s_fNetError; +} + +HB_EXPORT void hb_rddSetNetErr( BOOL fNetErr ) +{ + s_fNetError = fNetErr; +} + +/* + * Get (/set) default RDD driver + */ +HB_EXPORT const char * hb_rddDefaultDrv( const char * szDriver ) +{ + static char s_szDefDriver[ HARBOUR_MAX_RDD_DRIVERNAME_LENGTH + 1 ] = ""; + static BOOL s_fInit = FALSE; + + if( szDriver && *szDriver ) + { + char szNewDriver[ HARBOUR_MAX_RDD_DRIVERNAME_LENGTH + 1 ]; + + hb_strncpyUpper( szNewDriver, szDriver, HARBOUR_MAX_RDD_DRIVERNAME_LENGTH ); + if( !hb_rddFindNode( szNewDriver, NULL ) ) + return NULL; + hb_strncpy( s_szDefDriver, szNewDriver, HARBOUR_MAX_RDD_DRIVERNAME_LENGTH ); + } + else if( !s_fInit && !s_szDefDriver[ 0 ] && hb_rddGetNode( 0 ) ) + { + char *szDrvTable[] = { "DBFNTX", "DBFCDX", "DBFFPT", "DBF", NULL }; + int i; + + for( i = 0; szDrvTable[ i ]; ++i ) + { + if( hb_rddFindNode( szDrvTable[ i ], NULL ) ) + { + hb_strncpy( s_szDefDriver, szDrvTable[ i ], HARBOUR_MAX_RDD_DRIVERNAME_LENGTH ); + break; + } + } + s_fInit = TRUE; + } + + return s_szDefDriver; +} + +/* + * Function for getting given workarea pointer + */ +HB_EXPORT void * hb_rddGetWorkAreaPointer( int iArea ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_rddGetWorkAreaPointer(%d)", iArea)); + + if( iArea == 0 ) + return s_pCurrArea; + else if( iArea >= 1 && ( UINT ) iArea < ( UINT ) s_uiWaNumMax ) + return s_WaList[ s_WaNums[ iArea ] ]; + else + return NULL; +} + +/* + * Function for getting current workarea pointer + */ +HB_EXPORT void * hb_rddGetCurrentWorkAreaPointer( void ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_rddGetCurrentWorkAreaPointer()")); + + return s_pCurrArea; +} + +/* + * Return the current WorkArea number. + */ +HB_EXPORT int hb_rddGetCurrentWorkAreaNumber( void ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_rddGetCurrentWorkAreaNumber()")); + + return s_uiCurrArea; +} + +/* + * Select a WorkArea by the number. + */ +HB_EXPORT ERRCODE hb_rddSelectWorkAreaNumber( int iArea ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_rddSelectWorkAreaNumber(%d)", iArea)); + + if( iArea < 1 || iArea > HARBOUR_MAX_RDD_AREA_NUM ) + HB_SET_WA( 0 ); + else + HB_SET_WA( iArea ); + + return ( s_pCurrArea == NULL ) ? FAILURE : SUCCESS; +} diff --git a/harbour/source/rdd/wafunc.c b/harbour/source/rdd/wafunc.c new file mode 100644 index 0000000000..d3de423dfc --- /dev/null +++ b/harbour/source/rdd/wafunc.c @@ -0,0 +1,1108 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * Default RDD module + * + * Copyright 1999 Bruno Cantero + * Copyright 2007 Przemyslaw Czerpak + * www - http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +#include "hbapi.h" +#include "hbapirdd.h" +#include "hbapiitm.h" +#include "hbapierr.h" +#include "hbvm.h" +#include "rddsys.ch" + +/* + * check if a given name can be used as alias expression + */ +HB_EXPORT ERRCODE hb_rddVerifyAliasName( const char * szAlias ) +{ + char c; + + if( szAlias ) + { + while( *szAlias == ' ' ) + { + szAlias++; + } + c = *szAlias; + if( c >= 'a' && c <= 'z' ) + { + c -= 'a' - 'A'; + } + if( ( c >= 'A' && c <= 'Z' ) || c == '_' ) + { + c = *(++szAlias); + while( c != 0 && c != ' ' ) + { + if( c != '_' && ! ( c >= '0' && c <= '9' ) && + ! ( c >= 'A' && c <= 'Z' ) && ! ( c >= 'a' && c <= 'z' ) ) + { + return FAILURE; + } + c = *(++szAlias); + } + return SUCCESS; + } + } + return FAILURE; +} + +/* + * Prepares a new WorkArea node. + */ +HB_EXPORT void * hb_rddNewAreaNode( LPRDDNODE pRddNode, USHORT uiRddID ) +{ + AREAP pArea; + + HB_TRACE(HB_TR_DEBUG, ("hb_rddNewAreaNode(%p,%hu)", pRddNode, uiRddID)); + + if( pRddNode->uiAreaSize == 0 ) /* Calculate the size of WorkArea */ + { + USHORT uiSize; + + pArea = ( AREAP ) hb_xgrab( sizeof( AREA ) ); + memset( pArea, 0, sizeof( AREA ) ); + pArea->lprfsHost = &pRddNode->pTable; + pArea->rddID = uiRddID; + + if( SELF_STRUCTSIZE( pArea, &uiSize ) != SUCCESS ) + return NULL; + + /* Need more space? */ + if( uiSize > sizeof( AREA ) ) /* Size of Area changed */ + { + pArea = ( AREAP ) hb_xrealloc( pArea, uiSize ); + memset( pArea, 0, uiSize ); + pArea->lprfsHost = &pRddNode->pTable; + pArea->rddID = uiRddID; + } + + pRddNode->uiAreaSize = uiSize; /* Update the size of WorkArea */ + } + else + { + pArea = ( AREAP ) hb_xgrab( pRddNode->uiAreaSize ); + memset( pArea, 0, pRddNode->uiAreaSize ); + pArea->lprfsHost = &pRddNode->pTable; + pArea->rddID = uiRddID; + } + + if( SELF_NEW( pArea ) != SUCCESS ) + { + SELF_RELEASE( pArea ); + return NULL; + } + + return ( void * ) pArea; +} + +HB_EXPORT ERRCODE hb_rddGetTempAlias( char * szAliasTmp ) +{ + int i, iArea; + + for( i = 1 ; i < 1000 ; i++ ) + { + snprintf( szAliasTmp, 11, "__HBTMP%03i", i); + if( hb_rddGetAliasNumber( szAliasTmp, &iArea ) != SUCCESS ) + return SUCCESS; + } + szAliasTmp[0] = '\0'; + return FAILURE; +} + +/* + * allocate and return atomAlias for new workarea or NULL if alias already exist + */ +HB_EXPORT void * hb_rddAllocWorkAreaAlias( const char * szAlias, int iArea ) +{ + PHB_DYNS pSymAlias; + int iDummyArea; + + HB_TRACE(HB_TR_DEBUG, ("hb_rddAllocWorkAreaAlias(%s, %d)", szAlias, iArea)); + + /* Verify if the alias name is valid symbol */ + if( hb_rddVerifyAliasName( szAlias ) != SUCCESS ) + { + hb_errRT_DBCMD_Ext( EG_BADALIAS, EDBCMD_BADALIAS, NULL, szAlias, EF_CANDEFAULT ); + return NULL; + } + /* Verify if the alias is already in use */ + if( hb_rddGetAliasNumber( szAlias, &iDummyArea ) == SUCCESS ) + { + hb_errRT_DBCMD_Ext( EG_DUPALIAS, EDBCMD_DUPALIAS, NULL, szAlias, EF_CANDEFAULT ); + return NULL; + } + + pSymAlias = hb_dynsymGet( szAlias ); + if( hb_dynsymAreaHandle( pSymAlias ) != 0 ) + { + pSymAlias = NULL; + } + else + { + hb_dynsymSetAreaHandle( pSymAlias, iArea ); + } + + if( ! pSymAlias ) + { + hb_errRT_DBCMD_Ext( EG_DUPALIAS, EDBCMD_DUPALIAS, NULL, szAlias, EF_CANDEFAULT ); + } + + return pSymAlias; +} + +/* + * Find a field index by name + */ +HB_EXPORT USHORT hb_rddFieldIndex( AREAP pArea, const char * szName ) +{ + USHORT uiCount = 0; + LPFIELD pField; + + HB_TRACE(HB_TR_DEBUG, ("hb_rddFieldIndex(%p, %s)", pArea, szName)); + + while( HB_ISSPACE( *szName ) ) + { + ++szName; + } + + if( *szName ) + { + char szSym[ HB_SYMBOL_NAME_LEN + 1 ]; + hb_strncpyUpperTrim( szSym, szName, HB_SYMBOL_NAME_LEN ); + + pField = pArea->lpFields; + while( pField ) + { + ++uiCount; + if( strcmp( szSym, hb_dynsymName( ( PHB_DYNS ) pField->sym ) ) == 0 ) + return uiCount; + pField = pField->lpfNext; + } + } + return 0; +} + +/* + * find a field expression index, this function strips _FIELD->, FIELD->, + * alias-> prefixes + */ +HB_EXPORT USHORT hb_rddFieldExpIndex( AREAP pArea, const char * szField ) +{ + int n; + + while( HB_ISSPACE( *szField ) ) + { + ++szField; + } + + if( strchr( szField, '>' ) != NULL ) + { + char szAlias[ HARBOUR_MAX_RDD_ALIAS_LENGTH + 1 ]; + int i, j, l; + + n = 0; + if( SELF_ALIAS( pArea, ( BYTE * ) szAlias ) == SUCCESS ) + l = strlen( szAlias ); + else + l = 0; + + /* + * strip the _FIELD-> and FIELD-> prefix, it could be nested + * so repeat this process until all prefixes will be removed + */ + do + { + j = n; + if( hb_strnicmp( &szField[ n ], "FIELD", 5 ) == 0 ) + i = 5; + else if( hb_strnicmp( &szField[ n ], "_FIELD", 6 ) == 0 ) + i = 6; + else if( l > 0 && hb_strnicmp( &szField[ n ], szAlias, l ) == 0 ) + i = l; + else + i = 0; + + if( i > 0 ) + { + i += n; + while( HB_ISSPACE( szField[ i ] ) ) + i++; + if( szField[ i ] == '-' && szField[ i + 1 ] == '>' ) + { + n = i + 2; + while( szField[ n ] == ' ' ) + n++; + } + } + } + while( n != j ); + szField = &szField[ n ]; + } + return hb_rddFieldIndex( pArea, szField ); +} + +/* + * Find a WorkArea by the alias, return FAILURE if not found + */ +HB_EXPORT ERRCODE hb_rddGetAliasNumber( const char * szAlias, int * iArea ) +{ + BOOL fOneLetter; + char c; + + HB_TRACE(HB_TR_DEBUG, ("hb_rddGetAliasNumber(%s, %p)", szAlias, iArea)); + + while( *szAlias == ' ' ) + { + szAlias++; + } + c = szAlias[ 0 ]; + if( c >= 'a' && c <= 'z' ) + { + c -= 'a' - 'A'; + } + + fOneLetter = c && ( szAlias[ 1 ] == 0 || szAlias[ 1 ] == ' ' ); + + if( c >= '0' && c <= '9' ) + { + *iArea = atoi( szAlias ); + } + else if( fOneLetter && c >= 'A' && c <= 'K' ) + { + *iArea = c - 'A' + 1; + } + else if( fOneLetter && c == 'M' ) + { + *iArea = HARBOUR_MAX_RDD_AREA_NUM; + } + else + { + PHB_DYNS pSymAlias = hb_dynsymFindName( szAlias ); + + *iArea = pSymAlias ? ( int ) hb_dynsymAreaHandle( pSymAlias ) : 0; + if( *iArea == 0 ) + { + return FAILURE; + } + } + + return SUCCESS; +} + +/* + * Select a WorkArea by the symbol name. + */ +HB_EXPORT ERRCODE hb_rddSelectWorkAreaSymbol( PHB_SYMB pSymAlias ) +{ + HB_ITEM_PTR pError; + ERRCODE errCode; + char * szName; + int iArea; + + HB_TRACE(HB_TR_DEBUG, ("hb_rddSelectWorkAreaSymbol(%p)", pSymAlias)); + + iArea = ( int ) hb_dynsymAreaHandle( pSymAlias->pDynSym ); + if( iArea ) + { + hb_rddSelectWorkAreaNumber( iArea ); + return SUCCESS; + } + + szName = hb_dynsymName( pSymAlias->pDynSym ); + + if( szName[ 0 ] && ! szName[ 1 ] ) + { + if( szName[ 0 ] >= 'A' && szName[ 0 ] <= 'K' ) + { + hb_rddSelectWorkAreaNumber( szName[ 0 ] - 'A' + 1 ); + return SUCCESS; + } + else if( szName[ 0 ] >= 'a' && szName[ 0 ] <= 'k' ) + { + hb_rddSelectWorkAreaNumber( szName[ 0 ] - 'a' + 1 ); + return SUCCESS; + } + else if( szName[ 0 ] == 'M' || szName[ 0 ] == 'm' ) + { + hb_rddSelectWorkAreaNumber( HARBOUR_MAX_RDD_AREA_NUM ); + return SUCCESS; + } + } + + /* + * generate an error with retry possibility + * (user created error handler can open a missing database) + */ + + pError = hb_errRT_New( ES_ERROR, NULL, EG_NOALIAS, EDBCMD_NOALIAS, NULL, pSymAlias->szName, 0, EF_CANRETRY ); + errCode = FAILURE; + + do + { + if( hb_errLaunch( pError ) != E_RETRY ) + break; + iArea = ( int ) hb_dynsymAreaHandle( pSymAlias->pDynSym ); + if( iArea ) + { + hb_rddSelectWorkAreaNumber( iArea ); + errCode = SUCCESS; + } + } + while( errCode == FAILURE ); + + hb_itemRelease( pError ); + + return errCode; +} + +/* + * Select a WorkArea by the name. + */ +HB_EXPORT ERRCODE hb_rddSelectWorkAreaAlias( const char * szAlias ) +{ + ERRCODE errCode; + int iArea; + + HB_TRACE(HB_TR_DEBUG, ("hb_rddSelectWorkAreaAlias(%s)", szAlias)); + + errCode = hb_rddGetAliasNumber( szAlias, &iArea ); + + if( errCode == FAILURE ) + { + /* + * generate an error with retry possibility + * (user created error handler can open a missing database) + */ + HB_ITEM_PTR pError = hb_errRT_New( ES_ERROR, NULL, EG_NOALIAS, EDBCMD_NOALIAS, NULL, szAlias, 0, EF_CANRETRY ); + + do + { + if( hb_errLaunch( pError ) != E_RETRY ) + break; + errCode = hb_rddGetAliasNumber( szAlias, &iArea ); + } + while( errCode == FAILURE ); + + hb_itemRelease( pError ); + } + + if( errCode == SUCCESS ) + { + if( iArea < 1 || iArea > HARBOUR_MAX_RDD_AREA_NUM ) + errCode = hb_rddSelectFirstAvailable(); + else + errCode = hb_rddSelectWorkAreaNumber( iArea ); + } + + return errCode; +} + +/* + * Obtain the current value of a field. + */ +HB_EXPORT ERRCODE hb_rddFieldGet( HB_ITEM_PTR pItem, PHB_SYMB pFieldSymbol ) +{ + AREAP pArea; + + HB_TRACE(HB_TR_DEBUG, ("hb_rddFieldGet(%p, %p)", pItem, pFieldSymbol)); + + pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); + if( pArea ) + { + USHORT uiField = 1; + LPFIELD pField = pArea->lpFields; + PHB_DYNS pDynSym = pFieldSymbol->pDynSym; + + while( pField ) + { + if( ( PHB_DYNS ) pField->sym == pDynSym ) + { + return SELF_GETVALUE( pArea, uiField, pItem ); + } + ++uiField; + pField = pField->lpfNext; + } + } + return FAILURE; +} + +/* + * Assign a value to a field. + */ +HB_EXPORT ERRCODE hb_rddFieldPut( HB_ITEM_PTR pItem, PHB_SYMB pFieldSymbol ) +{ + AREAP pArea; + + HB_TRACE(HB_TR_DEBUG, ("hb_rddFieldPut(%p, %p)", pItem, pFieldSymbol)); + + pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); + if( pArea ) + { + USHORT uiField = 1; + LPFIELD pField = pArea->lpFields; + PHB_DYNS pDynSym = pFieldSymbol->pDynSym; + + while( pField ) + { + if( ( PHB_DYNS ) pField->sym == pDynSym ) + { + return SELF_PUTVALUE( pArea, uiField, pItem ); + } + ++uiField; + pField = pField->lpfNext; + } + } + return FAILURE; +} + +/* + * Obtain the current value of a field. + */ +HB_EXPORT ERRCODE hb_rddGetFieldValue( HB_ITEM_PTR pItem, PHB_SYMB pFieldSymbol ) +{ + ERRCODE errCode; + + HB_TRACE(HB_TR_DEBUG, ("hb_rddGetFieldValue(%p, %p)", pItem, pFieldSymbol)); + + errCode = hb_rddFieldGet( pItem, pFieldSymbol ); + + if( errCode == FAILURE && hb_vmRequestQuery() == 0 ) + { + /* + * generate an error with retry possibility + * (user created error handler can make this field accessible) + */ + PHB_ITEM pError = hb_errRT_New( ES_ERROR, NULL, EG_NOVAR, EDBCMD_NOVAR, + NULL, pFieldSymbol->szName, 0, EF_CANRETRY ); + + while( hb_errLaunch( pError ) == E_RETRY ) + { + errCode = hb_rddFieldGet( pItem, pFieldSymbol ); + + if( errCode == SUCCESS || hb_vmRequestQuery() != 0 ) + break; + } + hb_itemRelease( pError ); + } + + return errCode; +} + +/* + * Assign a value to a field. + */ +HB_EXPORT ERRCODE hb_rddPutFieldValue( HB_ITEM_PTR pItem, PHB_SYMB pFieldSymbol ) +{ + ERRCODE errCode; + + HB_TRACE(HB_TR_DEBUG, ("hb_rddPutFieldValue(%p, %p)", pItem, pFieldSymbol)); + + errCode = hb_rddFieldPut( pItem, pFieldSymbol ); + + if( errCode == FAILURE && hb_vmRequestQuery() == 0 ) + { + /* + * generate an error with retry possibility + * (user created error handler can make this field accessible) + */ + PHB_ITEM pError = hb_errRT_New( ES_ERROR, NULL, EG_NOVAR, EDBCMD_NOVAR, + NULL, pFieldSymbol->szName, 0, EF_CANRETRY ); + + while( hb_errLaunch( pError ) == E_RETRY ) + { + errCode = hb_rddFieldPut( pItem, pFieldSymbol ); + + if( errCode == SUCCESS || hb_vmRequestQuery() != 0 ) + break; + } + hb_itemRelease( pError ); + } + + return errCode; +} + +ERRCODE hb_rddOpenTable( const char * szFileName, const char * szDriver, + USHORT uiArea, const char *szAlias, + BOOL fShared, BOOL fReadonly, + const char * szCpId, ULONG ulConnection, + PHB_ITEM pStruct, PHB_ITEM pDelim ) +{ + char szDriverBuffer[ HARBOUR_MAX_RDD_DRIVERNAME_LENGTH + 1 ]; + DBOPENINFO pInfo; + ERRCODE errCode; + USHORT uiPrevArea; + AREAP pArea; + + /* Clipper clears NETERR flag before RT error below */ + hb_rddSetNetErr( FALSE ); + + if( !szFileName || !szFileName[ 0 ] ) + { + hb_errRT_DBCMD( EG_ARG, EDBCMD_USE_BADPARAMETER, NULL, "DBUSEAREA" ); + return FAILURE; + } + + if( szDriver && szDriver[ 0 ] ) + { + hb_strncpyUpper( szDriverBuffer, szDriver, HARBOUR_MAX_RDD_DRIVERNAME_LENGTH ); + szDriver = szDriverBuffer; + } + else + { + szDriver = hb_rddDefaultDrv( NULL ); + } + + uiPrevArea = hb_rddGetCurrentWorkAreaNumber(); + + /* + * 0 means chose first available in hb_rddInsertAreaNode() + * This hack is necessary to avoid race condition in MT + * if we don't want to lock whole RDD subsystem, Druzus + */ + hb_rddSelectWorkAreaNumber( uiArea ); + if( uiArea ) + { + hb_rddReleaseCurrentArea(); + } + + /* Create a new WorkArea node */ + if( ! hb_rddInsertAreaNode( szDriver ) ) + { + hb_errRT_DBCMD( EG_ARG, EDBCMD_BADPARAMETER, NULL, "DBUSEAREA" ); + return FAILURE; + } + pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); + + /* Fill pInfo structure */ + pInfo.uiArea = pArea->uiArea; + pInfo.abName = ( BYTE * ) szFileName; + pInfo.atomAlias = ( BYTE * ) szAlias; + pInfo.fShared = fShared; + pInfo.fReadonly = fReadonly; + pInfo.cdpId = ( BYTE * ) szCpId; + pInfo.ulConnection = ulConnection; + pInfo.lpdbHeader = NULL; + + if( pStruct ) + { + errCode = SELF_CREATEFIELDS( pArea, pStruct ); + } + else + { + errCode = SUCCESS; + } + + if( errCode == SUCCESS ) + { + if( pDelim && !HB_IS_NIL( pDelim ) ) + errCode = SELF_INFO( pArea, DBI_SETDELIMITER, pDelim ); + + if( errCode == SUCCESS ) + { + /* Open file */ + errCode = SELF_OPEN( pArea, &pInfo ); + + if( errCode != SUCCESS ) + { + hb_rddReleaseCurrentArea(); + hb_rddSelectWorkAreaNumber( uiPrevArea ); + } + } + } + + /* + * Warning: this is not Clipper compatible. NETERR() should be set by + * error handler not here + */ + if( errCode != SUCCESS ) + hb_rddSetNetErr( TRUE ); + + return errCode; +} + +ERRCODE hb_rddCreateTable( const char * szFileName, const char * szDriver, + USHORT uiArea, const char *szAlias, + BOOL fKeepOpen, + const char * szCpId, ULONG ulConnection, + PHB_ITEM pStruct, PHB_ITEM pDelim ) +{ + char szDriverBuffer[ HARBOUR_MAX_RDD_DRIVERNAME_LENGTH + 1 ]; + DBOPENINFO pInfo; + ERRCODE errCode; + USHORT uiPrevArea; + AREAP pArea; + + if( !szFileName || !szFileName[ 0 ] ) + { + hb_errRT_DBCMD( EG_ARG, EDBCMD_DBCMDBADPARAMETER, NULL, "DBCREATE" ); + return FAILURE; + } + + if( szDriver && szDriver[ 0 ] ) + { + hb_strncpyUpper( szDriverBuffer, szDriver, HARBOUR_MAX_RDD_DRIVERNAME_LENGTH ); + szDriver = szDriverBuffer; + } + else + { + szDriver = hb_rddDefaultDrv( NULL ); + } + + uiPrevArea = hb_rddGetCurrentWorkAreaNumber(); + + /* + * 0 means chose first available in hb_rddInsertAreaNode() + * This hack is necessary to avoid race condition in MT + * if we don't want to lock whole RDD subsystem, Druzus + */ + hb_rddSelectWorkAreaNumber( uiArea ); + if( uiArea ) + { + hb_rddReleaseCurrentArea(); + } + + /* Create a new WorkArea node */ + if( ! hb_rddInsertAreaNode( szDriver ) ) + { + hb_errRT_DBCMD( EG_CREATE, EDBCMD_BADPARAMETER, NULL, "DBCREATE" ); + return FAILURE; + } + pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); + + /* Fill pInfo structure */ + pInfo.uiArea = pArea->uiArea; + pInfo.abName = ( BYTE * ) szFileName; + pInfo.atomAlias = ( BYTE * ) szAlias; + pInfo.fShared = FALSE; + pInfo.fReadonly = FALSE; + pInfo.cdpId = ( BYTE * ) szCpId; + pInfo.ulConnection = ulConnection; + pInfo.lpdbHeader = NULL; + + if( pDelim && !HB_IS_NIL( pDelim ) ) + errCode = SELF_INFO( pArea, DBI_SETDELIMITER, pDelim ); + else + errCode = SUCCESS; + + if( errCode == SUCCESS ) + { + errCode = SELF_CREATEFIELDS( pArea, pStruct ); + if( errCode == SUCCESS ) + errCode = SELF_CREATE( pArea, &pInfo ); + } + + if( !fKeepOpen || errCode != SUCCESS ) + { + hb_rddReleaseCurrentArea(); + hb_rddSelectWorkAreaNumber( uiPrevArea ); + } + + return errCode; +} + +static void hb_fldStructure( AREAP pArea, USHORT uiField, PHB_ITEM pField ) +{ + hb_arrayNew( pField, 4 ); + + SELF_FIELDINFO( pArea, uiField, DBS_NAME, hb_arrayGetItemPtr( pField, 1 ) ); + SELF_FIELDINFO( pArea, uiField, DBS_TYPE, hb_arrayGetItemPtr( pField, 2 ) ); + SELF_FIELDINFO( pArea, uiField, DBS_LEN, hb_arrayGetItemPtr( pField, 3 ) ); + SELF_FIELDINFO( pArea, uiField, DBS_DEC, hb_arrayGetItemPtr( pField, 4 ) ); +} + +void hb_tblStructure( AREAP pArea, PHB_ITEM pStruct ) +{ + USHORT uiFields, uiCount; + + if( SELF_FIELDCOUNT( pArea, &uiFields ) == SUCCESS ) + { + if( hb_arraySize( pStruct, uiFields ) ) + { + for( uiCount = 1; uiCount <= uiFields; ++uiCount ) + hb_fldStructure( pArea, uiCount, + hb_arrayGetItemPtr( pStruct, uiCount ) ); + } + } +} + +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; +} + +ERRCODE hb_dbTransStruct( AREAP lpaSource, AREAP lpaDest, + LPDBTRANSINFO lpdbTransInfo, + PHB_ITEM *pStruct, PHB_ITEM pFields ) +{ + USHORT uiFields, uiSize, uiCount, uiPosSrc, uiPosDst, uiSizeSrc, uiSizeDst; + ERRCODE errCode; + char * szField; + BOOL fAll; + + errCode = SELF_FIELDCOUNT( lpaSource, &uiSizeSrc ); + if( errCode != SUCCESS ) + return errCode; + + if( lpaDest ) + { + errCode = SELF_FIELDCOUNT( lpaDest, &uiSizeDst ); + if( errCode != SUCCESS ) + return errCode; + uiSize = HB_MIN( uiSizeDst, uiSizeSrc ); + } + else + { + uiSize = uiSizeDst = uiSizeSrc; + } + + if( !uiSize ) + return FAILURE; + if( hb_itemType( pFields ) & HB_IT_ARRAY ) + { + uiFields = ( USHORT ) hb_arrayLen( pFields ); + if( uiFields ) + uiSize = uiFields; + } + else + uiFields = 0; + + fAll = ( uiSizeDst == uiSizeSrc ); + + lpdbTransInfo->lpaSource = lpaSource; + lpdbTransInfo->lpaDest = lpaDest; + lpdbTransInfo->lpTransItems = ( LPDBTRANSITEM ) + hb_xgrab( uiSize * sizeof( DBTRANSITEM ) ); + + if( !lpaDest ) + { + *pStruct = hb_itemNew( NULL ); + hb_arrayNew( *pStruct, 0 ); + } + + if( uiFields == 0 ) + { + if( lpaDest ) + { + PHB_ITEM pItem = hb_itemNew( NULL ); + uiSize = 0; + for( uiCount = 1; uiCount <= uiSizeSrc; ++uiCount ) + { + if( SELF_FIELDINFO( lpaSource, uiCount, DBS_NAME, pItem ) != SUCCESS ) + { + uiSize = 0; + break; + } + szField = hb_itemGetCPtr( pItem ); + uiPosDst = hb_rddFieldExpIndex( lpaDest, szField ); + if( uiPosDst != uiCount ) + fAll = FALSE; + if( uiPosDst ) + { + USHORT ui; + + /* check for replicated field names in source area */ + for( ui = 0; ui < uiSize; ++ui ) + { + if( lpdbTransInfo->lpTransItems[ ui ].uiDest == uiPosDst ) + break; + } + if( ui == uiSize ) + { + lpdbTransInfo->lpTransItems[ uiSize ].uiSource = uiCount; + lpdbTransInfo->lpTransItems[ uiSize++ ].uiDest = uiPosDst; + } + } + } + hb_itemRelease( pItem ); + } + else + { + hb_tblStructure( lpaSource, *pStruct ); + uiSize = ( USHORT ) hb_arrayLen( *pStruct ); + for( uiCount = 0; uiCount < uiSize; ++uiCount ) + { + lpdbTransInfo->lpTransItems[ uiCount ].uiSource = + lpdbTransInfo->lpTransItems[ uiCount ].uiDest = uiCount + 1; + } + } + } + else + { + uiSize = 0; + for( uiCount = 1; uiCount <= uiFields; ++uiCount ) + { + szField = hb_dbTransFieldPos( pFields, uiCount ); + if( szField ) + { + uiPosSrc = hb_rddFieldExpIndex( lpaSource, szField ); + if( !uiPosSrc ) + continue; + if( lpaDest ) + uiPosDst = hb_rddFieldExpIndex( lpaDest, szField ); + else + uiPosDst = uiSize + 1; + if( uiPosDst ) + { + if( uiPosSrc != uiPosDst ) + fAll = FALSE; + lpdbTransInfo->lpTransItems[ uiSize ].uiSource = uiPosSrc; + lpdbTransInfo->lpTransItems[ uiSize++ ].uiDest = uiPosDst; + if( !lpaDest ) + { + hb_arraySize( *pStruct, uiSize ); + hb_fldStructure( lpaSource, uiPosSrc, + hb_arrayGetItemPtr( *pStruct, uiSize ) ); + } + } + } + } + } + + if( uiSize != uiSizeSrc ) + fAll = FALSE; + + if( fAll && lpaDest ) + { + PHB_ITEM pSrcItm = hb_itemNew( NULL ), + pDstItm = hb_itemNew( NULL ); + /* + * if fAll is TRUE here then it means that all fields are included + * and they are on the same positions in both tables, so now check + * if their types and sizes are also equal + */ + for( uiCount = 1; uiCount <= uiSize; ++uiCount ) + { + if( SELF_FIELDINFO( lpaSource, uiCount, DBS_TYPE, pSrcItm ) != SUCCESS || + SELF_FIELDINFO( lpaDest, uiCount, DBS_TYPE, pDstItm ) != SUCCESS ) + { + uiSize = 0; + break; + } + if( hb_stricmp( hb_itemGetCPtr( pSrcItm ), + hb_itemGetCPtr( pDstItm ) ) != 0 ) + { + fAll = FALSE; + break; + } + if( SELF_FIELDINFO( lpaSource, uiCount, DBS_LEN, pSrcItm ) != SUCCESS || + SELF_FIELDINFO( lpaDest, uiCount, DBS_LEN, pDstItm ) != SUCCESS ) + { + uiSize = 0; + break; + } + if( hb_itemGetNL( pSrcItm ) != hb_itemGetNL( pDstItm ) ) + { + fAll = FALSE; + break; + } + if( SELF_FIELDINFO( lpaSource, uiCount, DBS_DEC, pSrcItm ) != SUCCESS || + SELF_FIELDINFO( lpaDest, uiCount, DBS_DEC, pDstItm ) != SUCCESS ) + { + uiSize = 0; + break; + } + if( hb_itemGetNL( pSrcItm ) != hb_itemGetNL( pDstItm ) ) + { + fAll = FALSE; + break; + } + } + hb_itemRelease( pSrcItm ); + hb_itemRelease( pDstItm ); + } + + lpdbTransInfo->uiFlags = fAll ? DBTF_MATCH : 0; + lpdbTransInfo->uiItemCount = uiSize; + + return uiSize ? SUCCESS : FAILURE; +} + +ERRCODE hb_rddTransRecords( AREAP pArea, + const char *szFileName, const char *szDriver, + ULONG ulConnection, + PHB_ITEM pFields, BOOL fExport, + PHB_ITEM pCobFor, PHB_ITEM pStrFor, + PHB_ITEM pCobWhile, PHB_ITEM pStrWhile, + PHB_ITEM pNext, PHB_ITEM pRecID, + PHB_ITEM pRest, + const char *szCpId, + PHB_ITEM pDelim ) +{ + AREAP lpaClose = NULL; + PHB_ITEM pStruct = NULL; + DBTRANSINFO dbTransInfo; + USHORT uiPrevArea, uiCount, uiSwap; + ERRCODE errCode; + + memset( &dbTransInfo, 0, sizeof( DBTRANSINFO ) ); + uiPrevArea = hb_rddGetCurrentWorkAreaNumber(); + + if( szDriver == NULL ) + /* szDriver = SELF_RDDNODE( pArea )->szName; */ + szDriver = hb_rddDefaultDrv( NULL ); + + if( fExport ) + { + errCode = hb_dbTransStruct( pArea, NULL, &dbTransInfo, + &pStruct, pFields ); + if( errCode == SUCCESS ) + { + errCode = hb_rddCreateTable( szFileName, szDriver, 0, "", + TRUE, + szCpId, ulConnection, pStruct, pDelim ); + if( errCode == SUCCESS ) + { + dbTransInfo.lpaDest = lpaClose = + ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); + } + } + } + else + { + LPRDDNODE pRddNode = hb_rddFindNode( szDriver, NULL ); + + if( !pRddNode ) + { + hb_errRT_DBCMD( EG_ARG, EDBCMD_USE_BADPARAMETER, NULL, "DBUSEAREA" ); + return FAILURE; + } + + if( pRddNode->uiType == RDT_TRANSFER ) + { + errCode = hb_dbTransStruct( pArea, NULL, &dbTransInfo, + &pStruct, pFields ); + + /* revert area and items */ + dbTransInfo.lpaDest = dbTransInfo.lpaSource; + for( uiCount = 0; uiCount < dbTransInfo.uiItemCount; ++uiCount ) + { + uiSwap = dbTransInfo.lpTransItems[uiCount].uiSource; + dbTransInfo.lpTransItems[uiCount].uiSource = + dbTransInfo.lpTransItems[uiCount].uiDest; + dbTransInfo.lpTransItems[uiCount].uiDest = uiSwap; + } + + if( errCode == SUCCESS ) + { + errCode = hb_rddOpenTable( szFileName, szDriver, 0, "", TRUE, TRUE, + szCpId, ulConnection, pStruct, pDelim ); + if( errCode == SUCCESS ) + { + lpaClose = dbTransInfo.lpaSource = + ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); + } + } + } + else + { + errCode = hb_rddOpenTable( szFileName, szDriver, 0, "", TRUE, TRUE, + szCpId, ulConnection, NULL, pDelim ); + if( errCode == SUCCESS ) + { + lpaClose = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); + errCode = hb_dbTransStruct( lpaClose, pArea, &dbTransInfo, + NULL, pFields ); + } + } + } + + if( pStruct ) + hb_itemRelease( pStruct ); + + if( errCode == SUCCESS ) + { + hb_rddSelectWorkAreaNumber( dbTransInfo.lpaSource->uiArea ); + + dbTransInfo.dbsci.itmCobFor = pCobFor; + dbTransInfo.dbsci.lpstrFor = pStrFor; + dbTransInfo.dbsci.itmCobWhile = pCobWhile; + dbTransInfo.dbsci.lpstrWhile = pStrWhile; + dbTransInfo.dbsci.lNext = pNext; + dbTransInfo.dbsci.itmRecID = pRecID; + dbTransInfo.dbsci.fRest = pRest; + + 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 ); + if( lpaClose ) + { + hb_rddSelectWorkAreaNumber( lpaClose->uiArea ); + hb_rddReleaseCurrentArea(); + } + hb_rddSelectWorkAreaNumber( uiPrevArea ); + + return errCode; +} diff --git a/harbour/source/rdd/workarea.c b/harbour/source/rdd/workarea.c index f9651bac89..5b5e088df2 100644 --- a/harbour/source/rdd/workarea.c +++ b/harbour/source/rdd/workarea.c @@ -7,6 +7,7 @@ * Default RDD module * * Copyright 1999 Bruno Cantero + * Copyright 2004-2007 Przemyslaw Czerpak * www - http://www.harbour-project.org * * This program is free software; you can redistribute it and/or modify @@ -56,24 +57,23 @@ */ #include + #include "hbapi.h" #include "hbapirdd.h" -#include "hbinit.h" -#include "hbvm.h" #include "hbapiitm.h" #include "hbapierr.h" +#include "hbapilng.h" +#include "hbvm.h" #include "hbset.h" -#include "hbrddwrk.h" - /* - * -- METHODS -- + * -- BASIC RDD METHODS -- */ /* * Determine logical beginning of file. */ -ERRCODE hb_waBof( AREAP pArea, BOOL * pBof ) +static ERRCODE hb_waBof( AREAP pArea, BOOL * pBof ) { HB_TRACE(HB_TR_DEBUG, ("hb_waBof(%p, %p)", pArea, pBof)); @@ -84,7 +84,7 @@ ERRCODE hb_waBof( AREAP pArea, BOOL * pBof ) /* * Determine logical end of file. */ -ERRCODE hb_waEof( AREAP pArea, BOOL * pEof ) +static ERRCODE hb_waEof( AREAP pArea, BOOL * pEof ) { HB_TRACE(HB_TR_DEBUG, ("hb_waEof(%p, %p)", pArea, pEof)); @@ -95,7 +95,7 @@ ERRCODE hb_waEof( AREAP pArea, BOOL * pEof ) /* * Determine outcome of the last search operation. */ -ERRCODE hb_waFound( AREAP pArea, BOOL * pFound ) +static ERRCODE hb_waFound( AREAP pArea, BOOL * pFound ) { HB_TRACE(HB_TR_DEBUG, ("hb_waFound(%p, %p)", pArea, pFound)); @@ -106,7 +106,7 @@ ERRCODE hb_waFound( AREAP pArea, BOOL * pFound ) /* * Reposition cursor relative to current position. */ -ERRCODE hb_waSkip( AREAP pArea, LONG lToSkip ) +static ERRCODE hb_waSkip( AREAP pArea, LONG lToSkip ) { LONG lSkip; @@ -147,7 +147,7 @@ ERRCODE hb_waSkip( AREAP pArea, LONG lToSkip ) /* * Reposition cursor respecting any filter setting. */ -ERRCODE hb_waSkipFilter( AREAP pArea, LONG lUpDown ) +static ERRCODE hb_waSkipFilter( AREAP pArea, LONG lUpDown ) { BOOL fBottom, fDeleted; PHB_ITEM pResult; @@ -235,7 +235,7 @@ ERRCODE hb_waSkipFilter( AREAP pArea, LONG lUpDown ) /* * Add a field to the WorkArea. */ -ERRCODE hb_waAddField( AREAP pArea, LPDBFIELDINFO pFieldInfo ) +static ERRCODE hb_waAddField( AREAP pArea, LPDBFIELDINFO pFieldInfo ) { LPFIELD pField; char szFieldName[ HB_SYMBOL_NAME_LEN + 1 ], *szPtr; @@ -268,7 +268,7 @@ ERRCODE hb_waAddField( AREAP pArea, LPDBFIELDINFO pFieldInfo ) /* * Add all fields defined in an array to the WorkArea. */ -ERRCODE hb_waCreateFields( AREAP pArea, PHB_ITEM pStruct ) +static ERRCODE hb_waCreateFields( AREAP pArea, PHB_ITEM pStruct ) { USHORT uiItems, uiCount, uiLen, uiDec; ERRCODE errCode = SUCCESS; @@ -387,7 +387,7 @@ ERRCODE hb_waCreateFields( AREAP pArea, PHB_ITEM pStruct ) /* * Determine the number of fields in the WorkArea. */ -ERRCODE hb_waFieldCount( AREAP pArea, USHORT * uiFields ) +static ERRCODE hb_waFieldCount( AREAP pArea, USHORT * uiFields ) { HB_TRACE(HB_TR_DEBUG, ("hb_waFieldCount(%p, %p)", pArea, uiFields)); @@ -398,7 +398,7 @@ ERRCODE hb_waFieldCount( AREAP pArea, USHORT * uiFields ) /* * Retrieve information about a field. */ -ERRCODE hb_waFieldInfo( AREAP pArea, USHORT uiIndex, USHORT uiType, PHB_ITEM pItem ) +static ERRCODE hb_waFieldInfo( AREAP pArea, USHORT uiIndex, USHORT uiType, PHB_ITEM pItem ) { LPFIELD pField; @@ -473,7 +473,7 @@ ERRCODE hb_waFieldInfo( AREAP pArea, USHORT uiIndex, USHORT uiType, PHB_ITEM pIt /* * Determine the name associated with a field number. */ -ERRCODE hb_waFieldName( AREAP pArea, USHORT uiIndex, void * szName ) +static ERRCODE hb_waFieldName( AREAP pArea, USHORT uiIndex, void * szName ) { LPFIELD pField; @@ -491,7 +491,7 @@ ERRCODE hb_waFieldName( AREAP pArea, USHORT uiIndex, void * szName ) /* * Establish the extent of the array of fields for a WorkArea. */ -ERRCODE hb_waSetFieldExtent( AREAP pArea, USHORT uiFieldExtent ) +static ERRCODE hb_waSetFieldExtent( AREAP pArea, USHORT uiFieldExtent ) { HB_TRACE(HB_TR_DEBUG, ("hb_waSetFieldExtent(%p, %hu)", pArea, uiFieldExtent)); @@ -510,7 +510,7 @@ ERRCODE hb_waSetFieldExtent( AREAP pArea, USHORT uiFieldExtent ) /* * Obtain the alias of the WorkArea. */ -ERRCODE hb_waAlias( AREAP pArea, BYTE * szAlias ) +static ERRCODE hb_waAlias( AREAP pArea, BYTE * szAlias ) { HB_TRACE(HB_TR_DEBUG, ("hb_waAlias(%p, %p)", pArea, szAlias)); @@ -525,12 +525,12 @@ ERRCODE hb_waAlias( AREAP pArea, BYTE * szAlias ) /* * Close the table in the WorkArea - helper function */ -static short hb_waCloseAux( AREAP pArea, int nChildArea ) +static ERRCODE hb_waCloseAux( AREAP pArea, void * pChildArea ) { USHORT uiPrevArea, uiArea; LPDBRELINFO lpdbRelation, lpdbRelPrev, lpdbRelTmp; - uiArea = ( USHORT ) nChildArea; + uiArea = ( ( AREAP ) pChildArea )->uiArea; if( pArea->lpdbRelations ) { uiPrevArea = hb_rddGetCurrentWorkAreaNumber(); @@ -565,13 +565,13 @@ static short hb_waCloseAux( AREAP pArea, int nChildArea ) } } } - return 1; + return SUCCESS; } /* * Close the table in the WorkArea. */ -ERRCODE hb_waClose( AREAP pArea ) +static ERRCODE hb_waClose( AREAP pArea ) { HB_TRACE(HB_TR_DEBUG, ("hb_waClose(%p)", pArea)); @@ -583,7 +583,7 @@ ERRCODE hb_waClose( AREAP pArea ) if( pArea->uiParents > 0 ) { /* Clear relations that has this area as a child */ - hb_rddIterateWorkAreas ( hb_waCloseAux, pArea->uiArea ); + hb_rddIterateWorkAreas( hb_waCloseAux, pArea ); } if( pArea->atomAlias ) @@ -595,7 +595,7 @@ ERRCODE hb_waClose( AREAP pArea ) /* * Retrieve information about the current driver. */ -ERRCODE hb_waInfo( AREAP pArea, USHORT uiIndex, PHB_ITEM pItem ) +static ERRCODE hb_waInfo( AREAP pArea, USHORT uiIndex, PHB_ITEM pItem ) { HB_TRACE(HB_TR_DEBUG, ("hb_waInfo(%p, %hu, %p)", pArea, uiIndex, pItem)); @@ -725,8 +725,7 @@ ERRCODE hb_waInfo( AREAP pArea, USHORT uiIndex, PHB_ITEM pItem ) * Retrieve information about the current order that SELF could not. * Called by SELF_ORDINFO if uiIndex is not supported. */ -#ifdef HB_COMPAT_C53 -ERRCODE hb_waOrderInfo( AREAP pArea, USHORT index, LPDBORDERINFO param ) +static ERRCODE hb_waOrderInfo( AREAP pArea, USHORT index, LPDBORDERINFO param ) { HB_TRACE(HB_TR_DEBUG, ("hb_waOrderInfo(%p, %hu, %p)", pArea, index, param)); @@ -737,12 +736,11 @@ ERRCODE hb_waOrderInfo( AREAP pArea, USHORT index, LPDBORDERINFO param ) hb_errRT_DBCMD( EG_ARG, EDBCMD_BADPARAMETER, NULL, "DBORDERINFO" ); return FAILURE; } -#endif /* * Clear the WorkArea for use. */ -ERRCODE hb_waNewArea( AREAP pArea ) +static ERRCODE hb_waNewArea( AREAP pArea ) { HB_TRACE(HB_TR_DEBUG, ("hb_waNewArea(%p)", pArea)); @@ -758,7 +756,7 @@ ERRCODE hb_waNewArea( AREAP pArea ) * Open a data store in the WorkArea. * Like in Clipper it's also mapped as Create() method at WA level */ -ERRCODE hb_waOpen( AREAP pArea, LPDBOPENINFO pInfo ) +static ERRCODE hb_waOpen( AREAP pArea, LPDBOPENINFO pInfo ) { if( !pArea->atomAlias && pInfo->atomAlias && pInfo->atomAlias[ 0 ] ) { @@ -773,7 +771,7 @@ ERRCODE hb_waOpen( AREAP pArea, LPDBOPENINFO pInfo ) return SUCCESS; } -ERRCODE hb_waOrderCondition( AREAP pArea, LPDBORDERCONDINFO param ) +static ERRCODE hb_waOrderCondition( AREAP pArea, LPDBORDERCONDINFO param ) { if( pArea->lpdbOrdCondInfo ) { @@ -811,7 +809,7 @@ ERRCODE hb_waOrderCondition( AREAP pArea, LPDBORDERCONDINFO param ) /* * Release all references to a WorkArea. */ -ERRCODE hb_waRelease( AREAP pArea ) +static ERRCODE hb_waRelease( AREAP pArea ) { HB_TRACE(HB_TR_DEBUG, ("hb_waRelease(%p)", pArea)); @@ -830,7 +828,7 @@ ERRCODE hb_waRelease( AREAP pArea ) /* * Retrieve the size of the WorkArea structure. */ -ERRCODE hb_waStructSize( AREAP pArea, USHORT * uiSize ) +static ERRCODE hb_waStructSize( AREAP pArea, USHORT * uiSize ) { HB_TRACE(HB_TR_DEBUG, ("hb_waStrucSize(%p, %p)", pArea, uiSize)); HB_SYMBOL_UNUSED( pArea ); @@ -842,7 +840,7 @@ ERRCODE hb_waStructSize( AREAP pArea, USHORT * uiSize ) /* * Obtain the name of replaceable database driver (RDD) subsystem. */ -ERRCODE hb_waSysName( AREAP pArea, BYTE * pBuffer ) +static ERRCODE hb_waSysName( AREAP pArea, BYTE * pBuffer ) { HB_TRACE(HB_TR_DEBUG, ("hb_waSysName(%p, %p)", pArea, pBuffer)); @@ -855,7 +853,7 @@ ERRCODE hb_waSysName( AREAP pArea, BYTE * pBuffer ) /* * Evaluate code block for each record in WorkArea. */ -ERRCODE hb_waEval( AREAP pArea, LPDBEVALINFO pEvalInfo ) +static ERRCODE hb_waEval( AREAP pArea, LPDBEVALINFO pEvalInfo ) { LONG lNext = 1; BOOL fEof; @@ -912,7 +910,7 @@ ERRCODE hb_waEval( AREAP pArea, LPDBEVALINFO pEvalInfo ) /* * Locate a record which pass given condition */ -ERRCODE hb_waLocate( AREAP pArea, BOOL fContinue ) +static ERRCODE hb_waLocate( AREAP pArea, BOOL fContinue ) { LONG lNext = 1; BOOL fEof; @@ -983,7 +981,7 @@ ERRCODE hb_waLocate( AREAP pArea, BOOL fContinue ) /* * Copy one or more records from one WorkArea to another. */ -ERRCODE hb_waTrans( AREAP pArea, LPDBTRANSINFO pTransInfo ) +static ERRCODE hb_waTrans( AREAP pArea, LPDBTRANSINFO pTransInfo ) { LONG lNext = 1; BOOL fEof; @@ -1043,7 +1041,7 @@ ERRCODE hb_waTrans( AREAP pArea, LPDBTRANSINFO pTransInfo ) /* * Copy a record to another WorkArea. */ -ERRCODE hb_waTransRec( AREAP pArea, LPDBTRANSINFO pTransInfo ) +static ERRCODE hb_waTransRec( AREAP pArea, LPDBTRANSINFO pTransInfo ) { BOOL bDeleted; BYTE *pRecord; @@ -1115,7 +1113,7 @@ ERRCODE hb_waTransRec( AREAP pArea, LPDBTRANSINFO pTransInfo ) /* * Report end of relation. */ -ERRCODE hb_waChildEnd( AREAP pArea, LPDBRELINFO pRelInfo ) +static ERRCODE hb_waChildEnd( AREAP pArea, LPDBRELINFO pRelInfo ) { HB_TRACE(HB_TR_DEBUG, ("hb_waChildEnd(%p, %p)", pArea, pRelInfo)); @@ -1138,7 +1136,7 @@ ERRCODE hb_waChildEnd( AREAP pArea, LPDBRELINFO pRelInfo ) /* * Report initialization of a relation. */ -ERRCODE hb_waChildStart( AREAP pArea, LPDBRELINFO pRelInfo ) +static ERRCODE hb_waChildStart( AREAP pArea, LPDBRELINFO pRelInfo ) { HB_TRACE(HB_TR_DEBUG, ("hb_waChildStart(%p, %p)", pArea, pRelInfo)); HB_SYMBOL_UNUSED( pRelInfo ); @@ -1150,7 +1148,7 @@ ERRCODE hb_waChildStart( AREAP pArea, LPDBRELINFO pRelInfo ) /* * Force relational movement in child WorkAreas. */ -ERRCODE hb_waSyncChildren( AREAP pArea ) +static ERRCODE hb_waSyncChildren( AREAP pArea ) { LPDBRELINFO lpdbRelation; @@ -1170,7 +1168,7 @@ ERRCODE hb_waSyncChildren( AREAP pArea ) /* * Clear all relations in the specified WorkArea. */ -ERRCODE hb_waClearRel( AREAP pArea ) +static ERRCODE hb_waClearRel( AREAP pArea ) { HB_TRACE(HB_TR_DEBUG, ("hb_waClearRel(%p)", pArea )); @@ -1208,7 +1206,7 @@ ERRCODE hb_waClearRel( AREAP pArea ) /* * Obtain the workarea number of the specified relation. */ -ERRCODE hb_waRelArea( AREAP pArea, USHORT uiRelNo, void * pRelArea ) +static ERRCODE hb_waRelArea( AREAP pArea, USHORT uiRelNo, void * pRelArea ) { LPDBRELINFO lpdbRelations; USHORT uiIndex = 1; @@ -1234,7 +1232,7 @@ ERRCODE hb_waRelArea( AREAP pArea, USHORT uiRelNo, void * pRelArea ) /* * Evaluate a block against the relation in specified WorkArea. */ -ERRCODE hb_waRelEval( AREAP pArea, LPDBRELINFO pRelInfo ) +static ERRCODE hb_waRelEval( AREAP pArea, LPDBRELINFO pRelInfo ) { PHB_ITEM pResult; DBORDERINFO pInfo; @@ -1297,7 +1295,7 @@ ERRCODE hb_waRelEval( AREAP pArea, LPDBRELINFO pRelInfo ) /* * Obtain the character expression of the specified relation. */ -ERRCODE hb_waRelText( AREAP pArea, USHORT uiRelNo, void * pExpr ) +static ERRCODE hb_waRelText( AREAP pArea, USHORT uiRelNo, void * pExpr ) { LPDBRELINFO lpdbRelations; USHORT uiIndex = 1; @@ -1323,7 +1321,7 @@ ERRCODE hb_waRelText( AREAP pArea, USHORT uiRelNo, void * pExpr ) /* * Set a relation in the parent file. */ -ERRCODE hb_waSetRel( AREAP pArea, LPDBRELINFO lpdbRelInf ) +static ERRCODE hb_waSetRel( AREAP pArea, LPDBRELINFO lpdbRelInf ) { LPDBRELINFO lpdbRelations; @@ -1356,7 +1354,7 @@ ERRCODE hb_waSetRel( AREAP pArea, LPDBRELINFO lpdbRelInf ) /* * Clear the active filter expression. */ -ERRCODE hb_waClearFilter( AREAP pArea ) +static ERRCODE hb_waClearFilter( AREAP pArea ) { HB_TRACE(HB_TR_DEBUG, ("hb_waClearFilter(%p)", pArea)); @@ -1380,7 +1378,7 @@ ERRCODE hb_waClearFilter( AREAP pArea ) /* * Clear the active locate expression. */ -ERRCODE hb_waClearLocate( AREAP pArea ) +static ERRCODE hb_waClearLocate( AREAP pArea ) { HB_TRACE(HB_TR_DEBUG, ("hb_waClearLocate(%p)", pArea)); @@ -1427,7 +1425,7 @@ ERRCODE hb_waClearLocate( AREAP pArea ) /* * Return filter condition of the specified WorkArea. */ -ERRCODE hb_waFilterText( AREAP pArea, PHB_ITEM pFilter ) +static ERRCODE hb_waFilterText( AREAP pArea, PHB_ITEM pFilter ) { HB_TRACE(HB_TR_DEBUG, ("hb_waFilterText(%p, %p)", pArea, pFilter)); @@ -1440,7 +1438,7 @@ ERRCODE hb_waFilterText( AREAP pArea, PHB_ITEM pFilter ) /* * Set the filter condition for the specified WorkArea. */ -ERRCODE hb_waSetFilter( AREAP pArea, LPDBFILTERINFO pFilterInfo ) +static ERRCODE hb_waSetFilter( AREAP pArea, LPDBFILTERINFO pFilterInfo ) { HB_TRACE(HB_TR_DEBUG, ("hb_waSetFilter(%p, %p)", pArea, pFilterInfo)); @@ -1465,7 +1463,7 @@ ERRCODE hb_waSetFilter( AREAP pArea, LPDBFILTERINFO pFilterInfo ) /* * Set the locate scope for the specified WorkArea. */ -ERRCODE hb_waSetLocate( AREAP pArea, LPDBSCOPEINFO pScopeInfo ) +static ERRCODE hb_waSetLocate( AREAP pArea, LPDBSCOPEINFO pScopeInfo ) { HB_TRACE(HB_TR_DEBUG, ("hb_waSetLocate(%p, %p)", pArea, pScopeInfo)); @@ -1507,7 +1505,7 @@ ERRCODE hb_waSetLocate( AREAP pArea, LPDBSCOPEINFO pScopeInfo ) /* * Compile a character expression. */ -ERRCODE hb_waCompile( AREAP pArea, BYTE * pExpr ) +static ERRCODE hb_waCompile( AREAP pArea, BYTE * pExpr ) { HB_MACRO_PTR pMacro; @@ -1526,7 +1524,7 @@ ERRCODE hb_waCompile( AREAP pArea, BYTE * pExpr ) /* * Raise a runtime error. */ -ERRCODE hb_waError( AREAP pArea, PHB_ITEM pError ) +static ERRCODE hb_waError( AREAP pArea, PHB_ITEM pError ) { char * szRddName; @@ -1546,7 +1544,7 @@ ERRCODE hb_waError( AREAP pArea, PHB_ITEM pError ) /* * Evaluate a code block. */ -ERRCODE hb_waEvalBlock( AREAP pArea, PHB_ITEM pBlock ) +static ERRCODE hb_waEvalBlock( AREAP pArea, PHB_ITEM pBlock ) { PHB_ITEM pItem; int iCurrArea; @@ -1573,7 +1571,7 @@ ERRCODE hb_waEvalBlock( AREAP pArea, PHB_ITEM pBlock ) /* * RDD info */ -ERRCODE hb_rddInfo( LPRDDNODE pRDD, USHORT uiIndex, ULONG ulConnection, PHB_ITEM pItem ) +static ERRCODE hb_waRddInfo( LPRDDNODE pRDD, USHORT uiIndex, ULONG ulConnection, PHB_ITEM pItem ) { BOOL fResult; int iResult; @@ -1691,3 +1689,396 @@ ERRCODE hb_rddInfo( LPRDDNODE pRDD, USHORT uiIndex, ULONG ulConnection, PHB_ITEM } return SUCCESS; } + +/* + * Raise a runtime error if an method is not defined. + */ +static ERRCODE hb_waUnsupported( AREAP pArea ) +{ + PHB_ITEM pError; + + HB_TRACE(HB_TR_DEBUG, ("hb_waUnsupported(%p)", pArea)); + + pError = hb_errNew(); + hb_errPutGenCode( pError, EG_UNSUPPORTED ); + hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_UNSUPPORTED ) ); + SELF_ERROR( pArea, pError ); + hb_itemRelease( pError ); + + return FAILURE; +} + +/* + * Raise a runtime error if an method is not defined. + */ +static ERRCODE hb_waRddUnsupported( LPRDDNODE pRDD ) +{ + PHB_ITEM pError; + + HB_TRACE(HB_TR_DEBUG, ("hb_waRDDUnsupported(%p)", pRDD)); + + pError = hb_errNew(); + hb_errPutGenCode( pError, EG_UNSUPPORTED ); + hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_UNSUPPORTED ) ); + + hb_errPutSeverity( pError, ES_ERROR ); + hb_errPutSubSystem( pError, pRDD->szName ); + hb_errLaunch( pError ); + hb_itemRelease( pError ); + + return FAILURE; +} + +#if 0 +/* + * Empty method. + */ +static ERRCODE hb_waNull( AREAP pArea ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_waNull(%p)", pArea)); + + HB_SYMBOL_UNUSED( pArea ); + + return SUCCESS; +} +#endif + +/* + * The default virtual method table for all WorkAreas. + */ +static const RDDFUNCS waTable = +{ + /* Movement and positioning methods */ +/* ( DBENTRYP_BP ) */ hb_waBof, /* Bof */ +/* ( DBENTRYP_BP ) */ hb_waEof, /* Eof */ +/* ( DBENTRYP_BP ) */ hb_waFound, /* Found */ + ( DBENTRYP_V ) hb_waUnsupported, /* GoBottom */ + ( DBENTRYP_UL ) hb_waUnsupported, /* GoTo */ + ( DBENTRYP_I ) hb_waUnsupported, /* GoToId */ + ( DBENTRYP_V ) hb_waUnsupported, /* GoTop */ + ( DBENTRYP_BIB ) hb_waUnsupported, /* Seek */ +/* ( DBENTRYP_L ) */ hb_waSkip, /* Skip */ +/* ( DBENTRYP_L ) */ hb_waSkipFilter, /* SkipFilter */ + ( DBENTRYP_L ) hb_waUnsupported, /* SkipRaw */ + + /* Data management */ +/* ( DBENTRYP_VF ) */ hb_waAddField, /* AddField */ + ( DBENTRYP_B ) hb_waUnsupported, /* Append */ +/* ( DBENTRYP_I ) */ hb_waCreateFields, /* CreateFields */ + ( DBENTRYP_V ) hb_waUnsupported, /* DeleteRec */ + ( DBENTRYP_BP ) hb_waUnsupported, /* Deleted */ +/* ( DBENTRYP_SP ) */ hb_waFieldCount, /* FieldCount */ + ( DBENTRYP_VF ) hb_waUnsupported, /* FieldDisplay */ +/* ( DBENTRYP_SSI ) */ hb_waFieldInfo, /* FieldInfo */ +/* ( DBENTRYP_SVP ) */ hb_waFieldName, /* FieldName */ + ( DBENTRYP_V ) hb_waUnsupported, /* Flush */ + ( DBENTRYP_PP ) hb_waUnsupported, /* GetRec */ + ( DBENTRYP_SI ) hb_waUnsupported, /* GetValue */ + ( DBENTRYP_SVL ) hb_waUnsupported, /* GetVarLen */ + ( DBENTRYP_V ) hb_waUnsupported, /* GoCold */ + ( DBENTRYP_V ) hb_waUnsupported, /* GoHot */ + ( DBENTRYP_P ) hb_waUnsupported, /* PutRec */ + ( DBENTRYP_SI ) hb_waUnsupported, /* PutValue */ + ( DBENTRYP_V ) hb_waUnsupported, /* Recall */ + ( DBENTRYP_ULP ) hb_waUnsupported, /* RecCount */ + ( DBENTRYP_ISI ) hb_waUnsupported, /* RecInfo */ + ( DBENTRYP_ULP ) hb_waUnsupported, /* RecNo */ + ( DBENTRYP_I ) hb_waUnsupported, /* RecId */ +/* ( DBENTRYP_S ) */ hb_waSetFieldExtent, /* SetFieldExtent */ + + /* WorkArea/Database management */ +/* ( DBENTRYP_P ) */ hb_waAlias, /* Alias */ +/* ( DBENTRYP_V ) */ hb_waClose, /* Close */ + /* Like in Clipper map CREATE() method at work area level to OPEN() */ +/* ( DBENTRYP_VP ) */ hb_waOpen, /* Create */ +/* ( DBENTRYP_SI ) */ hb_waInfo, /* Info */ +/* ( DBENTRYP_V ) */ hb_waNewArea, /* NewArea */ +/* ( DBENTRYP_VP ) */ hb_waOpen, /* Open */ +/* ( DBENTRYP_V ) */ hb_waRelease, /* Release */ +/* ( DBENTRYP_SP ) */ hb_waStructSize, /* StructSize */ +/* ( DBENTRYP_P ) */ hb_waSysName, /* SysName */ +/* ( DBENTRYP_VEI ) */ hb_waEval, /* Eval */ + ( DBENTRYP_V ) hb_waUnsupported, /* Pack */ + ( DBENTRYP_LSP ) hb_waUnsupported, /* PackRec */ + ( DBENTRYP_VS ) hb_waUnsupported, /* Sort */ +/* ( DBENTRYP_VT ) */ hb_waTrans, /* Trans */ +/* ( DBENTRYP_VT ) */ hb_waTransRec, /* TransRec */ + ( DBENTRYP_V ) hb_waUnsupported, /* Zap */ + + /* Relational Methods */ +/* ( DBENTRYP_VR ) */ hb_waChildEnd, /* ChildEnd */ +/* ( DBENTRYP_VR ) */ hb_waChildStart, /* ChildStart */ + ( DBENTRYP_VR ) hb_waUnsupported, /* ChildSync */ +/* ( DBENTRYP_V ) */ hb_waSyncChildren, /* SyncChildren */ +/* ( DBENTRYP_V ) */ hb_waClearRel, /* ClearRel */ + ( DBENTRYP_V ) hb_waUnsupported, /* ForceRel */ +/* ( DBENTRYP_SVP ) */ hb_waRelArea, /* RelArea */ +/* ( DBENTRYP_VR ) */ hb_waRelEval, /* RelEval */ +/* ( DBENTRYP_SVP ) */ hb_waRelText, /* RelText */ +/* ( DBENTRYP_VR ) */ hb_waSetRel, /* SetRel */ + + /* Order Management */ + ( DBENTRYP_OI ) hb_waUnsupported, /* OrderListAdd */ + ( DBENTRYP_V ) hb_waUnsupported, /* OrderListClear */ + ( DBENTRYP_OI ) hb_waUnsupported, /* OrderListDelete */ + ( DBENTRYP_OI ) hb_waUnsupported, /* OrderListFocus */ + ( DBENTRYP_V ) hb_waUnsupported, /* OrderListRebuild */ +/* ( DBENTRYP_VOI ) */ hb_waOrderCondition, /* OrderCondition */ + ( DBENTRYP_VOC ) hb_waUnsupported, /* OrderCreate */ + ( DBENTRYP_OI ) hb_waUnsupported, /* OrderDestroy */ +/* ( DBENTRYP_OII ) */ hb_waOrderInfo, /* OrderInfo */ + + /* Filters and Scope Settings */ +/* ( DBENTRYP_V ) */ hb_waClearFilter, /* ClearFilter */ +/* ( DBENTRYP_V ) */ hb_waClearLocate, /* ClearLocate */ + ( DBENTRYP_V ) hb_waUnsupported, /* ClearScope */ + ( DBENTRYP_VPLP ) hb_waUnsupported, /* CountScope */ +/* ( DBENTRYP_I ) */ hb_waFilterText, /* FilterText */ + ( DBENTRYP_SI ) hb_waUnsupported, /* ScopeInfo */ +/* ( DBENTRYP_VFI ) */ hb_waSetFilter, /* SetFilter */ +/* ( DBENTRYP_VLO ) */ hb_waSetLocate, /* SetLocate */ + ( DBENTRYP_VOS ) hb_waUnsupported, /* SetScope */ + ( DBENTRYP_VPL ) hb_waUnsupported, /* SkipScope */ +/* ( DBENTRYP_B ) */ hb_waLocate, /* Locate */ + + /* Miscellaneous */ +/* ( DBENTRYP_P ) */ hb_waCompile, /* Compile */ +/* ( DBENTRYP_I ) */ hb_waError, /* Error */ +/* ( DBENTRYP_I ) */ hb_waEvalBlock, /* EvalBlock */ + + /* Network operations */ + ( DBENTRYP_VSP ) hb_waUnsupported, /* RawLock */ + ( DBENTRYP_VL ) hb_waUnsupported, /* Lock */ + ( DBENTRYP_I ) hb_waUnsupported, /* UnLock */ + + /* Memofile functions */ + ( DBENTRYP_V ) hb_waUnsupported, /* CloseMemFile */ + ( DBENTRYP_VP ) hb_waUnsupported, /* CreateMemFile */ + ( DBENTRYP_SVPB ) hb_waUnsupported, /* GetValueFile */ + ( DBENTRYP_VP ) hb_waUnsupported, /* OpenMemFile */ + ( DBENTRYP_SVPB ) hb_waUnsupported, /* PutValueFile */ + + /* Database file header handling */ + ( DBENTRYP_V ) hb_waUnsupported, /* ReadDBHeader */ + ( DBENTRYP_V ) hb_waUnsupported, /* WriteDBHeader */ + + /* non WorkArea functions */ + ( DBENTRYP_R ) NULL, /* Init */ + ( DBENTRYP_R ) NULL, /* Exit */ + ( DBENTRYP_RVV ) hb_waRddUnsupported, /* Drop */ + ( DBENTRYP_RVV ) hb_waRddUnsupported, /* Exists */ +/* ( DBENTRYP_RSLV ) */ hb_waRddInfo, /* RddInfo */ + + /* Special and reserved methods */ + ( DBENTRYP_SVP ) hb_waUnsupported /* WhoCares */ +}; + +/* common for all threads list of registered RDDs */ +static LPRDDNODE * s_RddList = NULL; /* Registered RDDs */ +static USHORT s_uiRddMax = 0; /* Number of registered RDD */ + +/* + * Get RDD node poionter + */ +HB_EXPORT LPRDDNODE hb_rddGetNode( USHORT uiNode ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_rddGetNode(%hu)", uiNode)); + + return uiNode < s_uiRddMax ? s_RddList[ uiNode ] : NULL; +} + +HB_EXPORT PHB_ITEM hb_rddList( USHORT uiType ) +{ + USHORT uiCount, uiIndex, uiRdds; + PHB_ITEM pRddArray; + LPRDDNODE pNode; + + HB_TRACE(HB_TR_DEBUG, ("hb_rddList(%hu)", uiType)); + + for( uiCount = uiRdds = 0; uiCount < s_uiRddMax; ++uiCount ) + { + if( uiType == 0 || s_RddList[ uiCount ]->uiType == uiType ) + ++uiRdds; + } + pRddArray = hb_itemArrayNew( uiRdds ); + for( uiCount = uiIndex = 0; uiCount < s_uiRddMax && uiIndex < uiRdds; ++uiCount ) + { + pNode = s_RddList[ uiCount ]; + if( uiType == 0 || pNode->uiType == uiType ) + hb_itemPutC( hb_arrayGetItemPtr( pRddArray, ++uiIndex ), pNode->szName ); + } + return pRddArray; +} + +/* + * Find a RDD node. + */ +HB_EXPORT LPRDDNODE hb_rddFindNode( const char * szDriver, USHORT * uiIndex ) +{ + USHORT uiCount; + + HB_TRACE(HB_TR_DEBUG, ("hb_rddFindNode(%s, %p)", szDriver, uiIndex)); + + for( uiCount = 0; uiCount < s_uiRddMax; uiCount++ ) + { + LPRDDNODE pNode = s_RddList[ uiCount ]; + if( strcmp( pNode->szName, szDriver ) == 0 ) /* Matched RDD */ + { + if( uiIndex ) + * uiIndex = uiCount; + return pNode; + } + } + if( uiIndex ) + * uiIndex = 0; + return NULL; +} + +/* + * Shutdown the RDD system. + */ +HB_EXPORT void hb_rddShutDown( void ) +{ + USHORT uiCount; + + HB_TRACE(HB_TR_DEBUG, ("hb_rddShutDown()")); + + if( s_uiRddMax > 0 ) + { + hb_rddCloseAll(); + for( uiCount = 0; uiCount < s_uiRddMax; uiCount++ ) + { + if( s_RddList[ uiCount ]->pTable.exit != NULL ) + { + SELF_EXIT( s_RddList[ uiCount ] ); + } + hb_xfree( s_RddList[ uiCount ] ); + } + hb_xfree( s_RddList ); + s_RddList = NULL; + s_uiRddMax = 0; + } +} + +/* + * Register a RDD driver. + */ +HB_EXPORT int hb_rddRegister( const char * szDriver, USHORT uiType ) +{ + LPRDDNODE pRddNewNode; + PHB_DYNS pGetFuncTable; + char szGetFuncTable[ HARBOUR_MAX_RDD_DRIVERNAME_LENGTH + 14 ]; + USHORT uiFunctions; + + HB_TRACE(HB_TR_DEBUG, ("hb_rddRegister(%s, %hu)", szDriver, uiType)); + + if( hb_rddFindNode( szDriver, NULL ) ) /* Duplicated RDD */ + { + return 1; + } + + snprintf( szGetFuncTable, sizeof( szGetFuncTable ), "%s_GETFUNCTABLE", + szDriver ); + pGetFuncTable = hb_dynsymFindName( szGetFuncTable ); + if( !pGetFuncTable ) + { + return 2; /* Not valid RDD */ + } + + /* Create a new RDD node */ + pRddNewNode = ( LPRDDNODE ) hb_xgrab( sizeof( RDDNODE ) ); + memset( pRddNewNode, 0, sizeof( RDDNODE ) ); + + /* Fill the new RDD node */ + hb_strncpy( pRddNewNode->szName, szDriver, HARBOUR_MAX_RDD_DRIVERNAME_LENGTH ); + pRddNewNode->uiType = uiType; + pRddNewNode->rddID = s_uiRddMax; + + /* Call _GETFUNCTABLE() */ + hb_vmPushSymbol( hb_dynsymSymbol( pGetFuncTable ) ); + hb_vmPushNil(); + hb_vmPushPointer( ( void * ) &uiFunctions ); + hb_vmPushPointer( ( void * ) &pRddNewNode->pTable ); + hb_vmPushPointer( ( void * ) &pRddNewNode->pSuperTable ); + hb_vmPushInteger( s_uiRddMax ); + hb_vmDo( 4 ); + if( hb_parni( -1 ) != SUCCESS ) + { + hb_xfree( pRddNewNode ); /* Delete de new RDD node */ + return 3; /* Invalid FUNCTABLE */ + } + + if( s_uiRddMax == 0 ) /* First RDD node */ + s_RddList = (LPRDDNODE *) hb_xgrab( sizeof(LPRDDNODE) ); + else + s_RddList = (LPRDDNODE *) hb_xrealloc( s_RddList, sizeof(LPRDDNODE) * ( s_uiRddMax + 1 ) ); + + s_RddList[ s_uiRddMax++ ] = pRddNewNode; /* Add the new RDD node */ + + if( pRddNewNode->pTable.init != NULL ) + { + SELF_INIT( pRddNewNode ); + } + + return 0; /* Ok */ +} + +/* + * pTable - a table in new RDDNODE that will be filled + * pSubTable - a table with a list of supported functions + * pSuperTable - a current table in a RDDNODE + * szDrvName - a driver name that will be inherited + */ +HB_EXPORT ERRCODE hb_rddInherit( RDDFUNCS * pTable, const RDDFUNCS * pSubTable, RDDFUNCS * pSuperTable, const char * szDrvName ) +{ + LPRDDNODE pRddNode; + USHORT uiCount; + DBENTRYP_V * pFunction, * pSubFunction; + + HB_TRACE(HB_TR_DEBUG, ("hb_rddInherit(%p, %p, %p, %s)", pTable, pSubTable, pSuperTable, szDrvName)); + + if( !pTable ) + { + return FAILURE; + } + + /* Copy the pSuperTable into pTable */ + if( !szDrvName || ! *szDrvName ) + { + /* no name for inherited driver - use the default one */ + memcpy( pTable, &waTable, sizeof( RDDFUNCS ) ); + memcpy( pSuperTable, &waTable, sizeof( RDDFUNCS ) ); + } + else + { + char szSuperName[ HARBOUR_MAX_RDD_DRIVERNAME_LENGTH + 1 ]; + hb_strncpyUpper( szSuperName, szDrvName, HARBOUR_MAX_RDD_DRIVERNAME_LENGTH ); + pRddNode = hb_rddFindNode( szSuperName, NULL ); + + if( !pRddNode ) + { + return FAILURE; + } + + memcpy( pTable, &pRddNode->pTable, sizeof( RDDFUNCS ) ); + memcpy( pSuperTable, &pRddNode->pTable, sizeof( RDDFUNCS ) ); + } + + /* Copy the non NULL entries from pSubTable into pTable */ + pFunction = ( DBENTRYP_V * ) pTable; + pSubFunction = ( DBENTRYP_V * ) pSubTable; + for( uiCount = 0; uiCount < RDDFUNCSCOUNT; uiCount++ ) + { + if( * pSubFunction ) + * pFunction = * pSubFunction; + pFunction ++; + pSubFunction ++; + } + return SUCCESS; +} + +HB_FUNC_EXTERN( RDDSYS ); +void _hb_rddWorkAreaForceLink( void ) +{ + HB_FUNC_EXEC( RDDSYS ); +} diff --git a/harbour/source/rtl/errorsys.prg b/harbour/source/rtl/errorsys.prg index 950e449a07..ebc64e37f1 100644 --- a/harbour/source/rtl/errorsys.prg +++ b/harbour/source/rtl/errorsys.prg @@ -69,10 +69,18 @@ STATIC FUNCTION DefError( oError ) LOCAL n // By default, division by zero results in zero - IF oError:genCode == EG_ZERODIV + IF oError:genCode == EG_ZERODIV .AND. ; + oError:canSubstitute RETURN 0 ENDIF + // By default, retry on RDD lock error failure */ + IF oError:genCode == EG_LOCK .AND. ; + oError:canRetry + // oError:tries++ + RETURN .T. + ENDIF + // Set NetErr() of there was a database open error IF oError:genCode == EG_OPEN .AND. ; oError:osCode == 32 .AND. ; @@ -113,7 +121,7 @@ STATIC FUNCTION DefError( oError ) nChoice := 0 WHILE nChoice == 0 - IF Empty( oError:osCode ) + IF ISNIL( cDOSError ) nChoice := Alert( cMessage, aOptions ) ELSE nChoice := Alert( cMessage + ";" + cDOSError, aOptions ) @@ -134,7 +142,7 @@ STATIC FUNCTION DefError( oError ) // "Quit" selected - IF ! Empty( oError:osCode ) + IF ! ISNIL( cDOSError ) cMessage += " " + cDOSError ENDIF diff --git a/harbour/source/rtl/gtcrs/chrmap.c b/harbour/source/rtl/gtcrs/chrmap.c index 16053cc547..4ba988b2e1 100644 --- a/harbour/source/rtl/gtcrs/chrmap.c +++ b/harbour/source/rtl/gtcrs/chrmap.c @@ -323,7 +323,7 @@ int hb_gt_crs_chrmapinit( int *piTransTbl, char *pszTerm ) if ( pszTerm != NULL && *pszTerm != '\0' ) { - pszFile = getenv("HB_CHRMAP"); + pszFile = getenv("HB_CHARMAP"); if ( pszFile != NULL && *pszFile != '\0' ) nRet = hb_gt_crs_chrmapread( pszFile, pszTerm, piTransTbl ); if ( nRet == -1 )