From 620221a780be6be2917a75757767f0f63441268d Mon Sep 17 00:00:00 2001 From: Bruno Cantero Date: Mon, 26 Jul 1999 16:34:59 +0000 Subject: [PATCH] ChangeLogTag:19990726-18:24 GMT+1 Bruno Cantero --- harbour/ChangeLog | 5 + harbour/include/rdd.api | 208 +++++++-------- harbour/source/rdd/dbcmd.c | 413 ++++++++++++++++++++++++------ harbour/source/rdd/dbfntx1.c | 21 +- harbour/tests/working/testrdd.prg | 8 + 5 files changed, 468 insertions(+), 187 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 3f6044c525..9953642633 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,8 @@ +19990726-18:24 GMT+1 Bruno Cantero + * include/rdd.api, source/rdd/dbcmd.c, source/rdd/dbfntx1.c and tests/working/testrdd.prg + Added more RDD functions + Implemented dynamic WorkAreas + 19990726-18:12 GMT+1 Bruno Cantero * makefile.dos, source/makefile.dos and source/rdd/makefile.dos Added RDD support diff --git a/harbour/include/rdd.api b/harbour/include/rdd.api index fd98debee0..bd1b7ccb42 100644 --- a/harbour/include/rdd.api +++ b/harbour/include/rdd.api @@ -1,11 +1,111 @@ +/* + * $Id$ + */ + #ifndef HB_RDD_API #define HB_RDD_API -// C¢digos devueltos por los m‚todos RDD +typedef USHORT ERRCODE; + +// Return codes for RDD methods + #define SUCCESS 0 #define FAILURE 1 -typedef USHORT ERRCODE; +// Flags for DBTRANSINFO + +#define DBTF_MATCH 0x0001 +#define DBTF_PUTREC 0x0002 + +// Codes for Locking methods + +#define DBLM_EXCLUSIVE 1 +#define DBLM_MULTIPLE 2 +#define DBLM_FILE 3 + +// Codes for SELF_ORDINFO() + +#define DBOI_CONDITION 1 // Get the order condition +#define DBOI_EXPRESSION 2 // Get the order expression +#define DBOI_POSITION 3 // Get the order position +#define DBOI_RECNO 4 // Get the order record number +#define DBOI_NAME 5 // Get the order list name +#define DBOI_NUMBER 6 // Get the order list position +#define DBOI_BAGNAME 7 // Get the order Bag name +#define DBOI_BAGEXT 8 // Get the order Bag Extension +#define DBOI_INDEXEXT DBOI_BAGEXT +#define DBOI_INDEXNAME DBOI_BAGNAME +#define DBOI_ORDERCOUNT 9 // Get the number of orders in the index file +#define DBOI_FILEHANDLE 10 // Get the handle of the index file +#define DBOI_ISCOND 11 // Get the flag if the order has a for condition +#define DBOI_ISDESC 12 // Get the flag if the order is descending +#define DBOI_UNIQUE 13 // Get the flag if the order has the unique attribute set + +// Codes for SELF_INFO() + +#define DBI_ISDBF 1 // Logical: RDD support DBF file format? +#define DBI_CANPUTREC 2 // Logical: RDD support Putting Records? +#define DBI_GETHEADERSIZE 3 // Numeric: Get header size of the file +#define DBI_LASTUPDATE 4 // Date: Last date RDD file updated +#define DBI_GETDELIMITER 5 // String: Get default delimiter +#define DBI_SETDELIMITER 6 // String: Set default delimiter +#define DBI_GETRECSIZE 7 // Numeric: Get record size of the file +#define DBI_GETLOCKARRAY 8 // Array: Get an array of locked records +#define DBI_TABLEEXT 9 // String: Get table file extension + +#define DBI_ISFLOCK 20 // Get file lock status + +#define DBI_CHILDCOUNT 22 // Number of opened relations +#define DBI_FILEHANDLE 23 // Handle of opened file + +#define DBI_BOF 26 // BOF flag - alternate to bof() +#define DBI_EOF 27 // EOF flag - alternate to eof() +#define DBI_DBFILTER 28 // Filter expression +#define DBI_FOUND 29 // FOUND flag - alternate to found +#define DBI_FCOUNT 30 // Number of fields +#define DBI_LOCKCOUNT 31 // Get record size of the file +#define DBI_VALIDBUFFER 32 // Is the current buffer valid +#define DBI_ALIAS 33 // Alias name of workarea +#define DBI_GETSCOPE 34 // Locate codeblock +#define DBI_LOCKOFFSET 35 // New locking offset +#define DBI_SHARED 36 // Gets/Sets the shared flag + +#define DBI_MEMOEXT 37 // Gets/Sets the shared flag +#define DBI_MEMOHANDLE 38 // Dos handle for memo file +#define DBI_MEMOBLOCKSIZE 39 // Blocksize in memo files + +#define DBI_DB_VERSION 101 // HOST driver Version +#define DBI_RDD_VERSION 102 // RDD version (current RDD) + +#define DBI_USER 1000 // Start of user definable DBI_ values + +// codes for SELF_RECINFO() + +#define DBRI_DELETED 1 +#define DBRI_LOCKED 2 +#define DBRI_RECSIZE 3 +#define DBRI_RECNO 4 +#define DBRI_UPDATED 5 + + +// codes for SELF_FIELDINFO() + +#define DBS_NAME 1 +#define DBS_TYPE 2 +#define DBS_LEN 3 +#define DBS_DEC 4 + +// codes for RawLock types + +#define FILE_LOCK 1 +#define FILE_UNLOCK 2 +#define REC_LOCK 3 +#define REC_UNLOCK 4 +#define HEADER_LOCK 5 +#define HEADER_UNLOCK 6 +#define APPEND_LOCK 7 +#define APPEND_UNLOCK 8 + /* * DBFIELDINFO @@ -251,11 +351,6 @@ typedef struct //typedef DBTRANSINFO far * LPDBTRANSINFO; -// Flags for DBTRANSINFO -//#define DBTF_MATCH 0x0001 -//#define DBTF_PUTREC 0x0002 - - /* * DBSORTITEM @@ -365,7 +460,7 @@ typedef struct _AREA { struct _RDDFUNCS * lprfsHost; -// USHORT uiArea; // El n£mero asignado al  rea de trabajo + USHORT uiArea; // El n£mero asignado al  rea de trabajo // FARP atomAlias; // Puntero al s¡mbolo alias de este  rea // de trabajo // USHORT uiFieldExtent; // N£mero total de campos asignados @@ -442,7 +537,7 @@ typedef struct _RDDFUNCS // DBENTRYP_I goToId; DBENTRYP_V goTop; // DBENTRYP_SI seek; -// DBENTRYP_L skip; /* L */ + DBENTRYP_L skip; // DBENTRYP_L skipFilter; /* L */ // DBENTRYP_L skipRaw; /* L */ @@ -476,7 +571,7 @@ typedef struct _RDDFUNCS // DBENTRYP_VP alias; /* VP */ DBENTRYP_V close; -// DBENTRYP_VP create; /* VP */ + DBENTRYP_VP create; // DBENTRYP_SI info; /* SI */ // DBENTRYP_V newarea; /* V */ DBENTRYP_VP open; @@ -571,99 +666,6 @@ typedef RDDFUNCS * PRDDFUNCS; #define RDDFUNCSCOUNT ( sizeof( RDDFUNCS ) / sizeof( DBENTRYP_V ) ) -/*--------------------* Defines *---------------------*/ - -/* C¢digos para m‚todos de bloqueo */ - -//#define DBLM_EXCLUSIVE 1 -//#define DBLM_MULTIPLE 2 -//#define DBLM_FILE 3 - -/* C¢digos pora SELF_ORDINFO() */ - -//#define DBOI_CONDITION 1 /* Get the order condition */ -//#define DBOI_EXPRESSION 2 /* Get the order expression */ -//#define DBOI_POSITION 3 /* Get the order position */ -//#define DBOI_RECNO 4 /* Get the order record number */ -//#define DBOI_NAME 5 /* Get the order list name */ -//#define DBOI_NUMBER 6 /* Get the order list position */ -//#define DBOI_BAGNAME 7 /* Get the order Bag name */ -//#define DBOI_BAGEXT 8 /* Get the order Bag Extension */ -//#define DBOI_INDEXEXT DBOI_BAGEXT -//#define DBOI_INDEXNAME DBOI_BAGNAME -//#define DBOI_ORDERCOUNT 9 /* Get the number of orders in the index file */ -//#define DBOI_FILEHANDLE 10 /* Get the handle of the index file */ -//#define DBOI_ISCOND 11 /* Get the flag if the order has a for condition */ -//#define DBOI_ISDESC 12 /* Get the flag if the order is descending */ -//#define DBOI_UNIQUE 13 /* Get the flag if the order has the unique attribute set */ - -/* C¢digos para SELF_INFO() */ - -//#define DBI_ISDBF 1 /* Logical: RDD support DBF file format? */ -//#define DBI_CANPUTREC 2 /* Logical: RDD support Putting Records? */ -//#define DBI_GETHEADERSIZE 3 /* Numeric: Get header size of the file */ -//#define DBI_LASTUPDATE 4 /* Date: Last date RDD file updated */ -//#define DBI_GETDELIMITER 5 /* String: Get default delimiter */ -//#define DBI_SETDELIMITER 6 /* String: Set default delimiter */ -//#define DBI_GETRECSIZE 7 /* Numeric: Get record size of the file */ -//#define DBI_GETLOCKARRAY 8 /* Array: Get an array of locked records */ -//#define DBI_TABLEEXT 9 /* String: Get table file extension */ - -//#define DBI_ISFLOCK 20 /* Get file lock status */ - -//#define DBI_CHILDCOUNT 22 /* Number of opened relations */ -//#define DBI_FILEHANDLE 23 /* Handle of opened file */ - -//#define DBI_BOF 26 /* BOF flag - alternate to bof() */ -//#define DBI_EOF 27 /* EOF flag - alternate to eof() */ -//#define DBI_DBFILTER 28 /* Filter expression */ -//#define DBI_FOUND 29 /* FOUND flag - alternate to found */ -//#define DBI_FCOUNT 30 /* Number of fields */ -//#define DBI_LOCKCOUNT 31 /* Get record size of the file */ -//#define DBI_VALIDBUFFER 32 /* Is the current buffer valid */ -//#define DBI_ALIAS 33 /* Alias name of workarea */ -//#define DBI_GETSCOPE 34 /* Locate codeblock */ -//#define DBI_LOCKOFFSET 35 /* New locking offset */ -//#define DBI_SHARED 36 /* Gets/Sets the shared flag */ - -//#define DBI_MEMOEXT 37 /* Gets/Sets the shared flag */ -//#define DBI_MEMOHANDLE 38 /* Dos handle for memo file */ -//#define DBI_MEMOBLOCKSIZE 39 /* Blocksize in memo files */ - -//#define DBI_DB_VERSION 101 /* HOST driver Version */ -//#define DBI_RDD_VERSION 102 /* RDD version (current RDD) */ - -//#define DBI_USER 1000 /* Start of user definable DBI_ values */ - - -/* C¢digos para SELF_RECINFO() */ - -//#define DBRI_DELETED 1 -//#define DBRI_LOCKED 2 -//#define DBRI_RECSIZE 3 -//#define DBRI_RECNO 4 -//#define DBRI_UPDATED 5 - - -/* C¢digos para SELF_FIELDINFO() */ - -//#define DBS_NAME 1 -//#define DBS_TYPE 2 -//#define DBS_LEN 3 -//#define DBS_DEC 4 - -/* C¢digos para tipos RawLock */ - -//#define FILE_LOCK 1 -//#define FILE_UNLOCK 2 -//#define REC_LOCK 3 -//#define REC_UNLOCK 4 -//#define HEADER_LOCK 5 -//#define HEADER_UNLOCK 6 -//#define APPEND_LOCK 7 -//#define APPEND_UNLOCK 8 - - /*--------------------* M‚todos SELF *------------------------*/ /* M‚todos de posicionamiento y desplazamiento */ diff --git a/harbour/source/rdd/dbcmd.c b/harbour/source/rdd/dbcmd.c index d1c0825217..913aff6e20 100644 --- a/harbour/source/rdd/dbcmd.c +++ b/harbour/source/rdd/dbcmd.c @@ -32,7 +32,6 @@ #include #define HARBOUR_MAX_RDD_DRIVERNAME_LENGTH 32 -#define MAX_WORKAREAS 250 #define RDD_BOF 0 #define RDD_EOF 1 @@ -40,23 +39,28 @@ #define RDD_GOBOTTOM 3 #define RDD_GO 4 #define RDD_GOTOP 5 -#define RDD_CLOSE 6 -#define RDD_OPEN 7 +#define RDD_SKIP 6 +#define RDD_CLOSE 7 +#define RDD_CREATE 8 +#define RDD_OPEN 9 typedef struct { - char szName[ HARBOUR_MAX_RDD_DRIVERNAME_LENGTH ]; + char szName[ HARBOUR_MAX_RDD_DRIVERNAME_LENGTH + 1 ]; USHORT uiType; RDDFUNCS pTable; } RDDNODE, * PRDDNODE; HARBOUR HB_BOF( void ); +HARBOUR HB_DBCLOSEALL( void ); HARBOUR HB_DBCLOSEAREA( void ); +HARBOUR HB_DBCREATE( void ); HARBOUR HB_DBGOBOTTOM( void ); HARBOUR HB_DBGOTO( void ); HARBOUR HB_DBGOTOP( void ); HARBOUR HB_DBSELECTAREA( void ); HARBOUR HB_DBSETDRIVER( void ); +HARBOUR HB_DBSKIP( void ); HARBOUR HB_DBUSEAREA( void ); HARBOUR HB_EOF( void ); HARBOUR HB_FOUND( void ); @@ -66,12 +70,15 @@ HARBOUR HB_RDDSETDEFAULT( void ); HB_INIT_SYMBOLS_BEGIN( dbCmd__InitSymbols ) { "BOF", FS_PUBLIC, HB_BOF, 0 }, +{ "DBCLOSEALL", FS_PUBLIC, HB_DBCLOSEALL, 0 }, { "DBCLOSEAREA", FS_PUBLIC, HB_DBCLOSEAREA, 0 }, +{ "DBCREATE", FS_PUBLIC, HB_DBCREATE, 0 }, { "DBGOBOTTOM", FS_PUBLIC, HB_DBGOBOTTOM, 0 }, { "DBGOTO", FS_PUBLIC, HB_DBGOTO, 0 }, { "DBGOTOP", FS_PUBLIC, HB_DBGOTOP, 0 }, { "DBSELECTAREA", FS_PUBLIC, HB_DBSELECTAREA, 0 }, { "DBSETDRIVER", FS_PUBLIC, HB_DBSETDRIVER, 0 }, +{ "DBSKIP", FS_PUBLIC, HB_DBSKIP, 0 }, { "DBUSEAREA", FS_PUBLIC, HB_DBUSEAREA, 0 }, { "EOF", FS_PUBLIC, HB_EOF, 0 }, { "FOUND", FS_PUBLIC, HB_FOUND, 0 }, @@ -95,27 +102,65 @@ static PRDDNODE pRDDList = 0; /* Registered RDD's */ static USHORT uiRDDCount = 0; static USHORT uiNetError = 0; -static AREA pWorkAreas[ MAX_WORKAREAS - 1 ]; +static AREAP pWorkAreas = 0; +static USHORT uiWorkAreas = 0; /* WorkAreas allocated */ + +static void hb_CloseAll( void ); void hb_rddInitialize( void ) { - memset( pWorkAreas, 0, sizeof( AREA ) ); szDefDriver = ( char * ) hb_xgrab( 1 ); szDefDriver[ 0 ] = '\0'; + pWorkAreas = ( AREAP ) hb_xgrab( sizeof( AREA ) ); + uiWorkAreas = 1; } void hb_rddRelease( void ) { + hb_CloseAll(); hb_xfree( szDefDriver ); if( pRDDList ) hb_xfree( pRDDList ); + hb_xfree( pWorkAreas ); +} + +static void hb_CloseAll( void ) +{ + DBENTRYP_V * pFunction; + PHB_ITEM pError; + USHORT uiCount; + + for( uiCount = 0; uiCount < uiWorkAreas; uiCount++ ) + { + if( pWorkAreas[ uiCount ].rddID != 0 ) + { + if( !pWorkAreas[ uiCount ].lprfsHost ) + { + pError = hb_errNew(); + hb_errPutDescription( pError, "No Table, error 9xxx" ); + hb_errLaunch( pError ); + hb_errRelease( pError ); + return; + } + pFunction = ( ( DBENTRYP_V * ) pWorkAreas[ uiCount ].lprfsHost ) + RDD_CLOSE; + if( ! * pFunction ) + { + pError = hb_errNew(); + hb_errPutDescription( pError, "Internal error 9xxx" ); + hb_errLaunch( pError ); + hb_errRelease( pError ); + return; + } + ( * pFunction )( &pWorkAreas[ uiCount ] ); + pWorkAreas[ uiCount ].rddID = 0; + } + } } static USHORT hb_GetRDDId( char * szDriver ) { PRDDNODE pList; USHORT uiCount; - PHB_ITEM pError; for( uiCount = 0; uiCount < uiRDDCount; uiCount++ ) { @@ -123,11 +168,6 @@ static USHORT hb_GetRDDId( char * szDriver ) if( strcmp( pList->szName, szDriver ) == 0 ) return uiCount + 1; } - /* TODO: hb_errorRT_INTERNAL() */ - pError = hb_errNew(); - hb_errPutDescription( pError, "Internal error 9001" ); - hb_errLaunch( pError ); - hb_errRelease( pError ); return 0; } @@ -145,7 +185,7 @@ static BOOL hb_rddRegister( char * szDriver, USHORT uiType ) return 0; } - szGetFuncTable = (char *)hb_xgrab( strlen( szDriver ) + 14 ); + szGetFuncTable = ( char * ) hb_xgrab( strlen( szDriver ) + 14 ); strcpy( szGetFuncTable, szDriver ); strcat( szGetFuncTable, "_GETFUNCTABLE" ); pGetFuncTable = hb_FindDynSym( szGetFuncTable ); @@ -153,13 +193,14 @@ static BOOL hb_rddRegister( char * szDriver, USHORT uiType ) if( !pGetFuncTable ) return 0; + if( !pRDDList ) - pRDDList = (PRDDNODE)hb_xgrab( sizeof( RDDNODE ) ); + pRDDList = ( PRDDNODE ) hb_xgrab( sizeof( RDDNODE ) ); else - pRDDList = (PRDDNODE)hb_xrealloc( pRDDList, sizeof( RDDNODE ) * ( uiRDDCount + 1 ) ); + pRDDList = ( PRDDNODE ) hb_xrealloc( pRDDList, sizeof( RDDNODE ) * ( uiRDDCount + 1 ) ); pList = pRDDList + ( sizeof( RDDNODE ) * uiRDDCount ); - strcpy( pList->szName, szDriver ); + strncpy( pList->szName, szDriver, HARBOUR_MAX_RDD_DRIVERNAME_LENGTH ); pList->uiType = uiType; uiRDDCount++; @@ -181,13 +222,12 @@ static void hb_SelectFirstAvailable( void ) { USHORT uiCount; - for( uiCount = 0; uiCount < MAX_WORKAREAS; uiCount++ ) + uiCurrArea = 1; + for( uiCount = 0; uiCount < uiWorkAreas; uiCount++ ) { - if( pWorkAreas[ uiCount ].rddID == 0 ) - { - uiCurrArea = uiCount + 1; - return; - } + if( ( pWorkAreas[ uiCount ].rddID == 0 ) && /* Free WorkArea */ + ( pWorkAreas[ uiCount ].uiArea < uiCurrArea ) ) + uiCurrArea = pWorkAreas[ uiCount ].uiArea; } } @@ -215,12 +255,32 @@ ERRCODE hb_rddInherit( PRDDFUNCS pTable, PRDDFUNCS pSubTable, PRDDFUNCS pSuperTa return SUCCESS; } -static void hb_dbSelectArea( USHORT uiNewArea ) +static void hb_SelectArea( USHORT uiNewArea ) { - if( uiNewArea == 0) + USHORT uiCount; + BOOL bCreateNewArea = TRUE; + + if( uiNewArea == 0 ) hb_SelectFirstAvailable(); - else if( uiNewArea <= MAX_WORKAREAS ) + else uiCurrArea = uiNewArea; + + for( uiCount = 0; uiCount < uiWorkAreas; uiCount++ ) + { + if( pWorkAreas[ uiCount ].uiArea == uiCurrArea ) + { + bCreateNewArea = FALSE; + break; + } + } + + if( bCreateNewArea ) + { + pWorkAreas = ( AREAP ) hb_xrealloc( pWorkAreas, + sizeof( AREAP ) * ( uiWorkAreas + 1 ) ); + pWorkAreas[ uiWorkAreas ].uiArea = uiCurrArea; + uiWorkAreas++; + } } HARBOUR HB_BOF( void ) @@ -228,12 +288,21 @@ HARBOUR HB_BOF( void ) BOOL bBof = TRUE; DBENTRYP_BP * pFunction; - pFunction = ( ( DBENTRYP_BP * ) pWorkAreas[ uiCurrArea - 1 ].lprfsHost ) + RDD_BOF; - if( * pFunction ) - ( * pFunction )( &pWorkAreas[ uiCurrArea - 1 ], &bBof ); + if( pWorkAreas[ uiCurrArea - 1 ].lprfsHost ) + { + pFunction = ( ( DBENTRYP_BP * ) pWorkAreas[ uiCurrArea - 1 ].lprfsHost ) + RDD_BOF; + if( * pFunction ) + ( * pFunction )( &pWorkAreas[ uiCurrArea - 1 ], &bBof ); + } hb_retl( bBof ); } +HARBOUR HB_DBCLOSEALL( void ) +{ + hb_CloseAll(); + uiCurrArea = 1; +} + HARBOUR HB_DBCLOSEAREA( void ) { DBENTRYP_V * pFunction; @@ -242,20 +311,90 @@ HARBOUR HB_DBCLOSEAREA( void ) if( pWorkAreas[ uiCurrArea - 1 ].rddID == 0 ) return; - pFunction = ( ( DBENTRYP_V * ) pWorkAreas[ uiCurrArea - 1 ].lprfsHost ) + RDD_CLOSE; + if( !pWorkAreas[ uiCurrArea - 1 ].lprfsHost ) + { + pError = hb_errNew(); + hb_errPutDescription( pError, "No Table, error 9xxx" ); + hb_errLaunch( pError ); + hb_errRelease( pError ); + } + else + { + pFunction = ( ( DBENTRYP_V * ) pWorkAreas[ uiCurrArea - 1 ].lprfsHost ) + RDD_CLOSE; + if( ! * pFunction ) + { + pError = hb_errNew(); + hb_errPutDescription( pError, "Internal error 9xxx" ); + hb_errLaunch( pError ); + hb_errRelease( pError ); + } + else + ( * pFunction )( &pWorkAreas[ uiCurrArea - 1 ] ); + } + pWorkAreas[ uiCurrArea - 1 ].rddID = 0; +} + +HARBOUR HB_DBCREATE( void ) +{ + char * szFileName, * szDriver; + USHORT uiRDDId; + PHB_ITEM pError; + PRDDNODE pList; + DBENTRYP_VP * pFunction; + DBOPENINFO pInfo; + + if( !ISCHAR( 1 ) || !ISARRAY( 2 ) ) + { + hb_errorRT_BASE( EG_ARG, 1068, "Argument error", "DBCREATE" ); + return; + } + szFileName = hb_parc( 1 ); + + if( ISCHAR( 3 ) ) + { + szDriver = hb_parc( 3 ); + szDriver = hb_strUpper( szDriver, strlen( szDriver ) ); + } + else + szDriver = szDefDriver; + + if( ( uiRDDId = hb_GetRDDId( szDriver ) ) == 0 ) + { + pError = hb_errNew(); + hb_errPutDescription( pError, "Internal error 9001" ); + hb_errLaunch( pError ); + hb_errRelease( pError ); + pWorkAreas[ uiCurrArea - 1 ].rddID = 0; + return; + } + + pList = pRDDList + ( sizeof( RDDNODE ) * ( uiRDDId - 1 ) ); + pWorkAreas[ uiCurrArea - 1 ].rddID = uiRDDId; + pWorkAreas[ uiCurrArea - 1 ].lprfsHost = &pList->pTable; + + if( !pWorkAreas[ uiCurrArea - 1 ].lprfsHost ) + { + pError = hb_errNew(); + hb_errPutDescription( pError, "No Table, error 9xxx" ); + hb_errLaunch( pError ); + hb_errRelease( pError ); + pWorkAreas[ uiCurrArea - 1 ].rddID = 0; + return; + } + pFunction = ( ( DBENTRYP_VP * ) pWorkAreas[ uiCurrArea - 1 ].lprfsHost ) + RDD_CREATE; + if( ! * pFunction ) { pError = hb_errNew(); hb_errPutDescription( pError, "Internal error 9xxx" ); hb_errLaunch( pError ); hb_errRelease( pError ); - pWorkAreas[ uiCurrArea - 1 ].rddID = 0; - } - else - { - ( * pFunction )( &pWorkAreas[ uiCurrArea - 1 ] ); - pWorkAreas[ uiCurrArea - 1 ].rddID = 0; + return; } + + pInfo.abName = szFileName; + ( * pFunction )( &pWorkAreas[ uiCurrArea - 1 ], &pInfo ); + pWorkAreas[ uiCurrArea - 1 ].rddID = 0; } HARBOUR HB_DBGOBOTTOM( void ) @@ -263,6 +402,15 @@ HARBOUR HB_DBGOBOTTOM( void ) DBENTRYP_V * pFunction; PHB_ITEM pError; + if( !pWorkAreas[ uiCurrArea - 1 ].lprfsHost ) + { + pError = hb_errNew(); + hb_errPutDescription( pError, "No Table, error 9xxx" ); + hb_errLaunch( pError ); + hb_errRelease( pError ); + pWorkAreas[ uiCurrArea - 1 ].rddID = 0; + return; + } pFunction = ( ( DBENTRYP_V * ) pWorkAreas[ uiCurrArea - 1 ].lprfsHost ) + RDD_GOBOTTOM; if( ! * pFunction ) { @@ -281,6 +429,15 @@ HARBOUR HB_DBGOTO( void ) DBENTRYP_L * pFunction; PHB_ITEM pError; + if( !pWorkAreas[ uiCurrArea - 1 ].lprfsHost ) + { + pError = hb_errNew(); + hb_errPutDescription( pError, "No Table, error 9xxx" ); + hb_errLaunch( pError ); + hb_errRelease( pError ); + pWorkAreas[ uiCurrArea - 1 ].rddID = 0; + return; + } pFunction = ( ( DBENTRYP_L * ) pWorkAreas[ uiCurrArea - 1 ].lprfsHost ) + RDD_GO; if( ! * pFunction ) { @@ -301,6 +458,15 @@ HARBOUR HB_DBGOTOP( void ) DBENTRYP_V * pFunction; PHB_ITEM pError; + if( !pWorkAreas[ uiCurrArea - 1 ].lprfsHost ) + { + pError = hb_errNew(); + hb_errPutDescription( pError, "No Table, error 9xxx" ); + hb_errLaunch( pError ); + hb_errRelease( pError ); + pWorkAreas[ uiCurrArea - 1 ].rddID = 0; + return; + } pFunction = ( ( DBENTRYP_V * ) pWorkAreas[ uiCurrArea - 1 ].lprfsHost ) + RDD_GOTOP; if( ! * pFunction ) { @@ -314,46 +480,133 @@ HARBOUR HB_DBGOTOP( void ) ( * pFunction )( &pWorkAreas[ uiCurrArea - 1 ] ); } +HARBOUR HB_DBSELECTAREA( void ) +{ + USHORT uiNewArea; + char * szAlias; + + if( ISCHAR( 1 ) ) + { + szAlias = hb_parc( 1 ); + if( ( uiNewArea = hb_FindAlias( szAlias ) ) == 0 ) + { + hb_errorRT_BASE( EG_ARG, 1002, "Alias not found", szAlias ); + return; + } + hb_SelectArea( uiNewArea ); + } + else if( ISNUM( 1 ) ) + hb_SelectArea( hb_parni( 1 ) ); +} + +HARBOUR HB_DBSETDRIVER( void ) +{ + HB_RDDSETDEFAULT(); +} + +HARBOUR HB_DBSKIP( void ) +{ + PHB_ITEM pError, pItem; + DBENTRYP_L * pFunction; + LONG lToSkip = 1; + + if( !pWorkAreas[ uiCurrArea - 1 ].lprfsHost ) + { + pError = hb_errNew(); + hb_errPutDescription( pError, "No Table, error 9xxx" ); + hb_errLaunch( pError ); + hb_errRelease( pError ); + pWorkAreas[ uiCurrArea - 1 ].rddID = 0; + return; + } + pFunction = ( ( DBENTRYP_L * ) pWorkAreas[ uiCurrArea - 1 ].lprfsHost ) + RDD_SKIP; + if( ! * pFunction ) + { + pError = hb_errNew(); + hb_errPutDescription( pError, "Internal error 9xxx" ); + hb_errLaunch( pError ); + hb_errRelease( pError ); + pWorkAreas[ uiCurrArea - 1 ].rddID = 0; + return; + } + pItem = hb_param( 1 , IT_NUMERIC ); + if( pItem ) + { + if( pItem->type == IT_INTEGER ) + lToSkip = pItem->item.asInteger.value; + else if( pItem->type == IT_LONG ) + lToSkip = pItem->item.asLong.value; + } + ( * pFunction )( &pWorkAreas[ uiCurrArea - 1 ], lToSkip ); +} + HARBOUR HB_DBUSEAREA( void ) { USHORT uiRDDId; char * szDriver, * szFileName, * szAlias; - WORD wLen; PRDDNODE pList; - DBENTRYP_VP * pFunction; + DBENTRYP_V * pFunction1; + DBENTRYP_VP * pFunction2; DBOPENINFO pInfo; PHB_ITEM pError; uiNetError = 0; if( ISLOG( 1 ) ) + { hb_SelectFirstAvailable(); + hb_SelectArea( uiCurrArea ); + } else if( pWorkAreas[ uiCurrArea - 1 ].rddID != 0 ) { - // CloseArea() + pFunction1 = ( ( DBENTRYP_V * ) pWorkAreas[ uiCurrArea - 1 ].lprfsHost ) + RDD_CLOSE; + if( ! * pFunction1 ) + { + pError = hb_errNew(); + hb_errPutDescription( pError, "Internal error 9xxx" ); + hb_errLaunch( pError ); + hb_errRelease( pError ); + pWorkAreas[ uiCurrArea - 1 ].rddID = 0; + return; + } + else + ( * pFunction1 )( &pWorkAreas[ uiCurrArea - 1 ] ); + pWorkAreas[ uiCurrArea - 1 ].rddID = 0; } - szDriver = szDefDriver; - uiRDDId = 1; if( ISCHAR( 2 ) ) { szDriver = hb_parc( 2 ); - if( ( wLen = strlen( szDriver ) ) > 0 ) - { - szDriver = hb_strUpper( szDriver, wLen ); - if( ( uiRDDId = hb_GetRDDId( szDriver ) ) == 0 ) - { - pWorkAreas[ uiCurrArea - 1 ].rddID = 0; - return; - } - } + szDriver = hb_strUpper( szDriver, strlen( szDriver ) ); } + else + szDriver = szDefDriver; + + if( ( uiRDDId = hb_GetRDDId( szDriver ) ) == 0 ) + { + pError = hb_errNew(); + hb_errPutDescription( pError, "Internal error 9xxx" ); + hb_errLaunch( pError ); + hb_errRelease( pError ); + pWorkAreas[ uiCurrArea - 1 ].rddID = 0; + return; + } + pList = pRDDList + ( sizeof( RDDNODE ) * ( uiRDDId - 1 ) ); pWorkAreas[ uiCurrArea - 1 ].rddID = uiRDDId; pWorkAreas[ uiCurrArea - 1 ].lprfsHost = &pList->pTable; - pFunction = ( ( DBENTRYP_VP * ) pWorkAreas[ uiCurrArea - 1 ].lprfsHost ) + RDD_OPEN; - if( ! * pFunction ) + if( !pWorkAreas[ uiCurrArea - 1 ].lprfsHost ) + { + pError = hb_errNew(); + hb_errPutDescription( pError, "No Table, error 9xxx" ); + hb_errLaunch( pError ); + hb_errRelease( pError ); + pWorkAreas[ uiCurrArea - 1 ].rddID = 0; + return; + } + pFunction2 = ( ( DBENTRYP_VP * ) pWorkAreas[ uiCurrArea - 1 ].lprfsHost ) + RDD_OPEN; + if( ! * pFunction2 ) { pError = hb_errNew(); hb_errPutDescription( pError, "Internal error 9xxx" ); @@ -371,46 +624,32 @@ HARBOUR HB_DBUSEAREA( void ) } szFileName = hb_parc( 3 ); - /* TODO: Implement alias from szFilename */ + /* TODO: Implement szAlias from szFilename */ szAlias = ISCHAR( 4 ) ? hb_parc( 4 ) : szFileName; pInfo.uiArea = uiCurrArea; - pInfo.abName = (PBYTE)szFileName; - pInfo.atomAlias = (PBYTE)szAlias; + pInfo.abName = szFileName; + pInfo.atomAlias = szAlias; pInfo.fShared = ISLOG( 5 ) ? hb_parl( 5 ) : !hb_set.HB_SET_EXCLUSIVE; pInfo.fReadonly = ISLOG( 6 ) ? hb_parl( 6 ) : FALSE; - ( * pFunction )( &pWorkAreas[ uiCurrArea - 1 ], &pInfo ); -} - -HARBOUR HB_DBSELECTAREA( void ) -{ - USHORT uiNewArea; - char * szAlias; - - if( ISCHAR( 1 ) ) - { - szAlias = hb_parc( 1 ); - if( ( uiNewArea = hb_FindAlias( szAlias ) ) == 0 ) - { - hb_errorRT_BASE( EG_ARG, 1002, "Alias not found", szAlias ); - return; - } - hb_dbSelectArea( uiNewArea ); - } - else if( ISNUM( 1 ) ) - hb_dbSelectArea( hb_parni( 1 ) ); -} - -HARBOUR HB_DBSETDRIVER( void ) -{ - HB_RDDSETDEFAULT(); + ( * pFunction2 )( &pWorkAreas[ uiCurrArea - 1 ], &pInfo ); } HARBOUR HB_EOF( void ) { BOOL bEof = TRUE; DBENTRYP_BP * pFunction; + PHB_ITEM pError; + if( !pWorkAreas[ uiCurrArea - 1 ].lprfsHost ) + { + pError = hb_errNew(); + hb_errPutDescription( pError, "No Table, error 9xxx" ); + hb_errLaunch( pError ); + hb_errRelease( pError ); + pWorkAreas[ uiCurrArea - 1 ].rddID = 0; + return; + } pFunction = ( ( DBENTRYP_BP * ) pWorkAreas[ uiCurrArea - 1 ].lprfsHost ) + RDD_EOF; if( * pFunction ) ( * pFunction )( &pWorkAreas[ uiCurrArea - 1 ], &bEof ); @@ -421,7 +660,17 @@ HARBOUR HB_FOUND( void ) { BOOL bFound = FALSE; DBENTRYP_BP * pFunction; + PHB_ITEM pError; + if( !pWorkAreas[ uiCurrArea - 1 ].lprfsHost ) + { + pError = hb_errNew(); + hb_errPutDescription( pError, "No Table, error 9xxx" ); + hb_errLaunch( pError ); + hb_errRelease( pError ); + pWorkAreas[ uiCurrArea - 1 ].rddID = 0; + return; + } pFunction = ( ( DBENTRYP_BP * ) pWorkAreas[ uiCurrArea - 1 ].lprfsHost ) + RDD_FOUND; if( * pFunction ) ( * pFunction )( &pWorkAreas[ uiCurrArea - 1 ], &bFound ); @@ -458,6 +707,7 @@ HARBOUR HB_RDDREGISTER( void ) { char * szDriver; WORD wLen; + PHB_ITEM pError; if( ISCHAR( 1 ) ) { @@ -468,7 +718,7 @@ HARBOUR HB_RDDREGISTER( void ) if( !hb_rddRegister( szDriver, hb_parni( 2 ) ) ) { /* TODO: hb_errorRT_INTERNAL() */ - PHB_ITEM pError = hb_errNew(); + pError = hb_errNew(); hb_errPutDescription( pError, "Internal error 9001" ); hb_errLaunch( pError ); hb_errRelease( pError ); @@ -492,6 +742,7 @@ HARBOUR HB_RDDSETDEFAULT( void ) szDefDriver = ( char * ) hb_xrealloc( szDefDriver, wLen + 1 ); strcpy( szDefDriver, szNewDriver ); } - else hb_errorRT_DBCMD( EG_ARG, 1015, "Argument error", "RDDSETDEFAULT" ); + else + hb_errorRT_DBCMD( EG_ARG, 1015, "Argument error", "RDDSETDEFAULT" ); } } diff --git a/harbour/source/rdd/dbfntx1.c b/harbour/source/rdd/dbfntx1.c index 29b6d611ca..88d55bf1b5 100644 --- a/harbour/source/rdd/dbfntx1.c +++ b/harbour/source/rdd/dbfntx1.c @@ -59,7 +59,7 @@ ERRCODE dbfntxGoBottom( AREAP pArea ) return SUCCESS; } -ERRCODE dbfntxGoTo( AREAP pArea, LONG uRecNo ) +ERRCODE dbfntxGoTo( AREAP pArea, LONG lRecNo ) { printf( "Calling dbfntxGoTo()\n" ); return SUCCESS; @@ -71,12 +71,24 @@ ERRCODE dbfntxGoTop( AREAP pArea ) return SUCCESS; } +ERRCODE dbfntxSkip( AREAP pArea, LONG lToSkip ) +{ + printf( "Calling dbfntxSkip()\n" ); + return SUCCESS; +} + ERRCODE dbfntxClose( AREAP pArea ) { printf( "Calling dbfntxClose()\n" ); return SUCCESS; } +ERRCODE dbfntxCreate( AREAP pArea, DBOPENINFOP pCreateInfo ) +{ + printf( "Calling dbfntxCreate()\n" ); + return SUCCESS; +} + ERRCODE dbfntxOpen( AREAP pArea, DBOPENINFOP pOpenInfo ) { printf( "Calling dbfntxOpen()\n" ); @@ -92,7 +104,9 @@ static RDDFUNCS ntxTable = { dbfntxBof, dbfntxGoBottom, dbfntxGoTo, dbfntxGoTop, + dbfntxSkip, dbfntxClose, + dbfntxCreate, dbfntxOpen }; @@ -102,10 +116,11 @@ HARBOUR HB_REQUEST_DBFNTX1( void ) HARBOUR HB_DBFNTX_GETFUNCTABLE( void ) { + USHORT * uiCount; RDDFUNCS * pTable; + *uiCount = RDDFUNCSCOUNT; - * ( USHORT * ) hb_parnl( 1 ) = RDDFUNCSCOUNT; - + uiCount = ( USHORT * ) hb_parnl( 1 ); pTable = ( RDDFUNCS * ) hb_parnl( 2 ); if( pTable ) hb_rddInherit( pTable, &ntxTable, &ntxSuper, 0 ); diff --git a/harbour/tests/working/testrdd.prg b/harbour/tests/working/testrdd.prg index 737883c243..f6473a0c44 100644 --- a/harbour/tests/working/testrdd.prg +++ b/harbour/tests/working/testrdd.prg @@ -1,8 +1,15 @@ function main() + local aRdd := rddList() + QOut( "Testing RDD's" ) QOut( "=============" ) QOut() + QOut( "Registered RDD's:", LTrim( Str( Len( aRdd ) ) ), "=>" ) + aEval( aRdd, { | aDriver | QQOut( "", aDriver[ 1 ] ) } ) + QOut() + QOut() + dbCreate( "File.dbf", {} ) dbUseArea( .T., "dbfntx", "AnyFile" ) Bof() @@ -11,6 +18,7 @@ function main() dbGoBottom() dbGoTo(1) dbGoTop() + dbSkip() dbCloseArea() return nil