diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 78be692b30..f2399e4752 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,57 @@ +3000-08-29 22:00 GMT+1 Bruno Cantero + * include/hbapirdd.h + * Changed WORKAREA structure, 100% Clipper compatible. + ! Uncommented disabled RDD methods. + + + include/hbrddwrk.h + + source/rdd/workarea.c + + Basic RDD (waNew, waOpen, ...) like Clipper. + + * source/rdd/dbcmd.c + + Added __dbArrange(), dbInfo(), dbFieldInfo(), dbRecordInfo(), + dbFileGet() and dbFilePut() functions. + ! Removed default RDD functions. + + * source/rtl/dummy.prg + ! Removed __dbArrange(), dbSort(), dbInfo(), dbFieldInfo(), dbRecordInfo(), + dbFileGet() and dbFilePut() functions. + + + include/hbdbsort.h + + source/rdd/dbsort.prg + + source/rdd/hbdbsort.c + + Added dbSort() function. + + + include/hbrdddbf.h + + include/hbrdddel.h + + include/hbrddsdf.h + * source/rdd/dbf0.prg + * source/rdd/dbf1.c + * source/rdd/delim0.prg + * source/rdd/delim1.c + * source/rdd/sdf0.prg + * source/rdd/sdf1.c + * Changed and added functions, now 100% Clipper compatible. + + * source/rdd/dbfntx/dbfntx0.prg + * Disabled RDD (broken). + + * source/rdd/Makefile + + Added new files. + + * source/rdd/dbfntx/Makefile + * source/rdd/dbfcdx/Makefile + * Disabled DBFNTX and DBFCDX RDD's. + + * makefile.bc + * makefile.vc + * Disabled DBFNTX and DBFCDX RDD's. + + Added new files. + + + tests/Makefile + + tests/newrdd.prg + + Test file for new DBF RDD. + + 2000-08-28 17:00 UTC+0800 Ron Pinkas * source/compiler/harbour.y - Removed 1 un-needed hb_comp_szDeclaredFun = NULL @@ -80,6 +134,7 @@ * source/compiler/simplex.c * Corrected Reset at +>>>>>>> 1.2574 2000-08-22 10:40 UTC+0800 Ron Pinkas * source/compiler/simplex.c * source/compiler/harbour.slx diff --git a/harbour/include/hbapirdd.h b/harbour/include/hbapirdd.h index 0ae9c91c6b..23dddd59dc 100644 --- a/harbour/include/hbapirdd.h +++ b/harbour/include/hbapirdd.h @@ -36,17 +36,21 @@ #ifndef HB_APIRDD_H_ #define HB_APIRDD_H_ -#include "hbapi.h" #include "hbapifs.h" #if defined(HB_EXTERN_C) extern "C" { #endif +#define HARBOUR_MAX_RDD_DRIVERNAME_LENGTH 32 +#define HARBOUR_MAX_RDD_ALIAS_LENGTH 32 +#define HARBOUR_MAX_RDD_FIELDNAME_LENGTH 32 + + + /* RDD virtual machine integration functions */ extern int hb_rddGetCurrentWorkAreaNumber( void ); -extern void * hb_rddGetCurrentWorkAreaPointer( void ); extern ERRCODE hb_rddSelectWorkAreaAlias( char * szAlias ); extern ERRCODE hb_rddSelectWorkAreaNumber( int iArea ); extern ERRCODE hb_rddSelectWorkAreaSymbol( PHB_SYMB pSymAlias ); @@ -57,12 +61,34 @@ extern ERRCODE hb_rddFieldPut( HB_ITEM_PTR pItem, PHB_SYMB pFieldSymbol ); extern void hb_rddShutDown( void ); + +/* DBCMD errors */ + +#define EDBCMD_SEEK_BADPARAMETER 1001 +#define EDBCMD_NOALIAS 1002 +#define EDBCMD_NOVAR 1003 +#define EDBCMD_USE_BADPARAMETER 1005 +#define EDBCMD_REL_BADPARAMETER 1006 +#define EDBCMD_FIELDNAME_BADPARAMETER 1009 +#define EDBCMD_DUPALIAS 1011 +#define EDBCMD_DBCMDBADPARAMETER 1014 +#define EDBCMD_BADPARAMETER 1015 +#define EDBCMD_INFOBADPARAMETER 1032 +#define EDBCMD_DBINFOBADPARAMETER 1034 +#define EDBCMD_DBFILEPUTBADPARAMETER 1041 +#define EDBCMD_DBFILEGETBADPARAMETER 1042 +#define EDBCMD_NOTABLE 2001 +#define EDBCMD_EVAL_BADPARAMETER 2019 + + + /* Flags for DBTRANSINFO */ #define DBTF_MATCH 0x0001 #define DBTF_PUTREC 0x0002 + /* Codes for Locking methods */ #define DBLM_EXCLUSIVE 1 @@ -70,6 +96,7 @@ extern void hb_rddShutDown( void ); #define DBLM_FILE 3 + /* Codes for SELF_ORDINFO() */ #define DBOI_CONDITION 1 /* Get the order condition */ @@ -89,6 +116,7 @@ extern void hb_rddShutDown( void ); #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? */ @@ -101,12 +129,9 @@ extern void hb_rddShutDown( void ); #define DBI_GETLOCKARRAY 8 /* Array: Get an array of locked records */ #define DBI_TABLEEXT 9 /* String: Get table file extension */ #define DBI_FULLPATH 10 /* String: Full path name of opened file */ - #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 */ @@ -118,17 +143,15 @@ extern void hb_rddShutDown( void ); #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 /* String: Get memo file extension */ #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 @@ -138,6 +161,7 @@ extern void hb_rddShutDown( void ); #define DBRI_UPDATED 5 + /* Codes for SELF_FIELDINFO() */ #define DBS_NAME 1 @@ -146,6 +170,7 @@ extern void hb_rddShutDown( void ); #define DBS_DEC 4 + /* Codes for RawLock types */ #define FILE_LOCK 1 @@ -157,114 +182,15 @@ extern void hb_rddShutDown( void ); #define APPEND_LOCK 7 #define APPEND_UNLOCK 8 -/* forward declarations + + +/* + * Forward declarations */ struct _RDDFUNCS; struct _AREA; -struct _TAGINFO; -struct _INDEXINFO; -typedef struct _FILEINFO -{ - FHANDLE hFile; - char * szFileName; /* Name of file */ - ULONG * pLocksPos; /* List of records locked */ - ULONG lNumLocksPos; /* Number of records locked */ - BOOL fFileLocked; /* TRUE if entire file is locked */ - BOOL fAppend; /* TRUE if new record is added */ - struct _FILEINFO * pNext; /* The next file in the list */ -} FILEINFO; - -typedef FILEINFO * LPFILEINFO; - - -typedef struct _KEYINFO -{ - PHB_ITEM pItem; - LONG Tag; - LONG Xtra; - struct _KEYINFO * pNext; -} KEYINFO; - -typedef KEYINFO * LPKEYINFO; - - -typedef struct HB_PAGEINFO_STRU -{ - LONG Page; - LONG Left; - LONG Right; - BOOL Changed; - BOOL NewRoot; - BOOL LastEntry; - BOOL Reload; - BOOL ChkBOF; - BOOL ChkEOF; - BYTE PageType; - LONG RNMask; - BYTE ReqByte; - BYTE RNBits; - BYTE DCBits; - BYTE TCBits; - BYTE DCMask; - BYTE TCMask; - USHORT Space; - LPKEYINFO pKeys; - USHORT uiKeys; - SHORT CurKey; - struct HB_PAGEINFO_STRU * Owner; - struct HB_PAGEINFO_STRU * Child; - struct _TAGINFO * TagParent; -} HB_PAGEINFO; - -typedef HB_PAGEINFO * LPPAGEINFO; - - -typedef struct _TAGINFO -{ - char * TagName; - char * KeyExpr; - char * ForExpr; - PHB_ITEM pKeyItem; - PHB_ITEM pForItem; - BOOL AscendKey; - BOOL UniqueKey; - BOOL TagChanged; - BOOL TagBOF; - BOOL TagEOF; - BYTE KeyType; - BYTE OptFlags; - LONG TagBlock; - LONG RootBlock; - USHORT KeyLength; - USHORT MaxKeys; - LPKEYINFO CurKeyInfo; - LPPAGEINFO RootPage; - struct _INDEXINFO * Owner; - struct _TAGINFO * pNext; -} TAGINFO; - -typedef TAGINFO * LPTAGINFO; - - - -typedef struct _INDEXINFO -{ - char * IndexName; - BOOL Exact; - BOOL Corrupted; - LONG TagRoot; - LONG NextAvail; - struct _AREA * Owner; - FHANDLE DiskFile; - LPTAGINFO CompoundTag; - LPTAGINFO TagList; - struct _INDEXINFO * pNext; /* The next index in the list */ -} INDEXINFO; - -typedef INDEXINFO * LPINDEXINFO; - /* * DBFIELDINFO @@ -276,7 +202,7 @@ typedef struct { BYTE * atomName; /* FIELD (symbol) name */ USHORT uiType; /* FIELD type */ - USHORT typeExtended; /* FIELD type extended */ + USHORT uiTypeExtended; /* FIELD type extended */ USHORT uiLen; /* Overall FIELD length */ USHORT uiDec; /* Decimal places of numeric FIELD */ } DBFIELDINFO; @@ -286,10 +212,10 @@ typedef DBFIELDINFO * LPDBFIELDINFO; /* -* DBOPENINFO -* ---------- -* The Open Info structure -*/ + * DBOPENINFO + * ---------- + * The Open Info structure + */ typedef struct { @@ -306,41 +232,10 @@ typedef DBOPENINFO * LPDBOPENINFO; /* -* DBEXTENDINFO -* ------------ -* Additional properties -*/ - -typedef struct -{ - USHORT uiHeaderLen; /* Size of header */ - USHORT uiRecordLen; /* Size of record */ - BYTE * bRecord; /* Buffer of the data */ - BOOL fValidBuffer; /* State of buffer */ - BOOL fHasMemo; /* Work Area with Memo fields */ - BOOL fHasMDX; /* MDX or CDX indexes */ - ULONG ulRecNo; /* Current record */ - ULONG ulNextBlock; /* Next block for memos */ - BOOL fExclusive; /* Share the file */ - BOOL fReadOnly; /* Read only file */ - BYTE bYear; /* Last update */ - BYTE bMonth; - BYTE bDay; - BOOL fRecordChanged; /* Record changed */ - ULONG ulRecCount; /* Total records */ - PHB_ITEM itmEval; /* EVAL expression for __dbPack() */ - ULONG ulEvery; /* Every records for eval itmEval */ -} DBEXTENDINFO; - -typedef DBEXTENDINFO * LPDBEXTENDINFO; - - - -/* -* DBORDERCONDINFO -* --------------- -* The Create Order conditional Info structure -*/ + * DBORDERCONDINFO + * --------------- + * The Create Order conditional Info structure + */ typedef struct _DBORDERCONDINFO { @@ -369,10 +264,10 @@ typedef DBORDERCONDINFO * LPDBORDERCONDINFO; /* -* DBORDERCREATE -* ------------- -* The Create Order Info structure -*/ + * DBORDERCREATE + * ------------- + * The Create Order Info structure + */ typedef struct { @@ -390,10 +285,10 @@ typedef DBORDERCREATEINFO * LPDBORDERCREATEINFO; /* -* DBORDERINFO -* ----------- -* The Set Index Info structure -*/ + * DBORDERINFO + * ----------- + * The Set Index Info structure + */ typedef struct { @@ -409,10 +304,10 @@ typedef DBORDERINFO * LPDBORDERINFO; /* -* DBSCOPEINFO -* ----------- -* The Scope Info structure -*/ + * DBSCOPEINFO + * ----------- + * The Scope Info structure + */ typedef struct { @@ -431,11 +326,13 @@ typedef struct typedef DBSCOPEINFO * LPDBSCOPEINFO; + + /* -* DBORDSCOPEINFO -* ----------- -* The Order Scope Info structure -*/ + * DBORDSCOPEINFO + * -------------- + * The Order Scope Info structure + */ typedef struct { @@ -445,11 +342,13 @@ typedef struct typedef DBORDSCOPEINFO * LPDBORDSCOPEINFO; + + /* -* DBFILTERINFO -* ------------ -* The Filter Info structure -*/ + * DBFILTERINFO + * ------------ + * The Filter Info structure + */ typedef struct { @@ -463,19 +362,19 @@ typedef DBFILTERINFO * LPDBFILTERINFO; /* -* DBRELINFO -* ------------ -* The Relationship Info structure -*/ + * DBRELINFO + * --------- + * The Relationship Info structure + */ typedef struct _DBRELINFO { - PHB_ITEM itmCobExpr; /* Block representation of the relational SEEK key */ - PHB_ITEM abKey; /* String representation of the relational SEEK key */ - BOOL isScoped; /* Is this relation scoped */ - struct _AREA *lpaParent; /* The parent of this relation */ - struct _AREA *lpaChild; /* The parents children */ - struct _DBRELINFO *lpdbriNext; /* Next child or parent */ + PHB_ITEM itmCobExpr; /* Block representation of the relational SEEK key */ + PHB_ITEM abKey; /* String representation of the relational SEEK key */ + BOOL isScoped; /* Is this relation scoped */ + struct _AREA * lpaParent; /* The parent of this relation */ + struct _AREA * lpaChild; /* The parents children */ + struct _DBRELINFO * lpdbriNext; /* Next child or parent */ } DBRELINFO; typedef DBRELINFO * LPDBRELINFO; @@ -483,13 +382,13 @@ typedef DBRELINFO * LPDBRELINFO; /* -* DBEVALINFO -* ------------ -* The Evaluation Info structure -* -* Contains information necessary for a block evaluation -* on each record of the workarea -*/ + * DBEVALINFO + * ---------- + * The Evaluation Info structure + * + * Contains information necessary for a block evaluation + * on each record of the workarea + */ typedef struct { @@ -502,13 +401,13 @@ typedef DBEVALINFO * LPDBEVALINFO; /* -* DBTRANSITEM -* ------------ -* The Transfer Item structure -* -* Defines a single transfer item (usually a field) from -* one database to another; used by DBTRANSINFO -*/ + * DBTRANSITEM + * ----------- + * The Transfer Item structure + * + * Defines a single transfer item (usually a field) from + * one database to another; used by DBTRANSINFO + */ typedef struct { @@ -521,22 +420,22 @@ typedef DBTRANSITEM * LPDBTRANSITEM; /* -* DBTRANSINFO -* ------------ -* The Transfer Info structure -* -* Defines a global transfer of data items from on workarea -* to another -*/ + * DBTRANSINFO + * ----------- + * The Transfer Info structure + * + * Defines a global transfer of data items from on workarea + * to another + */ typedef struct { - struct _AREA *lpaSource; /* Pointer to source work area */ - struct _AREA *lpaDest; /* Pointer to dest work area */ - DBSCOPEINFO dbsci; /* Scope to limit transfer */ - USHORT uiFlags; /* Transfer attributes */ - USHORT uiItemCount; /* Number of items below */ - LPDBTRANSITEM lpTransItems; /* Array of items */ + struct _AREA * lpaSource; /* Pointer to source work area */ + struct _AREA * lpaDest; /* Pointer to dest work area */ + DBSCOPEINFO dbsci; /* Scope to limit transfer */ + USHORT uiFlags; /* Transfer attributes */ + USHORT uiItemCount; /* Number of items below */ + LPDBTRANSITEM lpTransItems; /* Array of items */ } DBTRANSINFO; typedef DBTRANSINFO * LPDBTRANSINFO; @@ -544,14 +443,14 @@ typedef DBTRANSINFO * LPDBTRANSINFO; /* -* DBSORTITEM -* ---------- -* The Sort Item Structure -* -* An array of items that, together, indicate the key value to -* use while sorting data. The order of the array determines the -* order of the sorting. -*/ + * DBSORTITEM + * ---------- + * The Sort Item Structure + * + * An array of items that, together, indicate the key value to + * use while sorting data. The order of the array determines the + * order of the sorting. + */ typedef struct { @@ -573,12 +472,12 @@ typedef DBSORTITEM * LPDBSORTITEM; /* -* DBSORTINFO -* ---------- -* The Sort Info Structure -* -* Information for a physical sort on the workarea -*/ + * DBSORTINFO + * ---------- + * The Sort Info Structure + * + * Information for a physical sort on the workarea + */ typedef struct { @@ -592,18 +491,18 @@ typedef DBSORTINFO * LPDBSORTINFO; /* -* DBLOCKINFO -* ---------- -* The Lock Info Structure -* -* Information for a record or file lock -*/ + * DBLOCKINFO + * ---------- + * The Lock Info Structure + * + * Information for a record or file lock + */ typedef struct { - ULONG itmRecID; - USHORT uiMethod; - BOOL fResult; + PHB_ITEM itmRecID; + USHORT uiMethod; + BOOL fResult; } DBLOCKINFO; typedef DBLOCKINFO * LPDBLOCKINFO; @@ -611,12 +510,12 @@ typedef DBLOCKINFO * LPDBLOCKINFO; /* -* FIELD -* ----- -* The Field structure -* -* This is the basic unit of access for a workarea -*/ + * FIELD + * ----- + * The Field structure + * + * This is the basic unit of access for a workarea + */ typedef struct _FIELD { @@ -625,10 +524,8 @@ typedef struct _FIELD USHORT uiLen; /* Field length */ USHORT uiDec; /* Decimal length */ USHORT uiArea; /* Area this field resides in */ - USHORT uiOffset; /* Offset for this field */ void * sym; /* Symbol that represents the field */ - void * memo; /* Pointer to memo data */ - struct _FIELD *lpfNext; /* The next field in the list */ + struct _FIELD * lpfNext; /* The next field in the list */ } FIELD; typedef FIELD * LPFIELD; @@ -638,40 +535,36 @@ typedef FIELD * LPFIELD; /*--------------------* WORKAREA structure *----------------------*/ /* -* WORKAREA -* -------- -* The Workarea Structure -* -* Information to administrate the workarea -*/ - + * WORKAREA + * -------- + * The Workarea Structure + * + * Information to administrate the workarea + */ typedef struct _AREA { struct _RDDFUNCS * lprfsHost; /* Virtual method table for this workarea */ - USHORT uiArea; /* The number assigned to this workarea */ - void * atomAlias; /* Pointer to the alias symbol for this workarea */ - USHORT uiFieldExtent; /* Total number of fields allocated */ - USHORT uiFieldCount; /* Total number of fields used */ - LPFIELD lpFields; /* Pointer to an array of fields */ - void * lpFieldExtents; /* Void ptr for additional field properties */ + USHORT uiArea; /* The number assigned to this workarea */ + void * atomAlias; /* Pointer to the alias symbol for this workarea */ + USHORT uiFieldExtent; /* Total number of fields allocated */ + USHORT uiFieldCount; /* Total number of fields used */ + LPFIELD lpFields; /* Pointer to an array of fields */ + void * lpFieldExtents; /* Void ptr for additional field properties */ PHB_ITEM valResult; /* All purpose result holder */ BOOL fTop; /* TRUE if "top" */ BOOL fBottom; /* TRUE if "bottom" */ BOOL fBof; /* TRUE if "bof" */ BOOL fEof; /* TRUE if "eof" */ BOOL fFound; /* TRUE if "found" */ - DBSCOPEINFO dbsi; /* Info regarding last LOCATE */ + DBSCOPEINFO dbsi; /* Info regarding last LOCATE */ DBFILTERINFO dbfi; /* Filter in effect */ LPDBORDERCONDINFO lpdbOrdCondInfo; - LPDBRELINFO lpdbRelations; /* Parent/Child relationships used */ - USHORT uiParents; /* Number of parents for this area */ - USHORT heap; - USHORT heapSize; - USHORT rddID; - LPFILEINFO lpDataInfo; /* Data files used by this workarea */ - LPINDEXINFO lpIndexInfo; /* Indexes used by this workarea */ - LPDBEXTENDINFO lpExtendInfo; /* Additional properties */ + LPDBRELINFO lpdbRelations; /* Parent/Child relationships used */ + USHORT uiParents; /* Number of parents for this area */ + USHORT heap; + USHORT heapSize; + USHORT rddID; } AREA; typedef AREA * LPAREA; @@ -680,6 +573,8 @@ typedef AREA * LPAREA; #define AREAP LPAREA #endif + + /*--------------------* Virtual Method Table *----------------------*/ typedef USHORT ( * DBENTRYP_V )( AREAP area ); @@ -690,8 +585,11 @@ typedef USHORT ( * DBENTRYP_UL )( AREAP area, ULONG param ); typedef USHORT ( * DBENTRYP_I )( AREAP area, PHB_ITEM param ); typedef USHORT ( * DBENTRYP_SI )( AREAP area, USHORT index, PHB_ITEM param ); typedef USHORT ( * DBENTRYP_VP )( AREAP area, LPDBOPENINFO param ); +typedef USHORT ( * DBENTRYP_VT )( AREAP area, LPDBTRANSINFO param ); typedef USHORT ( * DBENTRYP_VF )( AREAP area, LPDBFIELDINFO param ); typedef USHORT ( * DBENTRYP_VL )( AREAP area, LPDBLOCKINFO param ); +typedef USHORT ( * DBENTRYP_VR )( AREAP area, LPDBRELINFO param ); +typedef USHORT ( * DBENTRYP_VS )( AREAP area, LPDBSORTINFO param ); typedef USHORT ( * DBENTRYP_VFI )( AREAP area, LPDBFILTERINFO param ); typedef USHORT ( * DBENTRYP_VEI )( AREAP area, LPDBEVALINFO param ); typedef USHORT ( * DBENTRYP_VLO )( AREAP area, LPDBSCOPEINFO param ); @@ -706,6 +604,7 @@ typedef USHORT ( * DBENTRYP_S )( AREAP area, USHORT param ); typedef USHORT ( * DBENTRYP_LP )( AREAP area, LONG * param ); typedef USHORT ( * DBENTRYP_ULP )( AREAP area, ULONG * param ); typedef USHORT ( * DBENTRYP_SVP )( AREAP area, USHORT index, void * param ); +typedef USHORT ( * DBENTRYP_SVPB )( AREAP area, USHORT index, void * param, BOOL p3 ); typedef USHORT ( * DBENTRYP_VSP )( AREAP area, USHORT action, ULONG lRecord ); typedef USHORT ( * DBENTRYP_SVL )( AREAP area, USHORT index, ULONG * param ); typedef USHORT ( * DBENTRYP_SSI )( AREAP area, USHORT p1, USHORT p2, PHB_ITEM p3 ); @@ -715,7 +614,6 @@ typedef USHORT ( * DBENTRYP_VPL )( AREAP area, void * p1, LONG p2); typedef USHORT ( * DBENTRYP_VPLP )( AREAP area, void * p1, LONG * p2); typedef USHORT ( * DBENTRYP_LSP )( AREAP area, LONG p1, USHORT * p2); - /*--------------------* Virtual Method Table *----------------------*/ typedef struct _RDDFUNCS @@ -775,36 +673,32 @@ typedef struct _RDDFUNCS DBENTRYP_P sysName; DBENTRYP_VEI dbEval; DBENTRYP_V pack; -#if 0 DBENTRYP_LSP packRec; - DBENTRYP_VP sort; - DBENTRYP_VP trans; - DBENTRYP_VP transRec; -#endif + DBENTRYP_VS sort; + DBENTRYP_VT trans; + DBENTRYP_VT transRec; DBENTRYP_V zap; /* Relational Methods */ - DBENTRYP_VP childEnd; - DBENTRYP_VP childStart; - DBENTRYP_VP childSync; + DBENTRYP_VR childEnd; + DBENTRYP_VR childStart; + DBENTRYP_VR childSync; DBENTRYP_V syncChildren; DBENTRYP_V clearRel; DBENTRYP_V forceRel; DBENTRYP_SVP relArea; - DBENTRYP_VP relEval; + DBENTRYP_VR relEval; DBENTRYP_SVP relText; - DBENTRYP_VP setRel; + DBENTRYP_VR setRel; /* Order Management */ DBENTRYP_OI orderListAdd; DBENTRYP_V orderListClear; -#if 0 DBENTRYP_VP orderListDelete; -#endif DBENTRYP_OI orderListFocus; DBENTRYP_V orderListRebuild; DBENTRYP_VOI orderCondition; @@ -845,7 +739,7 @@ typedef struct _RDDFUNCS DBENTRYP_V closeMemFile; DBENTRYP_VP createMemFile; - DBENTRYP_SVP getValueFile; + DBENTRYP_SVPB getValueFile; DBENTRYP_VP openMemFile; DBENTRYP_SVP putValueFile; @@ -866,6 +760,8 @@ typedef RDDFUNCS * PRDDFUNCS; #define RDDFUNCSCOUNT ( sizeof( RDDFUNCS ) / sizeof( DBENTRYP_V ) ) + + /*--------------------* SELF Methods *------------------------*/ /* Movement and positioning methods */ @@ -950,7 +846,6 @@ typedef RDDFUNCS * PRDDFUNCS; #define SELF_ORDLSTFOCUS(w, lp) ((*(w)->lprfsHost->orderListFocus)(w,lp)) #define SELF_ORDLSTREBUILD(w) ((*(w)->lprfsHost->orderListRebuild)(w)) #define SELF_ORDLSTCLEAR(w) ((*(w)->lprfsHost->orderListClear)(w)) - #define SELF_ORDSETCOND(w, ip) ((*(w)->lprfsHost->orderCondition)(w, ip)) #define SELF_ORDCREATE(w, ip) ((*(w)->lprfsHost->orderCreate)(w, ip)) #define SELF_ORDDESTROY(w, p) ((*(w)->lprfsHost->orderDestroy)(w, p)) @@ -998,7 +893,7 @@ typedef RDDFUNCS * PRDDFUNCS; #define SELF_CLOSEMEMFILE(w) ((*(w)->lprfsHost->closeMemFile)(w)) #define SELF_CREATEMEMFILE(w,bp) ((*(w)->lprfsHost->createMemFile)(w,bp)) -#define SELF_GETVALUEFILE(w,i,bp) ((*(w)->lprfsHost->getValueFile)(w,i,bp)) +#define SELF_GETVALUEFILE(w,i,bp,b) ((*(w)->lprfsHost->getValueFile)(w,i,bp,b)) #define SELF_OPENMEMFILE(w,bp) ((*(w)->lprfsHost->openMemFile)(w,bp)) #define SELF_PUTVALUEFILE(w,i,bp) ((*(w)->lprfsHost->putValueFile)(w,i,bp)) @@ -1104,7 +999,6 @@ typedef RDDFUNCS * PRDDFUNCS; #define SUPER_ORDLSTFOCUS(w, lp) ((*(SUPERTABLE)->orderListFocus)(w, lp)) #define SUPER_ORDLSTREBUILD(w) ((*(SUPERTABLE)->orderListRebuild)(w)) #define SUPER_ORDLSTCLEAR(w) ((*(SUPERTABLE)->orderListClear)(w)) - #define SUPER_ORDSETCOND(w,ip) ((*(SUPERTABLE)->orderCondition)(w, ip)) #define SUPER_ORDCREATE(w, ip) ((*(SUPERTABLE)->orderCreate)(w, ip)) #define SUPER_ORDDELETE(w, ip) ((*(SUPERTABLE)->orderDelete)(w, ip)) @@ -1152,7 +1046,7 @@ typedef RDDFUNCS * PRDDFUNCS; #define SUPER_CLOSEMEMFILE(w) ((*(SUPERTABLE)->closeMemFile)(w)) #define SUPER_CREATEMEMFILE(w,bp) ((*(SUPERTABLE)->createMemFile)(w,bp)) -#define SUPER_GETVALUEFILE(w,i,bp) ((*(SUPERTABLE)->getValueFile)(w,i,bp)) +#define SUPER_GETVALUEFILE(w,i,bp,b) ((*(SUPERTABLE)->getValueFile)(w,i,bp,b)) #define SUPER_OPENMEMFILE(w,bp) ((*(SUPERTABLE)->openMemFile)(w,bp)) #define SUPER_PUTVALUEFILE(w,i,bp) ((*(SUPERTABLE)->putValueFile)(w,i,bp)) @@ -1173,10 +1067,11 @@ typedef RDDFUNCS * PRDDFUNCS; #define SUPER_TABLEEXT(w, fp) ((*(SUPERTABLE)->info)(w, DBI_TABLEEXT, fp)) + /* -* PROTOTYPES -* ---------- -*/ + * PROTOTYPES + * ---------- + */ extern ERRCODE hb_rddInherit( PRDDFUNCS pTable, PRDDFUNCS pSubTable, PRDDFUNCS pSuperTable, BYTE * szDrvName ); extern ERRCODE hb_rddDisinherit( BYTE * drvName ); extern USHORT hb_rddExtendType( USHORT fieldType ); @@ -1186,4 +1081,4 @@ extern USHORT hb_rddFieldType( USHORT extendType ); } #endif -#endif /* HB_APIRDD_H_ */ +#endif /* HB_APIRDD_H_ */ \ No newline at end of file diff --git a/harbour/include/hbdbsort.h b/harbour/include/hbdbsort.h new file mode 100644 index 0000000000..58c995458b --- /dev/null +++ b/harbour/include/hbdbsort.h @@ -0,0 +1,80 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * SORT 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 of the License, or + * (at your option) any later version, with one exception: + * + * The exception is that if you link the Harbour Runtime Library (HRL) + * and/or the Harbour Virtual Machine (HVM) 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 HRL + * and/or HVM code into it. + * + * 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 program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA (or visit + * their web site at http://www.gnu.org/). + * + */ + +#ifndef HB_DBSORT_H_ +#define HB_DBSORT_H_ + +#include "hbrdddbf.h" + +#if defined(HB_EXTERN_C) +extern "C" { +#endif + +/* + * DBQUICKSORT + * ----------- + * The Quick Sort Item Structure + */ + +typedef struct _DBQUICKSORT +{ + FHANDLE hFile; + BYTE szTempName[ _POSIX_PATH_MAX + 1 ]; + BYTE * pBuffer; + BYTE * pSwapBufferA; + BYTE * pSwapBufferB; + BYTE * pCmpBufferA; + BYTE * pCmpBufferB; + USHORT uiRecordLen; + USHORT uiMaxRecords; + LPDBSORTINFO pSortInfo; +} DBQUICKSORT; + +typedef DBQUICKSORT * LPDBQUICKSORT; + +/* + * PROTOTYPES + * ---------- + */ +extern BOOL hb_dbQSortInit( LPDBQUICKSORT pQuickSort, LPDBSORTINFO pSortInfo, USHORT uiRecordLen ); +extern void hb_dbQSortExit( LPDBQUICKSORT pQuickSort ); +extern BOOL hb_dbQSortAdvance( LPDBQUICKSORT pQuickSort, USHORT uiCount ); +extern void hb_dbQSortComplete( LPDBQUICKSORT pQuickSort ); + +#if defined(HB_EXTERN_C) +} +#endif + +#endif /* HB_DBSORT_H_ */ \ No newline at end of file diff --git a/harbour/include/hbrdddbf.h b/harbour/include/hbrdddbf.h new file mode 100644 index 0000000000..ed202e1c4a --- /dev/null +++ b/harbour/include/hbrdddbf.h @@ -0,0 +1,287 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * DBF 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 of the License, or + * (at your option) any later version, with one exception: + * + * The exception is that if you link the Harbour Runtime Library (HRL) + * and/or the Harbour Virtual Machine (HVM) 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 HRL + * and/or HVM code into it. + * + * 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 program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA (or visit + * their web site at http://www.gnu.org/). + * + */ + +#ifndef HB_RDDDBF_H_ +#define HB_RDDDBF_H_ + +#include "hbapirdd.h" + +#if defined(HB_EXTERN_C) +extern "C" { +#endif + +/* DBF header */ + +typedef struct _DBFHEADER +{ + BYTE bVersion; + BYTE bYear; + BYTE bMonth; + BYTE bDay; + ULONG ulRecCount; + USHORT uiHeaderLen; + USHORT uiRecordLen; + BYTE bReserved1[ 16 ]; + BYTE bHasTags; + BYTE bReserved2[ 3 ]; +} DBFHEADER; + +typedef DBFHEADER * LPDBFHEADER; + + + +typedef struct _DBFFIELD +{ + BYTE bName[ 11 ]; + BYTE bType; + BYTE bReserved1[ 4 ]; + BYTE bLen; + BYTE bDec; + BYTE bReserved2[ 13 ]; + BYTE bHasTag; +} DBFFIELD; + +typedef DBFFIELD * LPDBFFIELD; + + + +/* DBF errors */ + +#define EDBF_OPEN_DBF 1001 +#define EDBF_CREATE_DBF 1004 +#define EDBF_READ 1010 +#define EDBF_WRITE 1011 +#define EDBF_CORRUPT 1012 +#define EDBF_DATATYPE 1020 +#define EDBF_DATAWIDTH 1021 +#define EDBF_UNLOCKED 1022 +#define EDBF_SHARED 1023 +#define EDBF_APPENDLOCK 1024 +#define EDBF_READONLY 1025 + + + +/* DBF default file extensions */ + +#define DBF_TABLEEXT ".dbf" +#define DBF_MEMOEXT ".dbt" + + + +/* DBF lock */ + +#define DBF_LOCKPOS 1000000000L + + +/* + * DBF WORKAREA + * ------------ + * The Workarea Structure of DBF RDD + * + */ + +typedef struct _DBFAREA +{ + struct _RDDFUNCS * lprfsHost; /* Virtual method table for this workarea */ + USHORT uiArea; /* The number assigned to this workarea */ + void * atomAlias; /* Pointer to the alias symbol for this workarea */ + USHORT uiFieldExtent; /* Total number of fields allocated */ + USHORT uiFieldCount; /* Total number of fields used */ + LPFIELD lpFields; /* Pointer to an array of fields */ + void * lpFieldExtents; /* Void ptr for additional field properties */ + PHB_ITEM valResult; /* All purpose result holder */ + BOOL fTop; /* TRUE if "top" */ + BOOL fBottom; /* TRUE if "bottom" */ + BOOL fBof; /* TRUE if "bof" */ + BOOL fEof; /* TRUE if "eof" */ + BOOL fFound; /* TRUE if "found" */ + DBSCOPEINFO dbsi; /* Info regarding last LOCATE */ + DBFILTERINFO dbfi; /* Filter in effect */ + LPDBORDERCONDINFO lpdbOrdCondInfo; + LPDBRELINFO lpdbRelations; /* Parent/Child relationships used */ + USHORT uiParents; /* Number of parents for this area */ + USHORT heap; + USHORT heapSize; + USHORT rddID; + + /* + * DBFS's additions to the workarea structure + * + * Warning: The above section MUST match WORKAREA exactly! Any + * additions to the structure MUST be added below, as in this + * example. + */ + + FHANDLE hDataFile; /* Data file handle */ + FHANDLE hMemoFile; /* Memo file handle */ + USHORT uiHeaderLen; /* Size of header */ + USHORT uiRecordLen; /* Size of record */ + ULONG ulRecCount; /* Total records */ + char * szDataFileName; /* Name of data file */ + char * szMemoFileName; /* Name of memo file */ + BOOL fHasMemo; /* WorkArea with Memo fields */ + BOOL fHasTags; /* WorkArea with MDX or CDX index */ + BOOL fShared; /* Shared file */ + BOOL fReadOnly; /* Read only file */ + USHORT * pFieldOffset; /* Pointer to field offset array */ + BYTE * pRecord; /* Buffer of record data */ + BOOL fValidBuffer; /* State of buffer */ + BOOL fPositioned; /* Positioned record */ + ULONG ulRecNo; /* Current record */ + BOOL fRecordChanged; /* Record changed */ + BOOL fAppend; /* TRUE if new record is added */ + BOOL fDeleted; /* TRUE if record is deleted */ + BOOL fUpdateHeader; /* Update header of file */ + BOOL fFLocked; /* TRUE if file is locked */ + LPDBRELINFO lpdbPendingRel; /* Pointer to parent rel struct */ + BYTE bYear; /* Last update */ + BYTE bMonth; + BYTE bDay; + ULONG * pLocksPos; /* List of records locked */ + ULONG ulNumLocksPos; /* Number of records locked */ +} DBFAREA; + +typedef DBFAREA * LPDBFAREA; + +#ifndef DBFAREAP +#define DBFAREAP LPDBFAREA +#endif + + + +/* + * -- DBF METHODS -- + */ + +#define SUPERTABLE ( &dbfSuper ) + +extern ERRCODE hb_dbfBof( DBFAREAP pArea, BOOL * pBof ); +extern ERRCODE hb_dbfEof( DBFAREAP pArea, BOOL * pEof ); +extern ERRCODE hb_dbfFound( DBFAREAP pArea, BOOL * pFound ); +extern ERRCODE hb_dbfGoBottom( DBFAREAP pArea ); +extern ERRCODE hb_dbfGoTo( DBFAREAP pArea, ULONG ulRecNo ); +extern ERRCODE hb_dbfGoToId( DBFAREAP pArea, PHB_ITEM pItem ); +extern ERRCODE hb_dbfGoTop( DBFAREAP pArea ); +#define hb_dbfSeek NULL +extern ERRCODE hb_dbfSkip( DBFAREAP pArea, LONG lToSkip ); +#define hb_dbfSkipFilter NULL +extern ERRCODE hb_dbfSkipRaw( DBFAREAP pArea, LONG lToSkip ); +extern ERRCODE hb_dbfAddField( DBFAREAP pArea, LPDBFIELDINFO pFieldInfo ); +extern ERRCODE hb_dbfAppend( DBFAREAP pArea, BOOL bUnLockAll ); +#define hb_dbfCreateFields NULL +extern ERRCODE hb_dbfDeleteRec( DBFAREAP pArea ); +extern ERRCODE hb_dbfDeleted( DBFAREAP pArea, BOOL * pDeleted ); +#define hb_dbfFieldCount NULL +#define hb_dbfFieldDisplay NULL +#define hb_dbfFieldInfo NULL +#define hb_dbfFieldName NULL +extern ERRCODE hb_dbfFlush( DBFAREAP pArea ); +#define hb_dbfGetRec NULL +extern ERRCODE hb_dbfGetValue( DBFAREAP pArea, USHORT uiIndex, PHB_ITEM pItem ); +extern ERRCODE hb_dbfGetVarLen( DBFAREAP pArea, USHORT uiIndex, ULONG * pLength ); +extern ERRCODE hb_dbfGoCold( DBFAREAP pArea ); +extern ERRCODE hb_dbfGoHot( DBFAREAP pArea ); +extern ERRCODE hb_dbfPutRec( DBFAREAP pArea, BYTE * pBuffer ); +extern ERRCODE hb_dbfPutValue( DBFAREAP pArea, USHORT uiIndex, PHB_ITEM pItem ); +extern ERRCODE hb_dbfRecAll( DBFAREAP pArea ); +extern ERRCODE hb_dbfRecCount( DBFAREAP pArea, ULONG * pRecCount ); +#define hb_dbfRecInfo NULL +extern ERRCODE hb_dbfRecNo( DBFAREAP pArea, PHB_ITEM pRecNo ); +extern ERRCODE hb_dbfSetFieldExtent( DBFAREAP pArea, USHORT uiFieldExtent ); +#define hb_dbfAlias NULL +extern ERRCODE hb_dbfClose( DBFAREAP pArea ); +extern ERRCODE hb_dbfCreate( DBFAREAP pArea, LPDBOPENINFO pCreateInfo ); +extern ERRCODE hb_dbfInfo( DBFAREAP pArea, USHORT uiIndex, PHB_ITEM pItem ); +extern ERRCODE hb_dbfNewArea( DBFAREAP pArea ); +extern ERRCODE hb_dbfOpen( DBFAREAP pArea, LPDBOPENINFO pOpenInfo ); +#define hb_dbfRelease NULL +extern ERRCODE hb_dbfStructSize( DBFAREAP pArea, USHORT * uiSize ); +extern ERRCODE hb_dbfSysName( DBFAREAP pArea, BYTE * pBuffer ); +#define hb_dbfEval NULL +extern ERRCODE hb_dbfPack( DBFAREAP pArea ); +#define hb_dbfPackRec NULL +extern ERRCODE hb_dbfSort( DBFAREAP pArea, LPDBSORTINFO pSortInfo ); +extern ERRCODE hb_dbfTrans( DBFAREAP pArea, LPDBTRANSINFO pTransInfo ); +extern ERRCODE hb_dbfTransRec( DBFAREAP pArea, LPDBTRANSINFO pTransInfo ); +extern ERRCODE hb_dbfZap( DBFAREAP pArea ); +extern ERRCODE hb_dbfChildEnd( DBFAREAP pArea, LPDBRELINFO pRelInfo ); +extern ERRCODE hb_dbfChildStart( DBFAREAP pArea, LPDBRELINFO pRelInfo ); +extern ERRCODE hb_dbfChildSync( DBFAREAP pArea, LPDBRELINFO pRelInfo ); +#define hb_dbfSyncChildren NULL +#define hb_dbfClearRel NULL +extern ERRCODE hb_dbfForceRel( DBFAREAP pArea ); +#define hb_dbfRelArea NULL +#define hb_dbfRelEval NULL +#define hb_dbfRelText NULL +#define hb_dbfSetRel NULL +#define hb_dbfOrderListAdd NULL +#define hb_dbfOrderListClear NULL +#define hb_dbfOrderListDelete NULL +#define hb_dbfOrderListFocus NULL +#define hb_dbfOrderListRebuild NULL +#define hb_dbfOrderCondition NULL +#define hb_dbfOrderCreate NULL +#define hb_dbfOrderDestroy NULL +#define hb_dbfOrderInfo NULL +#define hb_dbfClearFilter NULL +#define hb_dbfClearLocate NULL +#define hb_dbfClearScope NULL +#define hb_dbfCountScope NULL +#define hb_dbfFilterText NULL +#define hb_dbfScopeInfo NULL +extern ERRCODE hb_dbfSetFilter( DBFAREAP pArea, LPDBFILTERINFO pFilterInfo ); +#define hb_dbfSetLocate NULL +#define hb_dbfSetScope NULL +#define hb_dbfSkipScope NULL +#define hb_dbfCompile NULL +#define hb_dbfError NULL +#define hb_dbfEvalBlock NULL +#define hb_dbfRawLock NULL +extern ERRCODE hb_dbfLock( DBFAREAP pArea, LPDBLOCKINFO pLockInfo ); +extern ERRCODE hb_dbfUnLock( DBFAREAP pArea, ULONG ulRecNo ); +#define hb_dbfCloseMemFile NULL +#define hb_dbfCreateMemFile NULL +#define hb_dbfGetValueFile NULL +extern ERRCODE hb_dbfOpenMemFile( DBFAREAP pArea, LPDBOPENINFO pOpenInfo ); +#define hb_dbfPutValueFile NULL +extern ERRCODE hb_dbfReadDBHeader( DBFAREAP pArea ); +extern ERRCODE hb_dbfWriteDBHeader( DBFAREAP pArea ); +#define hb_dbfWhoCares NULL + +#if defined(HB_EXTERN_C) +} +#endif + +#endif /* HB_RDDDBF_H_ */ \ No newline at end of file diff --git a/harbour/include/hbrdddel.h b/harbour/include/hbrdddel.h new file mode 100644 index 0000000000..c19fdbb991 --- /dev/null +++ b/harbour/include/hbrdddel.h @@ -0,0 +1,146 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * DELIMITED 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 of the License, or + * (at your option) any later version, with one exception: + * + * The exception is that if you link the Harbour Runtime Library (HRL) + * and/or the Harbour Virtual Machine (HVM) 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 HRL + * and/or HVM code into it. + * + * 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 program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA (or visit + * their web site at http://www.gnu.org/). + * + */ + +#ifndef HB_RDDDEL_H_ +#define HB_RDDDEL_H_ + +#include "hbapirdd.h" + +#if defined(HB_EXTERN_C) +extern "C" { +#endif + +/* + * -- DELIMITED METHODS -- + */ + +#define hb_delimBof NULL +#define hb_delimEof NULL +#define hb_delimFound NULL +#define hb_delimGoBottom NULL +#define hb_delimGoTo NULL +#define hb_delimGoToId NULL +#define hb_delimGoTop NULL +#define hb_delimSeek NULL +#define hb_delimSkip NULL +#define hb_delimSkipFilter NULL +#define hb_delimSkipRaw NULL +#define hb_delimAddField NULL +#define hb_delimAppend NULL +#define hb_delimCreateFields NULL +#define hb_delimDeleteRec NULL +#define hb_delimDeleted NULL +#define hb_delimFieldCount NULL +#define hb_delimFieldDisplay NULL +#define hb_delimFieldInfo NULL +#define hb_delimFieldName NULL +#define hb_delimFlush NULL +#define hb_delimGetRec NULL +#define hb_delimGetValue NULL +#define hb_delimGetVarLen NULL +#define hb_delimGoCold NULL +#define hb_delimGoHot NULL +#define hb_delimPutRec NULL +#define hb_delimPutValue NULL +#define hb_delimRecAll NULL +#define hb_delimRecCount NULL +#define hb_delimRecInfo NULL +#define hb_delimRecNo NULL +#define hb_delimSetFieldExtent NULL +#define hb_delimAlias NULL +#define hb_delimClose NULL +#define hb_delimCreate NULL +#define hb_delimInfo NULL +#define hb_delimNewArea NULL +#define hb_delimOpen NULL +#define hb_delimRelease NULL +#define hb_delimStructSize NULL +#define hb_delimSysName NULL +#define hb_delimEval NULL +#define hb_delimPack NULL +#define hb_delimPackRec NULL +#define hb_delimSort NULL +#define hb_delimTrans NULL +#define hb_delimTransRec NULL +#define hb_delimZap NULL +#define hb_delimChildEnd NULL +#define hb_delimChildStart NULL +#define hb_delimChildSync NULL +#define hb_delimSyncChildren NULL +#define hb_delimClearRel NULL +#define hb_delimForceRel NULL +#define hb_delimRelArea NULL +#define hb_delimRelEval NULL +#define hb_delimRelText NULL +#define hb_delimSetRel NULL +#define hb_delimOrderListAdd NULL +#define hb_delimOrderListClear NULL +#define hb_delimOrderListDelete NULL +#define hb_delimOrderListFocus NULL +#define hb_delimOrderListRebuild NULL +#define hb_delimOrderCondition NULL +#define hb_delimOrderCreate NULL +#define hb_delimOrderDestroy NULL +#define hb_delimOrderInfo NULL +#define hb_delimClearFilter NULL +#define hb_delimClearLocate NULL +#define hb_delimClearScope NULL +#define hb_delimCountScope NULL +#define hb_delimFilterText NULL +#define hb_delimScopeInfo NULL +#define hb_delimSetFilter NULL +#define hb_delimSetLocate NULL +#define hb_delimSetScope NULL +#define hb_delimSkipScope NULL +#define hb_delimCompile NULL +#define hb_delimError NULL +#define hb_delimEvalBlock NULL +#define hb_delimRawLock NULL +#define hb_delimLock NULL +#define hb_delimUnLock NULL +#define hb_delimCloseMemFile NULL +#define hb_delimCreateMemFile NULL +#define hb_delimGetValueFile NULL +#define hb_delimOpenMemFile NULL +#define hb_delimPutValueFile NULL +#define hb_delimReadDBHeader NULL +#define hb_delimWriteDBHeader NULL +#define hb_delimWhoCares NULL + +#if defined(HB_EXTERN_C) +} +#endif + +#endif /* HB_RDDDEL_H_ */ \ No newline at end of file diff --git a/harbour/include/hbrddsdf.h b/harbour/include/hbrddsdf.h new file mode 100644 index 0000000000..7ae3166002 --- /dev/null +++ b/harbour/include/hbrddsdf.h @@ -0,0 +1,146 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * SDF 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 of the License, or + * (at your option) any later version, with one exception: + * + * The exception is that if you link the Harbour Runtime Library (HRL) + * and/or the Harbour Virtual Machine (HVM) 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 HRL + * and/or HVM code into it. + * + * 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 program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA (or visit + * their web site at http://www.gnu.org/). + * + */ + +#ifndef HB_RDDSDF_H_ +#define HB_RDDSDF_H_ + +#include "hbapirdd.h" + +#if defined(HB_EXTERN_C) +extern "C" { +#endif + +/* + * -- SDF METHODS -- + */ + +#define hb_sdfBof NULL +#define hb_sdfEof NULL +#define hb_sdfFound NULL +#define hb_sdfGoBottom NULL +#define hb_sdfGoTo NULL +#define hb_sdfGoToId NULL +#define hb_sdfGoTop NULL +#define hb_sdfSeek NULL +#define hb_sdfSkip NULL +#define hb_sdfSkipFilter NULL +#define hb_sdfSkipRaw NULL +#define hb_sdfAddField NULL +#define hb_sdfAppend NULL +#define hb_sdfCreateFields NULL +#define hb_sdfDeleteRec NULL +#define hb_sdfDeleted NULL +#define hb_sdfFieldCount NULL +#define hb_sdfFieldDisplay NULL +#define hb_sdfFieldInfo NULL +#define hb_sdfFieldName NULL +#define hb_sdfFlush NULL +#define hb_sdfGetRec NULL +#define hb_sdfGetValue NULL +#define hb_sdfGetVarLen NULL +#define hb_sdfGoCold NULL +#define hb_sdfGoHot NULL +#define hb_sdfPutRec NULL +#define hb_sdfPutValue NULL +#define hb_sdfRecAll NULL +#define hb_sdfRecCount NULL +#define hb_sdfRecInfo NULL +#define hb_sdfRecNo NULL +#define hb_sdfSetFieldExtent NULL +#define hb_sdfAlias NULL +#define hb_sdfClose NULL +#define hb_sdfCreate NULL +#define hb_sdfInfo NULL +#define hb_sdfNewArea NULL +#define hb_sdfOpen NULL +#define hb_sdfRelease NULL +#define hb_sdfStructSize NULL +#define hb_sdfSysName NULL +#define hb_sdfEval NULL +#define hb_sdfPack NULL +#define hb_sdfPackRec NULL +#define hb_sdfSort NULL +#define hb_sdfTrans NULL +#define hb_sdfTransRec NULL +#define hb_sdfZap NULL +#define hb_sdfChildEnd NULL +#define hb_sdfChildStart NULL +#define hb_sdfChildSync NULL +#define hb_sdfSyncChildren NULL +#define hb_sdfClearRel NULL +#define hb_sdfForceRel NULL +#define hb_sdfRelArea NULL +#define hb_sdfRelEval NULL +#define hb_sdfRelText NULL +#define hb_sdfSetRel NULL +#define hb_sdfOrderListAdd NULL +#define hb_sdfOrderListClear NULL +#define hb_sdfOrderListDelete NULL +#define hb_sdfOrderListFocus NULL +#define hb_sdfOrderListRebuild NULL +#define hb_sdfOrderCondition NULL +#define hb_sdfOrderCreate NULL +#define hb_sdfOrderDestroy NULL +#define hb_sdfOrderInfo NULL +#define hb_sdfClearFilter NULL +#define hb_sdfClearLocate NULL +#define hb_sdfClearScope NULL +#define hb_sdfCountScope NULL +#define hb_sdfFilterText NULL +#define hb_sdfScopeInfo NULL +#define hb_sdfSetFilter NULL +#define hb_sdfSetLocate NULL +#define hb_sdfSetScope NULL +#define hb_sdfSkipScope NULL +#define hb_sdfCompile NULL +#define hb_sdfError NULL +#define hb_sdfEvalBlock NULL +#define hb_sdfRawLock NULL +#define hb_sdfLock NULL +#define hb_sdfUnLock NULL +#define hb_sdfCloseMemFile NULL +#define hb_sdfCreateMemFile NULL +#define hb_sdfGetValueFile NULL +#define hb_sdfOpenMemFile NULL +#define hb_sdfPutValueFile NULL +#define hb_sdfReadDBHeader NULL +#define hb_sdfWriteDBHeader NULL +#define hb_sdfWhoCares NULL + +#if defined(HB_EXTERN_C) +} +#endif + +#endif /* HB_RDDSDF_H_ */ \ No newline at end of file diff --git a/harbour/include/hbrddwrk.h b/harbour/include/hbrddwrk.h new file mode 100644 index 0000000000..50b30f6d47 --- /dev/null +++ b/harbour/include/hbrddwrk.h @@ -0,0 +1,146 @@ +/* + * $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 of the License, or + * (at your option) any later version, with one exception: + * + * The exception is that if you link the Harbour Runtime Library (HRL) + * and/or the Harbour Virtual Machine (HVM) 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 HRL + * and/or HVM code into it. + * + * 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 program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA (or visit + * their web site at http://www.gnu.org/). + * + */ + +#ifndef HB_RDDWRK_H_ +#define HB_RDDWRK_H_ + +#include "hbapirdd.h" + +#if defined(HB_EXTERN_C) +extern "C" { +#endif + +/* + * -- 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_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 ); +#define hb_waCreate ( DBENTRYP_VP ) hb_waUnsupported +extern ERRCODE hb_waInfo( AREAP pArea, USHORT uiIndex, PHB_ITEM pItem ); +extern ERRCODE hb_waNewArea( AREAP pArea ); +#define hb_waOpen ( DBENTRYP_VP ) hb_waUnsupported +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_VP ) hb_waUnsupported +#define hb_waOrderListFocus ( DBENTRYP_OI ) hb_waUnsupported +#define hb_waOrderListRebuild hb_waUnsupported +#define hb_waOrderCondition ( DBENTRYP_VOI ) hb_waUnsupported +#define hb_waOrderCreate ( DBENTRYP_VOC ) hb_waUnsupported +#define hb_waOrderDestroy ( DBENTRYP_OI ) hb_waUnsupported +#define hb_waOrderInfo ( DBENTRYP_OII ) hb_waNull +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_VP ) hb_waUnsupported +#define hb_waSkipScope ( DBENTRYP_VPL ) hb_waUnsupported +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_UL ) 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_SVP ) hb_waUnsupported +#define hb_waReadDBHeader hb_waUnsupported +#define hb_waWriteDBHeader hb_waUnsupported +#define hb_waWhoCares ( DBENTRYP_SVP ) hb_waUnsupported + +#if defined(HB_EXTERN_C) +} +#endif + +#endif /* HB_RDDWRK_H_ */ \ No newline at end of file diff --git a/harbour/makefile.bc b/harbour/makefile.bc index 57fff189d6..1b630bee6e 100644 --- a/harbour/makefile.bc +++ b/harbour/makefile.bc @@ -366,6 +366,7 @@ MACRO_LIB_OBJS = \ RDD_LIB_OBJS = \ $(OBJ_DIR)\dbcmd.obj \ + $(OBJ_DIR)\workarea.obj \ $(OBJ_DIR)\dbf1.obj \ $(OBJ_DIR)\dbnubs.obj \ $(OBJ_DIR)\delim1.obj \ @@ -373,6 +374,8 @@ RDD_LIB_OBJS = \ \ $(OBJ_DIR)\dbf0.obj \ $(OBJ_DIR)\dblist.obj \ + $(OBJ_DIR)\dbsort.obj \ + $(OBJ_DIR)\hbdbsort.obj \ $(OBJ_DIR)\dbstrux.obj \ $(OBJ_DIR)\dbupdat.obj \ $(OBJ_DIR)\delim0.obj \ @@ -383,14 +386,20 @@ RDD_LIB_OBJS = \ NULSYS_LIB_OBJS = \ $(OBJ_DIR)\nulsys.obj +#DBFNTX_LIB_OBJS = \ +# $(OBJ_DIR)\dbfntx1.obj \ +# \ +# $(OBJ_DIR)\dbfntx0.obj + DBFNTX_LIB_OBJS = \ - $(OBJ_DIR)\dbfntx1.obj \ - \ $(OBJ_DIR)\dbfntx0.obj +#DBFCDX_LIB_OBJS = \ +# $(OBJ_DIR)\dbfcdx1.obj \ +# \ +# $(OBJ_DIR)\dbfcdx0.obj + DBFCDX_LIB_OBJS = \ - $(OBJ_DIR)\dbfcdx1.obj \ - \ $(OBJ_DIR)\dbfcdx0.obj # @@ -776,6 +785,10 @@ $(OBJ_DIR)\dbcmd.obj : $(RDD_DIR)\dbcmd.c $(CC) $(CLIBFLAGS) -o$@ $** tlib $(RDD_LIB) $(ARFLAGS) -+$@,, +$(OBJ_DIR)\workarea.obj : $(RDD_DIR)\workarea.c + $(CC) $(CLIBFLAGS) -o$@ $** + tlib $(RDD_LIB) $(ARFLAGS) -+$@,, + $(OBJ_DIR)\dbf0.c : $(RDD_DIR)\dbf0.prg $(HARBOUR_EXE) $(HARBOURFLAGS) $** -o$@ @@ -794,6 +807,17 @@ $(OBJ_DIR)\dblist.obj : $(OBJ_DIR)\dblist.c $(CC) $(CLIBFLAGS) -o$@ $** tlib $(RDD_LIB) $(ARFLAGS) -+$@,, +$(OBJ_DIR)\dbsort.c : $(RDD_DIR)\dbsort.prg + $(HARBOUR_EXE) $(HARBOURFLAGS) $** -o$@ + +$(OBJ_DIR)\dbsort.obj : $(OBJ_DIR)\dbsort.c + $(CC) $(CLIBFLAGS) -o$@ $** + tlib $(RDD_LIB) $(ARFLAGS) -+$@,, + +$(OBJ_DIR)\hbdbsort.obj : $(RDD_DIR)\hbdbsort.c + $(CC) $(CLIBFLAGS) -o$@ $** + tlib $(RDD_LIB) $(ARFLAGS) -+$@,, + $(OBJ_DIR)\dbnubs.obj : $(RDD_DIR)\dbnubs.c $(CC) $(CLIBFLAGS) -o$@ $** tlib $(RDD_LIB) $(ARFLAGS) -+$@,, @@ -1865,9 +1889,9 @@ $(OBJ_DIR)\dbfntx0.obj : $(OBJ_DIR)\dbfntx0.c $(CC) $(CLIBFLAGS) -o$@ $** tlib $(DBFNTX_LIB) $(ARFLAGS) -+$@,, -$(OBJ_DIR)\dbfntx1.obj : $(RDD_DIR)\dbfntx\dbfntx1.c - $(CC) $(CLIBFLAGS) -o$@ $** - tlib $(DBFNTX_LIB) $(ARFLAGS) -+$@,, +#$(OBJ_DIR)\dbfntx1.obj : $(RDD_DIR)\dbfntx\dbfntx1.c +# $(CC) $(CLIBFLAGS) -o$@ $** +# tlib $(DBFNTX_LIB) $(ARFLAGS) -+$@,, # # DBFCDX.LIB dependencies @@ -1880,9 +1904,9 @@ $(OBJ_DIR)\dbfcdx0.obj : $(OBJ_DIR)\dbfcdx0.c $(CC) $(CLIBFLAGS) -o$@ $** tlib $(DBFCDX_LIB) $(ARFLAGS) -+$@,, -$(OBJ_DIR)\dbfcdx1.obj : $(RDD_DIR)\dbfcdx\dbfcdx1.c - $(CC) $(CLIBFLAGS) -o$@ $** - tlib $(DBFCDX_LIB) $(ARFLAGS) -+$@,, +#$(OBJ_DIR)\dbfcdx1.obj : $(RDD_DIR)\dbfcdx\dbfcdx1.c +# $(CC) $(CLIBFLAGS) -o$@ $** +# tlib $(DBFCDX_LIB) $(ARFLAGS) -+$@,, # # DEBUG.LIB dependencies @@ -2262,4 +2286,4 @@ $(OBJ_DIR)\ft_funcs.c : $(HBDOC_DIR)\ft_funcs.prg $(HARBOUR_EXE) $(HARBOURFLAGS) $** -o$@ $(OBJ_DIR)\ft_funcs.obj : $(OBJ_DIR)\ft_funcs.c - $(CC) $(CLIBFLAGS) -o$@ $** + $(CC) $(CLIBFLAGS) -o$@ $** \ No newline at end of file diff --git a/harbour/makefile.vc b/harbour/makefile.vc index 35021f6c90..40df052ca8 100644 --- a/harbour/makefile.vc +++ b/harbour/makefile.vc @@ -402,6 +402,7 @@ MACRO_LIB_OBJS = \ RDD_LIB_OBJS = \ $(OBJ_DIR)\dbcmd.obj \ + $(OBJ_DIR)\workarea.obj \ $(OBJ_DIR)\dbf1.obj \ $(OBJ_DIR)\dbnubs.obj \ $(OBJ_DIR)\delim1.obj \ @@ -409,6 +410,8 @@ RDD_LIB_OBJS = \ \ $(OBJ_DIR)\dbf0.obj \ $(OBJ_DIR)\dblist.obj \ + $(OBJ_DIR)\dbsort.obj \ + $(OBJ_DIR)\hbdbsort.obj \ $(OBJ_DIR)\dbstrux.obj \ $(OBJ_DIR)\dbupdat.obj \ $(OBJ_DIR)\delim0.obj \ @@ -443,9 +446,11 @@ NULSYS_LIB_OBJS = \ $(HARBOUR_EXE) $(HARBOURFLAGS) -o$(OBJ_DIR)\ $< $(MAKE) -nologo /$(MK_FLAGS) /f$(MK_FILE) $(DBFNTX_LIB)2 +#DBFNTX_LIB_OBJS = \ +# $(OBJ_DIR)\dbfntx1.obj \ +# \ +# $(OBJ_DIR)\dbfntx0.obj DBFNTX_LIB_OBJS = \ - $(OBJ_DIR)\dbfntx1.obj \ - \ $(OBJ_DIR)\dbfntx0.obj # @@ -459,9 +464,11 @@ DBFNTX_LIB_OBJS = \ $(HARBOUR_EXE) $(HARBOURFLAGS) -o$(OBJ_DIR)\ $< $(MAKE) -nologo /$(MK_FLAGS) /f$(MK_FILE) $(DBFCDX_LIB)2 +#DBFCDX_LIB_OBJS = \ +# $(OBJ_DIR)\dbfcdx1.obj \ +# \ +# $(OBJ_DIR)\dbfcdx0.obj DBFCDX_LIB_OBJS = \ - $(OBJ_DIR)\dbfcdx1.obj \ - \ $(OBJ_DIR)\dbfcdx0.obj # diff --git a/harbour/source/rdd/Makefile b/harbour/source/rdd/Makefile index f1ffdcc569..be392e9b30 100644 --- a/harbour/source/rdd/Makefile +++ b/harbour/source/rdd/Makefile @@ -6,14 +6,17 @@ ROOT = ../../ C_SOURCES=\ dbcmd.c \ + workarea.c \ dbf1.c \ dbnubs.c \ sdf1.c \ delim1.c \ + hbdbsort.c \ PRG_SOURCES=\ dbf0.prg \ dblist.prg \ + dbsort.prg \ dbstrux.prg \ dbupdat.prg \ sdf0.prg \ diff --git a/harbour/source/rdd/dbcmd.c b/harbour/source/rdd/dbcmd.c index 9fb64f2cff..e8edeff789 100644 --- a/harbour/source/rdd/dbcmd.c +++ b/harbour/source/rdd/dbcmd.c @@ -34,42 +34,40 @@ */ #include - -#include "hbapi.h" -#include "hbapiitm.h" -#include "hbapierr.h" -#include "hbapirdd.h" -#include "hbapilng.h" -#include "hbset.h" #include "hbvm.h" +#include "hbapifs.h" +#include "hbset.h" +#include "hbapierr.h" +#include "hbapilng.h" +#include "hbapiitm.h" +#include "hbrddwrk.h" -#include "rddsys.ch" -#include "set.ch" -#define HARBOUR_MAX_RDD_DRIVERNAME_LENGTH 32 -#define HARBOUR_MAX_RDD_ALIAS_LENGTH 32 -#define HARBOUR_MAX_RDD_FIELDNAME_LENGTH 32 typedef struct _RDDNODE { - char szName[ HARBOUR_MAX_RDD_DRIVERNAME_LENGTH + 1 ]; - USHORT uiType; /* Type of RDD */ - RDDFUNCS pTable; /* Table of functions */ - USHORT uiAreaSize; /* Size of the WorkArea */ - struct _RDDNODE * pNext; /* Next RDD in the list */ + char szName[ HARBOUR_MAX_RDD_DRIVERNAME_LENGTH + 1 ]; /* Name of RDD */ + USHORT uiType; /* Type of RDD */ + RDDFUNCS pTable; /* Table of functions */ + USHORT uiAreaSize; /* Size of the WorkArea */ + struct _RDDNODE * pNext; /* Next RDD in the list */ } RDDNODE; typedef RDDNODE * LPRDDNODE; + + typedef struct _AREANODE { - void * pArea; /* WorkAreas with different sizes */ + void * pArea; /* WorkAreas with different sizes */ struct _AREANODE * pPrev; /* Prev WorkArea in the list */ struct _AREANODE * pNext; /* Next WorkArea in the list */ } AREANODE; typedef AREANODE * LPAREANODE; + + extern HB_FUNC( _DBF ); extern HB_FUNC( _SDF ); extern HB_FUNC( _DELIM ); @@ -84,840 +82,144 @@ static LPAREANODE s_pWorkAreas = NULL; /* WorkAreas */ static LPAREANODE s_pCurrArea = NULL; /* Pointer to a selectd and valid area */ /* - * -- BASIC RDD METHODS -- + * -- DEFAULT METHODS -- */ -static ERRCODE defAddField( AREAP pArea, LPDBFIELDINFO pFieldInfo ) -{ - LPFIELD pField; - ULONG ulLen; - - HB_TRACE(HB_TR_DEBUG, ("defAddField(%p, %p)", pArea, pFieldInfo)); - - /* Validate the name of field */ - ulLen = strlen( ( char * ) pFieldInfo->atomName ); - hb_strLTrim( ( char * ) pFieldInfo->atomName, &ulLen ); - if( !ulLen ) - return FAILURE; - - pField = pArea->lpFields + pArea->uiFieldCount; - if( pArea->uiFieldCount > 0 ) - { - ( ( LPFIELD ) ( pField - 1 ) )->lpfNext = pField; - if( ( ( LPFIELD ) ( pField - 1 ) )->uiType == 'C' ) - pField->uiOffset = ( ( LPFIELD ) ( pField - 1 ) )->uiOffset + - ( ( LPFIELD ) ( pField - 1 ) )->uiLen + - ( ( USHORT ) ( ( LPFIELD ) ( pField - 1 ) )->uiDec << 8 ); - else - pField->uiOffset = ( ( LPFIELD ) ( pField - 1 ) )->uiOffset + - ( ( LPFIELD ) ( pField - 1 ) )->uiLen; - } - else - pField->uiOffset = 1; - - pField->sym = ( void * ) hb_dynsymGet( ( char * ) pFieldInfo->atomName ); - pField->uiType = pFieldInfo->uiType; - pField->uiTypeExtended = pFieldInfo->typeExtended; - pField->uiLen = pFieldInfo->uiLen; - pField->uiDec = pFieldInfo->uiDec; - pField->uiArea = pArea->uiArea; - - pArea->uiFieldCount++; - - return SUCCESS; -} - -static ERRCODE defAlias( AREAP pArea, BYTE * szAlias ) -{ - HB_TRACE(HB_TR_DEBUG, ("defAlias(%p, %p)", pArea, szAlias)); - - strncpy( ( char * ) szAlias, - ( ( PHB_DYNS ) pArea->atomAlias )->pSymbol->szName, - HARBOUR_MAX_RDD_ALIAS_LENGTH ); - return SUCCESS; -} - -static ERRCODE defBof( AREAP pArea, BOOL * pBof ) -{ - HB_TRACE(HB_TR_DEBUG, ("defBof(%p, %p)", pArea, pBof)); - - * pBof = pArea->fBof; - return SUCCESS; -} - -static ERRCODE defClearFilter( AREAP pArea ) -{ - HB_TRACE(HB_TR_DEBUG, ("defClearFilter(%p)", pArea)); - - if( pArea->dbfi.fFilter ) - { - hb_itemRelease( pArea->dbfi.itmCobExpr ); - hb_itemRelease( pArea->dbfi.abFilterText ); - pArea->dbfi.fFilter = FALSE; - } - return SUCCESS; -} - -static ERRCODE defClearLocate( AREAP pArea ) -{ - HB_TRACE(HB_TR_DEBUG, ("defClearLocate(%p)", pArea)); - - if( pArea->dbsi.itmCobFor ) - { - hb_itemRelease( pArea->dbsi.itmCobFor ); - pArea->dbsi.itmCobFor = NULL; - } - if( pArea->dbsi.lpstrFor ) - { - hb_itemRelease( pArea->dbsi.lpstrFor ); - pArea->dbsi.lpstrFor = NULL; - } - if( pArea->dbsi.itmCobWhile ) - { - hb_itemRelease( pArea->dbsi.itmCobWhile ); - pArea->dbsi.itmCobWhile = NULL; - } - if( pArea->dbsi.lpstrWhile ) - { - hb_itemRelease( pArea->dbsi.lpstrWhile ); - pArea->dbsi.lpstrWhile = NULL; - } - if( pArea->dbsi.lNext ) - { - hb_itemRelease( pArea->dbsi.lNext ); - pArea->dbsi.lNext = NULL; - } - if( pArea->dbsi.itmRecID ) - { - hb_itemRelease( pArea->dbsi.itmRecID ); - pArea->dbsi.itmRecID = NULL; - } - if( pArea->dbsi.fRest ) - { - hb_itemRelease( pArea->dbsi.fRest ); - pArea->dbsi.fRest = NULL; - } - return SUCCESS; -} - -static ERRCODE defClose( AREAP pArea ) -{ - HB_TRACE(HB_TR_DEBUG, ("defClose(%p)", pArea)); - - SELF_CLEARFILTER( pArea ); - SELF_CLEARLOCATE( pArea ); - SELF_CLEARREL( pArea ); - ( ( PHB_DYNS ) pArea->atomAlias )->hArea = 0; - return SUCCESS; -} - -static ERRCODE defCompile( AREAP pArea, BYTE * szExpr ) -{ - HB_MACRO_PTR pMacro; - - HB_TRACE(HB_TR_DEBUG, ("defCompile(%p, %p)", pArea, szExpr)); - - pMacro = hb_macroCompile( ( char * ) szExpr ); - if( pMacro ) - { - pArea->valResult = hb_itemPutPtr( pArea->valResult, ( void * ) pMacro ); - return SUCCESS; - } - else - return FAILURE; -} - -static ERRCODE defCreateFields( AREAP pArea, PHB_ITEM pStruct ) -{ - DBFIELDINFO pFieldInfo; - USHORT uiCount; - USHORT uiItems; - - HB_TRACE(HB_TR_DEBUG, ("defCreateFields(%p, %p)", pArea, pStruct)); - - uiItems = ( USHORT ) hb_arrayLen( pStruct ); - SELF_SETFIELDEXTENT( pArea, uiItems ); - pFieldInfo.typeExtended = 0; - for( uiCount = 0; uiCount < uiItems; uiCount++ ) - { - PHB_ITEM pFieldDesc; - long lLong; - - pFieldDesc = hb_arrayGetItemPtr( pStruct, uiCount + 1 ); - pFieldInfo.uiType = toupper( hb_arrayGetCPtr( pFieldDesc, 2 )[ 0 ] ); - pFieldInfo.atomName = ( BYTE * ) hb_arrayGetCPtr( pFieldDesc, 1 ); - lLong = hb_arrayGetNL( pFieldDesc, 3 ); - if( lLong < 0 ) - lLong = 0; - pFieldInfo.uiLen = ( USHORT ) lLong; - lLong = hb_arrayGetNL( pFieldDesc, 4 ); - if( lLong < 0 ) - lLong = 0; - pFieldInfo.uiDec = ( USHORT ) lLong; - if( SELF_ADDFIELD( pArea, &pFieldInfo ) == FAILURE ) - return FAILURE; - } - return SUCCESS; -} - -static ERRCODE defEof( AREAP pArea, BOOL * pEof ) -{ - HB_TRACE(HB_TR_DEBUG, ("defEof(%p, %p)", pArea, pEof)); - - * pEof = pArea->fEof; - return SUCCESS; -} - -static ERRCODE defError( AREAP pArea, PHB_ITEM pError ) -{ - char * szRddName; - - HB_TRACE(HB_TR_DEBUG, ("defError(%p, %p)", pArea, pError)); - - szRddName = ( char * ) hb_xgrab( HARBOUR_MAX_RDD_DRIVERNAME_LENGTH + 1 ); - SELF_SYSNAME( pArea, ( BYTE * ) szRddName ); - hb_errPutSeverity( pError, ES_ERROR ); - hb_errPutSubSystem( pError, szRddName ); - hb_xfree( szRddName ); - return hb_errLaunch( pError ); -} - -static ERRCODE defEval( AREAP pArea, LPDBEVALINFO pEvalInfo ) -{ - BOOL bEof, bFor, bWhile; - ULONG ulNext = 0; - - HB_TRACE(HB_TR_DEBUG, ("defEval(%p, %p)", pArea, pEvalInfo)); - - if( pEvalInfo->dbsci.itmRecID ) - { - SELF_GOTOID( pArea, pEvalInfo->dbsci.itmRecID ); - SELF_EOF( pArea, &bEof ); - if( !bEof ) - { - if( pEvalInfo->dbsci.itmCobWhile ) - { - bWhile = hb_itemGetL( hb_vmEvalBlock( pEvalInfo->dbsci.itmCobWhile ) ); - } - else - bWhile = TRUE; - - if( pEvalInfo->dbsci.itmCobFor ) - { - bFor = hb_itemGetL( hb_vmEvalBlock( pEvalInfo->dbsci.itmCobFor ) ); - } - else - bFor = TRUE; - - if( bWhile && bFor ) - { - hb_vmEvalBlock( pEvalInfo->itmBlock ); - } - } - return SUCCESS; - } - - if( !pEvalInfo->dbsci.fRest || !hb_itemGetL( pEvalInfo->dbsci.fRest ) ) - SELF_GOTOP( pArea ); - - if( pEvalInfo->dbsci.lNext ) - ulNext = hb_itemGetNL( pEvalInfo->dbsci.lNext ); - - SELF_EOF( pArea, &bEof ); - while( !bEof ) - { - if( pEvalInfo->dbsci.lNext && ulNext-- < 1 ) - break; - - if( pEvalInfo->dbsci.itmCobWhile ) - { - bWhile = hb_itemGetL( hb_vmEvalBlock( pEvalInfo->dbsci.itmCobWhile ) ); - if( !bWhile ) - break; - } - else - bWhile = TRUE; - - if( pEvalInfo->dbsci.itmCobFor ) - { - bFor = hb_itemGetL( hb_vmEvalBlock( pEvalInfo->dbsci.itmCobFor ) ); - } - else - bFor = TRUE; - - if( bFor && bWhile ) - { - hb_vmEvalBlock( pEvalInfo->itmBlock ); - } - SELF_SKIP( pArea, 1 ); - SELF_EOF( pArea, &bEof ); - } - - return SUCCESS; -} - -static ERRCODE defEvalBlock( AREAP pArea, PHB_ITEM pBlock ) -{ - PHB_ITEM pResult; - - HB_TRACE(HB_TR_DEBUG, ("defEvalBlock(%p, %p)", pArea, pBlock)); - - if( ! pBlock || ! HB_IS_BLOCK( pBlock ) ) - { - PHB_ITEM pError; - - pError = hb_errNew(); - hb_errPutGenCode( pError, EG_NOMETHOD ); - hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_NOMETHOD ) ); - SELF_ERROR( pArea, pError ); - hb_errRelease( pError ); - return FAILURE; - } - - pResult = hb_vmEvalBlock( pBlock ); - if( ! pArea->valResult ) - pArea->valResult = hb_itemNew( NULL ); - hb_itemCopy( pArea->valResult, pResult ); - - return SUCCESS; -} - -static ERRCODE defclearRel( AREAP pArea ) -{ - LPDBRELINFO lpdbRelations = pArea->lpdbRelations; - LPDBRELINFO lpdbRelPrev; - - HB_TRACE(HB_TR_DEBUG, ("defclearRel(%p)", pArea )); - - if( lpdbRelations ) - { - do - { - ( ( AREAP ) lpdbRelations->lpaChild )->uiParents--; - lpdbRelPrev = lpdbRelations; - lpdbRelations = lpdbRelations->lpdbriNext; - hb_xfree( lpdbRelPrev ); - } - while( lpdbRelations ); - pArea->lpdbRelations = NULL; - } - return SUCCESS; -} - -static ERRCODE defsetRel( AREAP pArea, LPDBRELINFO lpdbRelInf ) -{ - LPDBRELINFO lpdbRelations; - - ( ( AREAP ) lpdbRelInf->lpaChild )->uiParents++; - lpdbRelations = pArea->lpdbRelations; - if( ! lpdbRelations ) - { - pArea->lpdbRelations = ( LPDBRELINFO ) hb_xgrab( sizeof( DBRELINFO ) ); - lpdbRelations = pArea->lpdbRelations; - } - else - { - while( lpdbRelations->lpdbriNext ) - lpdbRelations = lpdbRelations->lpdbriNext; - lpdbRelations->lpdbriNext = ( LPDBRELINFO ) hb_xgrab( sizeof( DBRELINFO ) ); - lpdbRelations = lpdbRelations->lpdbriNext; - } - lpdbRelations->lpaChild = lpdbRelInf->lpaChild; - lpdbRelations->itmCobExpr = lpdbRelInf->itmCobExpr; - lpdbRelations->abKey = lpdbRelInf->abKey; - lpdbRelations->lpdbriNext = lpdbRelInf->lpdbriNext; - - return SUCCESS; -} - -static ERRCODE defrelText( AREAP pArea, USHORT relNum, char * cExpr ) +/* + * Empty method. + */ +static ERRCODE hb_waNull( AREAP pArea ) { + HB_TRACE(HB_TR_DEBUG, ("hb_waNull(%p)", pArea)); HB_SYMBOL_UNUSED( pArea ); - HB_SYMBOL_UNUSED( relNum ); - HB_SYMBOL_UNUSED( cExpr ); return SUCCESS; } -static ERRCODE defFieldCount( AREAP pArea, USHORT * uiFields ) -{ - HB_TRACE(HB_TR_DEBUG, ("defFieldCount(%p, %p)", pArea, uiFields)); - - *uiFields = pArea->uiFieldCount; - - return SUCCESS; -} - -static ERRCODE defFieldInfo( AREAP pArea, USHORT uiIndex, USHORT uiType, PHB_ITEM pItem ) -{ - LPFIELD pField; - char szType[ 2 ]; - - HB_TRACE(HB_TR_DEBUG, ("defFieldInfo(%p, %hu, %hu, %p)", pArea, uiIndex, uiType, pItem)); - - if( uiIndex > pArea->uiFieldCount ) - return FAILURE; - - pField = pArea->lpFields + uiIndex - 1; - switch( uiType ) - { - case DBS_NAME: - hb_itemPutC( pItem, ( ( PHB_DYNS ) pField->sym )->pSymbol->szName ); - break; - - case DBS_TYPE: - szType[ 0 ] = ( char ) pField->uiType; - szType[ 1 ] = '\0'; - hb_itemPutC( pItem, szType ); - break; - - case DBS_LEN: - hb_itemPutNL( pItem, pField->uiLen ); - break; - - case DBS_DEC: - hb_itemPutNL( pItem, pField->uiDec ); - break; - - default: - return FAILURE; - - } - return SUCCESS; -} - - -static ERRCODE defFieldName( AREAP pArea, USHORT uiIndex, void * szName ) -{ - LPFIELD pField; - - HB_TRACE(HB_TR_DEBUG, ("defFieldName(%p, %hu, %p)", pArea, uiIndex, szName)); - - if( uiIndex > pArea->uiFieldCount ) - return FAILURE; - - pField = pArea->lpFields + uiIndex - 1; - strncpy( ( char * ) szName, ( ( PHB_DYNS ) pField->sym )->pSymbol->szName, - HARBOUR_MAX_RDD_FIELDNAME_LENGTH ); - return SUCCESS; -} - -static ERRCODE defFilterText( AREAP pArea, PHB_ITEM pFilter ) -{ - HB_TRACE(HB_TR_DEBUG, ("defFilterText(%p, %p)", pArea, pFilter)); - - if( pArea->dbfi.fFilter ) - hb_itemCopy( pFilter, pArea->dbfi.abFilterText ); - return SUCCESS; -} - -static ERRCODE defFound( AREAP pArea, BOOL * pFound ) -{ - HB_TRACE(HB_TR_DEBUG, ("defFound(%p, %p)", pArea, pFound)); - - * pFound = pArea->fFound; - return SUCCESS; -} - -static ERRCODE defNewArea( AREAP pArea ) -{ - HB_TRACE(HB_TR_DEBUG, ("defNewArea(%p)", pArea)); - - pArea->lpDataInfo = ( LPFILEINFO ) hb_xgrab( sizeof( FILEINFO ) ); - memset( pArea->lpDataInfo, 0, sizeof( FILEINFO ) ); - pArea->lpDataInfo->hFile = FS_ERROR; - pArea->lpExtendInfo = ( LPDBEXTENDINFO ) hb_xgrab( sizeof( DBEXTENDINFO ) ); - memset( pArea->lpExtendInfo, 0, sizeof( DBEXTENDINFO ) ); - pArea->lpdbRelations = NULL; - pArea->uiParents = 0; - return SUCCESS; -} - -static ERRCODE defOpen( AREAP pArea, LPDBOPENINFO pOpenInfo ) -{ - HB_TRACE(HB_TR_DEBUG, ("defOpen(%p, %p)", pArea, pOpenInfo)); - - pArea->atomAlias = hb_dynsymGet( ( char * ) pOpenInfo->atomAlias ); - if( ( ( PHB_DYNS ) pArea->atomAlias )->hArea ) - { - hb_errRT_DBCMD( EG_DUPALIAS, 1011, NULL, ( char * ) pOpenInfo->atomAlias ); - return FAILURE; - } - - ( ( PHB_DYNS ) pArea->atomAlias )->hArea = pOpenInfo->uiArea; - pArea->lpExtendInfo->fExclusive = !pOpenInfo->fShared; - pArea->lpExtendInfo->fReadOnly = pOpenInfo->fReadonly; - - return SUCCESS; -} - -static ERRCODE defOrderCondition( AREAP pArea, LPDBORDERCONDINFO pOrderInfo ) -{ - if( pArea->lpdbOrdCondInfo ) - { - if( pArea->lpdbOrdCondInfo->abFor ) - hb_xfree( pArea->lpdbOrdCondInfo->abFor ); - if( pArea->lpdbOrdCondInfo->itmCobFor ) - hb_itemRelease( pArea->lpdbOrdCondInfo->itmCobFor ); - if( pArea->lpdbOrdCondInfo->itmCobWhile ) - hb_itemRelease( pArea->lpdbOrdCondInfo->itmCobWhile ); - if( pArea->lpdbOrdCondInfo->itmCobEval ) - hb_itemRelease( pArea->lpdbOrdCondInfo->itmCobEval ); - hb_xfree( pArea->lpdbOrdCondInfo ); - } - pArea->lpdbOrdCondInfo = pOrderInfo; - - return SUCCESS; -} - -static ERRCODE defRelease( AREAP pArea ) -{ - HB_TRACE(HB_TR_DEBUG, ("defRelease(%p)", pArea)); - - SELF_ORDSETCOND( pArea, NULL ); - - if( pArea->valResult ) - hb_itemRelease( pArea->valResult ); - - if( pArea->lpFields ) - { - hb_xfree( pArea->lpFields ); - pArea->uiFieldCount = 0; - } - - while( pArea->lpDataInfo ) - { - LPFILEINFO pFileInfo; - - pFileInfo = pArea->lpDataInfo; - pArea->lpDataInfo = pArea->lpDataInfo->pNext; - if( pFileInfo->szFileName ) - hb_xfree( pFileInfo->szFileName ); - hb_xfree( pFileInfo ); - } - - if( pArea->lpExtendInfo ) - { - if( pArea->lpExtendInfo->bRecord ) - hb_xfree( pArea->lpExtendInfo->bRecord ); - hb_xfree( pArea->lpExtendInfo ); - } - - return SUCCESS; -} - -static ERRCODE defSetFieldExtent( AREAP pArea, USHORT uiFieldExtent ) -{ - HB_TRACE(HB_TR_DEBUG, ("defSetFieldExtent(%p, %hu)", pArea, uiFieldExtent)); - - pArea->uiFieldExtent = uiFieldExtent; - pArea->lpFields = ( LPFIELD ) hb_xgrab( uiFieldExtent * sizeof( FIELD ) ); - memset( pArea->lpFields, 0, uiFieldExtent * sizeof( FIELD ) ); - return SUCCESS; -} - -static ERRCODE defSetFilter( AREAP pArea, LPDBFILTERINFO pFilterInfo ) -{ - HB_TRACE(HB_TR_DEBUG, ("defSetFilter(%p, %p)", pArea, pFilterInfo)); - - if( pArea->dbfi.fFilter ) - { - hb_itemCopy( pArea->dbfi.itmCobExpr, pFilterInfo->itmCobExpr ); - hb_itemCopy( pArea->dbfi.abFilterText, pFilterInfo->abFilterText ); - } - else - { - pArea->dbfi.itmCobExpr = hb_itemNew( NULL ); - hb_itemCopy( pArea->dbfi.itmCobExpr, pFilterInfo->itmCobExpr ); - pArea->dbfi.abFilterText = hb_itemNew( NULL ); - hb_itemCopy( pArea->dbfi.abFilterText, pFilterInfo->abFilterText ); - pArea->dbfi.fFilter = TRUE; - } - return SUCCESS; -} - -static ERRCODE defSetLocate( AREAP pArea, LPDBSCOPEINFO pScopeInfo ) -{ - HB_TRACE(HB_TR_DEBUG, ("defSetLocate(%p, %p)", pArea, pScopeInfo)); - - if( pArea->dbsi.itmCobFor ) - hb_itemRelease( pArea->dbsi.itmCobFor ); - pArea->dbsi.itmCobFor = pScopeInfo->itmCobFor; - if( pArea->dbsi.itmCobWhile ) - hb_itemRelease( pArea->dbsi.itmCobWhile ); - pArea->dbsi.itmCobWhile = pScopeInfo->itmCobWhile; - if( pArea->dbsi.lNext ) - hb_itemRelease( pArea->dbsi.lNext ); - pArea->dbsi.lNext = pScopeInfo->lNext; - if( pArea->dbsi.itmRecID ) - hb_itemRelease( pArea->dbsi.itmRecID ); - pArea->dbsi.itmRecID = pScopeInfo->itmRecID; - if( pArea->dbsi.fRest ) - hb_itemRelease( pArea->dbsi.fRest ); - pArea->dbsi.fRest = pScopeInfo->fRest; - return SUCCESS; -} - -static ERRCODE defSkip( AREAP pArea, LONG lToSkip ) -{ - BOOL bExit; - - HB_TRACE(HB_TR_DEBUG, ("defSkip(%p, %ld)", pArea, lToSkip)); - - if( pArea->dbfi.fFilter || hb_set.HB_SET_DELETED ) - { - if( lToSkip > 0 ) - { - while( lToSkip > 0 ) - { - SELF_SKIPRAW( pArea, 1 ); - SELF_SKIPFILTER( pArea, 1 ); - - SELF_EOF( pArea, &bExit ); - if( bExit ) - return SUCCESS; - - lToSkip--; - } - } - else if( lToSkip < 0 ) - { - while( lToSkip < 0 ) - { - SELF_SKIPRAW( pArea, -1 ); - SELF_SKIPFILTER( pArea, -1 ); - - SELF_BOF( pArea, &bExit ); - if( bExit ) - return SELF_SKIPFILTER( pArea, 1 ); - - lToSkip++; - } - } - else - { - SELF_SKIPRAW( pArea, 0 ); - SELF_SKIPFILTER( pArea, 1 ); - - SELF_EOF( pArea, &bExit ); - if( bExit ) - return SUCCESS; - } - } - - return SELF_SKIPRAW( pArea, lToSkip ); -} - -static ERRCODE defSkipFilter( AREAP pArea, LONG lUpDown ) -{ - BOOL bExit, bDeleted; - - HB_TRACE(HB_TR_DEBUG, ("defSkipFilter(%p, %ld)", pArea, lUpDown)); - - if( lUpDown > 0 ) - { - while( TRUE ) - { - SELF_EOF( pArea, &bExit ); - if( bExit ) - return SUCCESS; - - /* SET DELETED */ - if( hb_set.HB_SET_DELETED ) - { - SELF_DELETED( pArea, &bDeleted ); - if( bDeleted ) - { - SELF_SKIPRAW( pArea, 1 ); - continue; - } - } - - /* SET FILTER TO */ - if( pArea->dbfi.fFilter ) - { - PHB_ITEM pResult = hb_vmEvalBlock( pArea->dbfi.itmCobExpr ); - if( HB_IS_LOGICAL( pResult ) && !hb_itemGetL( pResult ) ) - { - SELF_SKIPRAW( pArea, 1 ); - continue; - } - } - return SUCCESS; - } - } - else if( lUpDown < 0 ) - { - while( TRUE ) - { - SELF_BOF( pArea, &bExit ); - if( bExit ) - return SELF_SKIPFILTER( pArea, 1 ); - - /* SET DELETED */ - if( hb_set.HB_SET_DELETED ) - { - SELF_DELETED( pArea, &bDeleted ); - if( bDeleted ) - { - SELF_SKIPRAW( pArea, -1 ); - continue; - } - } - - /* SET FILTER TO */ - if( pArea->dbfi.fFilter ) - { - PHB_ITEM pResult = hb_vmEvalBlock( pArea->dbfi.itmCobExpr ); - if( HB_IS_LOGICAL( pResult ) && !hb_itemGetL( pResult ) ) - { - SELF_SKIPRAW( pArea, 1 ); - continue; - } - } - return SUCCESS; - } - } - return SUCCESS; -} - -static ERRCODE defSkipRaw( AREAP pArea, LONG lToSkip ) -{ - HB_TRACE(HB_TR_DEBUG, ("defSkipRaw(%p, %ld)", pArea, lToSkip)); - - return SELF_GOTO( pArea, pArea->lpExtendInfo->ulRecNo + lToSkip ); -} - -static ERRCODE defStructSize( AREAP pArea, USHORT * uiSize ) -{ - HB_TRACE(HB_TR_DEBUG, ("defStrucSize(%p, %p)", pArea, uiSize)); - - HB_SYMBOL_UNUSED( pArea ); - HB_SYMBOL_UNUSED( uiSize ); - - return SUCCESS; -} - -static ERRCODE defSysName( AREAP pArea, BYTE * pBuffer ) -{ - USHORT uiCount; - LPRDDNODE pRddNode; - - HB_TRACE(HB_TR_DEBUG, ("defSysName(%p, %p)", pArea, pBuffer)); - - pRddNode = s_pRddList; - for( uiCount = 0; uiCount < pArea->rddID; uiCount++ ) - pRddNode = pRddNode->pNext; - strncpy( ( char * ) pBuffer, pRddNode->szName, HARBOUR_MAX_RDD_DRIVERNAME_LENGTH ); - return SUCCESS; -} - -static ERRCODE defUnSupported( AREAP pArea ) +/* + * Raise a runtime error if an method is not defined. + */ +static ERRCODE hb_waUnsupported( AREAP pArea ) { PHB_ITEM pError; - HB_TRACE(HB_TR_DEBUG, ("defUnSupported(%p)", pArea)); - - HB_SYMBOL_UNUSED( pArea ); + 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_errRelease( pError ); + return FAILURE; } -static RDDFUNCS defTable = { defBof, - defEof, - defFound, - defUnSupported, - ( DBENTRYP_UL ) defUnSupported, - ( DBENTRYP_I ) defUnSupported, - defUnSupported, - ( DBENTRYP_BIB ) defUnSupported, - defSkip, - defSkipFilter, - defSkipRaw, - defAddField, - ( DBENTRYP_B ) defUnSupported, - defCreateFields, - defUnSupported, - ( DBENTRYP_BP ) defUnSupported, - defFieldCount, - ( DBENTRYP_VF ) defUnSupported, - defFieldInfo, - defFieldName, - defUnSupported, - ( DBENTRYP_PP ) defUnSupported, - ( DBENTRYP_SI ) defUnSupported, - ( DBENTRYP_SVL ) defUnSupported, - defUnSupported, - defUnSupported, - ( DBENTRYP_P ) defUnSupported, - ( DBENTRYP_SI ) defUnSupported, - defUnSupported, - ( DBENTRYP_ULP ) defUnSupported, - ( DBENTRYP_ISI ) defUnSupported, - ( DBENTRYP_I ) defUnSupported, - defSetFieldExtent, - defAlias, - defClose, - ( DBENTRYP_VP ) defUnSupported, - ( DBENTRYP_SI ) defUnSupported, - defNewArea, - defOpen, - defRelease, - defStructSize, - defSysName, - defEval, - defUnSupported, - defUnSupported, - ( DBENTRYP_VP ) defUnSupported, - ( DBENTRYP_VP ) defUnSupported, - ( DBENTRYP_VP ) defUnSupported, - ( DBENTRYP_V ) defUnSupported, - defclearRel, - ( DBENTRYP_V ) defUnSupported, - ( DBENTRYP_SVP ) defUnSupported, - ( DBENTRYP_VP ) defUnSupported, - ( DBENTRYP_SVP ) defrelText, - ( DBENTRYP_VP ) defsetRel, - ( DBENTRYP_OI ) defUnSupported, - defUnSupported, - ( DBENTRYP_OI ) defUnSupported, - defUnSupported, - defOrderCondition, - ( DBENTRYP_VOC ) defUnSupported, - ( DBENTRYP_OI ) defUnSupported, - ( DBENTRYP_OII ) defUnSupported, - defClearFilter, - defClearLocate, - ( DBENTRYP_V ) defUnSupported, - ( DBENTRYP_VPLP ) defUnSupported, - defFilterText, - ( DBENTRYP_SI ) defUnSupported, - defSetFilter, - defSetLocate, - ( DBENTRYP_VP ) defUnSupported, - ( DBENTRYP_VPL ) defUnSupported, - defCompile, - defError, - defEvalBlock, - ( DBENTRYP_VSP ) defUnSupported, - ( DBENTRYP_VL ) defUnSupported, - ( DBENTRYP_UL ) defUnSupported, - defUnSupported, - ( DBENTRYP_VP ) defUnSupported, - ( DBENTRYP_SVP ) defUnSupported, - ( DBENTRYP_VP ) defUnSupported, - ( DBENTRYP_SVP ) defUnSupported, - defUnSupported, - defUnSupported, - ( DBENTRYP_SVP ) defUnSupported +/* + * 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_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_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_waWhoCares }; + +/* + * -- BASIC RDD METHODS -- + */ + +/* + * Force link the built-in RDD's. + */ static void hb_rddCheck( void ) { HB_TRACE(HB_TR_DEBUG, ("hb_rddCheck()")); @@ -935,31 +237,23 @@ static void hb_rddCheck( void ) } } +/* + * Closes all WorkAreas. + */ static void hb_rddCloseAll( void ) { - int nCycl = 0; - LPAREANODE s_pArea; + LPAREANODE pAreaNode; + HB_TRACE(HB_TR_DEBUG, ("hb_rddCloseAll()")); - while( nCycl < 2 ) + pAreaNode = s_pWorkAreas; + while( pAreaNode ) { - s_pArea = s_pWorkAreas; - while( s_pArea ) - { - s_pCurrArea = s_pArea; - s_pArea = s_pArea->pNext; - if( ( !nCycl && ( ( AREAP ) s_pCurrArea->pArea )->lpdbRelations ) || - ( nCycl && s_pCurrArea->pArea ) ) - { - SELF_CLOSE( ( AREAP ) s_pCurrArea->pArea ); - SELF_RELEASE( ( AREAP ) s_pCurrArea->pArea ); - hb_xfree( s_pCurrArea->pArea ); - s_pCurrArea->pArea = NULL; - } - if( nCycl == 1 ) - hb_xfree( s_pCurrArea ); - } - nCycl ++; + s_pCurrArea = pAreaNode; + pAreaNode = pAreaNode->pNext; + SELF_CLOSE( ( AREAP ) s_pCurrArea->pArea ); + SELF_RELEASE( ( AREAP ) s_pCurrArea->pArea ); + hb_xfree( s_pCurrArea ); } s_uiCurrArea = 1; @@ -967,6 +261,9 @@ static void hb_rddCloseAll( void ) s_pWorkAreas = NULL; } +/* + * Find a RDD node. + */ static LPRDDNODE hb_rddFindNode( char * szDriver, USHORT * uiIndex ) { LPRDDNODE pRddNode; @@ -992,6 +289,9 @@ static LPRDDNODE hb_rddFindNode( char * szDriver, USHORT * uiIndex ) return NULL; } +/* + * Register a RDD driver. + */ static int hb_rddRegister( char * szDriver, USHORT uiType ) { LPRDDNODE pRddNode, pRddNewNode; @@ -1001,7 +301,7 @@ static int hb_rddRegister( char * szDriver, USHORT uiType ) HB_TRACE(HB_TR_DEBUG, ("hb_rddRegister(%s, %hu)", szDriver, uiType)); - if( hb_rddFindNode( szDriver, 0 ) ) /* Duplicated RDD */ + if( hb_rddFindNode( szDriver, NULL ) ) /* Duplicated RDD */ return 1; szGetFuncTable = ( char * ) hb_xgrab( strlen( szDriver ) + 14 ); @@ -1032,7 +332,7 @@ static int hb_rddRegister( char * szDriver, USHORT uiType ) return 3; /* Invalid FUNCTABLE */ } - if( !s_pRddList ) /* First RDD node */ + if( !s_pRddList ) /* First RDD node */ s_pRddList = pRddNewNode; else { @@ -1044,6 +344,9 @@ static int hb_rddRegister( char * szDriver, USHORT uiType ) return 0; /* Ok */ } +/* + * Find a WorkArea by the alias. + */ static USHORT hb_rddSelect( char * szAlias ) { PHB_DYNS pSymAlias; @@ -1057,6 +360,9 @@ static USHORT hb_rddSelect( char * szAlias ) return 0; } +/* + * Return thne next free WorkArea for later use. + */ static void hb_rddSelectFirstAvailable( void ) { LPAREANODE pAreaNode; @@ -1084,6 +390,7 @@ static void hb_rddSelectFirstAvailable( void ) */ ERRCODE hb_rddInherit( PRDDFUNCS pTable, PRDDFUNCS pSubTable, PRDDFUNCS pSuperTable, BYTE * szDrvName ) { + char * szSuperName; LPRDDNODE pRddNode; USHORT uiCount; DBENTRYP_V * pFunction, * pSubFunction; @@ -1094,24 +401,20 @@ ERRCODE hb_rddInherit( PRDDFUNCS pTable, PRDDFUNCS pSubTable, PRDDFUNCS pSuperTa return FAILURE; /* Copy the pSuperTable into pTable */ - if( !szDrvName || ( uiCount = strlen( ( const char * ) szDrvName ) )==0 ) + if( !szDrvName || ( uiCount = strlen( ( const char * ) szDrvName ) ) == 0 ) { /* no name for inherited driver - use the default one */ - memcpy( pTable, &defTable, sizeof( RDDFUNCS ) ); - memcpy( pSuperTable, &defTable, sizeof( RDDFUNCS ) ); + memcpy( pTable, &waTable, sizeof( RDDFUNCS ) ); + memcpy( pSuperTable, &waTable, sizeof( RDDFUNCS ) ); } else { - char * szSuperName; - szSuperName = ( char * ) hb_xgrab( uiCount + 1 ); hb_strncpyUpper( szSuperName, ( char * ) szDrvName, uiCount ); - pRddNode = hb_rddFindNode( szSuperName, 0 ); + pRddNode = hb_rddFindNode( szSuperName, NULL ); hb_xfree( szSuperName ); if( !pRddNode ) - { return FAILURE; - } memcpy( pTable, &pRddNode->pTable, sizeof( RDDFUNCS ) ); memcpy( pSuperTable, &pRddNode->pTable, sizeof( RDDFUNCS ) ); } @@ -1123,19 +426,19 @@ ERRCODE hb_rddInherit( PRDDFUNCS pTable, PRDDFUNCS pSubTable, PRDDFUNCS pSuperTa { if( * pSubFunction ) * pFunction = * pSubFunction; - pFunction += 1; - pSubFunction += 1; + pFunction ++; + pSubFunction ++; } return SUCCESS; } -/* closes (if requested) and releases the current area preparing it - * to be used with a new database -*/ -void hb_rddReleaseCurrentArea( BOOL bClose ) +/* + * Closes and releases the current WorkArea preparing it + * to be used with a new database. + */ +void hb_rddReleaseCurrentArea( void ) { - if( bClose ) - SELF_CLOSE( ( AREAP ) s_pCurrArea->pArea ); + SELF_CLOSE( ( AREAP ) s_pCurrArea->pArea ); SELF_RELEASE( ( AREAP ) s_pCurrArea->pArea ); if( s_pWorkAreas == s_pCurrArea ) @@ -1152,30 +455,33 @@ void hb_rddReleaseCurrentArea( BOOL bClose ) s_pCurrArea->pNext->pPrev = s_pCurrArea->pPrev; } - hb_xfree( s_pCurrArea->pArea ); hb_xfree( s_pCurrArea ); s_pCurrArea = NULL; } -/* Prepares a new area node -*/ +/* + * Prepares a new WorkArea node. + */ LPAREANODE hb_rddNewAreaNode( LPRDDNODE pRddNode, USHORT uiRddID ) { - LPAREANODE pCurrArea = ( LPAREANODE ) hb_xgrab( sizeof( AREANODE ) ); + LPAREANODE pCurrArea; + USHORT uiSize; + pCurrArea = ( LPAREANODE ) hb_xgrab( sizeof( AREANODE ) ); if( pRddNode->uiAreaSize == 0 ) /* Calculate the size of WorkArea */ { - USHORT uiSize; - - uiSize = sizeof( AREA ); /* Default Size Area */ - pCurrArea->pArea = ( AREAP ) hb_xgrab( uiSize ); - memset( pCurrArea->pArea, 0, uiSize ); + pCurrArea->pArea = ( AREAP ) hb_xgrab( sizeof( AREA ) ); + memset( pCurrArea->pArea, 0, sizeof( AREA ) ); ( ( AREAP ) pCurrArea->pArea )->lprfsHost = &pRddNode->pTable; /* Need more space? */ SELF_STRUCTSIZE( ( AREAP ) pCurrArea->pArea, &uiSize ); if( uiSize > sizeof( AREA ) ) /* Size of Area changed */ + { pCurrArea->pArea = ( AREAP ) hb_xrealloc( pCurrArea->pArea, uiSize ); + memset( pCurrArea->pArea, 0, uiSize ); + ( ( AREAP ) pCurrArea->pArea )->lprfsHost = &pRddNode->pTable; + } pRddNode->uiAreaSize = uiSize; /* Update the size of WorkArea */ } @@ -1196,22 +502,33 @@ LPAREANODE hb_rddNewAreaNode( LPRDDNODE pRddNode, USHORT uiRddID ) return pCurrArea; } - /* - * Function for getting current workarea pointer + * Find a field. */ - -void * hb_rddGetCurrentWorkAreaPointer( void ) +static USHORT hb_rddFieldIndex( AREAP pArea, char * szName ) { - HB_TRACE(HB_TR_DEBUG, ("hb_rddGetCurrentWorkAreaPointer()")); + USHORT uiCount; + LPFIELD pField; - return s_pCurrArea->pArea; + uiCount = 0; + pField = pArea->lpFields; + while( pField ) + { + ++uiCount; + if( strcmp( szName, ( ( PHB_DYNS ) pField->sym )->pSymbol->szName ) == 0 ) + return uiCount; + pField = pField->lpfNext; + } + return 0; } /* * -- FUNCTIONS ACCESSED FROM VIRTUAL MACHINE -- */ +/* + * Return the current WorkArea number. + */ int hb_rddGetCurrentWorkAreaNumber( void ) { HB_TRACE(HB_TR_DEBUG, ("hb_rddGetCurrentWorkAreaNumber()")); @@ -1219,6 +536,9 @@ int hb_rddGetCurrentWorkAreaNumber( void ) return s_uiCurrArea; } +/* + * Select a WorkArea by the number. + */ ERRCODE hb_rddSelectWorkAreaNumber( int iArea ) { LPAREANODE pAreaNode; @@ -1237,13 +557,17 @@ ERRCODE hb_rddSelectWorkAreaNumber( int iArea ) } pAreaNode = pAreaNode->pNext; } - s_pCurrArea = NULL; /* Selected WorkArea is closed */ + s_pCurrArea = NULL; /* Selected WorkArea is closed */ return FAILURE; } +/* + * Select a WorkArea by the symbol name. + */ ERRCODE hb_rddSelectWorkAreaSymbol( PHB_SYMB pSymAlias ) { ERRCODE bResult; + char * szName; HB_TRACE(HB_TR_DEBUG, ("hb_rddSelectWorkAreaSymbol(%p)", pSymAlias)); @@ -1251,19 +575,20 @@ ERRCODE hb_rddSelectWorkAreaSymbol( PHB_SYMB pSymAlias ) bResult = hb_rddSelectWorkAreaNumber( pSymAlias->pDynSym->hArea ); else { - char * szName = pSymAlias->pDynSym->pSymbol->szName; + szName = pSymAlias->pDynSym->pSymbol->szName; if( strlen( szName ) == 1 && toupper( szName[ 0 ] ) >= 'A' && toupper( szName[ 0 ] ) <= 'K' ) bResult = hb_rddSelectWorkAreaNumber( toupper( szName[ 0 ] ) - 'A' + 1 ); else { - /* generate an error with retry possibility + /* + * generate an error with retry possibility * (user created error handler can open a missing database) */ USHORT uiAction = E_RETRY; HB_ITEM_PTR pError; - pError = hb_errRT_New( ES_ERROR, NULL, EG_NOALIAS, 1002, + pError = hb_errRT_New( ES_ERROR, NULL, EG_NOALIAS, EDBCMD_NOALIAS, NULL, pSymAlias->szName, 0, EF_CANRETRY ); bResult = FAILURE; @@ -1283,10 +608,16 @@ ERRCODE hb_rddSelectWorkAreaSymbol( PHB_SYMB pSymAlias ) return bResult; } +/* + * Select a WorkArea by the name. + */ ERRCODE hb_rddSelectWorkAreaAlias( char * szName ) { ERRCODE bResult; ULONG ulLen; + PHB_DYNS pSymArea; + USHORT uiAction; + HB_ITEM_PTR pError; HB_TRACE(HB_TR_DEBUG, ("hb_rddSelectWorkAreaAlias(%s)", szName)); @@ -1297,20 +628,17 @@ ERRCODE hb_rddSelectWorkAreaAlias( char * szName ) bResult = hb_rddSelectWorkAreaNumber( toupper( szName[ 0 ] ) - 'A' + 1 ); else { - PHB_DYNS pSymArea; - pSymArea = hb_dynsymFindName( szName ); if( pSymArea && pSymArea->hArea ) bResult = hb_rddSelectWorkAreaNumber( pSymArea->hArea ); else { - /* generate an error with retry possibility + /* + * generate an error with retry possibility * (user created error handler can open a missing database) */ - USHORT uiAction = E_RETRY; - HB_ITEM_PTR pError; - - pError = hb_errRT_New( ES_ERROR, NULL, EG_NOALIAS, 1002, + uiAction = E_RETRY; + pError = hb_errRT_New( ES_ERROR, NULL, EG_NOALIAS, EDBCMD_NOALIAS, NULL, szName, 0, EF_CANRETRY ); bResult = FAILURE; @@ -1334,22 +662,26 @@ ERRCODE hb_rddSelectWorkAreaAlias( char * szName ) return bResult; } +/* + * Obtain the current value of a field. + */ ERRCODE hb_rddGetFieldValue( HB_ITEM_PTR pItem, PHB_SYMB pFieldSymbol ) { ERRCODE bSuccess; + USHORT uiAction; + HB_ITEM_PTR pError; HB_TRACE(HB_TR_DEBUG, ("hb_rddGetFieldValue(%p, %p)", pItem, pFieldSymbol)); bSuccess = hb_rddFieldGet( pItem, pFieldSymbol ); if( bSuccess == FAILURE ) { - /* generate an error with retry possibility + /* + * generate an error with retry possibility * (user created error handler can make this field accessible) */ - USHORT uiAction = E_RETRY; - HB_ITEM_PTR pError; - - pError = hb_errRT_New( ES_ERROR, NULL, EG_NOVAR, 1003, + uiAction = E_RETRY; + pError = hb_errRT_New( ES_ERROR, NULL, EG_NOVAR, EDBCMD_NOVAR, NULL, pFieldSymbol->szName, 0, EF_CANRETRY ); while( uiAction == E_RETRY ) @@ -1367,22 +699,26 @@ ERRCODE hb_rddGetFieldValue( HB_ITEM_PTR pItem, PHB_SYMB pFieldSymbol ) return bSuccess; } +/* + * Assign a value to a field. + */ ERRCODE hb_rddPutFieldValue( HB_ITEM_PTR pItem, PHB_SYMB pFieldSymbol ) { ERRCODE bSuccess; + USHORT uiAction; + HB_ITEM_PTR pError; HB_TRACE(HB_TR_DEBUG, ("hb_rddPutFieldValue(%p, %p)", pItem, pFieldSymbol)); bSuccess = hb_rddFieldPut( pItem, pFieldSymbol ); if( bSuccess == FAILURE ) { - /* generate an error with retry possibility + /* + * generate an error with retry possibility * (user created error handler can make this field accessible) */ - USHORT uiAction = E_RETRY; - HB_ITEM_PTR pError; - - pError = hb_errRT_New( ES_ERROR, NULL, EG_NOVAR, 1003, + uiAction = E_RETRY; + pError = hb_errRT_New( ES_ERROR, NULL, EG_NOVAR, EDBCMD_NOVAR, NULL, pFieldSymbol->szName, 0, EF_CANRETRY ); while( uiAction == E_RETRY ) @@ -1400,15 +736,18 @@ ERRCODE hb_rddPutFieldValue( HB_ITEM_PTR pItem, PHB_SYMB pFieldSymbol ) return bSuccess; } +/* + * Assign a value to a field. + */ ERRCODE hb_rddFieldPut( HB_ITEM_PTR pItem, PHB_SYMB pFieldSymbol ) { + LPFIELD pField; + USHORT uiField; + HB_TRACE(HB_TR_DEBUG, ("hb_rddFieldPut(%p, %p)", pItem, pFieldSymbol)); if( s_pCurrArea ) { - LPFIELD pField; - USHORT uiField; - uiField = 1; pField = ( ( AREAP ) s_pCurrArea->pArea )->lpFields; while( pField ) @@ -1425,15 +764,18 @@ ERRCODE hb_rddFieldPut( HB_ITEM_PTR pItem, PHB_SYMB pFieldSymbol ) return FAILURE; } +/* + * Obtain the current value of a field. + */ ERRCODE hb_rddFieldGet( HB_ITEM_PTR pItem, PHB_SYMB pFieldSymbol ) { + LPFIELD pField; + USHORT uiField; + HB_TRACE(HB_TR_DEBUG, ("hb_rddFieldGet(%p, %p)", pItem, pFieldSymbol)); if( s_pCurrArea ) { - LPFIELD pField; - USHORT uiField; - uiField = 1; pField = ( ( AREAP ) s_pCurrArea->pArea )->lpFields; while( pField ) @@ -1450,8 +792,13 @@ ERRCODE hb_rddFieldGet( HB_ITEM_PTR pItem, PHB_SYMB pFieldSymbol ) return FAILURE; } +/* + * Shutdown the RDD system. + */ void hb_rddShutDown( void ) { + LPRDDNODE pRddNode; + HB_TRACE(HB_TR_DEBUG, ("hb_rddShutDown()")); hb_rddCloseAll(); @@ -1460,8 +807,6 @@ void hb_rddShutDown( void ) while( s_pRddList ) { - LPRDDNODE pRddNode; - pRddNode = s_pRddList; s_pRddList = s_pRddList->pNext; hb_xfree( pRddNode ); @@ -1475,7 +820,7 @@ void hb_rddShutDown( void ) HB_FUNC( AFIELDS ) { PHB_ITEM pName, pType, pLen, pDec, pItem; - USHORT uiFields, uiArrayLen = 0, uiCount; + USHORT uiFields, uiArrayLen, uiCount; if( !s_pCurrArea ) { @@ -1493,6 +838,7 @@ HB_FUNC( AFIELDS ) return; } + uiArrayLen = 0; pItem = hb_itemNew( NULL ); SELF_FIELDCOUNT( ( AREAP ) s_pCurrArea->pArea, &uiFields ); if( pName ) @@ -1575,76 +921,62 @@ HB_FUNC( ALIAS ) HB_FUNC( DBEVAL ) { + DBEVALINFO pEvalInfo; + if( s_pCurrArea ) { - DBEVALINFO pEvalInfo; - pEvalInfo.itmBlock = hb_param( 1, HB_IT_BLOCK ); if( !pEvalInfo.itmBlock ) { - hb_errRT_DBCMD( EG_ARG, 2019, NULL, "DBEVAL" ); + hb_errRT_DBCMD( EG_ARG, EDBCMD_EVAL_BADPARAMETER, NULL, "DBEVAL" ); return; } pEvalInfo.dbsci.itmCobFor = hb_param( 2, HB_IT_BLOCK ); - if( !pEvalInfo.dbsci.itmCobFor ) + if( !pEvalInfo.dbsci.itmCobFor && !ISNIL( 2 ) ) { - if( !ISNIL( 2 ) ) - { - hb_errRT_DBCMD( EG_ARG, 2019, NULL, "DBEVAL" ); - return; - } + hb_errRT_DBCMD( EG_ARG, EDBCMD_EVAL_BADPARAMETER, NULL, "DBEVAL" ); + return; } pEvalInfo.dbsci.itmCobWhile = hb_param( 3, HB_IT_BLOCK ); - if( !pEvalInfo.dbsci.itmCobWhile ) + if( !pEvalInfo.dbsci.itmCobWhile && !ISNIL( 3 ) ) { - if( !ISNIL( 3 ) ) - { - hb_errRT_DBCMD( EG_ARG, 2019, NULL, "DBEVAL" ); - return; - } + hb_errRT_DBCMD( EG_ARG, EDBCMD_EVAL_BADPARAMETER, NULL, "DBEVAL" ); + return; } pEvalInfo.dbsci.lNext = hb_param( 4, HB_IT_NUMERIC ); - if( !pEvalInfo.dbsci.lNext ) + if( !pEvalInfo.dbsci.lNext && !ISNIL( 4 ) ) { - if( !ISNIL( 4 ) ) - { - hb_errRT_DBCMD( EG_ARG, 2019, NULL, "DBEVAL" ); - return; - } + hb_errRT_DBCMD( EG_ARG, EDBCMD_EVAL_BADPARAMETER, NULL, "DBEVAL" ); + return; } pEvalInfo.dbsci.itmRecID = hb_param( 5, HB_IT_NUMERIC ); - if( !pEvalInfo.dbsci.itmRecID ) + if( !pEvalInfo.dbsci.itmRecID && !ISNIL( 5 ) ) { - if( !ISNIL( 5 ) ) - { - hb_errRT_DBCMD( EG_ARG, 2019, NULL, "DBEVAL" ); - return; - } + hb_errRT_DBCMD( EG_ARG, EDBCMD_EVAL_BADPARAMETER, NULL, "DBEVAL" ); + return; } pEvalInfo.dbsci.fRest = hb_param( 6, HB_IT_LOGICAL ); - if( !pEvalInfo.dbsci.fRest ) + if( !pEvalInfo.dbsci.fRest && !ISNIL( 6 ) ) { - if( !ISNIL( 6 ) ) - { - hb_errRT_DBCMD( EG_ARG, 2019, NULL, "DBEVAL" ); - return; - } + hb_errRT_DBCMD( EG_ARG, EDBCMD_EVAL_BADPARAMETER, NULL, "DBEVAL" ); + return; } SELF_DBEVAL( ( AREAP ) s_pCurrArea->pArea, &pEvalInfo ); } else - hb_errRT_DBCMD( EG_NOTABLE, 2001, NULL, "DBEVAL" ); + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "DBEVAL" ); } HB_FUNC( DBF ) { LPAREANODE pAreaNode = s_pWorkAreas; + char * szAlias; while( pAreaNode ) { @@ -1653,7 +985,7 @@ HB_FUNC( DBF ) if( ( ( AREAP ) pAreaNode->pArea )->atomAlias && ( ( PHB_DYNS ) ( ( AREAP ) pAreaNode->pArea )->atomAlias )->hArea ) { - char * szAlias = ( char * ) hb_xgrab( HARBOUR_MAX_RDD_ALIAS_LENGTH + 1 ); + szAlias = ( char * ) hb_xgrab( HARBOUR_MAX_RDD_ALIAS_LENGTH + 1 ); SELF_ALIAS( ( AREAP ) pAreaNode->pArea, ( BYTE * ) szAlias ); hb_retc( szAlias ); hb_xfree( szAlias ); @@ -1677,14 +1009,16 @@ HB_FUNC( BOF ) HB_FUNC( DBAPPEND ) { + BOOL bUnLockAll; + if( s_pCurrArea ) { - BOOL bUnLockAll = ISLOG( 1 ) ? hb_parl( 1 ) : TRUE; - - s_bNetError = ( SELF_APPEND( ( AREAP ) s_pCurrArea->pArea, bUnLockAll ) == FAILURE ); + bUnLockAll = ISLOG( 1 ) ? hb_parl( 1 ) : TRUE; + s_bNetError = FALSE; + SELF_APPEND( ( AREAP ) s_pCurrArea->pArea, bUnLockAll ); } else - hb_errRT_DBCMD( EG_NOTABLE, 2001, NULL, "DBAPPEND" ); + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "DBAPPEND" ); } HB_FUNC( DBCLEARFILTER ) @@ -1692,7 +1026,7 @@ HB_FUNC( DBCLEARFILTER ) if( s_pCurrArea ) SELF_CLEARFILTER( ( AREAP ) s_pCurrArea->pArea ); else - hb_errRT_DBCMD( EG_NOTABLE, 2001, NULL, "DBCLEARFILTER" ); + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "DBCLEARFILTER" ); } HB_FUNC( DBCLOSEALL ) @@ -1702,10 +1036,8 @@ HB_FUNC( DBCLOSEALL ) HB_FUNC( DBCLOSEAREA ) { - if( !s_pCurrArea ) - return; - - hb_rddReleaseCurrentArea( TRUE ); /* close before releasing */ + if( s_pCurrArea ) + hb_rddReleaseCurrentArea(); } HB_FUNC( DBCOMMIT ) @@ -1713,7 +1045,7 @@ HB_FUNC( DBCOMMIT ) if( s_pCurrArea ) SELF_FLUSH( ( AREAP ) s_pCurrArea->pArea ); else - hb_errRT_DBCMD( EG_NOTABLE, 2001, NULL, "DBCOMMIT" ); + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "DBCOMMIT" ); } HB_FUNC( DBCOMMITALL ) @@ -1730,27 +1062,24 @@ HB_FUNC( DBCOMMITALL ) HB_FUNC( __DBCONTINUE ) { - BOOL bEof; - if( !s_pCurrArea ) { - hb_errRT_DBCMD( EG_NOTABLE, 2001, NULL, "DBCONTINUE" ); + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "DBCONTINUE" ); return; } if( !( ( AREAP ) s_pCurrArea->pArea )->dbsi.itmCobFor ) return; + ( ( AREAP ) s_pCurrArea->pArea )->fFound = FALSE; SELF_SKIP( ( AREAP ) s_pCurrArea->pArea, 1 ); - SELF_EOF( ( AREAP ) s_pCurrArea->pArea, &bEof ); - if( bEof ) + if( ( ( AREAP ) s_pCurrArea->pArea )->fEof ) return; ( ( AREAP ) s_pCurrArea->pArea )->fFound = hb_itemGetL( hb_vmEvalBlock( ( ( AREAP ) s_pCurrArea->pArea )->dbsi.itmCobFor ) ); - while( !bEof && !( ( AREAP ) s_pCurrArea->pArea )->fFound ) + while( !( ( AREAP ) s_pCurrArea->pArea )->fEof && !( ( AREAP ) s_pCurrArea->pArea )->fFound ) { SELF_SKIP( ( AREAP ) s_pCurrArea->pArea, 1 ); - SELF_EOF( ( AREAP ) s_pCurrArea->pArea, &bEof ); ( ( AREAP ) s_pCurrArea->pArea )->fFound = hb_itemGetL( hb_vmEvalBlock( ( ( AREAP ) s_pCurrArea->pArea )->dbsi.itmCobFor ) ); } } @@ -1758,23 +1087,25 @@ HB_FUNC( __DBCONTINUE ) HB_FUNC( DBCREATE ) { char * szDriver, * szFileName; - USHORT uiSize, uiLen, uiRddID; - ULONG ulRecCount; + USHORT uiSize, uiLen, uiRddID, uiPrevArea; LPRDDNODE pRddNode; LPAREANODE pAreaNode; DBOPENINFO pInfo; PHB_FNAME pFileName; PHB_ITEM pStruct, pFieldDesc, pFileExt; char cDriverBuffer[ HARBOUR_MAX_RDD_DRIVERNAME_LENGTH ]; - BOOL bError = FALSE; + BOOL bOpen; + char szAlias[ HARBOUR_MAX_RDD_ALIAS_LENGTH + 1 ]; + hb_retl( FALSE ); szFileName = hb_parc( 1 ); pStruct = hb_param( 2 , HB_IT_ARRAY ); - uiLen = ( USHORT ) hb_arrayLen( pStruct ); + if( pStruct ) + uiLen = ( USHORT ) hb_arrayLen( pStruct ); if( ( strlen( szFileName ) == 0 ) || !pStruct || uiLen == 0 ) { - hb_errRT_DBCMD( EG_ARG, 1014, NULL, "DBCREATE" ); + hb_errRT_DBCMD( EG_ARG, EDBCMD_DBCMDBADPARAMETER, NULL, "DBCREATE" ); return; } @@ -1783,21 +1114,36 @@ HB_FUNC( DBCREATE ) pFieldDesc = hb_arrayGetItemPtr( pStruct, uiSize + 1 ); if( hb_arrayLen( pFieldDesc ) < 4 ) { - hb_errRT_DBCMD( EG_ARG, 1014, NULL, "DBCREATE" ); + hb_errRT_DBCMD( EG_ARG, EDBCMD_DBCMDBADPARAMETER, NULL, "DBCREATE" ); return; } - /* Validate items type, name, size and decimals of field */ + /* Validate items types of fields */ if( !( hb_arrayGetType( pFieldDesc, 1 ) & HB_IT_STRING ) || !( hb_arrayGetType( pFieldDesc, 2 ) & HB_IT_STRING ) || !( hb_arrayGetType( pFieldDesc, 3 ) & HB_IT_NUMERIC ) || !( hb_arrayGetType( pFieldDesc, 4 ) & HB_IT_NUMERIC ) ) { - hb_errRT_DBCMD( EG_ARG, 1014, NULL, "DBCREATE" ); + hb_errRT_DBCMD( EG_ARG, EDBCMD_DBCMDBADPARAMETER, NULL, "DBCREATE" ); return; } } + if( !ISLOG( 4 ) ) + { + bOpen = FALSE; + uiPrevArea = s_uiCurrArea; + hb_rddSelectFirstAvailable(); + } + else + { + bOpen = TRUE; + if( hb_parl( 4 ) ) + hb_rddSelectFirstAvailable(); + else if( s_pCurrArea ) /* If current WorkArea is used then close it */ + hb_rddReleaseCurrentArea(); + } + hb_rddCheck(); uiLen = ( USHORT ) hb_parclen( 3 ); if( uiLen > 0 ) @@ -1811,59 +1157,56 @@ HB_FUNC( DBCREATE ) else szDriver = s_szDefDriver; - uiRddID = 0; pRddNode = hb_rddFindNode( szDriver, &uiRddID ) ; if( !pRddNode ) { - hb_errRT_DBCMD( EG_ARG, 1015, NULL, "DBCREATE" ); - return; - } - - if( !ISLOG( 4 ) ) - hb_rddSelectFirstAvailable(); - else - { - if( hb_parl( 4 ) ) - hb_rddSelectFirstAvailable(); - else if( s_pCurrArea ) /* If current WorkArea is in use then close it */ - { - hb_rddReleaseCurrentArea( TRUE ); /* close before releasing */ - } - } - - /* Create a new WorkArea node */ - - s_pCurrArea = hb_rddNewAreaNode( pRddNode, uiRddID ); - - if( SELF_CREATEFIELDS( ( AREAP ) s_pCurrArea->pArea, pStruct ) == FAILURE ) - { - SELF_RELEASE( ( AREAP ) s_pCurrArea->pArea ); - hb_xfree( s_pCurrArea->pArea ); - hb_xfree( s_pCurrArea ); - s_pCurrArea = NULL; - hb_errRT_DBCMD( EG_ARG, 1014, NULL, "DBCREATE" ); + hb_errRT_DBCMD( EG_ARG, EDBCMD_BADPARAMETER, NULL, "DBCREATE" ); return; } pFileName = hb_fsFNameSplit( szFileName ); - szFileName = ( char * ) hb_xgrab( _POSIX_PATH_MAX + 3 ); - strcpy( szFileName, hb_parc( 1 ) ); + strncpy( szAlias, hb_parc( 5 ), HARBOUR_MAX_RDD_ALIAS_LENGTH ); + uiLen = strlen( szAlias ); + if( uiLen == 0 ) + strncpy( szAlias, pFileName->szName, HARBOUR_MAX_RDD_ALIAS_LENGTH ); + else if( uiLen == 1 ) + { + /* Alias with a single letter. Only are valid 'L' and > 'M' */ + if( toupper( szAlias[ 0 ] ) < 'N' && toupper( szAlias[ 0 ] ) != 'L' ) + { + hb_xfree( pFileName ); + hb_errRT_DBCMD( EG_DUPALIAS, EDBCMD_DUPALIAS, NULL, "DBCREATE" ); + return; + } + } + + /* Create a new WorkArea node */ + s_pCurrArea = hb_rddNewAreaNode( pRddNode, uiRddID ); + + szFileName = ( char * ) hb_xgrab( _POSIX_PATH_MAX + 1 ); + strncpy( szFileName, hb_parc( 1 ), _POSIX_PATH_MAX ); if( !pFileName->szExtension ) { pFileExt = hb_itemPutC( NULL, "" ); SELF_INFO( ( AREAP ) s_pCurrArea->pArea, DBI_TABLEEXT, pFileExt ); - strcat( szFileName, hb_itemGetCPtr( pFileExt ) ); + strncat( szFileName, hb_itemGetCPtr( pFileExt ), _POSIX_PATH_MAX - + strlen( szFileName ) ); hb_itemRelease( pFileExt ); } hb_xfree( pFileName ); - pInfo.abName = ( BYTE * ) szFileName; - pInfo.atomAlias = ( BYTE * ) hb_parc( 5 ); - pInfo.uiArea = s_uiCurrArea; + /* Fill pInfo structure */ + pInfo.uiArea = s_uiCurrArea; + pInfo.abName = ( BYTE * ) szFileName; + pInfo.atomAlias = ( BYTE * ) szAlias; + pInfo.fShared = FALSE; + pInfo.fReadonly = FALSE; + + ( ( AREAP ) s_pCurrArea->pArea )->atomAlias = hb_dynsymGet( ( char * ) szAlias ); + ( ( PHB_DYNS ) ( ( AREAP ) s_pCurrArea->pArea )->atomAlias )->hArea = s_uiCurrArea; ( ( AREAP ) s_pCurrArea->pArea )->uiArea = s_uiCurrArea; /* Insert the new WorkArea node */ - if( !s_pWorkAreas ) s_pWorkAreas = s_pCurrArea; /* The new WorkArea node is the first */ else @@ -1895,96 +1238,49 @@ HB_FUNC( DBCREATE ) } } - ( ( AREAP ) s_pCurrArea->pArea )->lpDataInfo->szFileName = szFileName; - ( ( AREAP ) s_pCurrArea->pArea )->atomAlias = hb_dynsymGet( ( char * ) pInfo.atomAlias ); - if( ( ( PHB_DYNS ) ( ( AREAP ) s_pCurrArea->pArea )->atomAlias )->hArea ) + if( SELF_CREATEFIELDS( ( AREAP ) s_pCurrArea->pArea, pStruct ) == FAILURE ) { - hb_errRT_DBCMD( EG_DUPALIAS, 1011, NULL, ( char * ) pInfo.atomAlias ); - bError = TRUE; + hb_xfree( szFileName ); + hb_rddReleaseCurrentArea(); + hb_errRT_DBCMD( EG_ARG, EDBCMD_BADPARAMETER, NULL, "DBCREATE" ); + return; } - if( !bError ) - bError = ( SELF_CREATE( ( AREAP ) s_pCurrArea->pArea, &pInfo ) == FAILURE ); - - if( !bError ) - ( ( PHB_DYNS ) ( ( AREAP ) s_pCurrArea->pArea )->atomAlias )->hArea = pInfo.uiArea; - - if( !bError && ( ( AREAP ) s_pCurrArea->pArea )->lpExtendInfo->fHasMemo ) + if( SELF_CREATE( ( AREAP ) s_pCurrArea->pArea, &pInfo ) == FAILURE ) { - pFileExt = hb_itemPutC( NULL, "" ); - SELF_INFO( ( AREAP ) s_pCurrArea->pArea, DBI_MEMOEXT, pFileExt ); - pFileName = hb_fsFNameSplit( ( char * ) pInfo.abName ); - szFileName = ( char * ) hb_xgrab( _POSIX_PATH_MAX + 3 ); - szFileName[ 0 ] = '\0'; - if( pFileName->szDrive ) - strcat( szFileName, pFileName->szDrive ); - if( pFileName->szPath ) - strcat( szFileName, pFileName->szPath ); - strcat( szFileName, pFileName->szName ); - strcat( szFileName, hb_itemGetCPtr( pFileExt ) ); - pInfo.abName = ( BYTE * ) szFileName; - hb_xfree( pFileName ); - hb_itemRelease( pFileExt ); - ( ( AREAP ) s_pCurrArea->pArea )->lpDataInfo->pNext = - ( LPFILEINFO ) hb_xgrab( sizeof( FILEINFO ) ); - memset( ( ( AREAP ) s_pCurrArea->pArea )->lpDataInfo->pNext, 0, - sizeof( FILEINFO ) ); - ( ( AREAP ) s_pCurrArea->pArea )->lpDataInfo->pNext->hFile = FS_ERROR; - ( ( AREAP ) s_pCurrArea->pArea )->lpDataInfo->pNext->szFileName = szFileName; - bError = ( SELF_CREATEMEMFILE( ( AREAP ) s_pCurrArea->pArea, &pInfo ) == FAILURE ); + hb_rddReleaseCurrentArea(); + hb_errRT_DBCMD( EG_ARG, EDBCMD_BADPARAMETER, NULL, "DBCREATE" ); + return; } - ( ( PHB_DYNS ) ( ( AREAP ) s_pCurrArea->pArea )->atomAlias )->hArea = 0; - SELF_RELEASE( ( AREAP ) s_pCurrArea->pArea ); - if( !ISLOG( 4 ) || bError ) + if( !bOpen ) { - if( s_pWorkAreas == s_pCurrArea ) - { - s_pWorkAreas = s_pCurrArea->pNext; - if( s_pWorkAreas ) - s_pWorkAreas->pPrev = NULL; - } - else - { - if( s_pCurrArea->pPrev ) - s_pCurrArea->pPrev->pNext = s_pCurrArea->pNext; - if( s_pCurrArea->pNext ) - s_pCurrArea->pNext->pPrev = s_pCurrArea->pPrev; - } - - hb_xfree( s_pCurrArea->pArea ); - hb_xfree( s_pCurrArea ); - s_pCurrArea = NULL; + hb_rddReleaseCurrentArea(); + hb_rddSelectWorkAreaNumber( uiPrevArea ); } else { + /* Save filename for later use */ + szFileName = ( char * ) hb_xgrab( _POSIX_PATH_MAX + 1 ); + strncpy( szFileName, ( const char * ) pInfo.abName, _POSIX_PATH_MAX ); + + /* Close and release WorkArea */ + SELF_CLOSE( ( AREAP ) s_pCurrArea->pArea ); + SELF_RELEASE( ( AREAP ) s_pCurrArea->pArea ); + + /* Prepare WorkArea and open it */ + s_pCurrArea->pArea = ( AREAP ) hb_xgrab( pRddNode->uiAreaSize ); + memset( s_pCurrArea->pArea, 0, pRddNode->uiAreaSize ); + ( ( AREAP ) s_pCurrArea->pArea )->lprfsHost = &pRddNode->pTable; + ( ( AREAP ) s_pCurrArea->pArea )->rddID = uiRddID; SELF_NEW( ( AREAP ) s_pCurrArea->pArea ); - szFileName = hb_parc( 1 ); - pFileName = hb_fsFNameSplit( szFileName ); - szFileName = ( char * ) hb_xgrab( _POSIX_PATH_MAX + 3 ); - strcpy( szFileName, hb_parc( 1 ) ); - if( !pFileName->szExtension ) - { - pFileExt = hb_itemPutC( NULL, "" ); - SELF_INFO( ( AREAP ) s_pCurrArea->pArea, DBI_TABLEEXT, pFileExt ); - strcat( szFileName, hb_itemGetCPtr( pFileExt ) ); - hb_itemRelease( pFileExt ); - } - hb_xfree( pFileName ); pInfo.abName = ( BYTE * ) szFileName; pInfo.fShared = !hb_set.HB_SET_EXCLUSIVE; - pInfo.fReadonly = FALSE; ( ( AREAP ) s_pCurrArea->pArea )->uiArea = s_uiCurrArea; - ( ( AREAP ) s_pCurrArea->pArea )->lpDataInfo->szFileName = szFileName; if( SELF_OPEN( ( AREAP ) s_pCurrArea->pArea, &pInfo ) == FAILURE ) - { - SELF_RELEASE( ( AREAP ) s_pCurrArea->pArea ); - hb_xfree( s_pCurrArea->pArea ); - hb_xfree( s_pCurrArea ); - s_pCurrArea = NULL; - } - SELF_RECCOUNT( ( AREAP ) s_pCurrArea->pArea, &ulRecCount ); - ( ( AREAP ) s_pCurrArea->pArea )->lpExtendInfo->ulRecCount = ulRecCount; + hb_rddReleaseCurrentArea(); + else + hb_retl( TRUE ); } } @@ -1993,15 +1289,15 @@ HB_FUNC( DBDELETE ) if( s_pCurrArea ) SELF_DELETE( ( AREAP ) s_pCurrArea->pArea ); else - hb_errRT_DBCMD( EG_NOTABLE, 2001, NULL, "DBDELETE" ); + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "DBDELETE" ); } HB_FUNC( DBFILTER ) { + PHB_ITEM pFilter; + if( s_pCurrArea ) { - PHB_ITEM pFilter; - pFilter = hb_itemPutC( NULL, "" ); SELF_FILTERTEXT( ( AREAP ) s_pCurrArea->pArea, pFilter ); hb_retc( hb_itemGetCPtr( pFilter ) ); @@ -2016,7 +1312,7 @@ HB_FUNC( DBGOBOTTOM ) if( s_pCurrArea ) SELF_GOBOTTOM( ( AREAP ) s_pCurrArea->pArea ); else - hb_errRT_DBCMD( EG_NOTABLE, 2001, NULL, "DBGOBOTTOM" ); + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "DBGOBOTTOM" ); } HB_FUNC( DBGOTO ) @@ -2025,13 +1321,13 @@ HB_FUNC( DBGOTO ) if( !s_pCurrArea ) { - hb_errRT_DBCMD( EG_NOTABLE, 2001, NULL, "DBGOTO" ); + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "DBGOTO" ); return; } pItem = hb_param( 1, HB_IT_ANY ); if( !pItem ) - hb_errRT_DBCMD( EG_ARG, 1003, NULL, "DBGOTO" ); + hb_errRT_DBCMD( EG_ARG, EDBCMD_NOVAR, NULL, "DBGOTO" ); else SELF_GOTOID( ( AREAP ) s_pCurrArea->pArea, pItem ); } @@ -2041,188 +1337,153 @@ HB_FUNC( DBGOTOP ) if( s_pCurrArea ) SELF_GOTOP( ( AREAP ) s_pCurrArea->pArea ); else - hb_errRT_DBCMD( EG_NOTABLE, 2001, NULL, "DBGOTOP" ); + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "DBGOTOP" ); } HB_FUNC( __DBLOCATE ) { - PHB_ITEM pFor, pFor2, pWhile, pNext, pRecord, pRest; + PHB_ITEM pFor, pNewFor, pWhile, pNext, pRecord, pRest, pNewRest; DBSCOPEINFO pScopeInfo; ULONG lNext; - BOOL bEof, bFor, bWhile; + BOOL bFor, bWhile; if( !s_pCurrArea ) { - hb_errRT_DBCMD( EG_NOTABLE, 2001, NULL, "DBSETFILTER" ); + hb_errRT_DBCMD( EG_NOTABLE, EG_NOTABLE, NULL, "__DBLOCATE" ); return; } memset( &pScopeInfo, 0, sizeof( DBSCOPEINFO ) ); - pFor2 = hb_param( 1, HB_IT_BLOCK ); + pFor = hb_param( 1, HB_IT_BLOCK ); pWhile = hb_param( 2, HB_IT_BLOCK ); pNext = hb_param( 3, HB_IT_NUMERIC ); pRecord = hb_param( 4, HB_IT_NUMERIC ); pRest = hb_param( 5, HB_IT_LOGICAL ); - if( !pWhile ) + pNewRest = NULL; + if( pWhile ) { - pWhile = hb_itemPutL( NULL, TRUE ); - pScopeInfo.itmCobWhile = pWhile; + pNewRest = hb_itemPutL( NULL, TRUE ); + pScopeInfo.fRest = pNewRest; } + if( !pFor ) + pNewFor = hb_itemPutL( NULL, TRUE ); else - { - pRest = hb_itemPutL( NULL, TRUE ); - pScopeInfo.fRest = pRest; - } - if( !pFor2 ) - pFor = hb_itemPutL( NULL, TRUE ); - else - { - pFor = hb_itemNew( NULL ); - hb_itemCopy( pFor, pFor2 ); - } + pNewFor = hb_itemNew( pFor ); + pScopeInfo.itmCobFor = pNewFor; if( !pRest ) { - pRest = hb_itemPutL( NULL, FALSE ); - pScopeInfo.fRest = pRest; + pNewRest = hb_itemPutL( pNewRest, FALSE ); + pScopeInfo.fRest = pNewRest; } - pScopeInfo.itmCobFor = pFor; SELF_SETLOCATE( ( AREAP ) s_pCurrArea->pArea, &pScopeInfo ); ( ( AREAP ) s_pCurrArea->pArea )->fFound = FALSE; if( pRecord ) { SELF_GOTOID( ( AREAP ) s_pCurrArea->pArea, pRecord ); - SELF_EOF( ( AREAP ) s_pCurrArea->pArea, &bEof ); - if( bEof ) + if( ( ( AREAP ) s_pCurrArea->pArea )->fEof ) return; if( hb_itemType( pWhile ) == HB_IT_BLOCK ) - { bWhile = hb_itemGetL( hb_vmEvalBlock( pWhile ) ); - } else - bWhile = hb_itemGetL( pWhile ); - if( hb_itemType( pFor ) == HB_IT_BLOCK ) + bWhile = TRUE; + if( hb_itemType( pNewFor ) == HB_IT_BLOCK ) { - bFor = hb_itemGetL( hb_vmEvalBlock( pFor ) ); + bFor = hb_itemGetL( hb_vmEvalBlock( pNewFor ) ); ( ( AREAP ) s_pCurrArea->pArea )->fFound = ( bWhile && bFor ); } else - ( ( AREAP ) s_pCurrArea->pArea )->fFound = ( bWhile && hb_itemGetL( pFor ) ); + ( ( AREAP ) s_pCurrArea->pArea )->fFound = ( bWhile && hb_itemGetL( pNewFor ) ); } else if( pNext ) { - SELF_EOF( ( AREAP ) s_pCurrArea->pArea, &bEof ); lNext = hb_parnl( 3 ); - if( bEof || lNext <= 0 ) + if( ( ( AREAP ) s_pCurrArea->pArea )->fEof || lNext <= 0 ) return; if( hb_itemType( pWhile ) == HB_IT_BLOCK ) - { bWhile = hb_itemGetL( hb_vmEvalBlock( pWhile ) ); - } else - bWhile = hb_itemGetL( pWhile ); - if( hb_itemType( pFor ) == HB_IT_BLOCK ) - { - bFor = hb_itemGetL( hb_vmEvalBlock( pFor ) ); - } + bWhile = TRUE; + if( hb_itemType( pNewFor ) == HB_IT_BLOCK ) + bFor = hb_itemGetL( hb_vmEvalBlock( pNewFor ) ); else - bFor = hb_itemGetL( pFor ); - while( !bEof && lNext-- > 0 && bWhile && !bFor ) + bFor = hb_itemGetL( pNewFor ); + while( !( ( AREAP ) s_pCurrArea->pArea )->fEof && lNext-- > 0 && bWhile && !bFor ) { SELF_SKIP( ( AREAP ) s_pCurrArea->pArea, 1 ); - SELF_EOF( ( AREAP ) s_pCurrArea->pArea, &bEof ); if( hb_itemType( pWhile ) == HB_IT_BLOCK ) - { bWhile = hb_itemGetL( hb_vmEvalBlock( pWhile ) ); - } else - bWhile = hb_itemGetL( pWhile ); - if( hb_itemType( pFor ) == HB_IT_BLOCK ) - { - bFor = hb_itemGetL( hb_vmEvalBlock( pFor ) ); - } + bWhile = TRUE; + if( hb_itemType( pNewFor ) == HB_IT_BLOCK ) + bFor = hb_itemGetL( hb_vmEvalBlock( pNewFor ) ); else - bFor = hb_itemGetL( pFor ); + bFor = hb_itemGetL( pNewFor ); } ( ( AREAP ) s_pCurrArea->pArea )->fFound = bFor; } else if( hb_itemGetL( pRest ) ) { - SELF_EOF( ( AREAP ) s_pCurrArea->pArea, &bEof ); - if( bEof ) + if( ( ( AREAP ) s_pCurrArea->pArea )->fEof ) return; if( hb_itemType( pWhile ) == HB_IT_BLOCK ) - { bWhile = hb_itemGetL( hb_vmEvalBlock( pWhile ) ); - } else - bWhile = hb_itemGetL( pWhile ); - if( hb_itemType( pFor ) == HB_IT_BLOCK ) - { - bFor = hb_itemGetL( hb_vmEvalBlock( pFor ) ); - } + bWhile = TRUE; + if( hb_itemType( pNewFor ) == HB_IT_BLOCK ) + bFor = hb_itemGetL( hb_vmEvalBlock( pNewFor ) ); else - bFor = hb_itemGetL( pFor ); - while( !bEof && bWhile && !bFor ) + bFor = hb_itemGetL( pNewFor ); + while( !( ( AREAP ) s_pCurrArea->pArea )->fEof && bWhile && !bFor ) { SELF_SKIP( ( AREAP ) s_pCurrArea->pArea, 1 ); - SELF_EOF( ( AREAP ) s_pCurrArea->pArea, &bEof ); if( hb_itemType( pWhile ) == HB_IT_BLOCK ) - { bWhile = hb_itemGetL( hb_vmEvalBlock( pWhile ) ); - } else - bWhile = hb_itemGetL( pWhile ); - if( hb_itemType( pFor ) == HB_IT_BLOCK ) - { - bFor = hb_itemGetL( hb_vmEvalBlock( pFor ) ); - } + bWhile = TRUE; + if( hb_itemType( pNewFor ) == HB_IT_BLOCK ) + bFor = hb_itemGetL( hb_vmEvalBlock( pNewFor ) ); else - bFor = hb_itemGetL( pFor ); + bFor = hb_itemGetL( pNewFor ); } ( ( AREAP ) s_pCurrArea->pArea )->fFound = bFor; } else { SELF_GOTOP( ( AREAP ) s_pCurrArea->pArea ); - SELF_EOF( ( AREAP ) s_pCurrArea->pArea, &bEof ); - if( bEof ) + if( ( ( AREAP ) s_pCurrArea->pArea )->fEof ) return; - if( hb_itemType( pFor ) == HB_IT_BLOCK ) - { - bFor = hb_itemGetL( hb_vmEvalBlock( pFor ) ); - } + if( hb_itemType( pNewFor ) == HB_IT_BLOCK ) + bFor = hb_itemGetL( hb_vmEvalBlock( pNewFor ) ); else - bFor = hb_itemGetL( pFor ); - while( !bEof && !bFor ) + bFor = hb_itemGetL( pNewFor ); + while( !( ( AREAP ) s_pCurrArea->pArea )->fEof && !bFor ) { SELF_SKIP( ( AREAP ) s_pCurrArea->pArea, 1 ); - SELF_EOF( ( AREAP ) s_pCurrArea->pArea, &bEof ); - if( hb_itemType( pFor ) == HB_IT_BLOCK ) - { - bFor = hb_itemGetL( hb_vmEvalBlock( pFor ) ); - } + if( hb_itemType( pNewFor ) == HB_IT_BLOCK ) + bFor = hb_itemGetL( hb_vmEvalBlock( pNewFor ) ); else - bFor = hb_itemGetL( pFor ); + bFor = hb_itemGetL( pNewFor ); } ( ( AREAP ) s_pCurrArea->pArea )->fFound = bFor; } + + /* Release items */ + hb_itemRelease( pNewFor ); + hb_itemRelease( pNewRest ); } HB_FUNC( __DBSETLOCATE ) { + PHB_ITEM pLocate; + DBSCOPEINFO pScopeInfo; + if( s_pCurrArea ) { - PHB_ITEM pLocate = hb_param( 1, HB_IT_BLOCK ); - + pLocate = hb_param( 1, HB_IT_BLOCK ); if( pLocate ) { - PHB_ITEM pFor; - DBSCOPEINFO pScopeInfo; - - pFor = hb_itemNew( NULL ); - hb_itemCopy( pFor, pLocate ); memset( &pScopeInfo, 0, sizeof( DBSCOPEINFO ) ); - pScopeInfo.itmCobFor = pFor; + pScopeInfo.itmCobFor = pLocate; SELF_SETLOCATE( ( AREAP ) s_pCurrArea->pArea, &pScopeInfo ); } } @@ -2230,19 +1491,32 @@ HB_FUNC( __DBSETLOCATE ) HB_FUNC( __DBPACK ) { + PHB_ITEM pBlock, pEvery; + if( s_pCurrArea ) { - /* Additional feature: __dbPack( [, [] ) - Code Block to execute for every record. */ - ( ( AREAP ) s_pCurrArea->pArea )->lpExtendInfo->itmEval = hb_param( 1, HB_IT_BLOCK ); - ( ( AREAP ) s_pCurrArea->pArea )->lpExtendInfo->ulEvery = hb_parnl( 2 ); - if( !( ( AREAP ) s_pCurrArea->pArea )->lpExtendInfo->ulEvery ) - ( ( AREAP ) s_pCurrArea->pArea )->lpExtendInfo->ulEvery = 1; + /* + * Additional feature: __dbPack( [, [] ) + * Code Block to execute for every record. + */ + pBlock = hb_param( 1, HB_IT_BLOCK ); + if( pBlock ) + { + hb_itemRelease( ( ( AREAP ) s_pCurrArea->pArea )->valResult ); + ( ( AREAP ) s_pCurrArea->pArea )->valResult = hb_itemArrayNew( 2 ); + hb_arraySet( ( ( AREAP ) s_pCurrArea->pArea )->valResult, 1, pBlock ); + pEvery = hb_param( 2, HB_IT_ANY ); + if( pEvery && HB_IS_NUMERIC( pEvery ) ) + hb_arraySet( ( ( AREAP ) s_pCurrArea->pArea )->valResult, 2, pEvery ); + } + else + hb_itemClear( ( ( AREAP ) s_pCurrArea->pArea )->valResult ); SELF_PACK( ( AREAP ) s_pCurrArea->pArea ); - ( ( AREAP ) s_pCurrArea->pArea )->lpExtendInfo->itmEval = NULL; + if( pBlock ) + hb_itemClear( ( ( AREAP ) s_pCurrArea->pArea )->valResult ); } else - hb_errRT_DBCMD( EG_NOTABLE, 2001, NULL, "__DBPACK" ); + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "__DBPACK" ); } HB_FUNC( DBRECALL ) @@ -2250,24 +1524,27 @@ HB_FUNC( DBRECALL ) if( s_pCurrArea ) SELF_RECALL( ( AREAP ) s_pCurrArea->pArea ); else - hb_errRT_DBCMD( EG_NOTABLE, 2001, NULL, "DBRECALL" ); + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "DBRECALL" ); } HB_FUNC( DBRLOCK ) { - DBLOCKINFO pLockInfo; + DBLOCKINFO dbLockInfo; - pLockInfo.fResult = FALSE; + dbLockInfo.fResult = FALSE; if( s_pCurrArea ) { - pLockInfo.itmRecID = hb_parnl( 1 ); - pLockInfo.uiMethod = REC_LOCK; - SELF_LOCK( ( AREAP ) s_pCurrArea->pArea, &pLockInfo ); + dbLockInfo.itmRecID = hb_param( 1, HB_IT_ANY ); + if( !dbLockInfo.itmRecID || !HB_IS_NUMERIC( dbLockInfo.itmRecID ) ) + dbLockInfo.uiMethod = DBLM_EXCLUSIVE; + else + dbLockInfo.uiMethod = DBLM_MULTIPLE; + SELF_LOCK( ( AREAP ) s_pCurrArea->pArea, &dbLockInfo ); } else - hb_errRT_DBCMD( EG_NOTABLE, 2001, NULL, "DBRLOCK" ); + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "DBRLOCK" ); - hb_retl( pLockInfo.fResult ); + hb_retl( dbLockInfo.fResult ); } HB_FUNC( DBRLOCKLIST ) @@ -2278,7 +1555,7 @@ HB_FUNC( DBRLOCKLIST ) if( s_pCurrArea ) SELF_INFO( ( AREAP ) s_pCurrArea->pArea, DBI_GETLOCKARRAY, pList ); else - hb_errRT_DBCMD( EG_NOTABLE, 2001, NULL, "DBRLOCKLIST" ); + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "DBRLOCKLIST" ); hb_itemRelease( hb_itemReturn( pList ) ); } @@ -2288,18 +1565,18 @@ HB_FUNC( DBRUNLOCK ) if( s_pCurrArea ) SELF_UNLOCK( ( AREAP ) s_pCurrArea->pArea, hb_parnl( 1 ) ); else - hb_errRT_DBCMD( EG_NOTABLE, 2001, NULL, "DBRUNLOCK" ); + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "DBRUNLOCK" ); } HB_FUNC( DBSEEK ) { + PHB_ITEM pKey; + BOOL bSoftSeek, bFindLast; + if( s_pCurrArea ) { if( !ISNIL( 1 ) ) { - PHB_ITEM pKey; - BOOL bSoftSeek, bFindLast; - pKey = hb_param( 1, HB_IT_ANY ); bSoftSeek = ISLOG( 2 ) ? hb_parl( 2 ) : hb_set.HB_SET_SOFTSEEK; bFindLast = ISLOG( 3 ) ? hb_parl( 3 ) : FALSE; @@ -2310,10 +1587,11 @@ HB_FUNC( DBSEEK ) } } else - hb_errRT_DBCMD( EG_ARG, 1001, NULL, "DBSEEK" ); + hb_errRT_DBCMD( EG_ARG, EDBCMD_SEEK_BADPARAMETER, NULL, "DBSEEK" ); } else - hb_errRT_DBCMD( EG_NOTABLE, 2001, NULL, "DBSEEK" ); + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "DBSEEK" ); + hb_retl( FALSE ); } @@ -2322,15 +1600,12 @@ HB_FUNC( DBSELECTAREA ) USHORT uiNewArea; char * szAlias; LPAREANODE pAreaNode; + ULONG ulLen; if( ISCHAR( 1 ) ) { - ULONG ulLen; - szAlias = hb_parc( 1 ); - ulLen = strlen( szAlias ); - if( ulLen >= 1 && szAlias[ 0 ] >= '0' && szAlias[ 0 ] <= '9' ) uiNewArea = atoi( szAlias ); else if( ulLen == 1 && toupper( szAlias[ 0 ] ) >= 'A' && toupper( szAlias[ 0 ] ) <= 'K' ) @@ -2339,7 +1614,7 @@ HB_FUNC( DBSELECTAREA ) { if( ( uiNewArea = hb_rddSelect( szAlias ) ) == 0 ) { - hb_errRT_BASE( EG_NOALIAS, 1002, NULL, szAlias ); + hb_errRT_BASE( EG_NOALIAS, EDBCMD_NOALIAS, NULL, szAlias ); return; } } @@ -2367,10 +1642,11 @@ HB_FUNC( DBSELECTAREA ) HB_FUNC( __DBSETFOUND ) { + PHB_ITEM pFound; + if( s_pCurrArea ) { - PHB_ITEM pFound = hb_param( 1, HB_IT_LOGICAL ); - + pFound = hb_param( 1, HB_IT_LOGICAL ); if( pFound ) ( ( AREAP ) s_pCurrArea->pArea )->fFound = hb_itemGetL( pFound ); } @@ -2381,20 +1657,20 @@ HB_FUNC( DBSKIP ) if( s_pCurrArea ) SELF_SKIP( ( AREAP ) s_pCurrArea->pArea, ISNUM( 1 ) ? hb_parnl( 1 ) : 1 ); else - hb_errRT_DBCMD( EG_NOTABLE, 2001, NULL, "DBSKIP" ); + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "DBSKIP" ); } HB_FUNC( DBSETFILTER ) { + PHB_ITEM pBlock, pText; + DBFILTERINFO pFilterInfo; + if( s_pCurrArea ) { - PHB_ITEM pBlock = hb_param( 1, HB_IT_BLOCK ); - + pBlock = hb_param( 1, HB_IT_BLOCK ); if( pBlock ) { - DBFILTERINFO pFilterInfo; - PHB_ITEM pText = hb_param( 2, HB_IT_STRING ); - + pText = hb_param( 2, HB_IT_STRING ); pFilterInfo.itmCobExpr = pBlock; if( pText ) pFilterInfo.abFilterText = pText; @@ -2406,18 +1682,18 @@ HB_FUNC( DBSETFILTER ) } } else - hb_errRT_DBCMD( EG_NOTABLE, 2001, NULL, "DBSETFILTER" ); + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "DBSETFILTER" ); } HB_FUNC( DBSTRUCT ) { + PHB_ITEM pItem, pData; + USHORT uiFields, uiCount; + hb_arrayNew( &hb_stack.Return, 0 ); if( s_pCurrArea ) { - PHB_ITEM pItem, pData; - USHORT uiFields, uiCount; - SELF_FIELDCOUNT( ( AREAP ) s_pCurrArea->pArea, &uiFields ); pData = hb_itemNew( NULL ); pItem = hb_itemNew( NULL ); @@ -2441,16 +1717,14 @@ HB_FUNC( DBSTRUCT ) HB_FUNC( DBTABLEEXT ) { + LPRDDNODE pRddNode; + AREAP pTempArea; + USHORT uiSize, uiRddID; PHB_ITEM pItem; if( !s_pCurrArea ) { - LPRDDNODE pRddNode; - AREAP pTempArea; - USHORT uiSize, uiRddID; - hb_rddCheck(); - uiRddID = 0; pRddNode = hb_rddFindNode( s_szDefDriver, &uiRddID ); if( !pRddNode ) { @@ -2465,7 +1739,11 @@ HB_FUNC( DBTABLEEXT ) /* Need more space? */ SELF_STRUCTSIZE( ( AREAP ) pTempArea, &uiSize ); if( uiSize > sizeof( AREA ) ) /* Size of Area changed */ + { pTempArea = ( AREAP ) hb_xrealloc( pTempArea, uiSize ); + memset( pTempArea, 0, uiSize ); + pTempArea->lprfsHost = &pRddNode->pTable; + } pRddNode->uiAreaSize = uiSize; /* Update the size of WorkArea */ pTempArea->rddID = uiRddID; @@ -2478,9 +1756,8 @@ HB_FUNC( DBTABLEEXT ) SELF_INFO( ( AREAP ) pTempArea, DBI_TABLEEXT, pItem ); hb_retc( hb_itemGetCPtr( pItem ) ); hb_itemRelease( pItem ); - SELF_RELEASE( ( AREAP ) pTempArea ); + SELF_RELEASE( pTempArea ); } - hb_xfree( pTempArea ); } else { @@ -2494,9 +1771,9 @@ HB_FUNC( DBTABLEEXT ) HB_FUNC( DBUNLOCK ) { if( s_pCurrArea ) - SELF_RAWLOCK( ( AREAP ) s_pCurrArea->pArea, FILE_UNLOCK, 0 ); + SELF_UNLOCK( ( AREAP ) s_pCurrArea->pArea, 0 ); else - hb_errRT_DBCMD( EG_NOTABLE, 2001, NULL, "DBUNLOCK" ); + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "DBUNLOCK" ); } HB_FUNC( DBUNLOCKALL ) @@ -2506,7 +1783,7 @@ HB_FUNC( DBUNLOCKALL ) pTempArea = s_pWorkAreas; while( pTempArea ) { - SELF_RAWLOCK( ( AREAP ) pTempArea->pArea, FILE_UNLOCK, 0 ); + SELF_UNLOCK( ( AREAP ) pTempArea->pArea, 0 ); pTempArea = pTempArea->pNext; } } @@ -2517,7 +1794,6 @@ HB_FUNC( DBUSEAREA ) LPRDDNODE pRddNode; LPAREANODE pAreaNode; USHORT uiRddID, uiLen; - ULONG ulLen; DBOPENINFO pInfo; PHB_FNAME pFileName; PHB_ITEM pFileExt; @@ -2526,12 +1802,11 @@ HB_FUNC( DBUSEAREA ) s_bNetError = FALSE; + /* New area? */ if( hb_parl( 1 ) ) hb_rddSelectFirstAvailable(); - else if( s_pCurrArea ) /* If current WorkArea is in use then close it */ - { - hb_rddReleaseCurrentArea( TRUE ); /* close before releasing */ - } + else if( s_pCurrArea ) /* If current WorkArea is in use then close it */ + hb_rddReleaseCurrentArea(); hb_rddCheck(); uiLen = ( USHORT ) hb_parclen( 2 ); @@ -2546,51 +1821,52 @@ HB_FUNC( DBUSEAREA ) else szDriver = s_szDefDriver; - uiRddID = 0; pRddNode = hb_rddFindNode( szDriver, &uiRddID ); if( !pRddNode ) { - hb_errRT_DBCMD( EG_ARG, 1015, NULL, "DBUSEAREA" ); + hb_errRT_DBCMD( EG_ARG, EDBCMD_BADPARAMETER, NULL, "DBUSEAREA" ); return; } szFileName = hb_parc( 3 ); if( strlen( szFileName ) == 0 ) { - hb_errRT_DBCMD( EG_ARG, 1005, NULL, "DBUSEAREA" ); + hb_errRT_DBCMD( EG_ARG, EDBCMD_USE_BADPARAMETER, NULL, "DBUSEAREA" ); return; } pFileName = hb_fsFNameSplit( szFileName ); strncpy( szAlias, hb_parc( 4 ), HARBOUR_MAX_RDD_ALIAS_LENGTH ); - ulLen = strlen( szAlias ); - if( ulLen == 0 ) + uiLen = strlen( szAlias ); + if( uiLen == 0 ) strncpy( szAlias, pFileName->szName, HARBOUR_MAX_RDD_ALIAS_LENGTH ); - else if( ulLen == 1 ) + else if( uiLen == 1 ) { /* Alias with a single letter. Only are valid 'L' and > 'M' */ if( toupper( szAlias[ 0 ] ) < 'N' && toupper( szAlias[ 0 ] ) != 'L' ) { hb_xfree( pFileName ); - hb_errRT_DBCMD( EG_DUPALIAS, 1011, NULL, "DBUSEAREA" ); + hb_errRT_DBCMD( EG_DUPALIAS, EDBCMD_DUPALIAS, NULL, "DBUSEAREA" ); return; } } /* Create a new WorkArea node */ - s_pCurrArea = hb_rddNewAreaNode( pRddNode, uiRddID ); - szFileName = ( char * ) hb_xgrab( _POSIX_PATH_MAX + 3 ); - strcpy( szFileName, hb_parc( 3 ) ); + szFileName = ( char * ) hb_xgrab( _POSIX_PATH_MAX + 1 ); + strncpy( szFileName, hb_parc( 3 ), _POSIX_PATH_MAX ); if( !pFileName->szExtension ) { pFileExt = hb_itemPutC( NULL, "" ); SELF_INFO( ( AREAP ) s_pCurrArea->pArea, DBI_TABLEEXT, pFileExt ); - strcat( szFileName, hb_itemGetCPtr( pFileExt ) ); + strncat( szFileName, hb_itemGetCPtr( pFileExt ), _POSIX_PATH_MAX - + strlen( szFileName ) ); hb_itemRelease( pFileExt ); } hb_xfree( pFileName ); + + /* Fill pInfo structure */ pInfo.uiArea = s_uiCurrArea; pInfo.abName = ( BYTE * ) szFileName; pInfo.atomAlias = ( BYTE * ) szAlias; @@ -2600,7 +1876,6 @@ HB_FUNC( DBUSEAREA ) ( ( AREAP ) s_pCurrArea->pArea )->uiArea = s_uiCurrArea; /* Insert the new WorkArea node */ - if( !s_pWorkAreas ) s_pWorkAreas = s_pCurrArea; /* The new WorkArea node is the first */ else @@ -2632,32 +1907,12 @@ HB_FUNC( DBUSEAREA ) } } - ( ( AREAP ) s_pCurrArea->pArea )->lpDataInfo->szFileName = szFileName; + /* Open file */ if( SELF_OPEN( ( AREAP ) s_pCurrArea->pArea, &pInfo ) == FAILURE ) { - SELF_RELEASE( ( AREAP ) s_pCurrArea->pArea ); - - if( s_pWorkAreas == s_pCurrArea ) - { - s_pWorkAreas = s_pCurrArea->pNext; - if( s_pWorkAreas ) - s_pWorkAreas->pPrev = NULL; - } - else - { - if( s_pCurrArea->pPrev ) - s_pCurrArea->pPrev->pNext = s_pCurrArea->pNext; - if( s_pCurrArea->pNext ) - s_pCurrArea->pNext->pPrev = s_pCurrArea->pPrev; - } - - hb_xfree( s_pCurrArea->pArea ); - hb_xfree( s_pCurrArea ); - s_pCurrArea = NULL; + hb_rddReleaseCurrentArea(); return; } - SELF_RECCOUNT( ( AREAP ) s_pCurrArea->pArea, &ulLen ); - ( ( AREAP ) s_pCurrArea->pArea )->lpExtendInfo->ulRecCount = ulLen; } HB_FUNC( __DBZAP ) @@ -2665,7 +1920,7 @@ HB_FUNC( __DBZAP ) if( s_pCurrArea ) SELF_ZAP( ( AREAP ) s_pCurrArea->pArea ); else - hb_errRT_DBCMD( EG_NOTABLE, 2001, NULL, "__DBZAP" ); + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "__DBZAP" ); } HB_FUNC( DELETED ) @@ -2698,100 +1953,84 @@ HB_FUNC( FCOUNT ) HB_FUNC( FIELDGET ) { PHB_ITEM pItem; - USHORT uiField; + USHORT uiField, uiFields; pItem = hb_itemNew( NULL ); uiField = hb_parni( 1 ); if( s_pCurrArea && uiField ) - SELF_GETVALUE( ( AREAP ) s_pCurrArea->pArea, uiField, pItem ); + { + if( SELF_FIELDCOUNT( ( AREAP ) s_pCurrArea->pArea, &uiFields ) == SUCCESS && + uiField > 0 && uiField <= uiFields ) + SELF_GETVALUE( ( AREAP ) s_pCurrArea->pArea, uiField, pItem ); + } hb_itemRelease( hb_itemReturn( pItem ) ); } HB_FUNC( FIELDNAME ) { + char * szName; + USHORT uiFields, uiIndex; + if( s_pCurrArea ) { - USHORT uiFields, uiIndex; - uiIndex = hb_parni( 1 ); - if( SELF_FIELDCOUNT( ( AREAP ) s_pCurrArea->pArea, &uiFields ) == SUCCESS ) + if( SELF_FIELDCOUNT( ( AREAP ) s_pCurrArea->pArea, &uiFields ) == SUCCESS && + uiIndex > 0 && uiIndex <= uiFields ) { - if( uiIndex > 0 && uiIndex <= uiFields ) - { - char * szName; - - szName = ( char * ) hb_xgrab( HARBOUR_MAX_RDD_FIELDNAME_LENGTH + 1 ); - SELF_FIELDNAME( ( AREAP ) s_pCurrArea->pArea, hb_parni( 1 ), szName ); - hb_retc( szName ); - hb_xfree( szName ); - return; - } - hb_errRT_DBCMD( EG_ARG, 1009, NULL, "FIELDNAME" ); + szName = ( char * ) hb_xgrab( HARBOUR_MAX_RDD_FIELDNAME_LENGTH + 1 ); + SELF_FIELDNAME( ( AREAP ) s_pCurrArea->pArea, hb_parni( 1 ), szName ); + hb_retc( szName ); + hb_xfree( szName ); + return; } + hb_errRT_DBCMD( EG_ARG, EDBCMD_FIELDNAME_BADPARAMETER, NULL, "FIELDNAME" ); } hb_retc( "" ); } HB_FUNC( FIELDPOS ) { + char szName[ HARBOUR_MAX_RDD_FIELDNAME_LENGTH ]; + if( s_pCurrArea ) { - USHORT uiCount; - LPFIELD pField; - - char szName[ HARBOUR_MAX_RDD_FIELDNAME_LENGTH ]; - hb_strncpyUpper( szName, hb_parc( 1 ), hb_parclen( 1 ) ); - uiCount = 0; - pField = ( ( AREAP ) s_pCurrArea->pArea )->lpFields; - while( pField ) - { - ++uiCount; - if( strcmp( szName, ( ( PHB_DYNS ) pField->sym )->pSymbol->szName ) == 0 ) - { - hb_retni( uiCount ); - return; - } - pField = pField->lpfNext; - } + hb_retni( hb_rddFieldIndex( ( AREAP ) s_pCurrArea->pArea, szName ) ); } - hb_retni( 0 ); + else + hb_retni( 0 ); } HB_FUNC( FIELDPUT ) { USHORT uiIndex; + PHB_ITEM pItem; uiIndex = hb_parni( 1 ); if( s_pCurrArea && uiIndex ) { - PHB_ITEM pItem; - pItem = hb_param( 2, HB_IT_ANY ); if( SELF_PUTVALUE( ( AREAP ) s_pCurrArea->pArea, uiIndex, pItem ) == SUCCESS ) - { hb_itemReturn( pItem ); - } } } HB_FUNC( FLOCK ) { - DBLOCKINFO pLockInfo; + DBLOCKINFO dbLockInfo; - pLockInfo.fResult = FALSE; + dbLockInfo.fResult = FALSE; if( s_pCurrArea ) { - pLockInfo.itmRecID = 0; - pLockInfo.uiMethod = FILE_LOCK; - SELF_LOCK( ( AREAP ) s_pCurrArea->pArea, &pLockInfo ); + dbLockInfo.uiMethod = DBLM_FILE; + SELF_LOCK( ( AREAP ) s_pCurrArea->pArea, &dbLockInfo ); } else - hb_errRT_DBCMD( EG_NOTABLE, 2001, NULL, "FLOCK" ); + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "FLOCK" ); - hb_retl( pLockInfo.fResult ); + hb_retl( dbLockInfo.fResult ); } HB_FUNC( FOUND ) @@ -2805,12 +2044,12 @@ HB_FUNC( FOUND ) HB_FUNC( HEADER ) { + PHB_ITEM pRecSize; + if( !s_pCurrArea ) hb_retni( 0 ); else { - PHB_ITEM pRecSize; - pRecSize = hb_itemNew( NULL ); SELF_INFO( ( AREAP ) s_pCurrArea->pArea, DBI_GETHEADERSIZE, pRecSize ); hb_itemRelease( hb_itemReturn( pRecSize ) ); @@ -2819,10 +2058,10 @@ HB_FUNC( HEADER ) HB_FUNC( INDEXORD ) { + DBORDERINFO pInfo; + if( s_pCurrArea ) { - DBORDERINFO pInfo; - pInfo.itmResult = hb_itemPutNI( NULL, 0 ); pInfo.itmOrder = NULL; SELF_ORDINFO( ( AREAP ) s_pCurrArea->pArea, DBOI_NUMBER, &pInfo ); @@ -2834,34 +2073,29 @@ HB_FUNC( INDEXORD ) } /* Same as RECCOUNT() */ - HB_FUNC( LASTREC ) { ULONG ulRecCount = 0; if( s_pCurrArea ) - { SELF_RECCOUNT( ( AREAP ) s_pCurrArea->pArea, &ulRecCount ); - ( ( AREAP ) s_pCurrArea->pArea )->lpExtendInfo->ulRecCount = ulRecCount; - } hb_retnl( ulRecCount ); } HB_FUNC( LOCK ) { - DBLOCKINFO pLockInfo; + DBLOCKINFO dbLockInfo; - pLockInfo.fResult = FALSE; + dbLockInfo.fResult = FALSE; if( s_pCurrArea ) { - pLockInfo.itmRecID = 0; - pLockInfo.uiMethod = FILE_LOCK; - SELF_LOCK( ( AREAP ) s_pCurrArea->pArea, &pLockInfo ); + dbLockInfo.uiMethod = DBLM_FILE; + SELF_LOCK( ( AREAP ) s_pCurrArea->pArea, &dbLockInfo ); } else - hb_errRT_DBCMD( EG_NOTABLE, 2001, NULL, "LOCK" ); + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "LOCK" ); - hb_retl( pLockInfo.fResult ); + hb_retl( dbLockInfo.fResult ); } HB_FUNC( LUPDATE ) @@ -2883,24 +2117,21 @@ HB_FUNC( NETERR ) HB_FUNC( ORDBAGEXT ) { DBORDERINFO pInfo; + LPRDDNODE pRddNode; + AREAP pTempArea; + USHORT uiSize, uiRddID; pInfo.itmOrder = NULL; - if( !s_pCurrArea ) { - LPRDDNODE pRddNode; - AREAP pTempArea; - USHORT uiSize, uiRddID; - hb_rddCheck(); - uiRddID = 0; pRddNode = hb_rddFindNode( s_szDefDriver, &uiRddID ); if( !pRddNode ) { hb_retc( "" ); return; } - uiSize = sizeof( AREA ); /* Default Size Area */ + uiSize = sizeof( AREA ); /* Default Size Area */ pTempArea = ( AREAP ) hb_xgrab( uiSize ); memset( pTempArea, 0, uiSize ); pTempArea->lprfsHost = &pRddNode->pTable; @@ -2908,9 +2139,13 @@ HB_FUNC( ORDBAGEXT ) /* Need more space? */ SELF_STRUCTSIZE( ( AREAP ) pTempArea, &uiSize ); if( uiSize > sizeof( AREA ) ) /* Size of Area changed */ + { pTempArea = ( AREAP ) hb_xrealloc( pTempArea, uiSize ); + memset( pTempArea, 0, uiSize ); + pTempArea->lprfsHost = &pRddNode->pTable; + } - pRddNode->uiAreaSize = uiSize; /* Update the size of WorkArea */ + pRddNode->uiAreaSize = uiSize; /* Update the size of WorkArea */ pTempArea->rddID = uiRddID; if( SELF_NEW( ( AREAP ) pTempArea ) == FAILURE ) @@ -2921,9 +2156,8 @@ HB_FUNC( ORDBAGEXT ) SELF_ORDINFO( pTempArea, DBOI_BAGEXT, &pInfo ); hb_retc( hb_itemGetCPtr( pInfo.itmResult ) ); hb_itemRelease( pInfo.itmResult ); - SELF_RELEASE( ( AREAP ) pTempArea ); + SELF_RELEASE( pTempArea ); } - hb_xfree( pTempArea ); } else { @@ -2936,16 +2170,16 @@ HB_FUNC( ORDBAGEXT ) HB_FUNC( ORDBAGNAME ) { + DBORDERINFO pOrderInfo; + if( s_pCurrArea ) { - DBORDERINFO pOrderInfo; - pOrderInfo.itmOrder = hb_param( 1, HB_IT_STRING ); if( !pOrderInfo.itmOrder ) pOrderInfo.itmOrder = hb_param( 1, HB_IT_NUMERIC ); if( !pOrderInfo.itmOrder ) { - hb_errRT_DBCMD( EG_ARG, 1006, NULL, "ORDBAGNAME" ); + hb_errRT_DBCMD( EG_ARG, EDBCMD_REL_BADPARAMETER, NULL, "ORDBAGNAME" ); return; } pOrderInfo.itmResult = hb_itemPutC( NULL, "" ); @@ -2954,71 +2188,76 @@ HB_FUNC( ORDBAGNAME ) hb_itemRelease( pOrderInfo.itmResult ); } else - hb_errRT_DBCMD( EG_NOTABLE, 2001, NULL, "ORDBAGNAME" ); + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "ORDBAGNAME" ); } HB_FUNC( ORDCONDSET ) { + DBORDERCONDINFO dbOrderCondInfo; + char * szFor; + ULONG ulLen; + PHB_ITEM pItem; + if( s_pCurrArea ) { - LPDBORDERCONDINFO pOrderCondInfo; - char * szFor; - ULONG ulLen; - PHB_ITEM pItem; - - pOrderCondInfo = ( LPDBORDERCONDINFO ) hb_xgrab( sizeof( DBORDERCONDINFO ) ); szFor = hb_parc( 1 ); ulLen = strlen( szFor ); if( ulLen ) { - pOrderCondInfo->abFor = ( BYTE * ) hb_xgrab( ulLen + 1 ); - strcpy( ( char * ) pOrderCondInfo->abFor, szFor ); + dbOrderCondInfo.abFor = ( BYTE * ) hb_xgrab( ulLen + 1 ); + strcpy( ( char * ) dbOrderCondInfo.abFor, szFor ); } else - pOrderCondInfo->abFor = NULL; + dbOrderCondInfo.abFor = NULL; + pItem = hb_param( 2, HB_IT_BLOCK ); if( pItem ) { - pOrderCondInfo->itmCobFor = hb_itemNew( NULL ); - hb_itemCopy( pOrderCondInfo->itmCobFor, pItem ); + dbOrderCondInfo.itmCobFor = hb_itemNew( NULL ); + hb_itemCopy( dbOrderCondInfo.itmCobFor, pItem ); } else - pOrderCondInfo->itmCobFor = NULL; + dbOrderCondInfo.itmCobFor = NULL; if( ISLOG( 3 ) ) - pOrderCondInfo->fAll = hb_parl( 3 ); + dbOrderCondInfo.fAll = hb_parl( 3 ); else - pOrderCondInfo->fAll = TRUE; + dbOrderCondInfo.fAll = TRUE; + pItem = hb_param( 4, HB_IT_BLOCK ); if( pItem ) { - pOrderCondInfo->itmCobWhile = hb_itemNew( NULL ); - hb_itemCopy( pOrderCondInfo->itmCobWhile, pItem ); + dbOrderCondInfo.itmCobWhile = hb_itemNew( NULL ); + hb_itemCopy( dbOrderCondInfo.itmCobWhile, pItem ); } else - pOrderCondInfo->itmCobWhile = NULL; + dbOrderCondInfo.itmCobWhile = NULL; + pItem = hb_param( 5, HB_IT_BLOCK ); if( pItem ) { - pOrderCondInfo->itmCobEval = hb_itemNew( NULL ); - hb_itemCopy( pOrderCondInfo->itmCobEval, pItem ); + dbOrderCondInfo.itmCobEval = hb_itemNew( NULL ); + hb_itemCopy( dbOrderCondInfo.itmCobEval, pItem ); } else - pOrderCondInfo->itmCobEval = NULL; - pOrderCondInfo->lStep = hb_parnl( 6 ); - pOrderCondInfo->lStartRecno = hb_parnl( 7 ); - pOrderCondInfo->lNextCount = hb_parnl( 8 ); - pOrderCondInfo->lRecno = hb_parnl( 9 ); - pOrderCondInfo->fRest = hb_parl( 10 ); - pOrderCondInfo->fDescending = hb_parl( 11 ); - pOrderCondInfo->fAdditive = hb_parl( 12 ); - pOrderCondInfo->fScoped = hb_parl( 13 ); - pOrderCondInfo->fCustom = hb_parl( 14 ); - pOrderCondInfo->fNoOptimize = hb_parl( 15 ); - if( !pOrderCondInfo->itmCobWhile ) - pOrderCondInfo->fRest = TRUE; - if( pOrderCondInfo->lNextCount || pOrderCondInfo->lRecno || pOrderCondInfo->fRest ) - pOrderCondInfo->fAll = FALSE; - hb_retl( SELF_ORDSETCOND( ( AREAP ) s_pCurrArea->pArea, pOrderCondInfo ) == SUCCESS ); + dbOrderCondInfo.itmCobEval = NULL; + + dbOrderCondInfo.lStep = hb_parnl( 6 ); + dbOrderCondInfo.lStartRecno = hb_parnl( 7 ); + dbOrderCondInfo.lNextCount = hb_parnl( 8 ); + dbOrderCondInfo.lRecno = hb_parnl( 9 ); + dbOrderCondInfo.fRest = hb_parl( 10 ); + dbOrderCondInfo.fDescending = hb_parl( 11 ); + dbOrderCondInfo.fAdditive = hb_parl( 12 ); + dbOrderCondInfo.fScoped = hb_parl( 13 ); + dbOrderCondInfo.fCustom = hb_parl( 14 ); + dbOrderCondInfo.fNoOptimize = hb_parl( 15 ); + + if( !dbOrderCondInfo.itmCobWhile ) + dbOrderCondInfo.fRest = TRUE; + if( dbOrderCondInfo.lNextCount || dbOrderCondInfo.lRecno || dbOrderCondInfo.fRest ) + dbOrderCondInfo.fAll = FALSE; + + hb_retl( SELF_ORDSETCOND( ( AREAP ) s_pCurrArea->pArea, &dbOrderCondInfo ) == SUCCESS ); } else hb_retl( FALSE ); @@ -3026,10 +2265,10 @@ HB_FUNC( ORDCONDSET ) HB_FUNC( ORDCREATE ) { + DBORDERCREATEINFO pOrderInfo; + if( s_pCurrArea ) { - DBORDERCREATEINFO pOrderInfo; - pOrderInfo.abBagName = ( BYTE * ) hb_parc( 1 ); pOrderInfo.atomBagName = ( BYTE * ) hb_parc( 2 ); pOrderInfo.abExpr = hb_param( 3, HB_IT_STRING ); @@ -3037,7 +2276,7 @@ HB_FUNC( ORDCREATE ) ( strlen( ( char * ) pOrderInfo.atomBagName ) == 0 ) ) || !pOrderInfo.abExpr ) { - hb_errRT_DBCMD( EG_ARG, 1006, NULL, "ORDCREATE" ); + hb_errRT_DBCMD( EG_ARG, EDBCMD_REL_BADPARAMETER, NULL, "ORDCREATE" ); return; } pOrderInfo.itmCobExpr = hb_param( 4, HB_IT_BLOCK ); @@ -3048,15 +2287,15 @@ HB_FUNC( ORDCREATE ) SELF_ORDCREATE( ( AREAP ) s_pCurrArea->pArea, &pOrderInfo ); } else - hb_errRT_DBCMD( EG_NOTABLE, 2001, NULL, "ORDCREATE" ); + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "ORDCREATE" ); } HB_FUNC( ORDDESTROY ) { + DBORDERINFO pOrderInfo; + if( s_pCurrArea ) { - DBORDERINFO pOrderInfo; - pOrderInfo.itmOrder = hb_param( 1, HB_IT_STRING ); if( !pOrderInfo.itmOrder ) pOrderInfo.itmOrder = hb_param( 1, HB_IT_NUMERIC ); @@ -3067,17 +2306,17 @@ HB_FUNC( ORDDESTROY ) HB_FUNC( ORDFOR ) { + DBORDERINFO pOrderInfo; + if( s_pCurrArea ) { - DBORDERINFO pOrderInfo; - pOrderInfo.itmOrder = hb_param( 1, HB_IT_STRING ); if( !pOrderInfo.itmOrder ) pOrderInfo.itmOrder = hb_param( 1, HB_IT_NUMERIC ); pOrderInfo.atomBagName = hb_param( 2, HB_IT_STRING ); if( !pOrderInfo.itmOrder ) { - hb_errRT_DBCMD( EG_ARG, 1006, NULL, "ORDFOR" ); + hb_errRT_DBCMD( EG_ARG, EDBCMD_REL_BADPARAMETER, NULL, "ORDFOR" ); return; } pOrderInfo.itmResult = hb_itemPutC( NULL, "" ); @@ -3086,22 +2325,22 @@ HB_FUNC( ORDFOR ) hb_itemRelease( pOrderInfo.itmResult ); } else - hb_errRT_DBCMD( EG_NOTABLE, 2001, NULL, "ORDFOR" ); + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "ORDFOR" ); } HB_FUNC( ORDKEY ) { + DBORDERINFO pOrderInfo; + if( s_pCurrArea ) { - DBORDERINFO pOrderInfo; - pOrderInfo.itmOrder = hb_param( 1, HB_IT_STRING ); if( !pOrderInfo.itmOrder ) pOrderInfo.itmOrder = hb_param( 1, HB_IT_NUMERIC ); pOrderInfo.atomBagName = hb_param( 2, HB_IT_STRING ); if( !pOrderInfo.itmOrder ) { - hb_errRT_DBCMD( EG_ARG, 1006, NULL, "ORDKEY" ); + hb_errRT_DBCMD( EG_ARG, EDBCMD_REL_BADPARAMETER, NULL, "ORDKEY" ); return; } pOrderInfo.itmResult = hb_itemPutC( NULL, "" ); @@ -3110,26 +2349,26 @@ HB_FUNC( ORDKEY ) hb_itemRelease( pOrderInfo.itmResult ); } else - hb_errRT_DBCMD( EG_NOTABLE, 2001, NULL, "ORDKEY" ); + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "ORDKEY" ); } HB_FUNC( ORDLISTADD ) { + DBORDERINFO pOrderInfo; + if( s_pCurrArea ) { - DBORDERINFO pOrderInfo; - pOrderInfo.atomBagName = hb_param( 1, HB_IT_STRING ); pOrderInfo.itmOrder = hb_param( 2, HB_IT_STRING ); if( !pOrderInfo.atomBagName ) { - hb_errRT_DBCMD( EG_ARG, 1006, NULL, "ORDLISTADD" ); + hb_errRT_DBCMD( EG_ARG, EDBCMD_REL_BADPARAMETER, NULL, "ORDLISTADD" ); return; } SELF_ORDLSTADD( ( AREAP ) s_pCurrArea->pArea, &pOrderInfo ); } else - hb_errRT_DBCMD( EG_NOTABLE, 2001, NULL, "ORDLISTADD" ); + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "ORDLISTADD" ); } HB_FUNC( ORDLISTCLEAR ) @@ -3137,7 +2376,7 @@ HB_FUNC( ORDLISTCLEAR ) if( s_pCurrArea ) SELF_ORDLSTCLEAR( ( AREAP ) s_pCurrArea->pArea ); else - hb_errRT_DBCMD( EG_NOTABLE, 2001, NULL, "ORDLISTCLEAR" ); + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "ORDLISTCLEAR" ); } HB_FUNC( ORDLISTREBUILD ) @@ -3145,20 +2384,20 @@ HB_FUNC( ORDLISTREBUILD ) if( s_pCurrArea ) SELF_ORDLSTREBUILD( ( AREAP ) s_pCurrArea->pArea ); else - hb_errRT_DBCMD( EG_NOTABLE, 2001, NULL, "ORDLISTCLEAR" ); + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "ORDLISTREBUILD" ); } HB_FUNC( ORDNAME ) { + DBORDERINFO pOrderInfo; + if( s_pCurrArea ) { - DBORDERINFO pOrderInfo; - pOrderInfo.itmOrder = hb_param( 1, HB_IT_NUMERIC ); pOrderInfo.atomBagName = hb_param( 2, HB_IT_STRING ); if( !pOrderInfo.itmOrder ) { - hb_errRT_DBCMD( EG_ARG, 1006, NULL, "ORDNAME" ); + hb_errRT_DBCMD( EG_ARG, EDBCMD_REL_BADPARAMETER, NULL, "ORDNAME" ); return; } pOrderInfo.itmResult = hb_itemPutC( NULL, "" ); @@ -3167,20 +2406,20 @@ HB_FUNC( ORDNAME ) hb_itemRelease( pOrderInfo.itmResult ); } else - hb_errRT_DBCMD( EG_NOTABLE, 2001, NULL, "ORDNAME" ); + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "ORDNAME" ); } HB_FUNC( ORDNUMBER ) { + DBORDERINFO pOrderInfo; + if( s_pCurrArea ) { - DBORDERINFO pOrderInfo; - pOrderInfo.itmOrder = hb_param( 1, HB_IT_STRING ); pOrderInfo.atomBagName = hb_param( 2, HB_IT_STRING ); if( !pOrderInfo.itmOrder ) { - hb_errRT_DBCMD( EG_ARG, 1006, NULL, "ORDNUMBER" ); + hb_errRT_DBCMD( EG_ARG, EDBCMD_REL_BADPARAMETER, NULL, "ORDNUMBER" ); return; } pOrderInfo.itmResult = hb_itemPutNI( NULL, 0 ); @@ -3189,15 +2428,15 @@ HB_FUNC( ORDNUMBER ) hb_itemRelease( pOrderInfo.itmResult ); } else - hb_errRT_DBCMD( EG_NOTABLE, 2001, NULL, "ORDNUMBER" ); + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "ORDNUMBER" ); } HB_FUNC( ORDSETFOCUS ) { + DBORDERINFO pInfo; + if( s_pCurrArea ) { - DBORDERINFO pInfo; - pInfo.itmOrder = hb_param( 1, HB_IT_STRING ); if( !pInfo.itmOrder ) pInfo.itmOrder = hb_param( 1, HB_IT_NUMERIC ); @@ -3208,7 +2447,7 @@ HB_FUNC( ORDSETFOCUS ) hb_itemRelease( pInfo.itmResult ); } else - hb_errRT_DBCMD( EG_NOTABLE, 2001, NULL, "ORDSETFOCUS" ); + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "ORDSETFOCUS" ); } HB_FUNC( RDDLIST ) @@ -3233,10 +2472,10 @@ HB_FUNC( RDDLIST ) HB_FUNC( RDDNAME ) { + char * pBuffer; + if( s_pCurrArea ) { - char * pBuffer; - pBuffer = ( char * ) hb_xgrab( HARBOUR_MAX_RDD_DRIVERNAME_LENGTH + 1 ); pBuffer[ 0 ] = '\0'; SELF_SYSNAME( ( AREAP ) s_pCurrArea->pArea, ( BYTE * ) pBuffer ); @@ -3245,7 +2484,7 @@ HB_FUNC( RDDNAME ) } else { - hb_errRT_DBCMD( EG_NOTABLE, 2001, NULL, "RDDNAME" ); + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "RDDNAME" ); hb_retc( "" ); } } @@ -3253,14 +2492,13 @@ HB_FUNC( RDDNAME ) HB_FUNC( RDDREGISTER ) { USHORT uiLen; + char szDriver[ HARBOUR_MAX_RDD_DRIVERNAME_LENGTH + 1 ]; hb_rddCheck(); uiLen = ( USHORT ) hb_parclen( 1 ); if( uiLen > 0 ) { - char szDriver[ HARBOUR_MAX_RDD_DRIVERNAME_LENGTH ]; - if( uiLen > HARBOUR_MAX_RDD_DRIVERNAME_LENGTH ) uiLen = HARBOUR_MAX_RDD_DRIVERNAME_LENGTH; @@ -3278,16 +2516,12 @@ HB_FUNC( RDDREGISTER ) } /* Same as LASTREC() */ - HB_FUNC( RECCOUNT ) { ULONG ulRecCount = 0; if( s_pCurrArea ) - { SELF_RECCOUNT( ( AREAP ) s_pCurrArea->pArea, &ulRecCount ); - ( ( AREAP ) s_pCurrArea->pArea )->lpExtendInfo->ulRecCount = ulRecCount; - } hb_retnl( ulRecCount ); } @@ -3303,10 +2537,10 @@ HB_FUNC( RECNO ) HB_FUNC( RECSIZE ) { + PHB_ITEM pRecSize; + if( s_pCurrArea ) { - PHB_ITEM pRecSize; - pRecSize = hb_itemNew( NULL ); SELF_INFO( ( AREAP ) s_pCurrArea->pArea, DBI_GETRECSIZE, pRecSize ); hb_itemRelease( hb_itemReturn( pRecSize ) ); @@ -3317,24 +2551,18 @@ HB_FUNC( RECSIZE ) HB_FUNC( RLOCK ) { - DBLOCKINFO pLockInfo; + DBLOCKINFO dbLockInfo; - pLockInfo.fResult = FALSE; + dbLockInfo.fResult = FALSE; if( s_pCurrArea ) { - PHB_ITEM pRecNo; - - pRecNo = hb_itemPutNL( NULL, 0 ); - SELF_RECNO( ( AREAP ) s_pCurrArea->pArea, pRecNo ); - pLockInfo.itmRecID = hb_itemGetNL( pRecNo ); - pLockInfo.uiMethod = REC_LOCK; - SELF_LOCK( ( AREAP ) s_pCurrArea->pArea, &pLockInfo ); - hb_itemRelease( pRecNo ); + dbLockInfo.uiMethod = DBLM_EXCLUSIVE; + SELF_LOCK( ( AREAP ) s_pCurrArea->pArea, &dbLockInfo ); } else - hb_errRT_DBCMD( EG_NOTABLE, 2001, NULL, "RLOCK" ); + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "RLOCK" ); - hb_retl( pLockInfo.fResult ); + hb_retl( dbLockInfo.fResult ); } HB_FUNC( SELECT ) @@ -3384,6 +2612,7 @@ HB_FUNC( __RDDSETDEFAULT ) HB_FUNC( RDDSETDEFAULT ) { USHORT uiLen; + char szNewDriver[ HARBOUR_MAX_RDD_DRIVERNAME_LENGTH ]; hb_rddCheck(); hb_retc( s_szDefDriver ); @@ -3391,8 +2620,6 @@ HB_FUNC( RDDSETDEFAULT ) uiLen = ( USHORT ) hb_parclen( 1 ); if( uiLen > 0 ) { - char szNewDriver[ HARBOUR_MAX_RDD_DRIVERNAME_LENGTH ]; - if( uiLen > HARBOUR_MAX_RDD_DRIVERNAME_LENGTH ) uiLen = HARBOUR_MAX_RDD_DRIVERNAME_LENGTH; @@ -3400,7 +2627,7 @@ HB_FUNC( RDDSETDEFAULT ) if( !hb_rddFindNode( szNewDriver, NULL ) ) { - hb_errRT_DBCMD( EG_ARG, 1015, NULL, "RDDSETDEFAULT" ); + hb_errRT_DBCMD( EG_ARG, EDBCMD_BADPARAMETER, NULL, "RDDSETDEFAULT" ); return; } @@ -3412,6 +2639,7 @@ HB_FUNC( RDDSETDEFAULT ) HB_FUNC( DBSETDRIVER ) { USHORT uiLen; + char szNewDriver[ HARBOUR_MAX_RDD_DRIVERNAME_LENGTH ]; hb_rddCheck(); hb_retc( s_szDefDriver ); @@ -3419,8 +2647,6 @@ HB_FUNC( DBSETDRIVER ) uiLen = ( USHORT ) hb_parclen( 1 ); if( uiLen > 0 ) { - char szNewDriver[ HARBOUR_MAX_RDD_DRIVERNAME_LENGTH ]; - if( uiLen > HARBOUR_MAX_RDD_DRIVERNAME_LENGTH ) uiLen = HARBOUR_MAX_RDD_DRIVERNAME_LENGTH; @@ -3428,7 +2654,7 @@ HB_FUNC( DBSETDRIVER ) if( !hb_rddFindNode( szNewDriver, NULL ) ) { - hb_errRT_DBCMD( EG_ARG, 1015, NULL, "DBSETDRIVER" ); + hb_errRT_DBCMD( EG_ARG, EDBCMD_BADPARAMETER, NULL, "DBSETDRIVER" ); return; } @@ -3439,23 +2665,22 @@ HB_FUNC( DBSETDRIVER ) HB_FUNC( ORDSCOPE ) { - PHB_ITEM pscopeValue; + PHB_ITEM pScopeValue; + DBORDSCOPEINFO sInfo; if( s_pCurrArea ) { - DBORDSCOPEINFO sInfo; - if( hb_pcount() == 0 || !(hb_parinfo( 1 ) & HB_IT_NUMERIC) || ( hb_pcount() > 1 && hb_parinfo( 2 ) != HB_IT_STRING ) ) { - hb_errRT_DBCMD( EG_ARG, 1006, NULL, "ORDSCOPE" ); + hb_errRT_DBCMD( EG_ARG, EDBCMD_REL_BADPARAMETER, NULL, "ORDSCOPE" ); return; } sInfo.nScope = hb_parni( 1 ); - pscopeValue = hb_itemPutC( NULL, "" ); - SELF_SCOPEINFO( ( AREAP ) s_pCurrArea->pArea, sInfo.nScope, pscopeValue ); - hb_retc( hb_itemGetCPtr( pscopeValue ) ); - hb_itemRelease( pscopeValue ); + pScopeValue = hb_itemPutC( NULL, "" ); + SELF_SCOPEINFO( ( AREAP ) s_pCurrArea->pArea, sInfo.nScope, pScopeValue ); + hb_retc( hb_itemGetCPtr( pScopeValue ) ); + hb_itemRelease( pScopeValue ); if( hb_pcount() > 1 ) sInfo.scopeValue = (BYTE*) hb_parc( 2 ); @@ -3464,44 +2689,43 @@ HB_FUNC( ORDSCOPE ) SELF_SETSCOPE( ( AREAP ) s_pCurrArea->pArea, (LPDBOPENINFO) &sInfo ); } else - hb_errRT_DBCMD( EG_NOTABLE, 2001, NULL, "ORDSCOPE" ); - + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "ORDSCOPE" ); } HB_FUNC( DBCLEARRELATION ) { if( s_pCurrArea ) - { SELF_CLEARREL( ( AREAP ) s_pCurrArea->pArea ); - } } HB_FUNC( DBSETRELATION ) { + char * szAlias; + DBRELINFO dbRelations; + LPAREANODE s_pArea, pAreaNode; + USHORT uiChildArea; if( s_pCurrArea ) { - char* szAlias = NULL; - DBRELINFO dbRelations; - LPAREANODE s_pArea = NULL, pAreaNode; - USHORT uiChildArea; + szAlias = NULL; + s_pArea = NULL; - if( hb_pcount() < 2 || ( !( hb_parinfo( 1 ) & HB_IT_NUMERIC ) && ( hb_parinfo( 1 ) != HB_IT_STRING ) ) || + if( hb_pcount() < 2 || ( !( hb_parinfo( 1 ) & HB_IT_NUMERIC ) && + ( hb_parinfo( 1 ) != HB_IT_STRING ) ) || ( hb_pcount() > 3 && !( hb_parinfo( 4 ) & HB_IT_LOGICAL ) ) ) { - hb_errRT_DBCMD( EG_ARG, 1006, NULL, "DBSETRELATION" ); + hb_errRT_DBCMD( EG_ARG, EDBCMD_REL_BADPARAMETER, NULL, "DBSETRELATION" ); return; } + if( hb_parinfo( 1 ) & HB_IT_NUMERIC ) - { uiChildArea = hb_parni( 1 ); - } else { szAlias = hb_parc( 1 ); if( ( uiChildArea = hb_rddSelect( szAlias ) ) == 0 ) { - hb_errRT_BASE( EG_NOALIAS, 1002, NULL, szAlias ); + hb_errRT_BASE( EG_NOALIAS, EDBCMD_NOALIAS, NULL, szAlias ); return; } } @@ -3518,7 +2742,7 @@ HB_FUNC( DBSETRELATION ) } if( !s_pArea ) { - hb_errRT_BASE( EG_NOTABLE, 1002, NULL, szAlias ); + hb_errRT_BASE( EG_NOALIAS, EDBCMD_NOALIAS, NULL, szAlias ); return; } @@ -3528,8 +2752,315 @@ HB_FUNC( DBSETRELATION ) dbRelations.isScoped = ( hb_pcount() > 3 )? hb_parl( 4 ):0; dbRelations.lpdbriNext = NULL; - SELF_SETREL( ( AREAP ) s_pCurrArea->pArea, (LPDBOPENINFO) &dbRelations ); + SELF_SETREL( ( AREAP ) s_pCurrArea->pArea, &dbRelations ); } else - hb_errRT_DBCMD( EG_NOTABLE, 2001, NULL, "DBSETRELATION" ); -} \ No newline at end of file + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "DBSETRELATION" ); +} + + +HB_FUNC( __DBARRANGE ) +{ + USHORT uiNewArea, uiCount; + ULONG ulSize; + char * szFieldLine, * szFieldName, * szPos; + PHB_ITEM pStruct, pFields; + DBSORTINFO dbSortInfo; + LPAREANODE pAreaNode; + + if( s_pCurrArea ) + { + memset( &dbSortInfo, 0, sizeof( DBSORTINFO ) ); + dbSortInfo.dbtri.uiFlags = DBTF_PUTREC; + uiNewArea = hb_parni( 1 ); + + /* Fields structure of source WorkArea */ + pStruct = hb_param( 2 , HB_IT_ARRAY ); + if( pStruct ) + { + dbSortInfo.dbtri.uiItemCount = ( USHORT ) hb_arrayLen( pStruct ); + if( dbSortInfo.dbtri.uiItemCount > 0 ) + { + pFields = hb_itemNew( NULL ); + dbSortInfo.dbtri.lpTransItems = ( LPDBTRANSITEM ) + hb_xgrab( dbSortInfo.dbtri.uiItemCount * + sizeof( DBTRANSITEM ) ); + for( uiCount = 0; uiCount < dbSortInfo.dbtri.uiItemCount; uiCount++ ) + { + if( hb_arrayGet( pStruct, uiCount + 1, pFields ) && HB_IS_ARRAY( pFields ) && + ( USHORT ) hb_arrayLen( pFields ) > 0 ) + { + dbSortInfo.dbtri.lpTransItems[ uiCount ].uiSource = + hb_rddFieldIndex( ( AREAP ) s_pCurrArea->pArea, + hb_arrayGetCPtr( pFields, 1 ) ); + dbSortInfo.dbtri.lpTransItems[ uiCount ].uiDest = + dbSortInfo.dbtri.lpTransItems[ uiCount ].uiSource; + } + else + { + hb_xfree( dbSortInfo.dbtri.lpTransItems ); + dbSortInfo.dbtri.uiItemCount = 0; + break; + } + } + hb_itemRelease( pFields ); + } + } + else + return; + + /* Invalid fields structure? */ + if( dbSortInfo.dbtri.uiItemCount == 0 ) + return; + + dbSortInfo.dbtri.dbsci.itmCobFor = hb_param( 3, HB_IT_BLOCK ); + dbSortInfo.dbtri.dbsci.lpstrFor = NULL; + dbSortInfo.dbtri.dbsci.itmCobWhile = hb_param( 4, HB_IT_BLOCK ); + dbSortInfo.dbtri.dbsci.lpstrWhile = NULL; + dbSortInfo.dbtri.dbsci.lNext = hb_param( 5, HB_IT_NUMERIC ); + dbSortInfo.dbtri.dbsci.itmRecID = hb_param( 6, HB_IT_NUMERIC ); + dbSortInfo.dbtri.dbsci.fRest = hb_param( 7, HB_IT_LOGICAL ); + dbSortInfo.dbtri.dbsci.fIgnoreFilter = dbSortInfo.dbtri.dbsci.fLast = + dbSortInfo.dbtri.dbsci.fIgnoreDuplicates = FALSE; + dbSortInfo.dbtri.dbsci.fIncludeDeleted = TRUE; + + pFields = hb_param( 8, HB_IT_ARRAY ); + if( pFields ) + dbSortInfo.uiItemCount = ( USHORT ) hb_arrayLen( pFields ); + else + dbSortInfo.uiItemCount = 0; + if( dbSortInfo.uiItemCount > 0 ) + { + dbSortInfo.lpdbsItem = ( LPDBSORTITEM ) hb_xgrab( dbSortInfo.uiItemCount * sizeof( DBSORTITEM ) ); + ulSize = 0; + for( uiCount = 1; uiCount <= dbSortInfo.uiItemCount; uiCount++ ) + if( hb_arrayGetCLen( pFields, uiCount ) > ulSize ) + ulSize = hb_arrayGetCLen( pFields, uiCount ); + szFieldLine = ( char * ) hb_xgrab( ulSize + 1 ); + for( uiCount = 0; uiCount < dbSortInfo.uiItemCount; uiCount++ ) + { + dbSortInfo.lpdbsItem[ uiCount ].uiFlags = 0; + ulSize = hb_arrayGetCLen( pFields, uiCount + 1 ); + hb_strncpyUpper( szFieldLine, hb_arrayGetCPtr( pFields, uiCount + 1 ), ulSize ); + szPos = strchr( szFieldLine, '/' ); + if( szPos ) + { + if( * ( szPos + 1 ) == 'D' ) + dbSortInfo.lpdbsItem[ uiCount ].uiFlags |= SF_DESCEND; + else if( * ( szPos + 1 ) == 'C' ) + { + dbSortInfo.lpdbsItem[ uiCount ].uiFlags |= SF_CASE; + dbSortInfo.lpdbsItem[ uiCount ].uiFlags |= SF_ASCEND; + } + else + dbSortInfo.lpdbsItem[ uiCount ].uiFlags |= SF_ASCEND; + if( * ( szPos + 1 ) != 0 && ( ( * ( szPos + 2 ) == 'C' ) || + ( * ( szPos + 2 ) != 0 && * ( szPos + 3 ) == 'C' ) ) ) + dbSortInfo.lpdbsItem[ uiCount ].uiFlags |= SF_CASE; + * szPos = 0; + ulSize = szFieldLine - szPos; + } + else + dbSortInfo.lpdbsItem[ uiCount ].uiFlags |= SF_ASCEND; + szFieldName = szFieldLine; + while( szFieldName[ 0 ] == ' ' ) + szFieldName++; + ulSize = strlen( szFieldName ); + while( ulSize > 1 && szFieldName[ ulSize - 1 ] == ' ' ) + { + ulSize --; + szFieldName[ ulSize ] = 0; + } + dbSortInfo.lpdbsItem[ uiCount ].uiField = + hb_rddFieldIndex( ( AREAP ) s_pCurrArea->pArea, szFieldName ); + + /* Field not found */ + if( dbSortInfo.lpdbsItem[ uiCount ].uiField == 0 ) + { + hb_xfree( dbSortInfo.lpdbsItem ); + dbSortInfo.lpdbsItem = NULL; + break; + } + } + hb_xfree( szFieldLine ); + } + else + return; + + /* Fields not found? */ + if( dbSortInfo.lpdbsItem == NULL ) + return; + + dbSortInfo.dbtri.lpaSource = ( AREAP ) s_pCurrArea->pArea; + dbSortInfo.dbtri.lpaDest = NULL; + pAreaNode = s_pWorkAreas; + while( pAreaNode ) + { + if( ( ( AREAP ) pAreaNode->pArea )->uiArea == uiNewArea ) + { + dbSortInfo.dbtri.lpaDest = ( AREAP ) pAreaNode->pArea; + break; + } + pAreaNode = pAreaNode->pNext; + } + + SELF_SORT( ( AREAP ) s_pCurrArea->pArea, &dbSortInfo ); + + /* Free items */ + if( dbSortInfo.lpdbsItem ) + hb_xfree( dbSortInfo.lpdbsItem ); + if( dbSortInfo.dbtri.uiItemCount > 0 ) + hb_xfree( dbSortInfo.dbtri.lpTransItems ); + } +} + +#ifdef HB_COMPAT_C53 +HB_FUNC( DBINFO ) +{ + PHB_ITEM pType, pInfo; + BOOL bDeleteItem; + + if( s_pCurrArea ) + { + pType = hb_param( 1 , HB_IT_NUMERIC ); + if( pType ) + { + pInfo = hb_param( 2 , HB_IT_ANY ); + if( !pInfo ) + { + pInfo = hb_itemNew( NULL ); + bDeleteItem = TRUE; + } + else + bDeleteItem = FALSE; + SELF_INFO( ( AREAP ) s_pCurrArea->pArea, hb_itemGetNI( pType ), pInfo ); + hb_itemReturn( pInfo ); + if( bDeleteItem ) + hb_itemRelease( pInfo ); + return; + } + hb_errRT_DBCMD( EG_ARG, EDBCMD_DBINFOBADPARAMETER, NULL, "DBINFO" ); + } + else + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "DBINFO" ); +} + +HB_FUNC( DBFIELDINFO ) +{ + PHB_ITEM pType, pInfo; + USHORT uiFields, uiIndex; + BOOL bDeleteItem; + + if( s_pCurrArea ) + { + pType = hb_param( 1 , HB_IT_NUMERIC ); + uiIndex = hb_parni( 2 ); + if( pType && + SELF_FIELDCOUNT( ( AREAP ) s_pCurrArea->pArea, &uiFields ) == SUCCESS && + uiIndex > 0 && uiIndex <= uiFields ) + { + pInfo = hb_param( 3 , HB_IT_ANY ); + if( !pInfo ) + { + pInfo = hb_itemNew( NULL ); + bDeleteItem = TRUE; + } + else + bDeleteItem = FALSE; + SELF_FIELDINFO( ( AREAP ) s_pCurrArea->pArea, uiIndex, hb_itemGetNI( pType ), pInfo ); + hb_itemReturn( pInfo ); + if( bDeleteItem ) + hb_itemRelease( pInfo ); + return; + } + hb_errRT_DBCMD( EG_ARG, EDBCMD_DBCMDBADPARAMETER, NULL, "DBFIELDINFO" ); + } + else + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "DBFIELDINFO" ); +} + +HB_FUNC( DBRECORDINFO ) +{ + PHB_ITEM pType, pRecNo, pInfo; + BOOL bDeleteItem; + + if( s_pCurrArea ) + { + pType = hb_param( 1 , HB_IT_NUMERIC ); + pRecNo = hb_param( 2 , HB_IT_NUMERIC ); + if( pType ) + { + pInfo = hb_param( 3 , HB_IT_ANY ); + if( !pInfo ) + { + pInfo = hb_itemNew( NULL ); + bDeleteItem = TRUE; + } + else + bDeleteItem = FALSE; + SELF_RECINFO( ( AREAP ) s_pCurrArea->pArea, pRecNo, hb_itemGetNI( pType ), pInfo ); + hb_itemReturn( pInfo ); + if( bDeleteItem ) + hb_itemRelease( pInfo ); + return; + } + hb_errRT_DBCMD( EG_ARG, EDBCMD_INFOBADPARAMETER, NULL, "DBRECORDINFO" ); + } + else + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "DBRECORDINFO" ); +} + +HB_FUNC( DBFILEGET ) +{ + PHB_ITEM pFileName, pMode; + char szFileName[ _POSIX_PATH_MAX + 1 ]; + USHORT uiFields, uiIndex; + + if( s_pCurrArea ) + { + uiIndex = hb_parni( 1 ); + pFileName = hb_param( 2 , HB_IT_STRING ); + pMode = hb_param( 3 , HB_IT_NUMERIC ); + if( pFileName && pMode && + SELF_FIELDCOUNT( ( AREAP ) s_pCurrArea->pArea, &uiFields ) == SUCCESS && + uiIndex > 0 && uiIndex <= uiFields ) + { + strncpy( szFileName, hb_itemGetCPtr( pFileName ), _POSIX_PATH_MAX ); + hb_retl( SELF_GETVALUEFILE( ( AREAP ) s_pCurrArea->pArea, uiIndex, szFileName, + hb_itemGetNI( pMode ) ) ); + return; + } + hb_errRT_DBCMD( EG_ARG, EDBCMD_DBFILEGETBADPARAMETER, NULL, "DBFILEGET" ); + } + else + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "DBFILEGET" ); + + hb_retl( FALSE ); +} + +HB_FUNC( DBFILEPUT ) +{ + PHB_ITEM pFileName; + char szFileName[ _POSIX_PATH_MAX + 1 ]; + USHORT uiFields, uiIndex; + + if( s_pCurrArea ) + { + uiIndex = hb_parni( 1 ); + pFileName = hb_param( 2 , HB_IT_STRING ); + if( pFileName && + SELF_FIELDCOUNT( ( AREAP ) s_pCurrArea->pArea, &uiFields ) == SUCCESS && + uiIndex > 0 && uiIndex <= uiFields ) + { + strncpy( szFileName, hb_itemGetCPtr( pFileName ), _POSIX_PATH_MAX ); + hb_retl( SELF_PUTVALUEFILE( ( AREAP ) s_pCurrArea->pArea, uiIndex, szFileName ) ); + return; + } + hb_errRT_DBCMD( EG_ARG, EDBCMD_DBFILEPUTBADPARAMETER, NULL, "DBFILEPUT" ); + } + else + hb_errRT_DBCMD( EG_NOTABLE, EDBCMD_NOTABLE, NULL, "DBFILEPUT" ); + + hb_retl( FALSE ); +} +#endif \ No newline at end of file diff --git a/harbour/source/rdd/dbf0.prg b/harbour/source/rdd/dbf0.prg index b792254fc1..0d12bdf47f 100644 --- a/harbour/source/rdd/dbf0.prg +++ b/harbour/source/rdd/dbf0.prg @@ -43,5 +43,4 @@ init procedure DBFInit rddRegister( "DBF", RDT_FULL ) -return - +return \ No newline at end of file diff --git a/harbour/source/rdd/dbf1.c b/harbour/source/rdd/dbf1.c index 9cfc001535..b7f567618a 100644 --- a/harbour/source/rdd/dbf1.c +++ b/harbour/source/rdd/dbf1.c @@ -33,68 +33,20 @@ * */ -#define SUPERTABLE ( &dbfSuper ) - -#include -#include #include "hbapi.h" -#include "hbapiitm.h" #include "hbinit.h" -#include "hbapirdd.h" -#include "rddsys.ch" -#include "hbapierr.h" -#include "hbdate.h" -#include "hbapilng.h" #include "hbvm.h" +#include "hbapiitm.h" +#include "hbrdddbf.h" +#include "hbapierr.h" +#include "hbapilng.h" +#include "hbset.h" +#include "hbdate.h" +#include "hbdbsort.h" +#include "error.ch" -typedef struct _DBFHEADER -{ - BYTE bVersion; - BYTE bYear; - BYTE bMonth; - BYTE bDay; - ULONG ulRecords; - USHORT uiHeaderLen; - USHORT uiRecordLen; - BYTE bReserved1[ 16 ]; - BYTE bHasTag; - BYTE bReserved2[ 3 ]; -} DBFHEADER; - -typedef DBFHEADER * LPDBFHEADER; - - -typedef struct _DBFFIELD -{ - BYTE bName[ 11 ]; - BYTE bType; - BYTE bReserved1[ 4 ]; - BYTE bLen; - BYTE bDec; - BYTE bReserved2[ 13 ]; - BYTE bHasTag; -} DBFFIELD; - -typedef DBFFIELD * LPDBFFIELD; - - -typedef struct -{ - ULONG lNextBlock; -} MEMOHEADER; - -typedef MEMOHEADER * LPMEMOHEADER; - - -typedef struct _DBFMEMO -{ - BOOL fChanged; /* Memo status */ - BYTE * pData; /* Memo data */ - USHORT uiLen; /* Len of data */ -} DBFMEMO; - -typedef DBFMEMO * LPDBFMEMO; - +/* DJGPP can sprintf a float that is almost 320 digits long */ +#define HB_MAX_DOUBLE_LENGTH 320 HB_FUNC( _DBFC ); HB_FUNC( DBF_GETFUNCTABLE ); @@ -116,729 +68,1274 @@ HB_INIT_SYMBOLS_END( dbf1__InitSymbols ) #pragma startup dbf1__InitSymbols #endif -#define LOCK_START 0x40000000L -#define LOCK_APPEND 0x7FFFFFFEL -#define LOCK_FILE 0x3FFFFFFFL -#define MEMO_BLOCK 512 +static RDDFUNCS dbfSuper = { NULL }; +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_I ) hb_dbfRecNo, + ( 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_VP ) 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_VP ) hb_dbfSetScope, + ( DBENTRYP_VPL ) hb_dbfSkipScope, + ( DBENTRYP_P ) hb_dbfCompile, + ( DBENTRYP_I ) hb_dbfError, + ( DBENTRYP_I ) hb_dbfEvalBlock, + ( DBENTRYP_VSP ) hb_dbfRawLock, + ( DBENTRYP_VL ) hb_dbfLock, + ( DBENTRYP_UL ) hb_dbfUnLock, + ( DBENTRYP_V ) hb_dbfCloseMemFile, + ( DBENTRYP_VP ) hb_dbfCreateMemFile, + ( DBENTRYP_SVPB ) hb_dbfGetValueFile, + ( DBENTRYP_VP ) hb_dbfOpenMemFile, + ( DBENTRYP_SVP ) hb_dbfPutValueFile, + ( DBENTRYP_V ) hb_dbfReadDBHeader, + ( DBENTRYP_V ) hb_dbfWriteDBHeader, + ( DBENTRYP_SVP ) hb_dbfWhoCares + }; -static BOOL hb_nltoa( LONG lValue, char * szBuffer, USHORT uiLen ) +/* + * Common functions. + */ + +/* + * Return the total number of records. + */ +static ULONG hb_dbfCalcRecCount( DBFAREAP pArea ) { - LONG lAbsNumber; - int iCount, iPos; + HB_TRACE(HB_TR_DEBUG, ("hb_dbfCalcRecCount(%p)", pArea)); - HB_TRACE(HB_TR_DEBUG, ("hb_nltoa(%ld, %p, %hu)", lValue, szBuffer, uiLen)); - - lAbsNumber = ( lValue > 0 ) ? lValue : - lValue; - iCount = iPos = uiLen; - while( iCount-- > 0 ) - { - szBuffer[ iCount ] = ( '0' + lAbsNumber % 10 ); - lAbsNumber /= 10; - } - - if( lAbsNumber > 0 ) - { - memset( szBuffer, ' ', uiLen ); - return FALSE; - } - - uiLen--; - for( iCount = 0; iCount < uiLen; iCount++ ) - if( szBuffer[ iCount ] == '0' ) - szBuffer[ iCount ] = ' '; - else - break; - - if( lValue < 0 ) - { - if( szBuffer[ 0 ] != ' ' ) - { - memset( szBuffer, ' ', iPos ); - return FALSE; - } - for( iCount = uiLen; iCount >= 0; iCount-- ) - { - if( szBuffer[ iCount ] == ' ' ) - { - szBuffer[ iCount ] = '-'; - break; - } - } - } - return TRUE; + return ( hb_fsSeek( pArea->hDataFile, 0, FS_END ) - pArea->uiHeaderLen ) / + pArea->uiRecordLen; } -static BOOL hb_ndtoa( double dValue, char * szBuffer, USHORT uiLen, USHORT uiDec ) +/* + * Read current record from file. + */ +static BOOL hb_dbfReadRecord( DBFAREAP pArea ) { - double dAbsNumber; - int iCount; - char szEndChar; + PHB_ITEM pError; - HB_TRACE(HB_TR_DEBUG, ("hb_ndtoa(%lf, %p, %hu, %hu)", dValue, szBuffer, uiLen, uiDec)); + HB_TRACE(HB_TR_DEBUG, ("hb_dbfReadRecord(%p)", pArea)); - if( uiLen > 19 ) - uiLen = 19; - if( uiDec + 2 > uiLen ) - uiDec = uiLen - 2 ; - if( uiDec > 15 ) - uiDec = 15; - dAbsNumber = ( dValue > 0 ) ? dValue : - dValue; - iCount = uiLen - uiDec - ( ( dValue < 0 ) ? 2 : 1 ); - while( iCount-- > 0 ) - dAbsNumber /= 10; - - if( dAbsNumber > 1 || dValue >= 10000000000000000000.0 ) + if( pArea->fEof ) { - memset( szBuffer, ' ', uiLen ); - return FALSE; + pArea->fValidBuffer = TRUE; + return TRUE; } - szEndChar = szBuffer[ uiLen ]; - sprintf( szBuffer, "%*.*f", uiLen, uiDec, dValue ); - szBuffer[ uiLen ] = szEndChar; - return TRUE; -} -static BOOL hb_dbfUpdateHeader( AREAP pArea, ULONG lRecCount ) -{ - DBFHEADER pHeader; - time_t t; - struct tm * pTime; - - HB_TRACE(HB_TR_DEBUG, ("hb_dbfUpdateHeader(%p, %lu)", pArea, lRecCount)); - - hb_fsSeek( pArea->lpDataInfo->hFile, 0, FS_SET ); - if( hb_fsRead( pArea->lpDataInfo->hFile, ( BYTE * ) &pHeader, - sizeof( DBFHEADER ) ) != sizeof( DBFHEADER ) ) - return FALSE; - - time( &t ); - pTime = localtime( &t ); - pHeader.bYear = ( BYTE ) pTime->tm_year; - pHeader.bMonth = ( BYTE ) pTime->tm_mon + 1; - pHeader.bDay = ( BYTE ) pTime->tm_mday; - pHeader.ulRecords = lRecCount; - - hb_fsSeek( pArea->lpDataInfo->hFile, 0, FS_SET ); - if( hb_fsWrite( pArea->lpDataInfo->hFile, ( BYTE * ) &pHeader, - sizeof( DBFHEADER ) ) != sizeof( DBFHEADER ) ) - return FALSE; - - pArea->lpExtendInfo->bYear = pHeader.bYear; - pArea->lpExtendInfo->bMonth = pHeader.bMonth; - pArea->lpExtendInfo->bDay = pHeader.bDay; - return TRUE; -} - -static BOOL hb_dbfWriteMemo( AREAP pArea, LPDBFMEMO pMemo, ULONG * lNewRecNo ) -{ - USHORT uiNumBlocks, uiBytesRead, uiRead, uiCount; - BYTE szBuffer[ MEMO_BLOCK ]; - MEMOHEADER pMemoHeader; - - HB_TRACE(HB_TR_DEBUG, ("hb_dbfWriteMemo(%p, %p, %p)", pArea, pMemo, lNewRecNo)); - - if( !pArea->lpExtendInfo->fExclusive && !pArea->lpDataInfo->fFileLocked && - !hb_fsLock( pArea->lpDataInfo->pNext->hFile, LOCK_APPEND - 1, 1, FL_LOCK ) ) - return FALSE; - - uiNumBlocks = ( pMemo->uiLen + MEMO_BLOCK - 1 ) / MEMO_BLOCK; - if( * lNewRecNo > 0 ) + if( pArea->ulRecNo > pArea->ulRecCount ) { - uiBytesRead = 0; - hb_fsSeek( pArea->lpDataInfo->pNext->hFile, * lNewRecNo * MEMO_BLOCK, FS_SET ); - do + /* Update record count */ + if( pArea->fShared ) + pArea->ulRecCount = hb_dbfCalcRecCount( pArea ); + + if( pArea->ulRecNo > pArea->ulRecCount ) { - uiBytesRead += MEMO_BLOCK; - uiRead = hb_fsRead( pArea->lpDataInfo->pNext->hFile, szBuffer, MEMO_BLOCK ); - if( !uiRead ) - { - if( !pArea->lpExtendInfo->fExclusive && !pArea->lpDataInfo->fFileLocked ) - hb_fsLock( pArea->lpDataInfo->pNext->hFile, LOCK_APPEND - 1, 1, FL_UNLOCK ); - return FALSE; - } - for( uiCount = 0; uiCount < uiRead; uiCount++ ) - if( szBuffer[ uiCount ] == 0x1A ) - break; - } while( uiCount >= MEMO_BLOCK && szBuffer[ uiCount ] != 0x1A ); - if( uiBytesRead <= pMemo->uiLen ) /* Not room for data */ - * lNewRecNo = 0; - } - - if( * lNewRecNo == 0 ) /* Add an entry at eof */ - { - hb_fsSeek( pArea->lpDataInfo->pNext->hFile, 0, FS_SET ); - hb_fsRead( pArea->lpDataInfo->pNext->hFile, ( BYTE * ) &pMemoHeader, - sizeof( MEMOHEADER ) ); - * lNewRecNo = pMemoHeader.lNextBlock; - pMemoHeader.lNextBlock = * lNewRecNo + uiNumBlocks; - hb_fsSeek( pArea->lpDataInfo->pNext->hFile, 0, FS_SET ); - hb_fsWrite( pArea->lpDataInfo->pNext->hFile, ( BYTE * ) &pMemoHeader, - sizeof( MEMOHEADER ) ); - } - - hb_fsSeek( pArea->lpDataInfo->pNext->hFile, * lNewRecNo * MEMO_BLOCK, FS_SET ); - if( hb_fsWrite( pArea->lpDataInfo->pNext->hFile, pMemo->pData, - pMemo->uiLen ) != pMemo->uiLen ) - { - if( !pArea->lpExtendInfo->fExclusive && !pArea->lpDataInfo->fFileLocked ) - hb_fsLock( pArea->lpDataInfo->pNext->hFile, LOCK_APPEND - 1, 1, FL_UNLOCK ); - return FALSE; - } - - szBuffer[ 0 ] = 0x1A; - if( hb_fsWrite( pArea->lpDataInfo->pNext->hFile, szBuffer, 1 ) != 1 ) - { - if( !pArea->lpExtendInfo->fExclusive && !pArea->lpDataInfo->fFileLocked ) - hb_fsLock( pArea->lpDataInfo->pNext->hFile, LOCK_APPEND - 1, 1, FL_UNLOCK ); - return FALSE; - } - - if( !pArea->lpExtendInfo->fExclusive && !pArea->lpDataInfo->fFileLocked ) - hb_fsLock( pArea->lpDataInfo->pNext->hFile, LOCK_APPEND - 1, 1, FL_UNLOCK ); - return TRUE; -} - -static BOOL hb_dbfUpdateRecord( AREAP pArea, ULONG ulRecNo ) -{ - ULONG ulRecCount = pArea->lpExtendInfo->ulRecCount; - USHORT uiCount; - LPFIELD pField; - BYTE pBuffer[ 1 ]; - - HB_TRACE(HB_TR_DEBUG, ("hb_dbfUpdateRecord(%p, %lu)", pArea, ulRecNo)); - - if( ulRecNo > pArea->lpExtendInfo->ulRecCount ) - { - if( SELF_RECCOUNT( pArea, &ulRecCount ) == FAILURE ) - return FALSE; - pArea->lpExtendInfo->ulRecCount = ulRecCount; - } - - if( ulRecNo > 0 && ( ulRecNo <= ulRecCount || pArea->lpDataInfo->fAppend ) ) - { - hb_fsSeek( pArea->lpDataInfo->hFile, pArea->lpExtendInfo->uiHeaderLen + - ( ulRecNo - 1 ) * pArea->lpExtendInfo->uiRecordLen, FS_SET ); - if( pArea->lpDataInfo->fAppend ) - pArea->lpExtendInfo->ulRecCount = ulRecNo; - if( pArea->lpExtendInfo->fHasMemo ) - { - for( uiCount = 0; uiCount < pArea->uiFieldCount; uiCount++ ) - { - pField = pArea->lpFields + uiCount; - if( pField->uiType == 'M' && ( ( LPDBFMEMO ) pField->memo )->fChanged ) - if( SELF_GETVALUEFILE( pArea, uiCount + 1, NULL ) == FAILURE ) - return FALSE; - } - } - if( hb_fsWrite( pArea->lpDataInfo->hFile, pArea->lpExtendInfo->bRecord, - pArea->lpExtendInfo->uiRecordLen ) != pArea->lpExtendInfo->uiRecordLen ) - return FALSE; - - /* Write EOF */ - if( pArea->lpDataInfo->fAppend ) - { - pBuffer[ 0 ] = 0x1A; - if( hb_fsWrite( pArea->lpDataInfo->hFile, pBuffer, 1 ) != 1 ) - return FALSE; - } - - if( !hb_dbfUpdateHeader( pArea, pArea->lpExtendInfo->ulRecCount ) ) - return FALSE; - } - - return TRUE; -} - -static void hb_dbfClearBuffer( AREAP pArea ) -{ - LPFIELD pField; - USHORT uiCount; - - HB_TRACE(HB_TR_DEBUG, ("hb_dbfClearBuffer(%p)", pArea)); - - memset( pArea->lpExtendInfo->bRecord, ' ', pArea->lpExtendInfo->uiRecordLen ); - pArea->lpExtendInfo->bRecord[ pArea->lpExtendInfo->uiRecordLen ] = 0; - pArea->lpExtendInfo->fValidBuffer = TRUE; - - if( pArea->lpExtendInfo->fHasMemo ) - { - for( uiCount = 0; uiCount < pArea->uiFieldCount; uiCount++ ) - { - pField = pArea->lpFields + uiCount; - if( pField->memo ) - { - if( ( ( LPDBFMEMO ) pField->memo )->pData ) - { - hb_xfree( ( ( LPDBFMEMO ) pField->memo )->pData ); - memset( pField->memo, 0, sizeof( DBFMEMO ) ); - } - } - } - } -} - -static void hb_dbfReadMemo( AREAP pArea, LPDBFMEMO pMemo, ULONG lMemoBlock ) -{ - USHORT uiBytesRead, uiMaxRead, uiRead; - BYTE * pData; - - HB_TRACE(HB_TR_DEBUG, ("hb_dbfReadMemo(%p, %p, %lu)", pArea, pMemo, lMemoBlock)); - - hb_fsSeek( pArea->lpDataInfo->pNext->hFile, lMemoBlock, FS_SET ); - uiBytesRead = 0; - uiMaxRead = pMemo->uiLen; - for(;;) - { - if( uiMaxRead < MEMO_BLOCK ) - { - pData = ( BYTE * ) hb_xgrab( uiBytesRead + MEMO_BLOCK + 1 ); - if( pMemo->uiLen > 0 ) - { - memcpy( pData, pMemo->pData, pMemo->uiLen ); - hb_xfree( pMemo->pData ); - } - pMemo->pData = pData; - pMemo->uiLen = uiBytesRead + MEMO_BLOCK + 1; - uiMaxRead = MEMO_BLOCK; - } - uiRead = hb_fsRead( pArea->lpDataInfo->pNext->hFile, - pMemo->pData + uiBytesRead, uiMaxRead ); - if( !uiRead ) - return; - - for(; uiRead > 0; uiBytesRead++, uiRead-- ) - { - if( pMemo->pData[ uiBytesRead ] == 0x1A ) - { - if( uiBytesRead > 0 ) - { - pData = ( BYTE * ) hb_xgrab( uiBytesRead + 1 ); - memcpy( pData, pMemo->pData, uiBytesRead ); - pData[ uiBytesRead ] = 0; - } - else - pData = 0; - hb_xfree( pMemo->pData ); - pMemo->pData = pData; - pMemo->uiLen = uiBytesRead; - return; - } - } - uiMaxRead = 0; - } -} - -static void hb_dbfReadBuffer( AREAP pArea, ULONG lRecNo ) -{ - LPFIELD pField; - USHORT uiCount; - - HB_TRACE(HB_TR_DEBUG, ("hb_dbfReadBuffer(%p, %lu)", pArea, lRecNo)); - - if( pArea->lpExtendInfo->fValidBuffer ) - return; - - pArea->lpExtendInfo->fValidBuffer = TRUE; - if( hb_fsSeek( pArea->lpDataInfo->hFile, pArea->lpExtendInfo->uiHeaderLen + - ( lRecNo - 1 ) * pArea->lpExtendInfo->uiRecordLen, FS_SET ) != - pArea->lpExtendInfo->uiHeaderLen + ( lRecNo - 1 ) * pArea->lpExtendInfo->uiRecordLen || - hb_fsRead( pArea->lpDataInfo->hFile, pArea->lpExtendInfo->bRecord, - pArea->lpExtendInfo->uiRecordLen ) != pArea->lpExtendInfo->uiRecordLen ) - { - hb_dbfClearBuffer( pArea ); - return; - } - - if( pArea->lpExtendInfo->fHasMemo && pArea->lpDataInfo->pNext ) - { - pField = pArea->lpFields; - for( uiCount = 0; uiCount < pArea->uiFieldCount; uiCount++ ) - { - if( pField->uiType == 'M' ) - SELF_PUTVALUEFILE( pArea, uiCount + 1, NULL ); - pField = pField->lpfNext; - } - } -} - -static BOOL hb_dbfIsLocked( AREAP pArea, ULONG lLockPos ) -{ - ULONG lNumLocksPos; - - HB_TRACE(HB_TR_DEBUG, ("hb_dbfIsLocked(%p, %lu)", pArea, lLockPos)); - - lNumLocksPos = pArea->lpDataInfo->lNumLocksPos; - while( lNumLocksPos > 0 ) - { - if( pArea->lpDataInfo->pLocksPos[ lNumLocksPos - 1 ] == lLockPos ) + pArea->fEof = pArea->fValidBuffer = TRUE; return TRUE; - lNumLocksPos--; + } + } + + /* Read data */ + hb_fsSeek( pArea->hDataFile, pArea->uiHeaderLen + ( pArea->ulRecNo - 1 ) * + pArea->uiRecordLen, FS_SET ); + if( hb_fsRead( pArea->hDataFile, pArea->pRecord, pArea->uiRecordLen ) != + pArea->uiRecordLen ) + { + pError = hb_errNew(); + hb_errPutGenCode( pError, EG_READ ); + hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_READ ) ); + hb_errPutSubCode( pError, EDBF_READ ); + SELF_ERROR( ( AREAP ) pArea, pError ); + hb_errRelease( pError ); + return FALSE; + } + + /* Set flags */ + pArea->fValidBuffer = pArea->fPositioned = TRUE; + pArea->fDeleted = ( pArea->pRecord[ 0 ] == '*' ); + return TRUE; +} + +/* + * Write current record to file. + */ +static BOOL hb_dbfWriteRecord( DBFAREAP pArea ) +{ + PHB_ITEM pError; + + HB_TRACE(HB_TR_DEBUG, ("hb_dbfWriteRecord(%p)", pArea)); + + /* Write data */ + hb_fsSeek( pArea->hDataFile, pArea->uiHeaderLen + ( pArea->ulRecNo - 1 ) * + pArea->uiRecordLen, FS_SET ); + if( hb_fsWrite( pArea->hDataFile, pArea->pRecord, pArea->uiRecordLen ) != + pArea->uiRecordLen ) + { + pError = hb_errNew(); + hb_errPutGenCode( pError, EG_WRITE ); + hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_WRITE ) ); + hb_errPutSubCode( pError, EDBF_WRITE ); + SELF_ERROR( ( AREAP ) pArea, pError ); + hb_errRelease( pError ); + return FALSE; + } + return TRUE; +} + +/* + * Unlock all records. + */ +static void hb_dbfUnlockAllRecords( DBFAREAP pArea ) +{ + ULONG ulCount; + + HB_TRACE(HB_TR_DEBUG, ("hb_dbfUnlockAllRecords(%p, %p)", pArea, pItem)); + + if( pArea->pLocksPos ) + { + for( ulCount = 0; ulCount < pArea->ulNumLocksPos; ulCount++ ) + hb_fsLock( pArea->hDataFile, DBF_LOCKPOS + pArea->pLocksPos[ ulCount ], + 1, FL_UNLOCK ); + hb_xfree( pArea->pLocksPos ); + pArea->pLocksPos = NULL; + } + pArea->ulNumLocksPos = 0; +} + +/* + * Unlock a records. + */ +static void hb_dbfUnlockRecord( DBFAREAP pArea, ULONG ulRecNo ) +{ + ULONG ulCount, * pList; + + HB_TRACE(HB_TR_DEBUG, ("hb_dbfUnlockRecord(%p, %lu)", pArea, ulRecNo)); + + if( hb_fsLock( pArea->hDataFile, DBF_LOCKPOS + pArea->pLocksPos[ ulRecNo - 1 ], + 1, FL_UNLOCK ) ) + { + if( pArea->ulNumLocksPos == 1 ) /* Delete the list */ + { + hb_xfree( pArea->pLocksPos ); + pArea->pLocksPos = NULL; + pArea->ulNumLocksPos = 0; + } + else /* Resize the list */ + { + /* Search the locked record */ + for( ulCount = 0; ulCount < pArea->ulNumLocksPos; ulCount++ ) + { + if( pArea->pLocksPos[ ulCount ] == ulRecNo ) + { + pList = pArea->pLocksPos + ulCount; + memmove( pList, pList + 1, ( pArea->ulNumLocksPos - ulCount - 1 ) * + sizeof( ULONG ) ); + pArea->pLocksPos = ( ULONG * ) hb_xrealloc( pArea->pLocksPos, + ( pArea->ulNumLocksPos - 1 ) * + sizeof( ULONG ) ); + pArea->ulNumLocksPos --; + return; + } + } + } + } +} + +/* + * Lock a record. + */ +static ERRCODE hb_dbfLockRecord( DBFAREAP pArea, ULONG ulRecNo, BOOL * pResult, + BOOL bExclusive ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_dbfLockRecord(%p, %lu, %p, %i)", pArea, ulRecNo, + pResult, (int) bExclusive)); + + if( pArea->lpdbPendingRel ) + SELF_FORCEREL( ( AREAP ) pArea ); + + if( bExclusive ) + hb_dbfUnlockAllRecords( pArea ); + + if( hb_fsLock( pArea->hDataFile, DBF_LOCKPOS + ulRecNo, 1, FL_LOCK ) ) + { + if( pArea->ulNumLocksPos == 0 ) /* Create the list */ + { + pArea->pLocksPos = ( ULONG * ) hb_xgrab( sizeof( ULONG ) ); + pArea->pLocksPos[ 0 ] = ulRecNo; + } + else /* Resize the list */ + { + pArea->pLocksPos = ( ULONG * ) hb_xrealloc( pArea->pLocksPos, + ( pArea->ulNumLocksPos + 1 ) * + sizeof( ULONG ) ); + pArea->pLocksPos[ pArea->ulNumLocksPos ] = ulRecNo; + } + pArea->ulNumLocksPos ++; + * pResult = TRUE; + if( !pArea->fPositioned ) + hb_dbfGoTo( pArea, pArea->ulRecNo ); + else + pArea->fValidBuffer = FALSE; + } + else + * pResult = FALSE; + return SUCCESS; +} + +/* + * Lock a file. + */ +static ERRCODE hb_dbfLockFile( DBFAREAP pArea, BOOL * pResult ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_dbfLockFile(%p, %p)", pArea, pResult)); + + if( !pArea->fFLocked ) + { + if( pArea->lpdbPendingRel ) + SELF_FORCEREL( ( AREAP ) pArea ); + + pArea->fFLocked = hb_fsLock( pArea->hDataFile, DBF_LOCKPOS + 1, + DBF_LOCKPOS, FL_LOCK ); + * pResult = pArea->fFLocked; + if( !pArea->fPositioned ) + hb_dbfGoTo( pArea, pArea->ulRecNo ); + else + pArea->fValidBuffer = FALSE; + } + else + * pResult = TRUE; + + return SUCCESS; +} + +/* + * Unlock a file. + */ +static void hb_dbfUnlockFile( DBFAREAP pArea ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_dbfUnlockFile(%p)", pArea)); + + if( pArea->fFLocked ) + pArea->fFLocked = !hb_fsLock( pArea->hDataFile, DBF_LOCKPOS + 1, + DBF_LOCKPOS, FL_UNLOCK ); +} + +/* + * Test if a record is locked. + */ +static BOOL hb_dbfIsLocked( DBFAREAP pArea, ULONG ulRecNo ) +{ + ULONG ulCount; + + HB_TRACE(HB_TR_DEBUG, ("hb_dbfIsLocked(%p)", pArea)); + + ulCount = pArea->ulNumLocksPos; + while( ulCount > 0 ) + { + if( pArea->pLocksPos[ ulCount - 1 ] == ulRecNo ) + return TRUE; + ulCount --; } return FALSE; } -static BOOL hb_dbfLockRecord( AREAP pArea, ULONG lRecNum ) +/* + * Return an array filled all locked records. + */ +static void hb_dbfGetLockArray( DBFAREAP pArea, PHB_ITEM pItem ) { - LPFILEINFO pFileInfo; + ULONG ulCount; + PHB_ITEM pRecNo; - HB_TRACE(HB_TR_DEBUG, ("hb_dbfLockRecord(%p, %lu)", pArea, lRecNum)); + pRecNo = hb_itemNew( NULL ); + HB_TRACE(HB_TR_DEBUG, ("hb_dbfGetLockArray(%p, %p)", pArea, pItem)); - if( pArea->lpExtendInfo->fExclusive || pArea->lpDataInfo->fFileLocked ) - return TRUE; - - pFileInfo = pArea->lpDataInfo; - if( hb_dbfIsLocked( pArea, lRecNum ) ) - return TRUE; - - if( !hb_fsLock( pArea->lpDataInfo->hFile, LOCK_START + - pArea->lpExtendInfo->uiHeaderLen + - ( lRecNum - 1 ) * pArea->lpExtendInfo->uiRecordLen, 1, FL_LOCK ) ) - return FALSE; - - if( pFileInfo->lNumLocksPos == 0 ) /* Create the list */ - { - pFileInfo->pLocksPos = ( ULONG * ) hb_xgrab( sizeof( ULONG ) ); - pFileInfo->pLocksPos[ 0 ] = lRecNum; - } - else /* Resize the list */ - { - pFileInfo->pLocksPos = ( ULONG * ) - hb_xrealloc( pFileInfo->pLocksPos, - ( pFileInfo->lNumLocksPos + 1 ) * - sizeof( ULONG ) ); - pFileInfo->pLocksPos[ pFileInfo->lNumLocksPos ] = lRecNum; - } - pFileInfo->lNumLocksPos++; - - return TRUE; + for( ulCount = 0; ulCount < pArea->ulNumLocksPos; ulCount++ ) + hb_arrayAdd( pItem, hb_itemPutNL( pRecNo, pArea->pLocksPos[ ulCount ] ) ); + hb_itemRelease( pRecNo ); } -static BOOL hb_dbfUnLockRecord( AREAP pArea, ULONG lRecNum ) -{ - LPFILEINFO pFileInfo; - ULONG lLockPos, * pList; - - HB_TRACE(HB_TR_DEBUG, ("hb_dbfUnLockRecord(%p, %lu)", pArea, lRecNum)); - - if( pArea->lpExtendInfo->fExclusive || pArea->lpDataInfo->fFileLocked ) - return TRUE; - - pFileInfo = pArea->lpDataInfo; - if( !hb_dbfIsLocked( pArea, lRecNum ) ) - return TRUE; - - if( !hb_fsLock( pArea->lpDataInfo->hFile, LOCK_START + - pArea->lpExtendInfo->uiHeaderLen + - ( lRecNum - 1 ) * pArea->lpExtendInfo->uiRecordLen, 1, FL_UNLOCK ) ) - return FALSE; - - if( pFileInfo->lNumLocksPos == 1 ) /* Delete the list */ - { - hb_xfree( pFileInfo->pLocksPos ); - pFileInfo->lNumLocksPos = 0; - } - else /* Resize the list */ - { - /* Search the locked record */ - for( lLockPos = 0; lLockPos < pFileInfo->lNumLocksPos; lLockPos++ ) - { - if( pFileInfo->pLocksPos[ lLockPos ] == lRecNum ) - { - pList = pFileInfo->pLocksPos + lLockPos; - memmove( pList, pList + 1, - ( pFileInfo->lNumLocksPos - lLockPos - 1 ) * - sizeof( ULONG ) ); - pFileInfo->pLocksPos = ( ULONG * ) - hb_xrealloc( pFileInfo->pLocksPos, - ( pFileInfo->lNumLocksPos - 1 ) * - sizeof( ULONG ) ); - pFileInfo->lNumLocksPos--; - return TRUE; - } - } - } - - return TRUE; -} - -static BOOL hb_dbfUnLockAllRecords( AREAP pArea ) -{ - LPFILEINFO pFileInfo; - ULONG lPosLocked; - BOOL bUnLocked = TRUE; - - HB_TRACE(HB_TR_DEBUG, ("hb_dbfUnLockAllRecords(%p)", pArea)); - - if( SELF_GOCOLD( pArea ) == FAILURE ) - return FALSE; - - if( pArea->lpExtendInfo->fExclusive ) - return TRUE; - - pFileInfo = pArea->lpDataInfo; - for( lPosLocked = 0; lPosLocked < pFileInfo->lNumLocksPos; lPosLocked++ ) - if( !hb_fsLock( pArea->lpDataInfo->hFile, LOCK_START + - pArea->lpExtendInfo->uiHeaderLen + - ( pFileInfo->pLocksPos[ lPosLocked ] - 1 ) * - pArea->lpExtendInfo->uiRecordLen, 1, FL_UNLOCK ) ) - bUnLocked = FALSE; - - if( pFileInfo->lNumLocksPos > 0 ) - hb_xfree( pFileInfo->pLocksPos ); - pFileInfo->pLocksPos = NULL; - pFileInfo->lNumLocksPos = 0; - - return bUnLocked; -} - -static BOOL hb_dbfLockFile( AREAP pArea ) -{ - HB_TRACE(HB_TR_DEBUG, ("hb_dbfLockFile(%p)", pArea)); - - if( pArea->lpExtendInfo->fExclusive || pArea->lpDataInfo->fFileLocked ) - return TRUE; - - if( !hb_fsLock( pArea->lpDataInfo->hFile, LOCK_START, LOCK_FILE, FL_LOCK ) ) - return FALSE; - pArea->lpDataInfo->fFileLocked = TRUE; - return TRUE; -} - -static BOOL hb_dbfUnLockFile( AREAP pArea ) -{ - HB_TRACE(HB_TR_DEBUG, ("hb_dbfUnLockFile(%p)", pArea)); - - if( SELF_GOCOLD( pArea ) == FAILURE ) - return FALSE; - - if( pArea->lpExtendInfo->fExclusive ) - return TRUE; - - hb_dbfUnLockAllRecords( pArea ); - if( pArea->lpDataInfo->fFileLocked ) - { - if( !hb_fsLock( pArea->lpDataInfo->hFile, LOCK_START, LOCK_FILE, FL_UNLOCK ) ) - return FALSE; - pArea->lpDataInfo->fFileLocked = FALSE; - } - return TRUE; -} - -static void hb_dbfGetLockArray( AREAP pArea, PHB_ITEM pItem ) -{ - ULONG lLockPos; - - HB_TRACE(HB_TR_DEBUG, ("hb_GetLockArray(%p, %p)", pArea, pItem)); - - for( lLockPos = 1; lLockPos <= pArea->lpDataInfo->lNumLocksPos; lLockPos++ ) - hb_arrayAdd( pItem, - hb_itemPutNL( NULL, pArea->lpDataInfo->pLocksPos[ lLockPos - 1 ] ) ); -} - -static RDDFUNCS dbfSuper = { 0 }; - - /* * -- DBF METHODS -- */ -#define dbfBof NULL -#define dbfEof NULL -#define dbfFound NULL -#define dbfSeek NULL -#define dbfSkip NULL -#define dbfSkipFilter NULL -#define dbfSkipRaw NULL -#define dbfCreateFields NULL -#define dbfFieldCount NULL -#define dbfFieldDisplay NULL -#define dbfFieldInfo NULL -#define dbfFieldName NULL -#define dbfSetFieldsExtent NULL -#define dbfAlias NULL -#define dbfNewArea NULL -#define dbfStructSize NULL -#define dbfSysName NULL -#define dbfEval NULL -#define dbfchildEnd NULL -#define dbfchildStart NULL -#define dbfchildSync NULL -#define dbfsyncChildren NULL -#define dbfclearRel NULL -#define dbfforceRel NULL -#define dbfrelArea NULL -#define dbfrelEval NULL -#define dbfrelText NULL -#define dbfsetRel NULL -#define dbfOrderListAdd NULL -#define dbfOrderListClear NULL -#define dbfOrderListFocus NULL -#define dbfOrderListRebuild NULL -#define dbfOrderCondition NULL -#define dbfOrderCreate NULL -#define dbfOrderDestroy NULL -#define dbfOrderInfo NULL -#define dbfClearFilter NULL -#define dbfClearLocate NULL -#define dbfClearScope NULL -#define dbfCountScope NULL -#define dbfFilterText NULL -#define dbfScopeInfo NULL -#define dbfSetFilter NULL -#define dbfSetLocate NULL -#define dbfSetScope NULL -#define dbfSkipScope NULL -#define dbfCompile NULL -#define dbfError NULL -#define dbfEvalBlock NULL -#define dbfWhoCares NULL - -static ERRCODE dbfAddField( AREAP pArea, LPDBFIELDINFO pFieldInfo ) +/* + * Determine logical beginning of file. + */ +ERRCODE hb_dbfBof( DBFAREAP pArea, BOOL * pBof ) { - LPFIELD pField; + HB_TRACE(HB_TR_DEBUG, ("hb_dbfBof(%p, %p)", pArea, pBof)); - HB_TRACE(HB_TR_DEBUG, ("dbfAddField(%p, %p)", pArea, pFieldInfo)); + if( pArea->lpdbPendingRel ) + SELF_FORCEREL( ( AREAP ) pArea ); - if( SUPER_ADDFIELD( pArea, pFieldInfo ) == SUCCESS ) - { - /* Validate the type */ - if( pFieldInfo->uiType != 'C' && pFieldInfo->uiType != 'N' && - pFieldInfo->uiType != 'M' && pFieldInfo->uiType != 'D' && - pFieldInfo->uiType != 'L' ) - return FAILURE; - - /* Validate the size */ - if( !pFieldInfo->uiLen ) - return FAILURE; - - if( pArea->lpExtendInfo->fHasMemo ) - { - pField = pArea->lpFields + pArea->uiFieldCount - 1; - pField->memo = ( void * ) hb_xgrab( sizeof( DBFMEMO ) ); - memset( pField->memo, 0, sizeof( DBFMEMO ) ); - } - return SUCCESS; - } - return FAILURE; + * pBof = pArea->fBof; + return SUCCESS; } -static ERRCODE dbfAppend( AREAP pArea, BOOL bUnLockAll ) +/* + * Determine logical end of file. + */ +ERRCODE hb_dbfEof( DBFAREAP pArea, BOOL * pEof ) { - ULONG ulRecCount, ulRecNo; - PHB_ITEM pError; + HB_TRACE(HB_TR_DEBUG, ("hb_dbfEof(%p, %p)", pArea, pEof)); - HB_TRACE(HB_TR_DEBUG, ("dbfAppend(%p, %d)", pArea, (int) bUnLockAll)); + if( pArea->lpdbPendingRel ) + SELF_FORCEREL( ( AREAP ) pArea ); - if( SELF_GOCOLD( pArea ) == FAILURE ) + * pEof = pArea->fEof; + return SUCCESS; +} + +/* + * Determine outcome of the last search operation. + */ +ERRCODE hb_dbfFound( DBFAREAP pArea, BOOL * pFound ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_dbfFound(%p, %p)", pArea, pFound)); + + if( pArea->lpdbPendingRel ) + SELF_FORCEREL( ( AREAP ) pArea ); + + * pFound = pArea->fFound; + return SUCCESS; +} + +/* + * Position cursor at the last record. + */ +ERRCODE hb_dbfGoBottom( DBFAREAP pArea ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_dbfGoBottom(%p)", pArea)); + + if( SELF_GOCOLD( ( AREAP ) pArea ) == FAILURE ) return FAILURE; - if( pArea->lpExtendInfo->fReadOnly ) + /* Update record count */ + if( pArea->fShared ) + pArea->ulRecCount = hb_dbfCalcRecCount( pArea ); + + pArea->fTop = FALSE; + pArea->fBottom = TRUE; + SELF_GOTO( ( AREAP ) pArea, pArea->ulRecCount ); + + return SELF_SKIPFILTER( ( AREAP ) pArea, -1 ); +} + +/* + * Position cursor at a specific physical record. + */ +ERRCODE hb_dbfGoTo( DBFAREAP pArea, ULONG ulRecNo ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_dbfGoTo(%p, %lu)", pArea, ulRecNo)); + + if( SELF_GOCOLD( ( AREAP ) pArea ) == FAILURE ) + return FAILURE; + + /* Reset parent rel struct */ + pArea->lpdbPendingRel = NULL; + + /* Update record count */ + if( pArea->fShared && ulRecNo > pArea->ulRecCount ) + pArea->ulRecCount = hb_dbfCalcRecCount( pArea ); + + if( ulRecNo <= pArea->ulRecCount && ulRecNo >= 1 ) + { + pArea->ulRecNo = ulRecNo; + pArea->fBof = pArea->fEof = pArea->fValidBuffer = FALSE; + pArea->fPositioned = TRUE; + } + else /* Out of space */ + { + pArea->ulRecNo = pArea->ulRecCount + 1; + pArea->fBof = pArea->fEof = pArea->fValidBuffer = TRUE; + pArea->fPositioned = pArea->fDeleted = FALSE; + + /* Clear buffer */ + memset( pArea->pRecord, ' ', pArea->uiRecordLen ); + } + pArea->fFound = FALSE; + + /* Force relational movement in child WorkAreas */ + if( pArea->lpdbRelations ) + return SELF_SYNCCHILDREN( ( AREAP ) pArea ); + else + return SUCCESS; +} + +/* + * Position the cursor to a specific, physical identity. + */ +ERRCODE hb_dbfGoToId( DBFAREAP pArea, PHB_ITEM pItem ) +{ + PHB_ITEM pError; + + HB_TRACE(HB_TR_DEBUG, ("hb_dbfGoToId(%p, %p)", pArea, pItem)); + + if( HB_IS_NUMERIC( pItem ) ) + return SELF_GOTO( ( AREAP ) pArea, hb_itemGetNL( pItem ) ); + else + { + pError = hb_errNew(); + hb_errPutGenCode( pError, EG_DATATYPE ); + hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_DATATYPE ) ); + hb_errPutSubCode( pError, EDBF_DATATYPE ); + SELF_ERROR( ( AREAP ) pArea, pError ); + hb_errRelease( pError ); + return FAILURE; + } +} + +/* + * Position cursor at the first record. + */ +ERRCODE hb_dbfGoTop( DBFAREAP pArea ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_dbfGoTop(%p)", pArea)); + + pArea->fTop = TRUE; + pArea->fBottom = FALSE; + + if( hb_dbfGoTo( pArea, 1 ) == FAILURE ) + return FAILURE; + + return SELF_SKIPFILTER( ( AREAP ) pArea, 1 ); +} + +/* + * Reposition cursor relative to current position. + */ +ERRCODE hb_dbfSkip( DBFAREAP pArea, LONG lToSkip ) +{ + ERRCODE uiError; + + HB_TRACE(HB_TR_DEBUG, ("hb_dbfSkip(%p, %ld)", pArea, lToSkip)); + + if( pArea->lpdbPendingRel ) + SELF_FORCEREL( ( AREAP ) pArea ); + + pArea->fTop = pArea->fBottom = FALSE; + + if( lToSkip == 0 || hb_set.HB_SET_DELETED || pArea->dbfi.itmCobExpr ) + return SUPER_SKIP( ( AREAP ) pArea, lToSkip ); + + uiError = SELF_SKIPRAW( ( AREAP ) pArea, lToSkip ); + + /* Move first record and set Bof flag */ + if( uiError == SUCCESS && pArea->fBof && lToSkip < 0 ) + { + uiError = SELF_GOTOP( ( AREAP ) pArea ); + pArea->fBof = TRUE; + } + + /* Update Bof and Eof flags */ + if( lToSkip < 0 ) + pArea->fEof = FALSE; + else if( lToSkip > 0 ) + pArea->fBof = FALSE; + return uiError; +} + +/* + * Reposition cursor, regardless of filter. + */ +ERRCODE hb_dbfSkipRaw( DBFAREAP pArea, LONG lToSkip ) +{ + BOOL bBof, bEof; + + HB_TRACE(HB_TR_DEBUG, ("hb_dbfSkipRaw(%p, %ld)", pArea, lToSkip)); + + if( lToSkip == 0 ) + { + /* Save flags */ + bBof = pArea->fBof; + bEof = pArea->fEof; + + SELF_GOTO( ( AREAP ) pArea, pArea->ulRecNo ); + + /* Restore flags */ + pArea->fBof = bBof; + pArea->fEof = bEof; + return SUCCESS; + } + else + return SELF_GOTO( ( AREAP ) pArea, pArea->ulRecNo + lToSkip ); +} + +/* + * Add a field to the WorkArea. + */ +ERRCODE hb_dbfAddField( DBFAREAP pArea, LPDBFIELDINFO pFieldInfo ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_dbfAddField(%p, %p)", pArea, pFieldInfo)); + + /* Update field offset */ + pArea->pFieldOffset[ pArea->uiFieldCount ] = pArea->uiRecordLen; + pArea->uiRecordLen += pFieldInfo->uiLen; + return SUPER_ADDFIELD( ( AREAP ) pArea, pFieldInfo ); +} + +/* + * Append a record to the WorkArea. + */ +ERRCODE hb_dbfAppend( DBFAREAP pArea, BOOL bUnLockAll ) +{ + ULONG ulNewRecord; + PHB_ITEM pError; + BOOL bLocked; + + HB_TRACE(HB_TR_DEBUG, ("hb_dbfAppend(%p, %d)", pArea, (int) bUnLockAll)); + + if( SELF_GOCOLD( ( AREAP ) pArea ) == FAILURE ) + return FAILURE; + + if( pArea->fReadOnly ) { pError = hb_errNew(); hb_errPutGenCode( pError, EG_READONLY ); hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_READONLY ) ); - hb_errPutSubCode( pError, 1025 ); - SELF_ERROR( pArea, pError ); + hb_errPutSubCode( pError, EDBF_READONLY ); + SELF_ERROR( ( AREAP ) pArea, pError ); hb_errRelease( pError ); return FAILURE; } - if( SELF_RECCOUNT( pArea, &ulRecCount ) == FAILURE ) - return FAILURE; - pArea->lpExtendInfo->ulRecCount = ulRecCount; + /* Reset parent rel struct */ + pArea->lpdbPendingRel = NULL; - if( !pArea->lpExtendInfo->fExclusive && !pArea->lpDataInfo->fFileLocked ) + if( pArea->fShared ) { - if( bUnLockAll && !hb_dbfUnLockAllRecords( pArea ) ) - return FAILURE; + /* Update RecCount */ + pArea->ulRecCount = hb_dbfCalcRecCount( pArea ); + ulNewRecord = pArea->ulRecCount + 1; - if( !hb_fsLock( pArea->lpDataInfo->hFile, LOCK_START, 1, FL_LOCK ) ) - return FAILURE; + if( !pArea->fFLocked && !hb_dbfIsLocked( pArea, ulNewRecord ) ) + { + hb_dbfLockRecord( pArea, ulNewRecord, &bLocked, bUnLockAll ); + if( !bLocked ) + { + pError = hb_errNew(); + hb_errPutGenCode( pError, EG_APPENDLOCK ); + hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_APPENDLOCK ) ); + hb_errPutSubCode( pError, EDBF_APPENDLOCK ); + SELF_ERROR( ( AREAP ) pArea, pError ); + hb_errRelease( pError ); + return FAILURE; + } + } } - ulRecNo = ulRecCount + 1; - SELF_GOTO( pArea, ulRecNo ); - pArea->fEof = FALSE; - hb_dbfClearBuffer( pArea ); - pArea->lpExtendInfo->fRecordChanged = TRUE; - pArea->lpDataInfo->fAppend = TRUE; - if( !hb_dbfUpdateRecord( pArea, ulRecNo ) ) + /* Clear buffer and update pArea */ + memset( pArea->pRecord, ' ', pArea->uiRecordLen ); + pArea->fValidBuffer = pArea->fUpdateHeader = pArea->fRecordChanged = + pArea->fAppend = pArea->fPositioned = TRUE; + pArea->ulRecCount ++; + pArea->ulRecNo = pArea->ulRecCount; + pArea->fDeleted = pArea->fBof = pArea->fEof = pArea->fFound = FALSE; + + if( pArea->fShared ) { - if( !pArea->lpExtendInfo->fExclusive && !pArea->lpDataInfo->fFileLocked ) - hb_fsLock( pArea->lpDataInfo->hFile, LOCK_START, 1, FL_UNLOCK ); + hb_dbfWriteRecord( pArea ); + hb_dbfWriteDBHeader( pArea ); + } + else + { + hb_dbfWriteDBHeader( pArea ); + pArea->fUpdateHeader = TRUE; /* To truncate the file later */ + } + return SUCCESS; +} + +/* + * Delete a record. + */ +ERRCODE hb_dbfDeleteRec( DBFAREAP pArea ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_dbfDeleteRec(%p)", pArea)); + + if( pArea->lpdbPendingRel ) + SELF_FORCEREL( ( AREAP ) pArea ); + + /* Read record */ + if( !pArea->fValidBuffer && !hb_dbfReadRecord( pArea ) ) return FAILURE; + + if( !pArea->fPositioned ) + return SUCCESS; + + /* Buffer is hot? */ + if( !pArea->fRecordChanged && SELF_GOHOT( ( AREAP ) pArea ) == FAILURE ) + return FAILURE; + + pArea->pRecord[ 0 ] = '*'; + pArea->fDeleted = TRUE; + return SUCCESS; +} + +/* + * Determine deleted status for a record. + */ +ERRCODE hb_dbfDeleted( DBFAREAP pArea, BOOL * pDeleted ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_dbfDeleted(%p, %p)", pArea, pDeleted)); + + if( pArea->lpdbPendingRel ) + SELF_FORCEREL( ( AREAP ) pArea ); + + /* Read record */ + if( !pArea->fValidBuffer && !hb_dbfReadRecord( pArea ) ) + return FAILURE; + + * pDeleted = pArea->fDeleted; + return SUCCESS; +} + +/* + * Write data buffer to the data store. + */ +ERRCODE hb_dbfFlush( DBFAREAP pArea ) +{ + ERRCODE uiError; + + HB_TRACE(HB_TR_DEBUG, ("hb_dbfFlush(%p)", pArea)); + + uiError = SELF_GOCOLD( ( AREAP ) pArea ); + if( pArea->fUpdateHeader ) + { + /* Update record count */ + if( pArea->fShared ) + pArea->ulRecCount = hb_dbfCalcRecCount( pArea ); + else + { + /* Seek to logical eof and write eof mark */ + hb_fsSeek( pArea->hDataFile, pArea->uiHeaderLen + + pArea->uiRecordLen * pArea->ulRecCount, FS_SET ); + hb_fsWrite( pArea->hDataFile, ( BYTE * ) "\032", 1 ); + hb_fsWrite( pArea->hDataFile, NULL, 0 ); + } + hb_dbfWriteDBHeader( pArea ); } - if( !hb_dbfLockRecord( pArea, ulRecNo ) ) - { - if( !pArea->lpExtendInfo->fExclusive && !pArea->lpDataInfo->fFileLocked ) - hb_fsLock( pArea->lpDataInfo->hFile, LOCK_START, 1, FL_UNLOCK ); + hb_fsCommit( pArea->hDataFile ); + if( pArea->fHasMemo && pArea->hMemoFile != FS_ERROR ) + hb_fsCommit( pArea->hMemoFile ); + return uiError; +} + +/* + * Obtain the current value of a field. + */ +ERRCODE hb_dbfGetValue( DBFAREAP pArea, USHORT uiIndex, PHB_ITEM pItem ) +{ + LPFIELD pField; + char szBuffer[ 21 ]; + BOOL bError; + PHB_ITEM pError; + + HB_TRACE(HB_TR_DEBUG, ("hb_dbfGetValue(%p, %hu, %p)", pArea, uiIndex, pItem)); + + if( pArea->lpdbPendingRel ) + SELF_FORCEREL( ( AREAP ) pArea ); + + /* Read record */ + if( !pArea->fValidBuffer && !hb_dbfReadRecord( pArea ) ) return FAILURE; + + bError = FALSE; + uiIndex --; + pField = pArea->lpFields + uiIndex; + switch( pField->uiType ) + { + case HB_IT_STRING: + hb_itemPutCL( pItem, ( char * ) pArea->pRecord + pArea->pFieldOffset[ uiIndex ], + pField->uiLen ); + break; + + case HB_IT_LOGICAL: + hb_itemPutL( pItem, pArea->pRecord[ pArea->pFieldOffset[ uiIndex ] ] == 'T' || + pArea->pRecord[ pArea->pFieldOffset[ uiIndex ] ] == 't' || + pArea->pRecord[ pArea->pFieldOffset[ uiIndex ] ] == 'Y' || + pArea->pRecord[ pArea->pFieldOffset[ uiIndex ] ] == 'y' ); + break; + + case HB_IT_MEMO: + printf( "\nTODO: hb_dbfReadMemo()\n" ); + break; + + case HB_IT_DATE: + memcpy( szBuffer, pArea->pRecord + pArea->pFieldOffset[ uiIndex ], 8 ); + szBuffer[ 8 ] = 0; + hb_itemPutDS( pItem, szBuffer ); + break; + + case HB_IT_LONG: + if( pField->uiLen > 20 ) + bError = TRUE; + else + { + memcpy( szBuffer, pArea->pRecord + pArea->pFieldOffset[ uiIndex ], + pField->uiLen ); + szBuffer[ pField->uiLen ] = 0; + if( pField->uiDec ) + hb_itemPutNDLen( pItem, atof( szBuffer ), + ( int ) pField->uiLen - ( ( int ) pField->uiDec + 1 ), + ( int ) pField->uiDec ); + else + hb_itemPutNLLen( pItem, atol( szBuffer ), ( int ) pField->uiLen ); + } + break; + + default: + bError = TRUE; + break; } - if( !pArea->lpExtendInfo->fExclusive && !pArea->lpDataInfo->fFileLocked && - !hb_fsLock( pArea->lpDataInfo->hFile, LOCK_START, 1, FL_UNLOCK ) ) + /* Any error? */ + if( bError ) + { + pError = hb_errNew(); + hb_errPutGenCode( pError, EG_DATATYPE ); + hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_DATATYPE ) ); + hb_errPutSubCode( pError, EDBF_DATATYPE ); + SELF_ERROR( ( AREAP ) pArea, pError ); + hb_errRelease( pError ); return FAILURE; + } + return SUCCESS; +} + +/* + * Obtain the length of a field value. + */ +ERRCODE hb_dbfGetVarLen( DBFAREAP pArea, USHORT uiIndex, ULONG * pLength ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_dbfGetVarLen(%p, %hu, %p)", pArea, uiIndex, pLength)); + HB_SYMBOL_UNUSED( uiIndex ); + + if( pArea->lpdbPendingRel ) + SELF_FORCEREL( ( AREAP ) pArea ); + + /* Read record */ + if( !pArea->fValidBuffer && !hb_dbfReadRecord( pArea ) ) + return FAILURE; + + if( pArea->fHasMemo ) + printf( "\nTODO: hb_dbfReadMemoLen()\n" ); +/* * pLength = hb_dbfReadMemoLen( pArea );*/ + else + * pLength = 0; return SUCCESS; } -static ERRCODE dbfClose( AREAP pArea ) +/* + * Perform a write of WorkArea memory to the data store. + */ +ERRCODE hb_dbfGoCold( DBFAREAP pArea ) { - HB_TRACE(HB_TR_DEBUG, ("dbfClose(%p)", pArea)); + HB_TRACE(HB_TR_DEBUG, ("hb_dbfGoCold(%p)", pArea)); - if( pArea->lpDataInfo->hFile != FS_ERROR ) + if( pArea->fRecordChanged ) { - SELF_GOCOLD( pArea ); - SELF_RAWLOCK( pArea, FILE_UNLOCK, 0 ); - SELF_FLUSH( pArea ); - hb_fsClose( pArea->lpDataInfo->hFile ); - pArea->lpDataInfo->hFile = FS_ERROR; + /* Write current record */ + if( !hb_dbfWriteRecord( pArea ) ) + return FAILURE; + + pArea->fRecordChanged = FALSE; + + if( !pArea->fAppend ) + pArea->fUpdateHeader = TRUE; + else + pArea->fAppend = FALSE; + + /* Update header */ + if( pArea->fShared ) + hb_dbfWriteDBHeader( pArea ); + + pArea->fAppend = FALSE; } - if( pArea->lpExtendInfo->fHasMemo ) - SELF_CLOSEMEMFILE( pArea ); - - return SUPER_CLOSE( pArea ); -} - -static ERRCODE dbfCloseMemFile( AREAP pArea ) -{ - HB_TRACE(HB_TR_DEBUG, ("dbfCloseMemFile(%p)", pArea)); - - if( pArea->lpDataInfo->pNext->hFile != FS_ERROR ) - { - SELF_FLUSH( pArea ); - hb_fsClose( pArea->lpDataInfo->pNext->hFile ); - pArea->lpDataInfo->pNext->hFile = FS_ERROR; - } - return SUCCESS; } -static ERRCODE dbfCreate( AREAP pArea, LPDBOPENINFO pCreateInfo ) +/* + * Mark the WorkArea data buffer as hot. + */ +ERRCODE hb_dbfGoHot( DBFAREAP pArea ) { - PHB_ITEM pError = NULL; - BOOL bRetry; + PHB_ITEM pError; - HB_TRACE(HB_TR_DEBUG, ("dbfCreate(%p, %p)", pArea, pCreateInfo)); + HB_TRACE(HB_TR_DEBUG, ("hb_dbfGoHot(%p)", pArea)); + if( pArea->fReadOnly ) + { + pError = hb_errNew(); + hb_errPutGenCode( pError, EG_READONLY ); + hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_READONLY ) ); + hb_errPutSubCode( pError, EDBF_READONLY ); + SELF_ERROR( ( AREAP ) pArea, pError ); + hb_errRelease( pError ); + return FAILURE; + } + else if( pArea->fShared && !pArea->fFLocked && + !hb_dbfIsLocked( pArea, pArea->ulRecNo ) ) + { + pError = hb_errNew(); + hb_errPutGenCode( pError, EG_UNLOCKED ); + hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_UNLOCKED ) ); + hb_errPutSubCode( pError, EDBF_UNLOCKED ); + SELF_ERROR( ( AREAP ) pArea, pError ); + hb_errRelease( pError ); + return FAILURE; + } + pArea->fRecordChanged = TRUE; + return SUCCESS; +} + +/* + * Replace the current record. + */ +ERRCODE hb_dbfPutRec( DBFAREAP pArea, BYTE * pBuffer ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_dbfPutRec(%p, %p)", pArea, pBuffer)); + + if( !pArea->fRecordChanged && SELF_GOHOT( ( AREAP ) pArea ) == FAILURE ) + return FAILURE; + + /* Copy data to buffer */ + memcpy( pArea->pRecord, pBuffer, pArea->uiRecordLen ); + return SUCCESS; +} + +/* + * Assign a value to a field. + */ +ERRCODE hb_dbfPutValue( DBFAREAP pArea, USHORT uiIndex, PHB_ITEM pItem ) +{ + USHORT uiSize; + LPFIELD pField; + char szBuffer[ HB_MAX_DOUBLE_LENGTH ]; + PHB_ITEM pError; + ERRCODE uiError; + + HB_TRACE(HB_TR_DEBUG, ("hb_dbfPutValue(%p, %hu, %p)", pArea, uiIndex, pItem)); + + if( pArea->lpdbPendingRel ) + SELF_FORCEREL( ( AREAP ) pArea ); + + /* Read record */ + if( !pArea->fValidBuffer && !hb_dbfReadRecord( pArea ) ) + return FAILURE; + + if( !pArea->fPositioned ) + return SUCCESS; + + /* Buffer is hot? */ + if( !pArea->fRecordChanged && SELF_GOHOT( ( AREAP ) pArea ) == FAILURE ) + return FAILURE; + + uiError = SUCCESS; + uiIndex --; + pField = pArea->lpFields + uiIndex; + if( pField->uiType == HB_IT_MEMO ) +// uiError = hb_dbfWriteMemo() ? SUCCESS : EDBF_DATAWIDTH; + printf( "\nTODO: hb_dbfWriteMemo()\n" ); + else + { + if( HB_IS_MEMO( pItem ) || HB_IS_STRING( pItem ) ) + { + if( pField->uiType == HB_IT_STRING ) + { + uiSize = ( USHORT ) hb_itemGetCLen( pItem ); + if( uiSize > pField->uiLen ) + uiSize = pField->uiLen; + memcpy( pArea->pRecord + pArea->pFieldOffset[ uiIndex ], + hb_itemGetCPtr( pItem ), uiSize ); + memset( pArea->pRecord + pArea->pFieldOffset[ uiIndex ] + uiSize, + ' ', pField->uiLen - uiSize ); + } + else + uiError = EDBF_DATATYPE; + } + else if( HB_IS_NUMERIC( pItem ) ) + { + if( pField->uiType == HB_IT_LONG ) + { + if( HB_IS_DOUBLE( pItem ) ) + { + if( pField->uiDec == 0 ) + uiSize = sprintf( szBuffer, "%*li", pField->uiLen, + ( LONG ) hb_numRound( hb_itemGetND( pItem ), 0 ) ); + else + uiSize = sprintf( szBuffer, "%*.*f", pField->uiLen - pField->uiDec - 1, + pField->uiDec, hb_numRound( hb_itemGetND( pItem ), + pField->uiDec ) ); + } + else + { + if( pField->uiDec == 0 ) + uiSize = sprintf( szBuffer, "%*li", pField->uiLen, hb_itemGetNL( pItem ) ); + else + uiSize = sprintf( szBuffer, "%*.*f", pField->uiLen, + pField->uiDec, hb_itemGetND( pItem ) ); + } + /* Overflow? */ + if( uiSize > pField->uiLen ) + { + uiError = EDBF_DATAWIDTH; + memset( pArea->pRecord + pArea->pFieldOffset[ uiIndex ], + '*', pField->uiLen ); + } + else + memcpy( pArea->pRecord + pArea->pFieldOffset[ uiIndex ], + szBuffer, pField->uiLen ); + } + else + uiError = EDBF_DATATYPE; + } + else if( HB_IS_DATE( pItem ) ) + { + if( pField->uiType == HB_IT_DATE ) + { + hb_itemGetDS( pItem, szBuffer ); + memcpy( pArea->pRecord + pArea->pFieldOffset[ uiIndex ], szBuffer, 8 ); + } + else + uiError = EDBF_DATATYPE; + } + else if( HB_IS_LOGICAL( pItem ) ) + { + if( pField->uiType == HB_IT_LOGICAL ) + pArea->pRecord[ pArea->pFieldOffset[ uiIndex ] ] = hb_itemGetL( pItem ) ? 'T' : 'F'; + else + uiError = EDBF_DATATYPE; + } + else + uiError = EDBF_DATATYPE; + } + + /* Exit if any error */ + if( uiError != SUCCESS ) + { + pError = hb_errNew(); + hb_errPutGenCode( pError, uiError == EDBF_DATAWIDTH ? EG_DATAWIDTH : EG_DATATYPE ); + hb_errPutDescription( pError, hb_langDGetErrorDesc( uiError == EDBF_DATAWIDTH ? + EG_DATAWIDTH : EG_DATATYPE ) ); + hb_errPutSubCode( pError, uiError ); + SELF_ERROR( ( AREAP ) pArea, pError ); + hb_errRelease( pError ); + return FAILURE; + } + + /* Update deleted flag */ + pArea->pRecord[ 0 ] = pArea->fDeleted ? '*' : ' '; + return SUCCESS; +} + +/* + * Undelete the current record. + */ +ERRCODE hb_dbfRecAll( DBFAREAP pArea ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_dbfRecAll(%p)", pArea)); + + if( pArea->lpdbPendingRel ) + SELF_FORCEREL( ( AREAP ) pArea ); + + /* Read record */ + if( !pArea->fValidBuffer && !hb_dbfReadRecord( pArea ) ) + return FAILURE; + + if( !pArea->fPositioned ) + return SUCCESS; + + /* Buffer is hot? */ + if( !pArea->fRecordChanged && SELF_GOHOT( ( AREAP ) pArea ) == FAILURE ) + return FAILURE; + + pArea->pRecord[ 0 ] = ' '; + pArea->fDeleted = TRUE; + return SUCCESS; +} + +/* + * Obtain number of records in WorkArea. + */ +ERRCODE hb_dbfRecCount( DBFAREAP pArea, ULONG * pRecCount ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_dbfRecCount(%p, %p)", pArea, pRecCount)); + + /* Update record count */ + if( pArea->fShared ) + pArea->ulRecCount = hb_dbfCalcRecCount( pArea ); + + * pRecCount = pArea->ulRecCount; + return SUCCESS; +} + +/* + * Obtain physical row number at current WorkArea cursor position. + */ +ERRCODE hb_dbfRecNo( DBFAREAP pArea, PHB_ITEM pRecNo ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_dbfRecNo(%p, %p)", pArea, pRecNo)); + + if( pArea->lpdbPendingRel ) + SELF_FORCEREL( ( AREAP ) pArea ); + hb_itemPutNL( pRecNo, pArea->ulRecNo ); + return SUCCESS; +} + +/* + * Establish the extent of the array of fields for a WorkArea. + */ +ERRCODE hb_dbfSetFieldExtent( DBFAREAP pArea, USHORT uiFieldExtent ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_dbfSetFieldExtent(%p, %hu)", pArea, uiFieldExtent)); + + if( SUPER_SETFIELDEXTENT( ( AREAP ) pArea, uiFieldExtent ) == FAILURE ) + return FAILURE; + + /* Alloc field offsets array */ + pArea->pFieldOffset = ( USHORT * ) hb_xgrab( uiFieldExtent * sizeof( USHORT * ) ); + memset( pArea->pFieldOffset, 0, uiFieldExtent * sizeof( USHORT * ) ); + return SUCCESS; +} + +/* + * Close the table in the WorkArea. + */ +ERRCODE hb_dbfClose( DBFAREAP pArea ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_dbfClose(%p)", pArea)); + + SUPER_CLOSE( ( AREAP ) pArea ); + + /* Update record and unlock records */ + if( pArea->hDataFile != FS_ERROR ) + { + SELF_GOCOLD( ( AREAP ) pArea ); + + /* Unlock all records */ + SELF_UNLOCK( ( AREAP ) pArea, 0 ); + + /* Update header */ + if( pArea->fUpdateHeader ) + { + /* Update record count */ + if( pArea->fShared ) + pArea->ulRecCount = hb_dbfCalcRecCount( pArea ); + + hb_dbfWriteDBHeader( pArea ); + + /* Seek to logical eof and write eof mark */ + hb_fsSeek( pArea->hDataFile, pArea->uiHeaderLen + + pArea->uiRecordLen * pArea->ulRecCount, FS_SET ); + hb_fsWrite( pArea->hDataFile, ( BYTE * ) "\032", 1 ); + hb_fsWrite( pArea->hDataFile, NULL, 0 ); + } + } + + /* Close the data file */ + if( pArea->hDataFile != FS_ERROR ) + { + hb_fsCommit( pArea->hDataFile ); + hb_fsClose( pArea->hDataFile ); + pArea->hDataFile = FS_ERROR; + } + + /* Close the memo file */ + if( pArea->fHasMemo && pArea->hMemoFile != FS_ERROR ) + { + hb_fsCommit( pArea->hMemoFile ); + hb_fsClose( pArea->hMemoFile ); + pArea->hMemoFile = FS_ERROR; + } + + /* Free field offset array */ + if( pArea->pFieldOffset ) + { + hb_xfree( pArea->pFieldOffset ); + pArea->pFieldOffset = NULL; + } + + /* Free buffer */ + if( pArea->pRecord ) + { + hb_xfree( pArea->pRecord ); + pArea->pRecord = NULL; + } + + /* Free all filenames */ + if( pArea->szDataFileName ) + { + hb_xfree( pArea->szDataFileName ); + pArea->szDataFileName = NULL; + } + if( pArea->szMemoFileName ) + { + hb_xfree( pArea->szMemoFileName ); + pArea->szMemoFileName = NULL; + } + return SUCCESS; +} + +/* + * Create a data store in the specified WorkArea. + */ +ERRCODE hb_dbfCreate( DBFAREAP pArea, LPDBOPENINFO pCreateInfo ) +{ + USHORT uiSize, uiCount; + BOOL bHasMemo, bRetry; + DBFFIELD * pBuffer, dbField; + PHB_ITEM pError; + + HB_TRACE(HB_TR_DEBUG, ("hb_dbfCreate(%p, %p)", pArea, pCreateInfo)); + + pArea->szDataFileName = ( char * ) pCreateInfo->abName; + uiSize = pArea->uiFieldCount * sizeof( DBFFIELD ); + pBuffer = ( DBFFIELD * ) hb_xgrab( uiSize ); + pArea->uiRecordLen = 1; + bHasMemo = FALSE; + memset( &dbField, 0, sizeof( DBFFIELD ) ); + for( uiCount = 0; uiCount < pArea->uiFieldCount; uiCount++ ) + { + strncpy( ( char * ) dbField.bName, + ( ( PHB_DYNS ) pArea->lpFields[ uiCount ].sym )->pSymbol->szName, 10 ); + switch( pArea->lpFields[ uiCount ].uiType ) + { + case HB_IT_STRING: + dbField.bType = 'C'; + dbField.bLen = ( BYTE ) pArea->lpFields[ uiCount ].uiLen; + dbField.bDec = ( BYTE ) ( pArea->lpFields[ uiCount ].uiLen / 256 ); + pArea->uiRecordLen += pArea->lpFields[ uiCount ].uiLen; + break; + + case HB_IT_LOGICAL: + dbField.bType = 'L'; + dbField.bLen = 1; + dbField.bDec = 0; + pArea->uiRecordLen ++; + break; + + case HB_IT_MEMO: + dbField.bType = 'M'; + dbField.bLen = 10; + dbField.bDec = 0; + pArea->uiRecordLen += 10; + bHasMemo = TRUE; + break; + + case HB_IT_DATE: + dbField.bType = 'D'; + dbField.bLen = 8; + dbField.bDec = 0; + pArea->uiRecordLen += 8; + break; + + case HB_IT_LONG: + dbField.bType = 'N'; + dbField.bLen = ( BYTE ) pArea->lpFields[ uiCount ].uiLen; + dbField.bDec = ( BYTE ) pArea->lpFields[ uiCount ].uiDec; + pArea->uiRecordLen += pArea->lpFields[ uiCount ].uiLen; + break; + + default: + hb_xfree( pBuffer ); + return FAILURE; + } + pBuffer[ uiCount ] = dbField; + } + + pError = NULL; + /* Try create */ do { - pArea->lpDataInfo->hFile = hb_fsCreate( pCreateInfo->abName, FC_NORMAL ); - if( pArea->lpDataInfo->hFile == FS_ERROR ) + pArea->hDataFile = hb_fsCreate( pCreateInfo->abName, FC_NORMAL ); + if( pArea->hDataFile == FS_ERROR ) { if( !pError ) { pError = hb_errNew(); hb_errPutGenCode( pError, EG_CREATE ); - hb_errPutSubCode( pError, 1004 ); + hb_errPutSubCode( pError, EDBF_CREATE_DBF ); hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_CREATE ) ); hb_errPutFileName( pError, ( char * ) pCreateInfo->abName ); hb_errPutFlags( pError, EF_CANRETRY ); } - bRetry = ( SELF_ERROR( pArea, pError ) == E_RETRY ); + bRetry = ( SELF_ERROR( ( AREAP ) pArea, pError ) == E_RETRY ); } else bRetry = FALSE; @@ -846,1283 +1343,856 @@ static ERRCODE dbfCreate( AREAP pArea, LPDBOPENINFO pCreateInfo ) if( pError ) hb_errRelease( pError ); - if( pArea->lpDataInfo->hFile == FS_ERROR ) - return FAILURE; - - if( SELF_WRITEDBHEADER( pArea ) == FAILURE ) + if( pArea->hDataFile == FS_ERROR ) { - hb_fsClose( pArea->lpDataInfo->hFile ); - pArea->lpDataInfo->hFile = FS_ERROR; + hb_xfree( pBuffer ); return FAILURE; } - hb_fsClose( pArea->lpDataInfo->hFile ); - pArea->lpDataInfo->hFile = FS_ERROR; + pArea->fShared = pCreateInfo->fShared; + pArea->ulRecCount = 0; + pArea->uiHeaderLen = sizeof( DBFHEADER ) + uiSize + 2; + + /* Write header */ + if( hb_dbfWriteDBHeader( pArea ) == FAILURE ) + { + hb_fsClose( pArea->hDataFile ); + pArea->hDataFile = FS_ERROR; + hb_xfree( pBuffer ); + return FAILURE; + } + + /* Write fields and eof mark */ + if( hb_fsWrite( pArea->hDataFile, ( BYTE * ) pBuffer, uiSize ) != uiSize || + hb_fsWrite( pArea->hDataFile, ( BYTE * ) "\r\0\032", 3 ) != 3 ) + { + hb_fsClose( pArea->hDataFile ); + pArea->hDataFile = FS_ERROR; + hb_xfree( pBuffer ); + return FAILURE; + } + hb_xfree( pBuffer ); + + /* Create memo file */ + if( bHasMemo ) + printf( "\nTODO: hb_dbfReadMemo()\n" ); return SUCCESS; } -static ERRCODE dbfCreateMemFile( AREAP pArea, LPDBOPENINFO pCreateInfo ) +/* + * Retrieve information about the current driver. + */ +ERRCODE hb_dbfInfo( DBFAREAP pArea, USHORT uiIndex, PHB_ITEM pItem ) { - LPFILEINFO lpMemInfo; - LPMEMOHEADER pMemoHeader; - BOOL bError; - PHB_ITEM pError = NULL; - BYTE * pBuffer; - - HB_TRACE(HB_TR_DEBUG, ("dbfCreateMemFile(%p, %p)", pArea, pCreateInfo)); - - lpMemInfo = pArea->lpDataInfo->pNext; - do - { - lpMemInfo->hFile = hb_fsCreate( pCreateInfo->abName, FC_NORMAL ); - if( lpMemInfo->hFile == FS_ERROR ) - { - if( !pError ) - { - pError = hb_errNew(); - hb_errPutGenCode( pError, EG_CREATE ); - hb_errPutSubCode( pError, 1005 ); - hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_CREATE ) ); - hb_errPutFileName( pError, ( char * ) pCreateInfo->abName ); - hb_errPutFlags( pError, EF_CANRETRY ); - } - bError = ( SELF_ERROR( pArea, pError ) == E_RETRY ); - } - else - bError = FALSE; - } while( bError ); - if( pError ) - hb_errRelease( pError ); - - if( lpMemInfo->hFile == FS_ERROR ) - return FAILURE; - - pMemoHeader = ( LPMEMOHEADER ) hb_xgrab( MEMO_BLOCK + 1 ); - memset( pMemoHeader, 0, MEMO_BLOCK + 1 ); - pMemoHeader->lNextBlock = 1; - pBuffer = ( BYTE * ) pMemoHeader; - pBuffer[ MEMO_BLOCK ] = 0x1A; - bError = ( hb_fsWrite( lpMemInfo->hFile, ( BYTE * ) pMemoHeader, - MEMO_BLOCK + 1 ) != MEMO_BLOCK + 1 ); - hb_xfree( pMemoHeader ); - hb_fsClose( lpMemInfo->hFile ); - lpMemInfo->hFile = FS_ERROR; - if( bError ) - return FAILURE; - else - return SUCCESS; -} - -static ERRCODE dbfDeleted( AREAP pArea, BOOL * pDeleted ) -{ - BYTE * pBuffer; - - HB_TRACE(HB_TR_DEBUG, ("dbfDeleted(%p, %p)", pArea, pDeleted)); - - SELF_GETREC( pArea, &pBuffer ); - * pDeleted = ( pBuffer[ 0 ] == '*' ); - - return SUCCESS; -} - -static ERRCODE dbfDeleteRec( AREAP pArea ) -{ - BYTE * pBuffer; - - HB_TRACE(HB_TR_DEBUG, ("dbfDeleteRec(%p)", pArea)); - - if( SELF_GOHOT( pArea ) == FAILURE ) - return FAILURE; - - SELF_GETREC( pArea, &pBuffer ); - if( pBuffer[ 0 ] == '*' ) - { - pArea->lpExtendInfo->fRecordChanged = FALSE; - return SUCCESS; - } - - pBuffer[ 0 ] = '*'; - return SUCCESS; -} - -static ERRCODE dbfFlush( AREAP pArea ) -{ - HB_TRACE(HB_TR_DEBUG, ("dbfFlush(%p)", pArea)); - - if( SELF_GOCOLD( pArea ) == FAILURE ) - return FAILURE; - - if( pArea->lpDataInfo->hFile != FS_ERROR ) - hb_fsCommit( pArea->lpDataInfo->hFile ); - if( pArea->lpExtendInfo->fHasMemo && pArea->lpDataInfo->pNext->hFile != FS_ERROR ) - hb_fsCommit( pArea->lpDataInfo->pNext->hFile ); - return FAILURE; -} - -static ERRCODE dbfGetRec( AREAP pArea, BYTE ** pBuffer ) -{ - HB_TRACE(HB_TR_DEBUG, ("dbfGetRec(%p, %p)", pArea, pBuffer)); - - if( !pArea->lpExtendInfo->fValidBuffer ) - hb_dbfReadBuffer( pArea, pArea->lpExtendInfo->ulRecNo ); - - * pBuffer = pArea->lpExtendInfo->bRecord; - return SUCCESS; -} - -static ERRCODE dbfGetValue( AREAP pArea, USHORT uiIndex, PHB_ITEM pItem ) -{ - LPFIELD pField; - BYTE * pBuffer, * szText, szEndChar; - - HB_TRACE(HB_TR_DEBUG, ("dbfGetValue(%p, %hu, %p)", pArea, uiIndex, pItem)); - - if( uiIndex > pArea->uiFieldCount ) - return FAILURE; - - SELF_GETREC( pArea, &pBuffer ); - pField = pArea->lpFields + uiIndex - 1; - szText = pBuffer + pField->uiOffset; - switch( pField->uiType ) - { - case 'C': - hb_itemPutCL( pItem, ( char * ) szText, - pField->uiLen + ( ( USHORT ) pField->uiDec << 8 ) ); - break; - - case 'N': - szEndChar = * ( szText + pField->uiLen ); - * ( szText + pField->uiLen ) = '\0'; - if( pField->uiDec ) - hb_itemPutNDLen( pItem, atof( ( char * ) szText ), ( int ) pField->uiLen - ( ( int ) pField->uiDec + 1 ), ( int ) pField->uiDec ); - else - hb_itemPutNLLen( pItem, atol( ( char * ) szText ), ( int ) pField->uiLen ); - * ( szText + pField->uiLen ) = szEndChar; - break; - - case 'D': - szEndChar = * ( szText + pField->uiLen ); - * ( szText + pField->uiLen ) = '\0'; - hb_itemPutDS( pItem, ( char * ) szText ); - * ( szText + pField->uiLen ) = szEndChar; - break; - - case 'L': - if( * szText == 'T' ) - hb_itemPutL( pItem, TRUE ); - else - hb_itemPutL( pItem, FALSE ); - break; - - case 'M': - if( ( ( LPDBFMEMO ) pField->memo )->pData ) - hb_itemPutCL( pItem, ( char * ) ( ( LPDBFMEMO ) pField->memo )->pData, - ( ( LPDBFMEMO ) pField->memo )->uiLen ); - else - hb_itemPutC( pItem, "" ); - - hb_itemSetCMemo( pItem ); - break; - } - return SUCCESS; -} - -static ERRCODE dbfGetValueFile( AREAP pArea, USHORT uiIndex, void * pFile ) -{ - ULONG lRecNo, lNewRecNo; - BYTE * pBuffer, * szText, szEndChar; - LPFIELD pField; - - HB_TRACE(HB_TR_DEBUG, ("dbfGetValueFile(%p, %hu, %p)", pArea, uiIndex, pFile)); - - HB_SYMBOL_UNUSED( pFile ); - - if( uiIndex > pArea->uiFieldCount ) - return FAILURE; - - SELF_GETREC( pArea, &pBuffer ); - pField = pArea->lpFields + uiIndex - 1; - szText = pBuffer + pField->uiOffset; - if( !( ( LPDBFMEMO ) pField->memo )->pData ) - memset( szText, ' ', pField->uiLen ); - else - { - szEndChar = * ( szText + pField->uiLen ); - * ( szText + pField->uiLen ) = 0; - lRecNo = atol( ( char * ) szText ); - lNewRecNo = lRecNo; - if( !hb_dbfWriteMemo( pArea, ( LPDBFMEMO ) pField->memo, &lNewRecNo ) ) - return FAILURE; - if( lNewRecNo != lRecNo ) - hb_nltoa( lNewRecNo, ( char * ) szText, pField->uiLen ); - * ( szText + pField->uiLen ) = szEndChar; - } - ( ( LPDBFMEMO ) pField->memo )->fChanged = FALSE; - - return SUCCESS; -} - -static ERRCODE dbfGetVarLen( AREAP pArea, USHORT uiIndex, ULONG * ulLen ) -{ - LPFIELD pField; - - HB_TRACE(HB_TR_DEBUG, ("dbfGetVarLen(%p, %hu, %p)", pArea, uiIndex, ulLen)); - - if( uiIndex > pArea->uiFieldCount ) - return FAILURE; - - pField = pArea->lpFields + uiIndex - 1; - if( pField->uiType == 'M' ) - * ulLen = ( ( LPDBFMEMO ) pField->memo )->uiLen; - else - * ulLen = pField->uiLen; - return SUCCESS; -} - -static ERRCODE dbfGoBottom( AREAP pArea ) -{ - ULONG ulRecCount; - - HB_TRACE(HB_TR_DEBUG, ("dbfGoBottom(%p)", pArea)); - - if( SELF_RECCOUNT( pArea, &ulRecCount ) == FAILURE ) - return FAILURE; - pArea->lpExtendInfo->ulRecCount = ulRecCount; - - SELF_GOTO( pArea, ulRecCount ); - return SELF_SKIPFILTER( pArea, -1 ); -} - -static ERRCODE dbfGoCold( AREAP pArea ) -{ - HB_TRACE(HB_TR_DEBUG, ("dbfGoCold(%p)", pArea)); - - if( pArea->lpExtendInfo->fRecordChanged && - !hb_dbfUpdateRecord( pArea, pArea->lpExtendInfo->ulRecNo ) ) - return FAILURE; - - pArea->lpExtendInfo->fRecordChanged = FALSE; - pArea->lpDataInfo->fAppend = FALSE; - return SUCCESS; -} - -static ERRCODE dbfGoHot( AREAP pArea ) -{ - PHB_ITEM pError; - - HB_TRACE(HB_TR_DEBUG, ("dbfGoHot(%p)", pArea)); - - if( !pArea->lpExtendInfo->fExclusive && !pArea->lpDataInfo->fFileLocked && - !hb_dbfIsLocked( pArea, pArea->lpExtendInfo->ulRecNo ) ) - { - pError = hb_errNew(); - hb_errPutGenCode( pError, EG_UNLOCKED ); - hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_UNLOCKED ) ); - hb_errPutSubCode( pError, 1022 ); - SELF_ERROR( pArea, pError ); - hb_errRelease( pError ); - return FAILURE; - } - - if( pArea->lpExtendInfo->fReadOnly ) - { - pError = hb_errNew(); - hb_errPutGenCode( pError, EG_READONLY ); - hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_READONLY ) ); - hb_errPutSubCode( pError, 1025 ); - SELF_ERROR( pArea, pError ); - hb_errRelease( pError ); - return FAILURE; - } - pArea->lpExtendInfo->fRecordChanged = TRUE; - return SUCCESS; -} - -static ERRCODE dbfGoTo( AREAP pArea, ULONG ulRecNo ) -{ - ULONG ulRecCount; - - HB_TRACE(HB_TR_DEBUG, ("dbfGoTo(%p, %lu)", pArea, ulRecNo)); - - if( SELF_GOCOLD( pArea ) == FAILURE ) - return FAILURE; - - if( ulRecNo > pArea->lpExtendInfo->ulRecCount ) - { - if( SELF_RECCOUNT( pArea, &ulRecCount ) == FAILURE ) - return FAILURE; - pArea->lpExtendInfo->ulRecCount = ulRecCount; - } - else - ulRecCount = pArea->lpExtendInfo->ulRecCount; - - if( ulRecCount < 1 ) - { - pArea->fBof = 1; - pArea->fEof = 1; - ulRecNo = 1; - } - else - { - if( ulRecNo > ulRecCount + 1 ) - ulRecNo = ulRecCount + 1; - - if( ulRecNo <= 0 ) - { - pArea->fBof = 1; - ulRecNo = 1; - } - else - pArea->fBof = ( ulRecNo == 1 && pArea->fBof ); - - pArea->fEof = ( ulRecNo == ulRecCount + 1 ); - } - - pArea->lpExtendInfo->ulRecNo = ulRecNo; - if( ulRecCount > 0 ) - pArea->lpExtendInfo->fValidBuffer = FALSE; - else - hb_dbfClearBuffer( pArea ); - - return SUCCESS; -} - -static ERRCODE dbfGoToId( AREAP pArea, PHB_ITEM pItem ) -{ - PHB_ITEM pError; - ULONG ulRecNo; - - HB_TRACE(HB_TR_DEBUG, ("dbfGoToId(%p, %p)", pArea, pItem)); - - if( HB_IS_NUMERIC( pItem ) ) - { - ulRecNo = hb_itemGetNL( pItem ); - if( ulRecNo == 0 ) - ulRecNo = pArea->lpExtendInfo->ulRecNo; - return SELF_GOTO( pArea, ulRecNo ); - } - else - { - pError = hb_errNew(); - hb_errPutGenCode( pError, EG_DATATYPE ); - hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_DATATYPE ) ); - hb_errPutSubCode( pError, 1020 ); - SELF_ERROR( pArea, pError ); - hb_errRelease( pError ); - return FAILURE; - } -} - -static ERRCODE dbfGoTop( AREAP pArea ) -{ - HB_TRACE(HB_TR_DEBUG, ("dbfGoTop(%p)", pArea)); - - pArea->fBof = 0; - SELF_GOTO( pArea, 1 ); - return SELF_SKIPFILTER( pArea, 1 ); -} - -static ERRCODE dbfInfo( AREAP pArea, USHORT uiIndex, PHB_ITEM pItem ) -{ - HB_TRACE(HB_TR_DEBUG, ("dbfInfo(%p, %hu, %p)", pArea, uiIndex, pItem)); + HB_TRACE(HB_TR_DEBUG, ("hb_dbfInfo(%p, %hu, %p)", pArea, uiIndex, pItem)); switch( uiIndex ) { - case DBI_DBFILTER: - SELF_FILTERTEXT( pArea, pItem ); - break; - case DBI_ISDBF: case DBI_CANPUTREC: hb_itemPutL( pItem, TRUE ); break; - case DBI_TABLEEXT: - hb_itemPutC( pItem, ".dbf" ); + case DBI_GETHEADERSIZE: + hb_itemPutNL( pItem, pArea->uiHeaderLen ); break; - case DBI_MEMOEXT: - hb_itemPutC( pItem, ".dbt" ); + case DBI_LASTUPDATE: + hb_itemPutD( pItem, 1900 + pArea->bYear, pArea->bMonth, pArea->bDay ); + break; + + case DBI_GETDELIMITER: + case DBI_SETDELIMITER: + break; + + case DBI_GETRECSIZE: + hb_itemPutNL( pItem, pArea->uiRecordLen ); break; case DBI_GETLOCKARRAY: hb_dbfGetLockArray( pArea, pItem ); break; - case DBI_LASTUPDATE: - hb_itemPutDL( pItem, hb_dateEncode( pArea->lpExtendInfo->bYear, - pArea->lpExtendInfo->bMonth, - pArea->lpExtendInfo->bDay ) ); + case DBI_TABLEEXT: + hb_itemPutC( pItem, DBF_TABLEEXT ); break; - case DBI_GETRECSIZE: - hb_itemPutNL( pItem, pArea->lpExtendInfo->uiRecordLen ); - break; - - case DBI_GETHEADERSIZE: - hb_itemPutNL( pItem, pArea->lpExtendInfo->uiHeaderLen ); + case DBI_MEMOEXT: + hb_itemPutC( pItem, DBF_MEMOEXT ); break; } - return SUCCESS; -} - -static ERRCODE dbfLock( AREAP pArea, LPDBLOCKINFO pLockInfo ) -{ - HB_TRACE(HB_TR_DEBUG, ("dbfLock(%p, %p)", pArea, pLockInfo)); - - if( pLockInfo->itmRecID == 0 ) - { - hb_dbfUnLockAllRecords( pArea ); - - /* Get current record */ - pLockInfo->itmRecID = pArea->lpExtendInfo->ulRecNo; - } - if( SELF_RAWLOCK( pArea, pLockInfo->uiMethod, pLockInfo->itmRecID ) == SUCCESS ) - pLockInfo->fResult = TRUE; - else - pLockInfo->fResult = FALSE; return SUCCESS; } -static ERRCODE dbfOpen( AREAP pArea, LPDBOPENINFO pOpenInfo ) +/* + * Clear the WorkArea for use. + */ +ERRCODE hb_dbfNewArea( DBFAREAP pArea ) { - USHORT uiFlags; - PHB_ITEM pFileExt; - char * szFileName; - PHB_FNAME pFileName; - PHB_ITEM pError = NULL; - BOOL bRetry; + HB_TRACE(HB_TR_DEBUG, ("hb_dbfNewArea(%p)", pArea)); - HB_TRACE(HB_TR_DEBUG, ("dbfOpen(%p, %p)", pArea, pOpenInfo)); - - if( SUPER_OPEN( pArea, pOpenInfo ) == FAILURE ) + if( SUPER_NEW( ( AREAP ) pArea ) == FAILURE ) return FAILURE; + pArea->hDataFile = pArea->hMemoFile = FS_ERROR; + + /* Size for deleted records flag */ + pArea->uiRecordLen = 1; + return SUCCESS; +} + +/* + * Open a data store in the WorkArea. + */ +ERRCODE hb_dbfOpen( DBFAREAP pArea, LPDBOPENINFO pOpenInfo ) +{ + USHORT uiFlags, uiFields, uiSize, uiCount; + BOOL bRetry, bError; + PHB_ITEM pError, pFileExt; + PHB_FNAME pFileName; + char * szFileName; + BYTE * pBuffer; + LPDBFFIELD pField; + DBFIELDINFO pFieldInfo; + + HB_TRACE(HB_TR_DEBUG, ("hb_dbfOpen(%p, %p)", pArea, pOpenInfo)); + + pArea->szDataFileName = ( char * ) pOpenInfo->abName; + pArea->atomAlias = hb_dynsymGet( ( char * ) pOpenInfo->atomAlias ); + if( ( ( PHB_DYNS ) pArea->atomAlias )->hArea ) + { + hb_errRT_DBCMD( EG_DUPALIAS, EDBCMD_DUPALIAS, NULL, ( char * ) pOpenInfo->atomAlias ); + return FAILURE; + } + + ( ( PHB_DYNS ) pArea->atomAlias )->hArea = pOpenInfo->uiArea; + pArea->fShared = pOpenInfo->fShared; + pArea->fReadOnly = pOpenInfo->fReadonly; uiFlags = pOpenInfo->fReadonly ? FO_READ : FO_READWRITE; uiFlags |= pOpenInfo->fShared ? FO_DENYNONE : FO_EXCLUSIVE; + pError = NULL; + + /* Try open */ do { - pArea->lpDataInfo->hFile = hb_fsOpen( pOpenInfo->abName, uiFlags ); - if( pArea->lpDataInfo->hFile == FS_ERROR ) + pArea->hDataFile = hb_fsOpen( pOpenInfo->abName, uiFlags ); + if( pArea->hDataFile == FS_ERROR ) { if( !pError ) { pError = hb_errNew(); hb_errPutGenCode( pError, EG_OPEN ); - hb_errPutSubCode( pError, 1001 ); + hb_errPutSubCode( pError, EDBF_OPEN_DBF ); hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_OPEN ) ); hb_errPutFileName( pError, ( char * ) pOpenInfo->abName ); hb_errPutFlags( pError, EF_CANRETRY | EF_CANDEFAULT ); } - bRetry = ( SELF_ERROR( pArea, pError ) == E_RETRY ); + bRetry = ( SELF_ERROR( ( AREAP ) pArea, pError ) == E_RETRY ); } else bRetry = FALSE; } while( bRetry ); if( pError ) + { hb_errRelease( pError ); + pError = NULL; + } - if( pArea->lpDataInfo->hFile == FS_ERROR ) + /* Exit if error */ + if( pArea->hDataFile == FS_ERROR ) + return FAILURE; + + /* Read file header and exit if error */ + if( hb_dbfReadDBHeader( pArea ) == FAILURE ) { - SELF_CLOSE( pArea ); + SELF_CLOSE( ( AREAP ) pArea ); return FAILURE; } - if( SELF_READDBHEADER( pArea ) == FAILURE ) - { - SELF_CLOSE( pArea ); - return FAILURE; - } - - if( pArea->lpExtendInfo->fHasMemo ) + /* Open memo file if exists */ + if( pArea->fHasMemo ) { pFileName = hb_fsFNameSplit( ( char * ) pOpenInfo->abName ); pFileExt = hb_itemPutC( NULL, "" ); - SELF_INFO( pArea, DBI_MEMOEXT, pFileExt ); - szFileName = ( char * ) hb_xgrab( _POSIX_PATH_MAX + 3 ); - szFileName[ 0 ] = '\0'; + SELF_INFO( ( AREAP ) pArea, DBI_MEMOEXT, pFileExt ); + szFileName = ( char * ) hb_xgrab( _POSIX_PATH_MAX + 1 ); + szFileName[ 0 ] = 0; if( pFileName->szPath ) - strcat( szFileName, pFileName->szPath ); - strcat( szFileName, pFileName->szName ); - strcat( szFileName, hb_itemGetCPtr( pFileExt ) ); - pOpenInfo->abName = ( BYTE * ) szFileName; + strncat( szFileName, pFileName->szPath, _POSIX_PATH_MAX ); + strncat( szFileName, pFileName->szName, _POSIX_PATH_MAX - strlen( szFileName ) ); + strncat( szFileName, hb_itemGetCPtr( pFileExt ), _POSIX_PATH_MAX - + strlen( szFileName ) ); hb_itemRelease( pFileExt ); hb_xfree( pFileName ); + pOpenInfo->abName = ( BYTE * ) szFileName; + pArea->szMemoFileName = szFileName; - pArea->lpDataInfo->pNext = ( LPFILEINFO ) hb_xgrab( sizeof( FILEINFO ) ); - memset( pArea->lpDataInfo->pNext, 0, sizeof( FILEINFO ) ); - pArea->lpDataInfo->pNext->hFile = FS_ERROR; - pArea->lpDataInfo->pNext->szFileName = szFileName; - - if( SELF_OPENMEMFILE( pArea, pOpenInfo ) == FAILURE ) + /* Open memo file and exit if error */ + if( SELF_OPENMEMFILE( ( AREAP ) pArea, pOpenInfo ) == FAILURE ) { - SELF_CLOSE( pArea ); + SELF_CLOSE( ( AREAP ) pArea ); return FAILURE; } } - return SELF_GOTOP( pArea ); -} -static ERRCODE dbfOpenMemFile( AREAP pArea, LPDBOPENINFO pOpenInfo ) -{ - LPFILEINFO lpMemInfo; - LPMEMOHEADER pMemoHeader; - USHORT uiFlags; - PHB_ITEM pError = NULL; - BOOL bRetry; + /* Add fields */ + uiFields = ( pArea->uiHeaderLen - sizeof( DBFHEADER ) ) / sizeof( DBFFIELD ); + SELF_SETFIELDEXTENT( ( AREAP ) pArea, uiFields ); + uiSize = uiFields * sizeof( DBFFIELD ); + pBuffer = ( BYTE * ) hb_xgrab( uiSize ); - HB_TRACE(HB_TR_DEBUG, ("dbfOpenMemFile(%p, %p)", pArea, pOpenInfo)); - - lpMemInfo = pArea->lpDataInfo->pNext; - uiFlags = pOpenInfo->fReadonly ? FO_READ : FO_READWRITE; - uiFlags |= pOpenInfo->fShared ? FO_DENYNONE : FO_EXCLUSIVE; + /* Read fields and exit if error */ do { - lpMemInfo->hFile = hb_fsOpen( pOpenInfo->abName, uiFlags ); - if( lpMemInfo->hFile == FS_ERROR ) + hb_fsSeek( pArea->hDataFile, sizeof( DBFHEADER ), FS_SET ); + if( hb_fsRead( pArea->hDataFile, pBuffer, uiSize ) != uiSize ) { + bError = TRUE; if( !pError ) { pError = hb_errNew(); - hb_errPutGenCode( pError, EG_OPEN ); - hb_errPutSubCode( pError, 1002 ); - hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_OPEN ) ); - hb_errPutFileName( pError, ( char * ) pOpenInfo->abName ); - hb_errPutFlags( pError, EF_CANRETRY ); + hb_errPutGenCode( pError, EG_CORRUPTION ); + hb_errPutSubCode( pError, EDBF_CORRUPT ); + hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_CORRUPTION ) ); + hb_errPutFileName( pError, pArea->szDataFileName ); + hb_errPutFlags( pError, EF_CANRETRY | EF_CANDEFAULT ); } - bRetry = ( SELF_ERROR( pArea, pError ) == E_RETRY ); + bRetry = ( SELF_ERROR( ( AREAP ) pArea, pError ) == E_RETRY ); } else - bRetry = FALSE; + bRetry = bError = FALSE; } while( bRetry ); if( pError ) - hb_errRelease( pError ); - - if( lpMemInfo->hFile == FS_ERROR ) - return FAILURE; - - pMemoHeader = ( LPMEMOHEADER ) hb_xgrab( MEMO_BLOCK + 1 ); - if( hb_fsRead( lpMemInfo->hFile, ( BYTE * ) pMemoHeader, - MEMO_BLOCK + 1 ) != MEMO_BLOCK + 1 ) { - hb_xfree( pMemoHeader ); + hb_errRelease( pError ); + pError = NULL; + } + + /* Exit if error */ + if( bError ) + { + hb_xfree( pBuffer ); + SELF_CLOSE( ( AREAP ) pArea ); return FAILURE; } - pArea->lpExtendInfo->ulNextBlock = pMemoHeader->lNextBlock; - hb_xfree( pMemoHeader ); + + /* Size for deleted flag */ + pArea->uiRecordLen = 1; + + pFieldInfo.uiTypeExtended = 0; + for( uiCount = 0; uiCount < uiFields; uiCount++ ) + { + pField = ( LPDBFFIELD ) ( pBuffer + uiCount * sizeof( DBFFIELD ) ); + pFieldInfo.atomName = pField->bName; + pFieldInfo.uiLen = pField->bLen; + pFieldInfo.uiDec = 0; + switch( pField->bType ) + { + case 'C': + pFieldInfo.uiType = HB_IT_STRING; + pFieldInfo.uiLen = pField->bLen + pField->bDec * 256; + break; + + case 'L': + pFieldInfo.uiType = HB_IT_LOGICAL; + pFieldInfo.uiLen = 1; + break; + + case 'M': + pFieldInfo.uiType = HB_IT_MEMO; + pFieldInfo.uiLen = 10; + break; + + case 'D': + pFieldInfo.uiType = HB_IT_DATE; + pFieldInfo.uiLen = 8; + break; + + case 'N': + pFieldInfo.uiType = HB_IT_LONG; + if( pField->bLen > 20 ) + bError = TRUE; + else + pFieldInfo.uiDec = pField->bDec; + break; + + default: + bError = TRUE; + break; + } + /* Add field */ + if( !bError ) + bError = ( SELF_ADDFIELD( ( AREAP ) pArea, &pFieldInfo ) == FAILURE ); + + /* Exit if error */ + if( bError ) + break; + } + hb_xfree( pBuffer ); + + /* Exit if error */ + if( bError ) + { + if( !pError ) + { + pError = hb_errNew(); + hb_errPutGenCode( pError, EG_CORRUPTION ); + hb_errPutSubCode( pError, EDBF_CORRUPT ); + hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_CORRUPTION ) ); + hb_errPutFileName( pError, pArea->szDataFileName ); + hb_errPutFlags( pError, EF_CANRETRY | EF_CANDEFAULT ); + } + SELF_ERROR( ( AREAP ) pArea, pError ); + hb_errRelease( pError ); + SELF_CLOSE( ( AREAP ) pArea ); + return FAILURE; + } + + /* Alloc buffer */ + pArea->pRecord = ( BYTE * ) hb_xgrab( pArea->uiRecordLen ); + pArea->fValidBuffer = FALSE; + + /* Position cursor at the first record */ + return SELF_GOTOP( ( AREAP ) pArea ); +} + +/* + * Retrieve the size of the WorkArea structure. + */ +ERRCODE hb_dbfStructSize( DBFAREAP pArea, USHORT * uiSize ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_dbfStrucSize(%p, %p)", pArea, uiSize)); + HB_SYMBOL_UNUSED( pArea ); + + * uiSize = sizeof( DBFAREA ); return SUCCESS; } -static ERRCODE dbfPack( AREAP pArea ) +/* + * Obtain the name of replaceable database driver (RDD) subsystem. + */ +ERRCODE hb_dbfSysName( DBFAREAP pArea, BYTE * pBuffer ) { - ULONG ulRecCount, ulRecIn, ulRecOut, ulEvery; - BOOL bDeleted; - PHB_ITEM pError; - BYTE * pBuffer, pEOF[ 1 ]; + HB_TRACE(HB_TR_DEBUG, ("hb_dbfSysName(%p, %p)", pArea, pBuffer)); + HB_SYMBOL_UNUSED( pArea ); - HB_TRACE(HB_TR_DEBUG, ("dbfPack(%p)", pArea)); + strncpy( ( char * ) pBuffer, "DBF", HARBOUR_MAX_RDD_DRIVERNAME_LENGTH ); + return SUCCESS; +} - if( !pArea->lpExtendInfo->fExclusive ) +/* + * Remove records marked for deletion from a database. + */ +ERRCODE hb_dbfPack( DBFAREAP pArea ) +{ + ULONG ulRecIn, ulRecOut, ulEvery, ulUserEvery; + PHB_ITEM pError, pBlock; + + HB_TRACE(HB_TR_DEBUG, ("hb_dbfPack(%p)", pArea)); + + if( pArea->fShared ) { pError = hb_errNew(); hb_errPutGenCode( pError, EG_SHARED ); hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_SHARED ) ); - hb_errPutSubCode( pError, 1023 ); - SELF_ERROR( pArea, pError ); + hb_errPutSubCode( pError, EDBF_SHARED ); + SELF_ERROR( ( AREAP ) pArea, pError ); hb_errRelease( pError ); return FAILURE; } - if( SELF_GOCOLD( pArea ) == FAILURE || pArea->lpExtendInfo->fReadOnly || - SELF_RECCOUNT( pArea, &ulRecCount ) == FAILURE ) + if( SELF_GOCOLD( ( AREAP ) pArea ) == FAILURE ) return FAILURE; - pArea->lpExtendInfo->ulRecCount = ulRecCount; - ulRecOut = 0; - ulRecIn = 1; - ulEvery = 0; - while ( ulRecIn <= ulRecCount ) + if( HB_IS_ARRAY( pArea->valResult ) && hb_arrayLen( pArea->valResult ) == 2 ) { - SELF_GOTO( pArea, ulRecIn ); - SELF_DELETED( pArea, &bDeleted ); + pBlock = hb_arrayGetItemPtr( pArea->valResult, 1 ); + ulUserEvery = hb_arrayGetNL( pArea->valResult, 2 ); + if( ulUserEvery < 1 ) + ulUserEvery = 1; + } + else + pBlock = NULL; + + /* Force write new header */ + pArea->fUpdateHeader = TRUE; + ulRecOut = ulEvery = 0; + ulRecIn = 1; + while ( ulRecIn <= pArea->ulRecCount ) + { + hb_dbfGoTo( pArea, ulRecIn ); + hb_dbfReadRecord( pArea ); /* Execute the Code Block */ - if( pArea->lpExtendInfo->itmEval ) + if( pBlock ) { - ulEvery++; - if( ulEvery >= pArea->lpExtendInfo->ulEvery ) + ulEvery ++; + if( ulEvery >= ulUserEvery ) { ulEvery = 0; hb_vmPushSymbol( &hb_symEval ); - hb_vmPush( pArea->lpExtendInfo->itmEval ); + hb_vmPush( pBlock ); hb_vmDo( 0 ); } } - if( !bDeleted ) + /* Copy record */ + if( !pArea->fDeleted ) { ulRecOut++; - if( ulRecIn != ulRecOut ) /* Copy record */ + if( ulRecIn != ulRecOut ) { - SELF_GETREC( pArea, &pBuffer ); - hb_fsSeek( pArea->lpDataInfo->hFile, pArea->lpExtendInfo->uiHeaderLen + - ( ulRecOut - 1 ) * pArea->lpExtendInfo->uiRecordLen, FS_SET ); - hb_fsWrite( pArea->lpDataInfo->hFile, pBuffer, pArea->lpExtendInfo->uiRecordLen ); + pArea->ulRecNo = ulRecOut; + hb_dbfWriteRecord( pArea ); + pArea->fRecordChanged = FALSE; } } ulRecIn++; } /* Execute the Code Block for pending record */ - if( pArea->lpExtendInfo->itmEval && ulEvery > 0 ) + if( pBlock && ulEvery > 0 ) { hb_vmPushSymbol( &hb_symEval ); - hb_vmPush( pArea->lpExtendInfo->itmEval ); + hb_vmPush( pBlock ); hb_vmDo( 0 ); } - - hb_dbfUpdateHeader( pArea, ulRecOut ); - - /* Write EOF */ - pEOF[ 0 ] = 0x1A; - hb_fsSeek( pArea->lpDataInfo->hFile, pArea->lpExtendInfo->uiHeaderLen + - ulRecOut * pArea->lpExtendInfo->uiRecordLen, FS_SET ); - hb_fsWrite( pArea->lpDataInfo->hFile, pEOF, 1 ); - - /* Truncate the file */ - hb_fsWrite( pArea->lpDataInfo->hFile, NULL, 0 ); - - return SELF_GOTOP( pArea ); + + pArea->ulRecCount = ulRecOut; + return hb_dbfGoTo( pArea, 1 ); } -static ERRCODE dbfPutRec( AREAP pArea, BYTE * pBuffer ) +/* + * Physically reorder a database. + */ +ERRCODE hb_dbfSort( DBFAREAP pArea, LPDBSORTINFO pSortInfo ) { - HB_TRACE(HB_TR_DEBUG, ("dbfPutRec(%p, %p)", pArea, pBuffer)); - - if( SELF_GOHOT( pArea ) == FAILURE ) - return FAILURE; - - memcpy( pArea->lpExtendInfo->bRecord, pBuffer, pArea->lpExtendInfo->uiRecordLen ); - pArea->lpExtendInfo->fValidBuffer = TRUE; - - return SUCCESS; -} - -static ERRCODE dbfPutValue( AREAP pArea, USHORT uiIndex, PHB_ITEM pItem ) -{ - LPFIELD pField; - USHORT uiCount; - BYTE * pBuffer, * szText, szEndChar; - BOOL bError; - long lDay, lMonth, lYear; - PHB_ITEM pError; - - HB_TRACE(HB_TR_DEBUG, ("dbfPutValue(%p, %hu, %p)", pArea, uiIndex, pItem)); - - if( uiIndex > pArea->uiFieldCount ) - return FAILURE; - - if( SELF_GOHOT( pArea ) == FAILURE ) - return FAILURE; - - SELF_GETREC( pArea, &pBuffer ); - pField = pArea->lpFields + uiIndex - 1; - szText = pBuffer + pField->uiOffset; - bError = TRUE; - switch( pField->uiType ) - { - case 'C': - if( HB_IS_STRING( pItem ) ) - { - uiCount = ( USHORT ) hb_itemGetCLen( pItem ); - if( uiCount > pField->uiLen ) - uiCount = pField->uiLen; - memcpy( szText, hb_itemGetCPtr( pItem ), uiCount ); - memset( szText + uiCount, ' ', pField->uiLen - uiCount ); - bError = FALSE; - } - break; - - case 'N': - if( HB_IS_NUMERIC( pItem ) ) - { - if( pField->uiDec ) - bError = !hb_ndtoa( hb_itemGetND( pItem ), ( char * ) szText, - pField->uiLen, pField->uiDec ); - else - bError = !hb_nltoa( hb_itemGetNL( pItem ), ( char * ) szText, - pField->uiLen ); - if( bError ) - { - pError = hb_errNew(); - hb_errPutGenCode( pError, EG_DATAWIDTH ); - hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_DATAWIDTH ) ); - hb_errPutSubCode( pError, 1021 ); - SELF_ERROR( pArea, pError ); - hb_errRelease( pError ); - } - bError = FALSE; - } - break; - - case 'D': - if( HB_IS_DATE( pItem ) ) - { - szEndChar = * ( szText + pField->uiLen ); - hb_dateDecode( hb_itemGetDL( pItem ), &lYear, &lMonth, &lDay ); - hb_dateStrPut( ( char * ) szText, lYear, lMonth, lDay ); - * ( szText + pField->uiLen ) = szEndChar; - bError = FALSE; - } - break; - - case 'L': - if( HB_IS_LOGICAL( pItem ) ) - { - *szText = hb_itemGetL( pItem ) ? 'T' : 'F'; - bError = FALSE; - } - break; - - case 'M': - if( HB_IS_STRING( pItem ) ) - { - uiCount = ( USHORT ) hb_itemGetCLen( pItem ); - if( ( ( LPDBFMEMO ) pField->memo )->uiLen < uiCount ) - { - if( ( ( LPDBFMEMO ) pField->memo )->pData ) - ( ( LPDBFMEMO ) pField->memo )->pData = - ( BYTE * ) hb_xrealloc( ( ( LPDBFMEMO ) pField->memo )->pData, - uiCount + 1 ); - else - ( ( LPDBFMEMO ) pField->memo )->pData = - ( BYTE * ) hb_xgrab( uiCount + 1 ); - } - ( ( LPDBFMEMO ) pField->memo )->uiLen = uiCount; - if( uiCount > 0 ) - { - memcpy( ( ( LPDBFMEMO ) pField->memo )->pData, hb_itemGetCPtr( pItem ), uiCount ); - ( ( LPDBFMEMO ) pField->memo )->pData[ uiCount ] = 0; - } - else - { - if( ( ( LPDBFMEMO ) pField->memo )->pData ) - { - hb_xfree( ( ( LPDBFMEMO ) pField->memo )->pData ); - memset( pField->memo, 0, sizeof( DBFMEMO ) ); - } - } - ( ( LPDBFMEMO ) pField->memo )->fChanged = TRUE; - bError = FALSE; - } - break; - } - - if( bError ) - { - pError = hb_errNew(); - hb_errPutGenCode( pError, EG_DATATYPE ); - hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_DATATYPE ) ); - hb_errPutSubCode( pError, 1020 ); - SELF_ERROR( pArea, pError ); - hb_errRelease( pError ); - pArea->lpExtendInfo->fRecordChanged = FALSE; - return FAILURE; - } - pArea->lpExtendInfo->fRecordChanged = TRUE; - return SUCCESS; -} - -static ERRCODE dbfPutValueFile( AREAP pArea, USHORT uiIndex, void * pFile ) -{ - LPFIELD pField; - BYTE * pBuffer, * szText, szEndChar; - ULONG lMemoBlock; - - HB_TRACE(HB_TR_DEBUG, ("dbfPutValueFile(%p, %hu, %p)", pArea, uiIndex, pFile)); - - HB_SYMBOL_UNUSED( pFile ); - - if( uiIndex > pArea->uiFieldCount ) - return FAILURE; - - SELF_GETREC( pArea, &pBuffer ); - pField = pArea->lpFields + uiIndex - 1;; - szText = pBuffer + pField->uiOffset; - szEndChar = * ( szText + pField->uiLen ); - * ( szText + pField->uiLen ) = 0; - lMemoBlock = atol( ( char * ) szText ) * MEMO_BLOCK; - * ( szText + pField->uiLen ) = szEndChar; - if( lMemoBlock > 0 ) - hb_dbfReadMemo( pArea, ( LPDBFMEMO ) pField->memo, lMemoBlock ); - else if( ( ( LPDBFMEMO ) pField->memo )->pData ) - { - hb_xfree( ( ( LPDBFMEMO ) pField->memo )->pData ); - memset( pField->memo, 0, sizeof( DBFMEMO ) ); - } - return SUCCESS; -} - -static ERRCODE dbfRawLock( AREAP pArea, USHORT uiAction, ULONG lRecNo ) -{ - HB_TRACE(HB_TR_DEBUG, ("dbfRawLock(%p, %hu, %lu)", pArea, uiAction, lRecNo)); - - if( SELF_GOCOLD( pArea ) == FAILURE ) - return FAILURE; - - switch( uiAction ) - { - case REC_LOCK: - if( !hb_dbfLockRecord( pArea, lRecNo ) ) - return FAILURE; - break; - - case REC_UNLOCK: - if( !hb_dbfUnLockRecord( pArea, lRecNo ) ) - return FAILURE; - break; - - case FILE_LOCK: - if( !hb_dbfLockFile( pArea ) ) - return FAILURE; - break; - - case FILE_UNLOCK: - if( !hb_dbfUnLockFile( pArea ) ) - return FAILURE; - break; - } - return SUCCESS; -} - -static ERRCODE dbfReadDBHeader( AREAP pArea ) -{ - DBFHEADER pHeader; - DBFIELDINFO pFieldInfo; - LPDBFFIELD pDBField; - USHORT uiDataLen; - char * szBuffer; - USHORT uiFields, uiCount; - - HB_TRACE(HB_TR_DEBUG, ("dbfReadHeader(%p)", pArea)); - - hb_fsSeek( pArea->lpDataInfo->hFile, 0, FS_SET ); - if( hb_fsRead( pArea->lpDataInfo->hFile, ( BYTE * ) &pHeader, - sizeof( DBFHEADER ) ) != sizeof( DBFHEADER ) ) - return FAILURE; - - pArea->lpExtendInfo->uiHeaderLen = pHeader.uiHeaderLen; - pArea->lpExtendInfo->bYear = pHeader.bYear; - pArea->lpExtendInfo->bMonth = pHeader.bMonth; - pArea->lpExtendInfo->bDay = pHeader.bDay; - uiDataLen = pHeader.uiHeaderLen - sizeof( DBFHEADER ); - szBuffer = ( char * ) hb_xgrab( uiDataLen ); - if( hb_fsRead( pArea->lpDataInfo->hFile, ( BYTE * ) szBuffer, - uiDataLen ) != uiDataLen ) - { - hb_xfree( szBuffer ); - return FAILURE; - } - - for( uiFields = 0; uiFields < uiDataLen; uiFields += 32 ) - if( szBuffer[ uiFields ] == 0xD ) - break; - - uiFields /= 32; - if( ( uiDataLen / 32 ) < uiFields ) - { - hb_xfree( szBuffer ); - return FAILURE; - } - - pArea->lpExtendInfo->uiRecordLen = 1; - SELF_SETFIELDEXTENT( pArea, uiFields ); - pFieldInfo.typeExtended = 0; - pFieldInfo.uiLen = 0; - pDBField = ( LPDBFFIELD ) szBuffer; - for( uiCount = 0; uiCount < uiFields; uiCount++ ) - { - pFieldInfo.atomName = ( BYTE * ) pDBField->bName; - pFieldInfo.uiType = toupper( pDBField->bType ); - - if( pFieldInfo.uiType == 'N' ) - { - pFieldInfo.uiLen = ( USHORT ) pDBField->bLen; - pFieldInfo.uiDec = ( USHORT ) pDBField->bDec; - } - else - { - if( pFieldInfo.uiType == 'L' || pFieldInfo.uiType == 'D' || - pFieldInfo.uiType == 'M' ) - { - pFieldInfo.uiLen = ( USHORT ) pDBField->bLen; - if( pFieldInfo.uiType == 'M' ) - pArea->lpExtendInfo->fHasMemo = TRUE; - } - else if( pFieldInfo.uiType == 'C' ) - { - pFieldInfo.uiLen = ( USHORT ) pDBField->bLen + - ( ( USHORT ) pDBField->bDec << 8 ); - } - pFieldInfo.uiDec = 0; - } - pArea->lpExtendInfo->uiRecordLen += pFieldInfo.uiLen; - SELF_ADDFIELD( pArea, &pFieldInfo ); - pDBField++; - } - hb_xfree( szBuffer ); - pArea->lpExtendInfo->bRecord = ( BYTE * ) hb_xgrab( pArea->lpExtendInfo->uiRecordLen + 1 ); - hb_dbfClearBuffer( pArea ); - pArea->lpExtendInfo->bRecord[ pArea->lpExtendInfo->uiRecordLen ] = 0; - return SUCCESS; -} - -static ERRCODE dbfRecAll( AREAP pArea ) -{ - BYTE * pBuffer; - - HB_TRACE(HB_TR_DEBUG, ("dbfRecAll(%p)", pArea)); - - if( SELF_GOHOT( pArea ) == FAILURE ) - return FAILURE; - - SELF_GETREC( pArea, &pBuffer ); - if( pBuffer[ 0 ] != '*' ) - { - pArea->lpExtendInfo->fRecordChanged = FALSE; - return SUCCESS; - } - pBuffer[ 0 ] = ' '; - - return SUCCESS; -} - -static ERRCODE dbfRecCount( AREAP pArea, ULONG * pRecCount ) -{ - DBFHEADER pHeader; - - HB_TRACE(HB_TR_DEBUG, ("dbfRecCount(%p, %p)", pArea, pRecCount)); - - hb_fsSeek( pArea->lpDataInfo->hFile, 0, FS_SET ); - if( hb_fsRead( pArea->lpDataInfo->hFile, ( BYTE * ) &pHeader, - sizeof( DBFHEADER ) ) != sizeof( DBFHEADER ) ) - return FAILURE; - * pRecCount = pHeader.ulRecords; - return SUCCESS; -} - -static ERRCODE dbfRecInfo( AREAP pArea, PHB_ITEM pRecNo, USHORT uiType, PHB_ITEM pItem ) -{ - BYTE * pBuffer; ULONG ulRecNo; - - HB_TRACE(HB_TR_DEBUG, ("dbfRecInfo(%p, %p, %hu, %p)", pArea, pRecNo, uiType, pItem)); - - ulRecNo = pArea->lpExtendInfo->ulRecNo; - if( SELF_GOTOID( pArea, pRecNo ) == SUCCESS ) - { - switch( uiType ) - { - case DBRI_DELETED: - SELF_GETREC( pArea, &pBuffer ); - hb_itemPutL( pItem, ( pBuffer[ 0 ] == '*' ) ); - break; - - case DBRI_LOCKED: - hb_itemPutL( pItem, hb_dbfIsLocked( pArea, pArea->lpExtendInfo->ulRecNo ) ); - break; - - case DBRI_RECNO: - SELF_RECNO( pArea, pItem ); - break; - - case DBRI_RECSIZE: - hb_itemPutNL( pItem, pArea->lpExtendInfo->uiRecordLen ); - break; - - case DBRI_UPDATED: - hb_itemPutL( pItem, pArea->lpExtendInfo->fRecordChanged ); - break; - } - } - SELF_GOTO( pArea, ulRecNo ); - - return SUCCESS; -} - -static ERRCODE dbfRecNo( AREAP pArea, PHB_ITEM pRecNo ) -{ - HB_TRACE(HB_TR_DEBUG, ("dbfRecNo(%p, %p)", pArea, pRecNo)); - - hb_itemPutNL( pRecNo, pArea->lpExtendInfo->ulRecNo ); - return SUCCESS; -} - -static ERRCODE dbfRelease( AREAP pArea ) -{ - USHORT uiCount; - LPFIELD pField; - - HB_TRACE(HB_TR_DEBUG, ("dbfRelease(%p)", pArea)); - - if( pArea->lpExtendInfo->fHasMemo ) - { - for( uiCount = 0; uiCount < pArea->uiFieldCount; uiCount++ ) - { - pField = pArea->lpFields + uiCount; - if( pField->memo ) - { - if( ( ( LPDBFMEMO ) pField->memo )->pData ) - hb_xfree( ( ( LPDBFMEMO ) pField->memo )->pData ); - hb_xfree( pField->memo ); - } - } - } - return SUPER_RELEASE( pArea ); -} - -static ERRCODE dbfUnLock( AREAP pArea, ULONG lRecNo ) -{ - HB_TRACE(HB_TR_DEBUG, ("dbfUnLock(%p, %lu)", pArea, lRecNo)); - - if( lRecNo == 0 ) - hb_dbfUnLockAllRecords( pArea ); - else - SELF_RAWLOCK( pArea, REC_UNLOCK, lRecNo ); - return SUCCESS; -} - -static ERRCODE dbfWriteDBHeader( AREAP pArea ) -{ - DBFHEADER pHeader; - DBFFIELD pDBField; USHORT uiCount; - LPFIELD pField; - time_t t; - struct tm * pTime; + BOOL bMoreRecords, bLimited, bValidRecord; + ERRCODE uiError; + DBQUICKSORT dbQuickSort; + BYTE * pBuffer; - HB_TRACE(HB_TR_DEBUG, ("dbfWriteDBHeader(%p)", pArea)); + HB_TRACE(HB_TR_DEBUG, ("hb_dbfSort(%p, %p)", pArea, pSortInfo)); - memset( &pHeader, 0, sizeof( DBFHEADER ) ); - pHeader.uiRecordLen = 1; - pHeader.bVersion = 0x03; - pField = pArea->lpFields; - for( uiCount = 0; uiCount < pArea->uiFieldCount; uiCount++ ) - { - switch( pField->uiType ) - { - case 'C': - case 'N': - pHeader.uiRecordLen += pField->uiLen; - break; - - case 'M': - pHeader.uiRecordLen += 10; - pHeader.bVersion = 0x83; - pArea->lpExtendInfo->fHasMemo = TRUE; - break; - - case 'D': - pHeader.uiRecordLen += 8; - break; - - case 'L': - pHeader.uiRecordLen += 1; - break; - } - pField++; - } - - time( &t ); - pTime = localtime( &t ); - pHeader.bYear = ( BYTE ) pTime->tm_year; - pHeader.bMonth = ( BYTE ) pTime->tm_mon + 1; - pHeader.bDay = ( BYTE ) pTime->tm_mday; - pHeader.uiHeaderLen = ( USHORT ) ( 32 * ( pArea->uiFieldCount + 1 ) + 1 ); - pHeader.bHasTag = 0; - pHeader.ulRecords = 0; - if( hb_fsWrite( pArea->lpDataInfo->hFile, ( BYTE * ) &pHeader, - sizeof( DBFHEADER ) ) != sizeof( DBFHEADER ) ) + if( !hb_dbQSortInit( &dbQuickSort, pSortInfo, pArea->uiRecordLen ) ) return FAILURE; - pField = pArea->lpFields; - for( uiCount = 0; uiCount < pArea->uiFieldCount; uiCount++ ) + uiError = SUCCESS; + uiCount = 0; + pBuffer = dbQuickSort.pBuffer; + if( pSortInfo->dbtri.dbsci.itmRecID ) { - memset( &pDBField, 0, sizeof( DBFFIELD ) ); - strncpy( ( char * ) pDBField.bName, ( ( PHB_DYNS ) pField->sym )->pSymbol->szName, - sizeof( pDBField.bName ) ); - pDBField.bType = ( BYTE ) pField->uiType; - switch( pDBField.bType ) + uiError = hb_dbfGoTo( pArea, hb_itemGetNL( pSortInfo->dbtri.dbsci.itmRecID ) ); + ulRecNo = 1; + bMoreRecords = bLimited = TRUE; + } + else if( pSortInfo->dbtri.dbsci.lNext ) + { + ulRecNo = hb_itemGetNL( pSortInfo->dbtri.dbsci.lNext ); + bLimited = TRUE; + bMoreRecords = ( ulRecNo >= 0 ); + } + else + { + if( !pSortInfo->dbtri.dbsci.itmCobWhile && + ( !pSortInfo->dbtri.dbsci.fRest || + !hb_itemGetL( pSortInfo->dbtri.dbsci.fRest ) ) ) + uiError = hb_dbfGoTop( pArea ); + bMoreRecords = TRUE; + bLimited = FALSE; + } + + while( uiError == SUCCESS && !pArea->fEof && bMoreRecords ) + { + if( pSortInfo->dbtri.dbsci.itmCobWhile ) + bMoreRecords = hb_itemGetL( hb_vmEvalBlock( pSortInfo->dbtri.dbsci.itmCobWhile ) ); + + if( bMoreRecords && pSortInfo->dbtri.dbsci.itmCobFor ) + bValidRecord = hb_itemGetL( hb_vmEvalBlock( pSortInfo->dbtri.dbsci.itmCobFor ) ); + else + bValidRecord = bMoreRecords; + + if( bValidRecord ) { - case 'C': - pDBField.bLen = pField->uiLen & 0xFF; - pDBField.bDec = pField->uiLen >> 8; - break; + if( uiCount == dbQuickSort.uiMaxRecords ) + { + if( !hb_dbQSortAdvance( &dbQuickSort, uiCount ) ) + { + hb_dbQSortExit( &dbQuickSort ); + return FAILURE; + } + pBuffer = dbQuickSort.pBuffer; + uiCount = 0; + } - case 'M': - pDBField.bLen = 10; - pDBField.bDec = 0; - break; + /* Read record */ + if( !pArea->fValidBuffer && !hb_dbfReadRecord( pArea ) ) + { + hb_dbQSortExit( &dbQuickSort ); + return FAILURE; + } - case 'D': - pDBField.bLen = 8; - pDBField.bDec = 0; - break; - - case 'L': - pDBField.bLen = 1; - pDBField.bDec = 0; - break; - - case 'N': - pDBField.bLen = ( BYTE ) pField->uiLen; - pDBField.bDec = ( BYTE ) pField->uiDec; - break; + /* Copy data */ + memcpy( pBuffer, pArea->pRecord, pArea->uiRecordLen ); + pBuffer += pArea->uiRecordLen; + uiCount++; } - if( hb_fsWrite( pArea->lpDataInfo->hFile, ( BYTE * ) &pDBField, - sizeof( DBFFIELD ) ) != sizeof( DBFFIELD ) ) + + if( bMoreRecords && bLimited ) + bMoreRecords = ( --ulRecNo > 0 ); + if( bMoreRecords ) + uiError = hb_dbfSkip( pArea, 1 ); + } + + /* Copy last records */ + if( uiCount > 0 ) + { + if( !hb_dbQSortAdvance( &dbQuickSort, uiCount ) ) + { + hb_dbQSortExit( &dbQuickSort ); return FAILURE; - pField++; + } } - if( hb_fsWrite( pArea->lpDataInfo->hFile, ( BYTE * ) "\15\32", 2 ) != 2 ) - return FAILURE; + + /* Sort records */ + hb_dbQSortComplete( &dbQuickSort ); return SUCCESS; } -static ERRCODE dbfZap( AREAP pArea ) +/* + * Copy one or more records from one WorkArea to another. + */ +ERRCODE hb_dbfTrans( DBFAREAP pArea, LPDBTRANSINFO pTransInfo ) +{ + PHB_ITEM pPutRec; + + HB_TRACE(HB_TR_DEBUG, ("hb_dbfTrans(%p, %p)", pArea, pTransInfo)); + + if( pTransInfo->uiFlags & DBTF_MATCH && !pArea->fHasMemo ) + { + pPutRec = hb_itemPutL( NULL, FALSE ); + SELF_INFO( ( AREAP ) pTransInfo->lpaDest, DBI_CANPUTREC, pPutRec ); + if( hb_itemGetL( pPutRec ) ) + pTransInfo->uiFlags |= DBTF_PUTREC; + hb_itemRelease( pPutRec ); + } + return SUPER_TRANS( ( AREAP ) pArea, pTransInfo ); +} + +/* + * Copy a record to another WorkArea. + */ +ERRCODE hb_dbfTransRec( DBFAREAP pArea, LPDBTRANSINFO pTransInfo ) +{ + BOOL bDeleted; + + HB_TRACE(HB_TR_DEBUG, ("hb_dbfTransRec(%p, %p)", pArea, pTransInfo)); + + if( pTransInfo->uiFlags & DBTF_PUTREC ) + { + /* Append a new record */ + if( SELF_APPEND( ( AREAP ) pTransInfo->lpaDest, TRUE ) == FAILURE ) + return FAILURE; + + /* Read record */ + if( !pArea->fValidBuffer && !hb_dbfReadRecord( pArea ) ) + return FAILURE; + + /* Copy record */ + if( SELF_PUTREC( ( AREAP ) pTransInfo->lpaDest, pArea->pRecord ) == FAILURE ) + return FAILURE; + + /* Record deleted? */ + if( SELF_DELETED( ( AREAP ) pArea, &bDeleted ) == FAILURE ) + return FAILURE; + + /* Delete the new record */ + if( bDeleted ) + return SELF_DELETE( ( AREAP ) pTransInfo->lpaDest ); + } + return SUPER_TRANSREC( ( AREAP ) pArea, pTransInfo ); +} + +/* + * Physically remove all records from data store. + */ +ERRCODE hb_dbfZap( DBFAREAP pArea ) { PHB_ITEM pError; - DBOPENINFO pInfo; - ULONG ulRecCount; - HB_TRACE(HB_TR_DEBUG, ("dbfZap(%p)", pArea)); + HB_TRACE(HB_TR_DEBUG, ("hb_dbfZap(%p)", pArea)); - if( !pArea->lpExtendInfo->fExclusive ) + if( pArea->fShared ) { pError = hb_errNew(); hb_errPutGenCode( pError, EG_SHARED ); hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_SHARED ) ); - hb_errPutSubCode( pError, 1023 ); - SELF_ERROR( pArea, pError ); + hb_errPutSubCode( pError, EDBF_SHARED ); + SELF_ERROR( ( AREAP ) pArea, pError ); hb_errRelease( pError ); return FAILURE; } - if( SELF_GOCOLD( pArea ) == FAILURE || pArea->lpExtendInfo->fReadOnly ) + if( SELF_GOCOLD( ( AREAP ) pArea ) == FAILURE ) return FAILURE; - /* Test if can write into file */ - SELF_RECCOUNT( pArea, &ulRecCount ); - pArea->lpExtendInfo->ulRecCount = ulRecCount; - if( !hb_dbfUpdateHeader( pArea, ulRecCount ) ) - return FAILURE; + hb_dbfGoTo( pArea, 0 ); + pArea->fUpdateHeader = TRUE; + pArea->ulRecCount = 0; - hb_dbfUnLockAllRecords( pArea ); - hb_fsClose( pArea->lpDataInfo->hFile ); - pInfo.abName = ( BYTE * ) pArea->lpDataInfo->szFileName; - SELF_CREATE( pArea, &pInfo ); - hb_fsClose( pArea->lpDataInfo->hFile ); - pArea->lpDataInfo->hFile = hb_fsOpen( pInfo.abName, FO_READWRITE | FO_EXCLUSIVE ); - if( pArea->lpExtendInfo->fHasMemo ) - { - hb_fsClose( pArea->lpDataInfo->pNext->hFile ); - pInfo.abName = ( BYTE * ) pArea->lpDataInfo->pNext->szFileName; - SELF_CREATEMEMFILE( pArea, &pInfo ); - hb_fsClose( pArea->lpDataInfo->pNext->hFile ); - pArea->lpDataInfo->pNext->hFile = hb_fsOpen( pInfo.abName, FO_READWRITE | FO_EXCLUSIVE ); - } - return SELF_GOTOP( pArea ); + /* Create memo file */ + if( pArea->fHasMemo ) + printf( "\nTODO: hb_dbfZapMemo()\n" ); + return SUCCESS; } -static RDDFUNCS dbfTable = { dbfBof, - dbfEof, - dbfFound, - dbfGoBottom, - dbfGoTo, - dbfGoToId, - dbfGoTop, - dbfSeek, - dbfSkip, - dbfSkipFilter, - dbfSkipRaw, - dbfAddField, - dbfAppend, - dbfCreateFields, - dbfDeleteRec, - dbfDeleted, - dbfFieldCount, - dbfFieldDisplay, - dbfFieldInfo, - dbfFieldName, - dbfFlush, - dbfGetRec, - dbfGetValue, - dbfGetVarLen, - dbfGoCold, - dbfGoHot, - dbfPutRec, - dbfPutValue, - dbfRecAll, - dbfRecCount, - dbfRecInfo, - dbfRecNo, - dbfSetFieldsExtent, - dbfAlias, - dbfClose, - dbfCreate, - dbfInfo, - dbfNewArea, - dbfOpen, - dbfRelease, - dbfStructSize, - dbfSysName, - dbfEval, - dbfPack, - dbfZap, - dbfchildEnd, - dbfchildStart, - dbfchildSync, - dbfsyncChildren, - dbfclearRel, - dbfforceRel, - dbfrelArea, - dbfrelEval, - dbfrelText, - dbfsetRel, - dbfOrderListAdd, - dbfOrderListClear, - dbfOrderListFocus, - dbfOrderListRebuild, - dbfOrderCondition, - dbfOrderCreate, - dbfOrderDestroy, - dbfOrderInfo, - dbfClearFilter, - dbfClearLocate, - dbfClearScope, - dbfCountScope, - dbfFilterText, - dbfScopeInfo, - dbfSetFilter, - dbfSetLocate, - dbfSetScope, - dbfSkipScope, - dbfCompile, - dbfError, - dbfEvalBlock, - dbfRawLock, - dbfLock, - dbfUnLock, - dbfCloseMemFile, - dbfCreateMemFile, - dbfGetValueFile, - dbfOpenMemFile, - dbfPutValueFile, - dbfReadDBHeader, - dbfWriteDBHeader, - dbfWhoCares - }; +/* + * Report end of relation. + */ +ERRCODE hb_dbfChildEnd( DBFAREAP pArea, LPDBRELINFO pRelInfo ) +{ + ERRCODE uiError; + + HB_TRACE(HB_TR_DEBUG, ("hb_dbfChildEnd(%p, %p)", pArea, pRelInfo)); + + if( pArea->lpdbPendingRel == pRelInfo ) + uiError = SELF_FORCEREL( ( AREAP ) pArea ); + else + uiError = SUCCESS; + SUPER_CHILDEND( ( AREAP ) pArea, pRelInfo ); + return uiError; +} + +/* + * Report initialization of a relation. + */ +ERRCODE hb_dbfChildStart( DBFAREAP pArea, LPDBRELINFO pRelInfo ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_dbfChildStart(%p, %p)", pArea, pRelInfo)); + + SELF_CHILDSYNC( ( AREAP ) pArea, pRelInfo ); + return SUPER_CHILDSTART( ( AREAP ) pArea, pRelInfo ); +} + +/* + * Post a pending relational movement. + */ +ERRCODE hb_dbfChildSync( DBFAREAP pArea, LPDBRELINFO pRelInfo ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_dbfChildSync(%p, %p)", pArea, pRelInfo)); + + SELF_GOCOLD( ( AREAP ) pArea ); + pArea->lpdbPendingRel = pRelInfo; + SELF_SYNCCHILDREN( ( AREAP ) pArea ); + return SUCCESS; +} + +/* + * Force relational seeks in the specified WorkArea. + */ +ERRCODE hb_dbfForceRel( DBFAREAP pArea ) +{ + LPDBRELINFO lpdbPendingRel; + ERRCODE uiError; + ULONG ulRecNo; + + HB_TRACE(HB_TR_DEBUG, ("hb_dbfForceRel(%p)", pArea)); + + if( pArea->lpdbPendingRel ) + { + lpdbPendingRel = pArea->lpdbPendingRel; + pArea->lpdbPendingRel = NULL; + uiError = SELF_RELEVAL( ( AREAP ) pArea, lpdbPendingRel ); + if( uiError == SUCCESS && !lpdbPendingRel->lpaParent->fEof && + HB_IS_NUMERIC( pArea->valResult ) ) + ulRecNo = hb_itemGetNL( pArea->valResult ); + else + ulRecNo = 0; + uiError = SELF_GOTO( ( AREAP ) pArea, ulRecNo ); + pArea->fFound = pArea->fPositioned; + pArea->fBof = FALSE; + return uiError; + } + return SUCCESS; +} + +/* + * Set the filter condition for the specified WorkArea. + */ +ERRCODE hb_dbfSetFilter( DBFAREAP pArea, LPDBFILTERINFO pFilterInfo ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_dbfSetFilter(%p, %p)", pArea, pFilterInfo)); + + if( pArea->lpdbPendingRel ) + SELF_FORCEREL( ( AREAP ) pArea ); + return SUPER_SETFILTER( ( AREAP ) pArea, pFilterInfo ); +} + +/* + * Perform a network lock in the specified WorkArea. + */ +ERRCODE hb_dbfLock( DBFAREAP pArea, LPDBLOCKINFO pLockInfo ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_dbfLock(%p, %p)", pArea, pLockInfo)); + + if( pArea->fShared ) + { + switch( pLockInfo->uiMethod ) + { + case DBLM_EXCLUSIVE: + return hb_dbfLockRecord( pArea, pArea->ulRecNo, &pLockInfo->fResult, + ( pLockInfo->uiMethod == DBLM_EXCLUSIVE ) ); + + case DBLM_MULTIPLE: + return hb_dbfLockRecord( pArea, hb_itemGetNL( pLockInfo->itmRecID ), + &pLockInfo->fResult, + ( pLockInfo->uiMethod == DBLM_EXCLUSIVE ) ); + + case DBLM_FILE: + return hb_dbfLockFile( pArea, &pLockInfo->fResult ); + + default: + pLockInfo->fResult = FALSE; + } + } + else + pLockInfo->fResult = TRUE; + + return SUCCESS; +} + +/* + * Release network locks in the specified WorkArea. + */ +ERRCODE hb_dbfUnLock( DBFAREAP pArea, ULONG ulRecNo ) +{ + ERRCODE uiError; + + HB_TRACE(HB_TR_DEBUG, ("dbfUnLock(%p, %lu)", pArea, ulRecNo)); + + uiError = SUCCESS; + if( pArea->fShared ) + { + if( pArea->ulNumLocksPos > 0 ) + { + uiError = SELF_GOCOLD( ( AREAP ) pArea ); + + /* Unlock all records? */ + if( ulRecNo == 0 ) + hb_dbfUnlockAllRecords( pArea ); + else if( hb_dbfIsLocked( pArea, ulRecNo ) ) + hb_dbfUnlockRecord( pArea, ulRecNo ); + } + if( pArea->fFLocked ) + { + uiError = SELF_GOCOLD( ( AREAP ) pArea ); + hb_dbfUnlockFile( pArea ); + } + } + return uiError; +} + +/* + * Open a memo file in the specified WorkArea. + */ +ERRCODE hb_dbfOpenMemFile( DBFAREAP pArea, LPDBOPENINFO pOpenInfo ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_dbfOpenMemFile(%p, %p)", pArea, pOpenInfo)); + HB_SYMBOL_UNUSED( pArea ); + HB_SYMBOL_UNUSED( pOpenInfo ); + + printf( "\nTODO: hb_dbfOpenMemFile()\n" ); + return SUCCESS; +} + +/* + * Read the database file header record in the WorkArea. + */ +ERRCODE hb_dbfReadDBHeader( DBFAREAP pArea ) +{ + DBFHEADER dbHeader; + BOOL bRetry, bError; + PHB_ITEM pError; + + HB_TRACE(HB_TR_DEBUG, ("hb_dbfReadHeader(%p)", pArea)); + + pError = NULL; + /* Try read */ + do + { + hb_fsSeek( pArea->hDataFile, 0, FS_SET ); + if( hb_fsRead( pArea->hDataFile, ( BYTE * ) &dbHeader, sizeof( DBFHEADER ) ) != + sizeof( DBFHEADER ) || ( dbHeader.bVersion != 0x03 && dbHeader.bVersion != 0x83 ) ) + { + bError = TRUE; + if( !pError ) + { + pError = hb_errNew(); + hb_errPutGenCode( pError, EG_CORRUPTION ); + hb_errPutSubCode( pError, EDBF_CORRUPT ); + hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_CORRUPTION ) ); + hb_errPutFileName( pError, pArea->szDataFileName ); + hb_errPutFlags( pError, EF_CANRETRY | EF_CANDEFAULT ); + } + bRetry = ( SELF_ERROR( ( AREAP ) pArea, pError ) == E_RETRY ); + } + else + bRetry = bError = FALSE; + } while( bRetry ); + + if( pError ) + hb_errRelease( pError ); + + /* Read error? */ + if( bError ) + return FAILURE; + + pArea->bDay = dbHeader.bDay; + pArea->bMonth = dbHeader.bMonth; + pArea->bYear = dbHeader.bYear; + pArea->uiHeaderLen = dbHeader.uiHeaderLen; + pArea->ulRecCount = dbHeader.ulRecCount; + pArea->fHasMemo = ( dbHeader.bVersion == 0x83 ); + pArea->fHasTags = dbHeader.bHasTags; + return SUCCESS; +} + +/* + * Write the database file header record in the WorkArea. + */ +ERRCODE hb_dbfWriteDBHeader( DBFAREAP pArea ) +{ + DBFHEADER dbfHeader; + long lYear, lMonth, lDay; + + HB_TRACE(HB_TR_DEBUG, ("hb_dbfWriteDBHeader(%p)", pArea)); + + if( pArea->fHasMemo ) + printf( "\nTODO: hb_dbfWriteMemoHeader()\n" ); + + memset( &dbfHeader, 0, sizeof( DBFHEADER ) ); + dbfHeader.bVersion = 0x03; + hb_dateToday( &lYear, &lMonth, &lDay ); + dbfHeader.bYear = ( BYTE ) ( lYear - 1900 ); + dbfHeader.bMonth = ( BYTE ) lMonth; + dbfHeader.bDay = ( BYTE ) lDay; + dbfHeader.bHasTags = ( BYTE ) pArea->fHasTags; + + /* Update record count */ + if( pArea->fShared ) + pArea->ulRecCount = hb_dbfCalcRecCount( pArea ); + + dbfHeader.ulRecCount = pArea->ulRecCount; + dbfHeader.uiHeaderLen = pArea->uiHeaderLen; + dbfHeader.uiRecordLen = pArea->uiRecordLen; + hb_fsSeek( pArea->hDataFile, 0, FS_SET ); + hb_fsWrite( pArea->hDataFile, ( BYTE * ) &dbfHeader, sizeof( DBFHEADER ) ); + pArea->fUpdateHeader = FALSE; + return SUCCESS; +} HB_FUNC( _DBFC ) { @@ -2143,5 +2213,4 @@ HB_FUNC( DBF_GETFUNCTABLE ) hb_retni( hb_rddInherit( pTable, &dbfTable, &dbfSuper, 0 ) ); else hb_retni( FAILURE ); -} - +} \ No newline at end of file diff --git a/harbour/source/rdd/dbfcdx/Makefile b/harbour/source/rdd/dbfcdx/Makefile index b089207922..dcdb01b739 100644 --- a/harbour/source/rdd/dbfcdx/Makefile +++ b/harbour/source/rdd/dbfcdx/Makefile @@ -4,8 +4,8 @@ ROOT = ../../../ -C_SOURCES=\ - dbfcdx1.c \ +#C_SOURCES=\ +# dbfcdx1.c \ PRG_SOURCES=\ dbfcdx0.prg \ diff --git a/harbour/source/rdd/dbfntx/Makefile b/harbour/source/rdd/dbfntx/Makefile index ce7f7ef235..9ad038f994 100644 --- a/harbour/source/rdd/dbfntx/Makefile +++ b/harbour/source/rdd/dbfntx/Makefile @@ -4,8 +4,8 @@ ROOT = ../../../ -C_SOURCES=\ - dbfntx1.c \ +#C_SOURCES=\ +# dbfntx1.c \ PRG_SOURCES=\ dbfntx0.prg \ diff --git a/harbour/source/rdd/dbfntx/dbfntx0.prg b/harbour/source/rdd/dbfntx/dbfntx0.prg index 7e7936b4f3..5260953a44 100644 --- a/harbour/source/rdd/dbfntx/dbfntx0.prg +++ b/harbour/source/rdd/dbfntx/dbfntx0.prg @@ -40,11 +40,11 @@ ANNOUNCE DBFNTX init procedure DBFNTXInit - REQUEST _DBFNTX - +/* REQUEST _DBFNTX +*/ rddRegister( "DBF", RDT_FULL ) - rddRegister( "DBFNTX", RDT_FULL ) - +/* rddRegister( "DBFNTX", RDT_FULL ) +*/ return /* NOTE: Commented out, because in Harbour the INIT order is not guaranteed, diff --git a/harbour/source/rdd/dbsort.prg b/harbour/source/rdd/dbsort.prg new file mode 100644 index 0000000000..935a1c24eb --- /dev/null +++ b/harbour/source/rdd/dbsort.prg @@ -0,0 +1,74 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * __DBSORT() function + * + * Copyright 2000 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 of the License, or + * (at your option) any later version, with one exception: + * + * The exception is that if you link the Harbour Runtime Library (HRL) + * and/or the Harbour Virtual Machine (HVM) 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 HRL + * and/or HVM code into it. + * + * 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 program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA (or visit + * their web site at http://www.gnu.org/). + * + */ + +FUNCTION __dbSort( cToFileName, aFields, bFor, bWhile, nNext, nRecord, lRest ) + LOCAL nArea + LOCAL nToArea + LOCAL aStruct + LOCAL oError + LOCAL lError := .F. + + nArea := Select() + + aStruct := dbStruct() + IF Empty( aStruct ) + RETURN .F. + ENDIF + + BEGIN SEQUENCE + + dbCreate( cToFileName, aStruct,, .T., "" ) + nToArea := Select() + dbSelectArea( nArea ) + __dbArrange( nToArea, aStruct, bFor, bWhile, nNext, nRecord, lRest, aFields ) + + RECOVER USING oError + + lError := .T. + + END SEQUENCE + + IF nToArea != NIL + dbSelectArea( nToArea ) + dbCloseArea() + ENDIF + + dbSelectArea( nArea ) + + IF lError + Break( oError ) + ENDIF + + RETURN .T. \ No newline at end of file diff --git a/harbour/source/rdd/delim0.prg b/harbour/source/rdd/delim0.prg index e686e08de5..6efabece0f 100644 --- a/harbour/source/rdd/delim0.prg +++ b/harbour/source/rdd/delim0.prg @@ -43,5 +43,4 @@ init procedure DELIMInit rddRegister( "DELIM", RDT_TRANSFER ) -return - +return \ No newline at end of file diff --git a/harbour/source/rdd/delim1.c b/harbour/source/rdd/delim1.c index 4716f6f008..b9fdd80ccc 100644 --- a/harbour/source/rdd/delim1.c +++ b/harbour/source/rdd/delim1.c @@ -33,13 +33,12 @@ * */ -#define SUPERTABLE ( &delimSuper ) - #include "hbapi.h" #include "hbinit.h" -#include "hbapiitm.h" +#include "hbvm.h" #include "hbapirdd.h" -#include "rddsys.ch" +#include "hbapiitm.h" +#include "hbrdddel.h" HB_FUNC( _DELIMC ); HB_FUNC( DELIM_GETFUNCTABLE ); @@ -61,13 +60,107 @@ HB_INIT_SYMBOLS_END( delim1__InitSymbols ) #pragma startup delim1__InitSymbols #endif -static RDDFUNCS delimSuper = { 0 }; +static RDDFUNCS delimSuper = { NULL }; + +static RDDFUNCS delimTable = { hb_delimBof, + hb_delimEof, + hb_delimFound, + hb_delimGoBottom, + hb_delimGoTo, + hb_delimGoToId, + hb_delimGoTop, + hb_delimSeek, + hb_delimSkip, + hb_delimSkipFilter, + hb_delimSkipRaw, + hb_delimAddField, + hb_delimAppend, + hb_delimCreateFields, + hb_delimDeleteRec, + hb_delimDeleted, + hb_delimFieldCount, + hb_delimFieldDisplay, + hb_delimFieldInfo, + hb_delimFieldName, + hb_delimFlush, + hb_delimGetRec, + hb_delimGetValue, + hb_delimGetVarLen, + hb_delimGoCold, + hb_delimGoHot, + hb_delimPutRec, + hb_delimPutValue, + hb_delimRecAll, + hb_delimRecCount, + hb_delimRecInfo, + hb_delimRecNo, + hb_delimSetFieldExtent, + hb_delimAlias, + hb_delimClose, + hb_delimCreate, + hb_delimInfo, + hb_delimNewArea, + hb_delimOpen, + hb_delimRelease, + hb_delimStructSize, + hb_delimSysName, + hb_delimEval, + hb_delimPack, + hb_delimPackRec, + hb_delimSort, + hb_delimTrans, + hb_delimTransRec, + hb_delimZap, + hb_delimChildEnd, + hb_delimChildStart, + hb_delimChildSync, + hb_delimSyncChildren, + hb_delimClearRel, + hb_delimForceRel, + hb_delimRelArea, + hb_delimRelEval, + hb_delimRelText, + hb_delimSetRel, + hb_delimOrderListAdd, + hb_delimOrderListClear, + hb_delimOrderListDelete, + hb_delimOrderListFocus, + hb_delimOrderListRebuild, + hb_delimOrderCondition, + hb_delimOrderCreate, + hb_delimOrderDestroy, + hb_delimOrderInfo, + hb_delimClearFilter, + hb_delimClearLocate, + hb_delimClearScope, + hb_delimCountScope, + hb_delimFilterText, + hb_delimScopeInfo, + hb_delimSetFilter, + hb_delimSetLocate, + hb_delimSetScope, + hb_delimSkipScope, + hb_delimCompile, + hb_delimError, + hb_delimEvalBlock, + hb_delimRawLock, + hb_delimLock, + hb_delimUnLock, + hb_delimCloseMemFile, + hb_delimCreateMemFile, + hb_delimGetValueFile, + hb_delimOpenMemFile, + hb_delimPutValueFile, + hb_delimReadDBHeader, + hb_delimWriteDBHeader, + hb_delimWhoCares + }; + /* * -- DELIM METHODS -- */ -static RDDFUNCS delimTable = { 0 }; HB_FUNC( _DELIMC ) { @@ -81,9 +174,11 @@ HB_FUNC( DELIM_GETFUNCTABLE ) uiCount = ( USHORT * ) hb_itemGetPtr( hb_param( 1, HB_IT_POINTER ) ); * uiCount = RDDFUNCSCOUNT; pTable = ( RDDFUNCS * ) hb_itemGetPtr( hb_param( 2, HB_IT_POINTER ) ); + + HB_TRACE(HB_TR_DEBUG, ("DELIM_GETFUNCTABLE(%i, %p)", uiCount, pTable)); + if( pTable ) hb_retni( hb_rddInherit( pTable, &delimTable, &delimSuper, 0 ) ); else hb_retni( FAILURE ); -} - +} \ No newline at end of file diff --git a/harbour/source/rdd/hbdbsort.c b/harbour/source/rdd/hbdbsort.c new file mode 100644 index 0000000000..9079df1f1c --- /dev/null +++ b/harbour/source/rdd/hbdbsort.c @@ -0,0 +1,234 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * SORT 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 of the License, or + * (at your option) any later version, with one exception: + * + * The exception is that if you link the Harbour Runtime Library (HRL) + * and/or the Harbour Virtual Machine (HVM) 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 HRL + * and/or HVM code into it. + * + * 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 program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA (or visit + * their web site at http://www.gnu.org/). + * + */ + +#include "hbdbsort.h" + +BOOL hb_dbQSortInit( LPDBQUICKSORT pQuickSort, LPDBSORTINFO pSortInfo, USHORT uiRecordLen ) +{ + /* Create temp file */ + hb_fsTempName( pQuickSort->szTempName, NULL, NULL ); + pQuickSort->hFile = hb_fsCreate( ( BYTE * ) pQuickSort->szTempName, FC_NORMAL ); + if( pQuickSort->hFile == FS_ERROR ) + return FALSE; + + /* Alloc buffers */ + pQuickSort->uiMaxRecords = USHRT_MAX / uiRecordLen; + pQuickSort->pBuffer = ( BYTE * ) hb_xgrab( pQuickSort->uiMaxRecords * uiRecordLen ); + pQuickSort->pSwapBufferA = ( BYTE * ) hb_xgrab( uiRecordLen ); + pQuickSort->pSwapBufferB = ( BYTE * ) hb_xgrab( uiRecordLen ); + pQuickSort->pCmpBufferA = ( BYTE * ) hb_xgrab( uiRecordLen ); + pQuickSort->pCmpBufferB = ( BYTE * ) hb_xgrab( uiRecordLen ); + + /* Fill structure */ + pQuickSort->uiRecordLen = uiRecordLen; + pQuickSort->pSortInfo = pSortInfo; + return TRUE; +} + +void hb_dbQSortExit( LPDBQUICKSORT pQuickSort ) +{ + /* Close and delete temp file */ + hb_fsClose( pQuickSort->hFile ); + hb_fsDelete( pQuickSort->szTempName ); + + /* Free buffers */ + hb_xfree( pQuickSort->pBuffer ); + hb_xfree( pQuickSort->pSwapBufferA ); + hb_xfree( pQuickSort->pSwapBufferB ); + hb_xfree( pQuickSort->pCmpBufferA ); + hb_xfree( pQuickSort->pCmpBufferB ); +} + +BOOL hb_dbQSortAdvance( LPDBQUICKSORT pQuickSort, USHORT uiCount ) +{ + USHORT uiSize; + + /* Write chunk */ + uiSize = uiCount * pQuickSort->uiRecordLen; + return ( hb_fsWrite( pQuickSort->hFile, pQuickSort->pBuffer, uiSize ) == uiSize ); +} + +static BOOL hb_dbQSortIsLess( LPDBQUICKSORT pQuickSort, ULONG ulRecNo1, ULONG ulRecNo2 ) +{ + USHORT uiCount, uiField; + DBFAREAP pArea; + LPFIELD pField; + BOOL bAscending, bIgnoreCase; + int iResult; + + pArea = ( DBFAREAP ) pQuickSort->pSortInfo->dbtri.lpaSource; + + /* Read records */ + hb_fsSeek( pQuickSort->hFile, ( ulRecNo1 - 1 ) * pQuickSort->uiRecordLen, FS_SET ); + hb_fsRead( pQuickSort->hFile, pQuickSort->pSwapBufferA, pQuickSort->uiRecordLen ); + hb_fsSeek( pQuickSort->hFile, ( ulRecNo2 - 1 ) * pQuickSort->uiRecordLen, FS_SET ); + hb_fsRead( pQuickSort->hFile, pQuickSort->pSwapBufferB, pQuickSort->uiRecordLen ); + + /* Compare fields */ + for( uiCount = 0; uiCount < pQuickSort->pSortInfo->uiItemCount; uiCount++ ) + { + /* Sort flags */ + bIgnoreCase = ( ( pQuickSort->pSortInfo->lpdbsItem[ uiCount ].uiFlags & SF_CASE ) == SF_CASE ); + bAscending = ( ( pQuickSort->pSortInfo->lpdbsItem[ uiCount ].uiFlags & SF_ASCEND ) == SF_ASCEND ); + + uiField = pQuickSort->pSortInfo->lpdbsItem[ uiCount ].uiField - 1; + pField = pArea->lpFields + uiField; + if( pField->uiType == HB_IT_MEMO ) + continue; + if( pField->uiType == HB_IT_LOGICAL ) + { + if( pQuickSort->pSwapBufferA[ pArea->pFieldOffset[ uiField ] ] == 'T' || + pQuickSort->pSwapBufferA[ pArea->pFieldOffset[ uiField ] ] == 't' || + pQuickSort->pSwapBufferA[ pArea->pFieldOffset[ uiField ] ] == 'Y' || + pQuickSort->pSwapBufferA[ pArea->pFieldOffset[ uiField ] ] == 'y' ) + * pQuickSort->pCmpBufferA = '1'; + else + * pQuickSort->pCmpBufferA = '0'; + if( pQuickSort->pSwapBufferB[ pArea->pFieldOffset[ uiField ] ] == 'T' || + pQuickSort->pSwapBufferB[ pArea->pFieldOffset[ uiField ] ] == 't' || + pQuickSort->pSwapBufferB[ pArea->pFieldOffset[ uiField ] ] == 'Y' || + pQuickSort->pSwapBufferB[ pArea->pFieldOffset[ uiField ] ] == 'y' ) + * pQuickSort->pCmpBufferB = '1'; + else + * pQuickSort->pCmpBufferB = '0'; + } + else + { + memcpy( pQuickSort->pCmpBufferA, pQuickSort->pSwapBufferA + + pArea->pFieldOffset[ uiField ], pField->uiLen ); + memcpy( pQuickSort->pCmpBufferB, pQuickSort->pSwapBufferB + + pArea->pFieldOffset[ uiField ], pField->uiLen ); + } + pQuickSort->pCmpBufferA[ pField->uiLen ] = 0; + pQuickSort->pCmpBufferB[ pField->uiLen ] = 0; + + /* Compare buffers */ + if( bIgnoreCase ) + iResult = stricmp( ( const char * ) pQuickSort->pCmpBufferA, + ( const char * ) pQuickSort->pCmpBufferB ); + else + iResult = strcmp( ( const char * ) pQuickSort->pCmpBufferA, + ( const char * ) pQuickSort->pCmpBufferB ); + + if( iResult == 0 ) + continue; + else if( bAscending ) + return ( iResult < 0 ); + else + return ( iResult > 0 ); + } + return FALSE; +} + +static void hb_dbQSortSwap( LPDBQUICKSORT pQuickSort, ULONG ulRecNo1, ULONG ulRecNo2 ) +{ + /* Swap records */ + hb_fsSeek( pQuickSort->hFile, ( ulRecNo1 - 1 ) * pQuickSort->uiRecordLen, FS_SET ); + hb_fsRead( pQuickSort->hFile, pQuickSort->pSwapBufferA, pQuickSort->uiRecordLen ); + hb_fsSeek( pQuickSort->hFile, ( ulRecNo2 - 1 ) * pQuickSort->uiRecordLen, FS_SET ); + hb_fsRead( pQuickSort->hFile, pQuickSort->pSwapBufferB, pQuickSort->uiRecordLen ); + hb_fsSeek( pQuickSort->hFile, ( ulRecNo1 - 1 ) * pQuickSort->uiRecordLen, FS_SET ); + hb_fsWrite( pQuickSort->hFile, pQuickSort->pSwapBufferB, pQuickSort->uiRecordLen ); + hb_fsSeek( pQuickSort->hFile, ( ulRecNo2 - 1 ) * pQuickSort->uiRecordLen, FS_SET ); + hb_fsWrite( pQuickSort->hFile, pQuickSort->pSwapBufferA, pQuickSort->uiRecordLen ); +} + +static void hb_dbQSortDo( LPDBQUICKSORT pQuickSort, ULONG ulFirst, ULONG ulLast ) +{ + ULONG ulPivot, ulLeft, ulRight; + + /* Select pivot */ + if( hb_dbQSortIsLess( pQuickSort, ulFirst, ulLast ) ) + ulPivot = ulLast; + else + ulPivot = ulFirst; + + ulLeft = ulFirst; + ulRight = ulLast; + do + { + /* partition into two segments */ + while( ulLeft <= ulLast && hb_dbQSortIsLess( pQuickSort, ulLeft, ulPivot ) ) + ulLeft++; + + while( ulRight >= ulFirst && hb_dbQSortIsLess( pQuickSort, ulPivot, ulRight ) ) + ulRight--; + + if( ulLeft <= ulRight ) + { + /* Swap records */ + if( ulLeft < ulRight ) + hb_dbQSortSwap( pQuickSort, ulLeft, ulRight ); + ulLeft++; + ulRight--; + } + } while( ulLeft <= ulRight ); + + /* Sort segment */ + if( ulFirst < ulRight ) + hb_dbQSortDo( pQuickSort, ulFirst, ulRight ); + + /* Sort segment */ + if( ulLeft < ulLast ) + hb_dbQSortDo( pQuickSort, ulLeft, ulLast ); +} + +void hb_dbQSortComplete( LPDBQUICKSORT pQuickSort ) +{ + ULONG ulRecCount; + AREAP pArea; + + ulRecCount = hb_fsSeek( pQuickSort->hFile, 0, FS_END ) / pQuickSort->uiRecordLen; + if( ulRecCount > 1 ) + { + hb_dbQSortDo( pQuickSort, 1, ulRecCount ); + pArea = pQuickSort->pSortInfo->dbtri.lpaDest; + hb_fsSeek( pQuickSort->hFile, 0, FS_SET ); + while( ulRecCount-- > 0 ) + { + /* Read sorted record */ + hb_fsRead( pQuickSort->hFile, pQuickSort->pSwapBufferA, pQuickSort->uiRecordLen ); + + /* Remove deleted flag */ + pQuickSort->pSwapBufferA[ 0 ] = ' '; + + /* Append a new record and copy data */ + if( SELF_APPEND( pArea, TRUE ) == FAILURE || + SELF_PUTREC( pArea, pQuickSort->pSwapBufferA ) == FAILURE ) + break; + } + } + hb_dbQSortExit( pQuickSort ); +} \ No newline at end of file diff --git a/harbour/source/rdd/sdf0.prg b/harbour/source/rdd/sdf0.prg index 807cb1ead9..486c6ac967 100644 --- a/harbour/source/rdd/sdf0.prg +++ b/harbour/source/rdd/sdf0.prg @@ -43,5 +43,4 @@ init procedure SDFInit rddRegister( "SDF", RDT_TRANSFER ) -return - +return \ No newline at end of file diff --git a/harbour/source/rdd/sdf1.c b/harbour/source/rdd/sdf1.c index c9c804b1cf..914ae032f6 100644 --- a/harbour/source/rdd/sdf1.c +++ b/harbour/source/rdd/sdf1.c @@ -33,13 +33,12 @@ * */ -#define SUPERTABLE ( &sdfSuper ) - #include "hbapi.h" #include "hbinit.h" -#include "hbapiitm.h" +#include "hbvm.h" #include "hbapirdd.h" -#include "rddsys.ch" +#include "hbapiitm.h" +#include "hbrddsdf.h" HB_FUNC( _SDFC ); HB_FUNC( SDF_GETFUNCTABLE ); @@ -61,13 +60,108 @@ HB_INIT_SYMBOLS_END( sdf1__InitSymbols ) #pragma startup sdf1__InitSymbols #endif -static RDDFUNCS sdfSuper = { 0 }; +static RDDFUNCS sdfSuper = { NULL }; + +static RDDFUNCS sdfTable = { hb_sdfBof, + hb_sdfEof, + hb_sdfFound, + hb_sdfGoBottom, + hb_sdfGoTo, + hb_sdfGoToId, + hb_sdfGoTop, + hb_sdfSeek, + hb_sdfSkip, + hb_sdfSkipFilter, + hb_sdfSkipRaw, + hb_sdfAddField, + hb_sdfAppend, + hb_sdfCreateFields, + hb_sdfDeleteRec, + hb_sdfDeleted, + hb_sdfFieldCount, + hb_sdfFieldDisplay, + hb_sdfFieldInfo, + hb_sdfFieldName, + hb_sdfFlush, + hb_sdfGetRec, + hb_sdfGetValue, + hb_sdfGetVarLen, + hb_sdfGoCold, + hb_sdfGoHot, + hb_sdfPutRec, + hb_sdfPutValue, + hb_sdfRecAll, + hb_sdfRecCount, + hb_sdfRecInfo, + hb_sdfRecNo, + hb_sdfSetFieldExtent, + hb_sdfAlias, + hb_sdfClose, + hb_sdfCreate, + hb_sdfInfo, + hb_sdfNewArea, + hb_sdfOpen, + hb_sdfRelease, + hb_sdfStructSize, + hb_sdfSysName, + hb_sdfEval, + hb_sdfPack, + hb_sdfPackRec, + hb_sdfSort, + hb_sdfTrans, + hb_sdfTransRec, + hb_sdfZap, + hb_sdfChildEnd, + hb_sdfChildStart, + hb_sdfChildSync, + hb_sdfSyncChildren, + hb_sdfClearRel, + hb_sdfForceRel, + hb_sdfRelArea, + hb_sdfRelEval, + hb_sdfRelText, + hb_sdfSetRel, + hb_sdfOrderListAdd, + hb_sdfOrderListClear, + hb_sdfOrderListDelete, + hb_sdfOrderListFocus, + hb_sdfOrderListRebuild, + hb_sdfOrderCondition, + hb_sdfOrderCreate, + hb_sdfOrderDestroy, + hb_sdfOrderInfo, + hb_sdfClearFilter, + hb_sdfClearLocate, + hb_sdfClearScope, + hb_sdfCountScope, + hb_sdfFilterText, + hb_sdfScopeInfo, + hb_sdfSetFilter, + hb_sdfSetLocate, + hb_sdfSetScope, + hb_sdfSkipScope, + hb_sdfCompile, + hb_sdfError, + hb_sdfEvalBlock, + hb_sdfRawLock, + hb_sdfLock, + hb_sdfUnLock, + hb_sdfCloseMemFile, + hb_sdfCreateMemFile, + hb_sdfGetValueFile, + hb_sdfOpenMemFile, + hb_sdfPutValueFile, + hb_sdfReadDBHeader, + hb_sdfWriteDBHeader, + hb_sdfWhoCares + }; + /* * -- SDF METHODS -- */ -static RDDFUNCS sdfTable = { 0 }; + HB_FUNC( _SDFC ) { @@ -81,9 +175,11 @@ HB_FUNC( SDF_GETFUNCTABLE ) uiCount = ( USHORT * ) hb_itemGetPtr( hb_param( 1, HB_IT_POINTER ) ); * uiCount = RDDFUNCSCOUNT; pTable = ( RDDFUNCS * ) hb_itemGetPtr( hb_param( 2, HB_IT_POINTER ) ); + + HB_TRACE(HB_TR_DEBUG, ("SDF_GETFUNCTABLE(%i, %p)", uiCount, pTable)); + if( pTable ) hb_retni( hb_rddInherit( pTable, &sdfTable, &sdfSuper, 0 ) ); else hb_retni( FAILURE ); -} - +} \ No newline at end of file diff --git a/harbour/source/rdd/workarea.c b/harbour/source/rdd/workarea.c new file mode 100644 index 0000000000..0d5e5094cc --- /dev/null +++ b/harbour/source/rdd/workarea.c @@ -0,0 +1,887 @@ +/* + * $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 of the License, or + * (at your option) any later version, with one exception: + * + * The exception is that if you link the Harbour Runtime Library (HRL) + * and/or the Harbour Virtual Machine (HVM) 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 HRL + * and/or HVM code into it. + * + * 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 program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA (or visit + * their web site at http://www.gnu.org/). + * + */ + +#include +#include "hbapi.h" +#include "hbinit.h" +#include "hbvm.h" +#include "hbapiitm.h" +#include "hbapierr.h" +#include "hbset.h" +#include "hbrddwrk.h" + + +/* + * -- METHODS -- + */ + +/* + * Determine logical beginning of file. + */ +ERRCODE hb_waBof( AREAP pArea, BOOL * pBof ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_waBof(%p, %p)", pArea, pBof)); + + * pBof = pArea->fBof; + return SUCCESS; +} + +/* + * Determine logical end of file. + */ +ERRCODE hb_waEof( AREAP pArea, BOOL * pEof ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_waEof(%p, %p)", pArea, pEof)); + + * pEof = pArea->fEof; + return SUCCESS; +} + +/* + * Determine outcome of the last search operation. + */ +ERRCODE hb_waFound( AREAP pArea, BOOL * pFound ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_waFound(%p, %p)", pArea, pFound)); + + * pFound = pArea->fFound; + return SUCCESS; +} + +/* + * Reposition cursor relative to current position. + */ +ERRCODE hb_waSkip( AREAP pArea, LONG lToSkip ) +{ + LONG lSkip; + + HB_TRACE(HB_TR_DEBUG, ("hb_waSkip(%p, %ld)", pArea, lToSkip)); + + /* Flush record and exit */ + if( lToSkip == 0 ) + return SELF_SKIPRAW( pArea, 0 ); + + pArea->fTop = pArea->fBottom = FALSE; + + if( lToSkip > 0 ) + lSkip = 1; + else + { + lSkip = -1; + lToSkip *= -1; + } + while( lToSkip-- > 0 ) + { + SELF_SKIPRAW( pArea, lSkip ); + SELF_SKIPFILTER( pArea, lSkip ); + if( pArea->fBof || pArea->fEof ) + break; + } + + /* Update Bof and Eof flags */ + if( lToSkip < 0 ) + pArea->fEof = FALSE; + else if( lToSkip > 0 ) + pArea->fBof = FALSE; + + return SUCCESS; +} + +/* + * Reposition cursor respecting any filter setting. + */ +ERRCODE hb_waSkipFilter( AREAP pArea, LONG lUpDown ) +{ + BOOL bTop, bBottom, bOutOfRange, bDeleted; + PHB_ITEM pResult; + ERRCODE uiError; + + HB_TRACE(HB_TR_DEBUG, ("hb_waSkipFilter(%p, %ld)", pArea, lUpDown)); + + if( !hb_set.HB_SET_DELETED && pArea->dbfi.itmCobExpr == NULL ) + return SUCCESS; + + bTop = pArea->fTop; + bBottom = pArea->fBottom; + bOutOfRange = FALSE; + while( TRUE ) + { + if( pArea->fBof || pArea->fEof ) + { + bOutOfRange = TRUE; + break; + } + + /* SET FILTER TO */ + if( pArea->dbfi.itmCobExpr ) + { + pResult = hb_vmEvalBlock( pArea->dbfi.itmCobExpr ); + if( HB_IS_LOGICAL( pResult ) && !hb_itemGetL( pResult ) ) + { + SELF_SKIPRAW( pArea, lUpDown ); + continue; + } + } + + /* SET DELETED */ + if( hb_set.HB_SET_DELETED ) + { + SELF_DELETED( pArea, &bDeleted ); + if( bDeleted ) + { + SELF_SKIPRAW( pArea, lUpDown ); + continue; + } + } + break; + } + if( bOutOfRange ) + { + if( bTop && lUpDown > 0 ) + uiError = SELF_GOTO( pArea, 0 ); + else if( bBottom && lUpDown < 0 ) + uiError = SELF_GOTO( pArea, 0 ); + else if( lUpDown < 0 ) + { + uiError = SELF_GOTOP( pArea ); + pArea->fBof = TRUE; + pArea->fEof = FALSE; + } + else + { + uiError = SELF_GOTO( pArea, 0 ); + pArea->fBof = FALSE; + } + } + else + uiError = SUCCESS; + + return uiError; +} + +/* + * Add a field to the WorkArea. + */ +ERRCODE hb_waAddField( AREAP pArea, LPDBFIELDINFO pFieldInfo ) +{ + ULONG ulSize; + LPFIELD pField; + + HB_TRACE(HB_TR_DEBUG, ("hb_waAddField(%p, %p)", pArea, pFieldInfo)); + + /* Validate the name of field */ + ulSize = strlen( ( char * ) pFieldInfo->atomName ); + hb_strLTrim( ( char * ) pFieldInfo->atomName, &ulSize ); + if( !ulSize ) + return FAILURE; + + pField = pArea->lpFields + pArea->uiFieldCount; + if( pArea->uiFieldCount > 0 ) + ( ( LPFIELD ) ( pField - 1 ) )->lpfNext = pField; + pField->sym = ( void * ) hb_dynsymGet( ( char * ) pFieldInfo->atomName ); + pField->uiType = pFieldInfo->uiType; + pField->uiTypeExtended = pFieldInfo->uiTypeExtended; + pField->uiLen = pFieldInfo->uiLen; + pField->uiDec = pFieldInfo->uiDec; + pField->uiArea = pArea->uiArea; + pArea->uiFieldCount ++; + return SUCCESS; +} + +/* + * Add all fields defined in an array to the WorkArea. + */ +ERRCODE hb_waCreateFields( AREAP pArea, PHB_ITEM pStruct ) +{ + USHORT uiItems, uiCount, uiLen, uiDec; + DBFIELDINFO pFieldInfo; + PHB_ITEM pFieldDesc; + int iData; + + HB_TRACE(HB_TR_DEBUG, ("hb_waCreateFields(%p, %p)", pArea, pStruct)); + + uiItems = ( USHORT ) hb_arrayLen( pStruct ); + SELF_SETFIELDEXTENT( pArea, uiItems ); + + pFieldInfo.uiTypeExtended = 0; + for( uiCount = 0; uiCount < uiItems; uiCount++ ) + { + pFieldDesc = hb_arrayGetItemPtr( pStruct, uiCount + 1 ); + pFieldInfo.atomName = ( BYTE * ) hb_arrayGetCPtr( pFieldDesc, 1 ); + iData = hb_arrayGetNI( pFieldDesc, 3 ); + if( iData < 0 ) + iData = 0; + uiLen = pFieldInfo.uiLen = ( USHORT ) iData; + iData = hb_arrayGetNI( pFieldDesc, 4 ); + if( iData < 0 ) + iData = 0; + uiDec = ( USHORT ) iData; + pFieldInfo.uiDec = 0; + iData = toupper( hb_arrayGetCPtr( pFieldDesc, 2 )[ 0 ] ); + switch( iData ) + { + case 'C': + pFieldInfo.uiType = HB_IT_STRING; + pFieldInfo.uiLen = uiLen + uiDec * 256; + break; + + case 'L': + pFieldInfo.uiType = HB_IT_LOGICAL; + pFieldInfo.uiLen = 1; + break; + + case 'M': + pFieldInfo.uiType = HB_IT_MEMO; + pFieldInfo.uiLen = 10; + break; + + case 'D': + pFieldInfo.uiType = HB_IT_DATE; + pFieldInfo.uiLen = 8; + break; + + case 'N': + pFieldInfo.uiType = HB_IT_LONG; + if( uiLen > 20 ) + return FAILURE; + else + pFieldInfo.uiDec = uiDec; + break; + + default: + return FAILURE; + } + /* Add field */ + if( SELF_ADDFIELD( pArea, &pFieldInfo ) == FAILURE ) + return FAILURE; + } + return SUCCESS; +} + +/* + * Determine the number of fields in the WorkArea. + */ +ERRCODE hb_waFieldCount( AREAP pArea, USHORT * uiFields ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_waFieldCount(%p, %p)", pArea, uiFields)); + + * uiFields = pArea->uiFieldCount; + return SUCCESS; +} + +/* + * Retrieve information about a field. + */ +ERRCODE hb_waFieldInfo( AREAP pArea, USHORT uiIndex, USHORT uiType, PHB_ITEM pItem ) +{ + LPFIELD pField; + + HB_TRACE(HB_TR_DEBUG, ("hb_waFieldInfo(%p, %hu, %hu, %p)", pArea, uiIndex, uiType, pItem)); + + if( uiIndex > pArea->uiFieldCount ) + return FAILURE; + + pField = pArea->lpFields + uiIndex - 1; + switch( uiType ) + { + case DBS_NAME: + hb_itemPutC( pItem, ( ( PHB_DYNS ) pField->sym )->pSymbol->szName ); + break; + + case DBS_TYPE: + switch( pField->uiType ) + { + case HB_IT_STRING: + hb_itemPutC( pItem, "C" ); + break; + + case HB_IT_LOGICAL: + hb_itemPutC( pItem, "L" ); + break; + + case HB_IT_MEMO: + hb_itemPutC( pItem, "M" ); + break; + + case HB_IT_DATE: + hb_itemPutC( pItem, "D" ); + break; + + case HB_IT_LONG: + hb_itemPutC( pItem, "N" ); + break; + + default: + hb_itemPutC( pItem, "U" ); + break; + } + break; + + case DBS_LEN: + hb_itemPutNL( pItem, pField->uiLen ); + break; + + case DBS_DEC: + hb_itemPutNL( pItem, pField->uiDec ); + break; + + default: + return FAILURE; + + } + return SUCCESS; +} + +/* + * Determine the name associated with a field number. + */ +ERRCODE hb_waFieldName( AREAP pArea, USHORT uiIndex, void * szName ) +{ + LPFIELD pField; + + HB_TRACE(HB_TR_DEBUG, ("hb_waFieldName(%p, %hu, %p)", pArea, uiIndex, szName)); + + if( uiIndex > pArea->uiFieldExtent ) + return FAILURE; + + pField = pArea->lpFields + uiIndex - 1; + strncpy( ( char * ) szName, ( ( PHB_DYNS ) pField->sym )->pSymbol->szName, + HARBOUR_MAX_RDD_FIELDNAME_LENGTH ); + return SUCCESS; +} + +/* + * Establish the extent of the array of fields for a WorkArea. + */ +ERRCODE hb_waSetFieldExtent( AREAP pArea, USHORT uiFieldExtent ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_waSetFieldExtent(%p, %hu)", pArea, uiFieldExtent)); + + pArea->uiFieldExtent = uiFieldExtent; + + /* Alloc field array */ + pArea->lpFields = ( LPFIELD ) hb_xgrab( uiFieldExtent * sizeof( FIELD ) ); + memset( pArea->lpFields, 0, uiFieldExtent * sizeof( FIELD ) ); + + return SUCCESS; +} + +/* + * Obtain the alias of the WorkArea. + */ +ERRCODE hb_waAlias( AREAP pArea, BYTE * szAlias ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_waAlias(%p, %p)", pArea, szAlias)); + + strncpy( ( char * ) szAlias, ( ( PHB_DYNS ) pArea->atomAlias )->pSymbol->szName, + HARBOUR_MAX_RDD_ALIAS_LENGTH ); + return SUCCESS; +} + +/* + * Close the table in the WorkArea. + */ +ERRCODE hb_waClose( AREAP pArea ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_waClose(%p)", pArea)); + + /* Clear items */ + SELF_CLEARFILTER( pArea ); + SELF_CLEARREL( pArea ); + SELF_CLEARLOCATE( pArea ); + + if( pArea->uiParents > 0 ) + printf( "\nTODO: hb_waClose()\n" ); + + ( ( PHB_DYNS ) pArea->atomAlias )->hArea = 0; + return SUCCESS; +} + +/* + * Retrieve information about the current driver. + */ +ERRCODE hb_waInfo( AREAP pArea, USHORT uiIndex, PHB_ITEM pItem ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_waInfo(%p, %hu, %p)", pArea, uiIndex, pItem)); + HB_SYMBOL_UNUSED( pArea ); + + if( uiIndex == DBI_ISDBF || uiIndex == DBI_CANPUTREC ) + { + hb_itemPutL( pItem, FALSE ); + return SUCCESS; + } + else + return FAILURE; +} + +/* + * Clear the WorkArea for use. + */ +ERRCODE hb_waNewArea( AREAP pArea ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_waNewArea(%p)", pArea)); + + pArea->valResult = hb_itemNew( NULL ); + return SUCCESS; +} + +/* + * Release all references to a WorkArea. + */ +ERRCODE hb_waRelease( AREAP pArea ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_waRelease(%p)", pArea)); + + /* Free all allocated pointers */ + if( pArea->lpFields ) + hb_xfree( pArea->lpFields ); + if( pArea->valResult ) + hb_itemRelease( pArea->valResult ); + hb_xfree( pArea ); + return SUCCESS; +} + +/* + * Retrieve the size of the WorkArea structure. + */ +ERRCODE hb_waStructSize( AREAP pArea, USHORT * uiSize ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_waStrucSize(%p, %p)", pArea, uiSize)); + HB_SYMBOL_UNUSED( pArea ); + + * uiSize = sizeof( AREA ); + return SUCCESS; +} + +/* + * Obtain the name of replaceable database driver (RDD) subsystem. + */ +ERRCODE hb_waSysName( AREAP pArea, BYTE * pBuffer ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_waSysName(%p, %p)", pArea, pBuffer)); + HB_SYMBOL_UNUSED( pArea ); + + pBuffer[ 0 ] = 0; + return SUCCESS; +} + +/* + * Evaluate code block for each record in WorkArea. + */ +ERRCODE hb_waEval( AREAP pArea, LPDBEVALINFO pEvalInfo ) +{ + BOOL bFor, bWhile; + ULONG ulNext; + + HB_TRACE(HB_TR_DEBUG, ("hb_waEval(%p, %p)", pArea, pEvalInfo)); + + ulNext = 0; + if( pEvalInfo->dbsci.itmRecID ) + { + SELF_GOTO( pArea, hb_itemGetNL( pEvalInfo->dbsci.itmRecID ) ); + if( !pArea->fEof ) + { + if( pEvalInfo->dbsci.itmCobWhile ) + bWhile = hb_itemGetL( hb_vmEvalBlock( pEvalInfo->dbsci.itmCobWhile ) ); + else + bWhile = TRUE; + + if( pEvalInfo->dbsci.itmCobFor ) + bFor = hb_itemGetL( hb_vmEvalBlock( pEvalInfo->dbsci.itmCobFor ) ); + else + bFor = TRUE; + + if( bWhile && bFor ) + hb_vmEvalBlock( pEvalInfo->itmBlock ); + } + return SUCCESS; + } + + if( !pEvalInfo->dbsci.fRest || !hb_itemGetL( pEvalInfo->dbsci.fRest ) ) + SELF_GOTOP( pArea ); + + if( pEvalInfo->dbsci.lNext ) + ulNext = hb_itemGetNL( pEvalInfo->dbsci.lNext ); + + while( !pArea->fEof ) + { + if( pEvalInfo->dbsci.lNext && ulNext-- < 1 ) + break; + + if( pEvalInfo->dbsci.itmCobWhile ) + { + bWhile = hb_itemGetL( hb_vmEvalBlock( pEvalInfo->dbsci.itmCobWhile ) ); + if( !bWhile ) + break; + } + else + bWhile = TRUE; + + if( pEvalInfo->dbsci.itmCobFor ) + bFor = hb_itemGetL( hb_vmEvalBlock( pEvalInfo->dbsci.itmCobFor ) ); + else + bFor = TRUE; + + if( bFor && bWhile ) + hb_vmEvalBlock( pEvalInfo->itmBlock ); + SELF_SKIP( pArea, 1 ); + } + + return SUCCESS; +} + +/* + * Copy one or more records from one WorkArea to another. + */ +ERRCODE hb_waTrans( AREAP pArea, LPDBTRANSINFO pTransInfo ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_waTrans(%p, %p)", pArea, pTransInfo)); + HB_SYMBOL_UNUSED( pArea ); + HB_SYMBOL_UNUSED( pTransInfo ); + + printf( "\nTODO: hb_waTrans()\n" ); + return SUCCESS; +} + +/* + * Copy a record to another WorkArea. + */ +ERRCODE hb_waTransRec( AREAP pArea, LPDBTRANSINFO pTransInfo ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_waTransRec(%p, %p)", pArea, pTransInfo)); + HB_SYMBOL_UNUSED( pArea ); + HB_SYMBOL_UNUSED( pTransInfo ); + + printf( "\nTODO: hb_waTransRec()\n" ); + return SUCCESS; +} + +/* + * Report end of relation. + */ +ERRCODE hb_waChildEnd( AREAP pArea, LPDBRELINFO pRelInfo ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_waChildEnd(%p, %p)", pArea, pRelInfo)); + HB_SYMBOL_UNUSED( pRelInfo ); + + pArea->uiParents --; + return SUCCESS; +} + +/* + * Report initialization of a relation. + */ +ERRCODE hb_waChildStart( AREAP pArea, LPDBRELINFO pRelInfo ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_waChildStart(%p, %p)", pArea, pRelInfo)); + HB_SYMBOL_UNUSED( pRelInfo ); + + pArea->uiParents ++; + return SUCCESS; +} + +/* + * Force relational movement in child WorkAreas. + */ +ERRCODE hb_waSyncChildren( AREAP pArea ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_waSyncChildren(%p)", pArea)); + HB_SYMBOL_UNUSED( pArea ); + + printf( "\nTODO: hb_waSyncChildren()\n" ); + return SUCCESS; +} + +/* + * Clear all relations in the specified WorkArea. + */ +ERRCODE hb_waClearRel( AREAP pArea ) +{ + LPDBRELINFO lpdbRelation; + + HB_TRACE(HB_TR_DEBUG, ("hb_waClearRel(%p)", pArea )); + + /* Free all relations */ + lpdbRelation = pArea->lpdbRelations; + while( lpdbRelation ) + { + SELF_CHILDEND( pArea, lpdbRelation ); + + if( lpdbRelation->itmCobExpr ) + hb_itemRelease( lpdbRelation->itmCobExpr ); + + if( lpdbRelation->abKey ) + hb_itemRelease( lpdbRelation->abKey ); + + hb_xfree( lpdbRelation ); + + pArea->lpdbRelations = pArea->lpdbRelations->lpdbriNext; + lpdbRelation = pArea->lpdbRelations; + } + + return SUCCESS; +} + +/* + * Obtain the logical number of the specified WorkArea. + */ +ERRCODE hb_waRelArea( AREAP pArea, USHORT uiRelNo, void * pRelArea ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_waRelArea(%p, %hu, %p)", pArea, uiRelNo, pExpr)); + HB_SYMBOL_UNUSED( pArea ); + HB_SYMBOL_UNUSED( uiRelNo ); + HB_SYMBOL_UNUSED( pRelArea ); + + printf( "\nTODO: hb_waRelArea()\n" ); + return SUCCESS; +} + +/* + * Evaluate a block against the relation in specified WorkArea. + */ +ERRCODE hb_waRelEval( AREAP pArea, LPDBRELINFO pRelInfo ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_waRelEval(%p, %p)", pArea, pRelInfo)); + HB_SYMBOL_UNUSED( pArea ); + HB_SYMBOL_UNUSED( pRelInfo ); + + printf( "\nTODO: hb_waRelEval()\n" ); + return SUCCESS; +} + +/* + * Obtain the character expression of the specified relation. + */ +ERRCODE hb_waRelText( AREAP pArea, USHORT uiRelNo, void * pExpr ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_waRelText(%p, %hu, %p)", pArea, uiRelNo, pExpr)); + HB_SYMBOL_UNUSED( pArea ); + HB_SYMBOL_UNUSED( pExpr ); + + printf( "\nTODO: hb_waRelText()\n" ); + return SUCCESS; +} + +/* + * Set a relation in the parent file. + */ +extern ERRCODE hb_waSetRel( AREAP pArea, LPDBRELINFO pRelInfo ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_waSetRel(%p, %p)", pArea, pRelInfo)); + HB_SYMBOL_UNUSED( pArea ); + HB_SYMBOL_UNUSED( pRelInfo ); + + printf( "\nTODO: hb_waSetRel()\n" ); + return SUCCESS; +} + +/* + * Clear the active filter expression. + */ +ERRCODE hb_waClearFilter( AREAP pArea ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_waClearFilter(%p)", pArea)); + + /* Free all items */ + if( pArea->dbfi.itmCobExpr ) + { + hb_itemRelease( pArea->dbfi.itmCobExpr ); + pArea->dbfi.itmCobExpr = NULL; + } + if( pArea->dbfi.abFilterText ) + { + hb_itemRelease( pArea->dbfi.abFilterText ); + pArea->dbfi.abFilterText = NULL; + } + + return SUCCESS; +} + +/* + * Clear the active locate expression. + */ +ERRCODE hb_waClearLocate( AREAP pArea ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_waClearLocate(%p)", pArea)); + + /* Free all items */ + if( pArea->dbsi.itmCobFor ) + { + hb_itemRelease( pArea->dbsi.itmCobFor ); + pArea->dbsi.itmCobFor = NULL; + } + if( pArea->dbsi.lpstrFor ) + { + hb_itemRelease( pArea->dbsi.lpstrFor ); + pArea->dbsi.lpstrFor = NULL; + } + if( pArea->dbsi.itmCobWhile ) + { + hb_itemRelease( pArea->dbsi.itmCobWhile ); + pArea->dbsi.itmCobWhile = NULL; + } + if( pArea->dbsi.lpstrWhile ) + { + hb_itemRelease( pArea->dbsi.lpstrWhile ); + pArea->dbsi.lpstrWhile = NULL; + } + if( pArea->dbsi.lNext ) + { + hb_itemRelease( pArea->dbsi.lNext ); + pArea->dbsi.lNext = NULL; + } + if( pArea->dbsi.itmRecID ) + { + hb_itemRelease( pArea->dbsi.itmRecID ); + pArea->dbsi.itmRecID = NULL; + } + if( pArea->dbsi.fRest ) + { + hb_itemRelease( pArea->dbsi.fRest ); + pArea->dbsi.fRest = NULL; + } + + return SUCCESS; +} + +/* + * Return filter condition of the specified WorkArea. + */ +ERRCODE hb_waFilterText( AREAP pArea, PHB_ITEM pFilter ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_waFilterText(%p, %p)", pArea, pFilter)); + + if( pArea->dbfi.abFilterText ) + hb_itemCopy( pFilter, pArea->dbfi.abFilterText ); + + return SUCCESS; +} + +/* + * Set the filter condition for the specified WorkArea. + */ +ERRCODE hb_waSetFilter( AREAP pArea, LPDBFILTERINFO pFilterInfo ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_wsSetFilter(%p, %p)", pArea, pFilterInfo)); + + /* Clear the active filter expression */ + SELF_CLEARFILTER( pArea ); + + if( pFilterInfo->itmCobExpr ) + pArea->dbfi.itmCobExpr = hb_itemNew( pFilterInfo->itmCobExpr ); + + if( pFilterInfo->abFilterText ) + pArea->dbfi.abFilterText = hb_itemNew( pFilterInfo->abFilterText ); + + return SUCCESS; +} + +/* + * Set the locate scope for the specified WorkArea. + */ +ERRCODE hb_waSetLocate( AREAP pArea, LPDBSCOPEINFO pScopeInfo ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_waSetLocate(%p, %p)", pArea, pScopeInfo)); + + /* Clear the active locate expression */ + SELF_CLEARLOCATE( pArea ); + + if( pScopeInfo->itmCobFor ) + pArea->dbsi.itmCobFor = hb_itemNew( pScopeInfo->itmCobFor ); + + if( pScopeInfo->lpstrFor ) + pArea->dbsi.lpstrFor = hb_itemNew( pScopeInfo->lpstrFor ); + + if( pScopeInfo->itmCobWhile ) + pArea->dbsi.itmCobWhile = hb_itemNew( pScopeInfo->itmCobWhile ); + + if( pScopeInfo->lpstrWhile ) + pArea->dbsi.lpstrWhile = hb_itemNew( pScopeInfo->lpstrWhile ); + + if( pScopeInfo->lNext ) + pArea->dbsi.lNext = hb_itemNew( pScopeInfo->lNext ); + + if( pScopeInfo->itmRecID ) + pArea->dbsi.itmRecID = hb_itemNew( pScopeInfo->itmRecID ); + + if( pScopeInfo->fRest ) + pArea->dbsi.fRest = hb_itemNew( pScopeInfo->fRest ); + + return SUCCESS; +} + +/* + * Compile a character expression. + */ +ERRCODE hb_waCompile( AREAP pArea, BYTE * pExpr ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_waCompile(%p, %p)", pArea, pExpr)); + HB_SYMBOL_UNUSED( pArea ); + HB_SYMBOL_UNUSED( pExpr ); + + printf( "\nTODO: hb_waCompile()\n" ); + return SUCCESS; +} + +/* + * Raise a runtime error. + */ +ERRCODE hb_waError( AREAP pArea, PHB_ITEM pError ) +{ + char * szRddName; + + HB_TRACE(HB_TR_DEBUG, ("hb_waError(%p, %p)", pArea, pError)); + + szRddName = ( char * ) hb_xgrab( HARBOUR_MAX_RDD_DRIVERNAME_LENGTH + 1 ); + if( ( pArea )->lprfsHost->sysName ) + SELF_SYSNAME( pArea, ( BYTE * ) szRddName ); + else + strcpy( szRddName, "???DRIVER" ); + hb_errPutSeverity( pError, ES_ERROR ); + hb_errPutSubSystem( pError, szRddName ); + hb_xfree( szRddName ); + return hb_errLaunch( pError ); +} + +/* + * Evaluate a code block. + */ +ERRCODE hb_waEvalBlock( AREAP pArea, PHB_ITEM pBlock ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_waEvalBlock(%p, %p)", pArea, pBlock)); + + hb_itemCopy( pArea->valResult, hb_vmEvalBlock( pBlock ) ); + return SUCCESS; +} \ No newline at end of file diff --git a/harbour/source/rtl/dummy.prg b/harbour/source/rtl/dummy.prg index 328aa5e8d7..6b40e8b918 100644 --- a/harbour/source/rtl/dummy.prg +++ b/harbour/source/rtl/dummy.prg @@ -52,12 +52,7 @@ FUNCTION ordSkipUnique() ; RETURN .F. #endif #ifdef HB_COMPAT_C53 -FUNCTION dbFileGet() ; RETURN .F. -FUNCTION dbFilePut() ; RETURN .F. -FUNCTION dbInfo() ; RETURN NIL FUNCTION dbOrderInfo() ; RETURN NIL -FUNCTION dbRecordInfo() ; RETURN NIL -FUNCTION dbFieldInfo() ; RETURN NIL #endif FUNCTION MLCToPos() ; RETURN 0 @@ -68,13 +63,10 @@ FUNCTION __dbCopy() ; RETURN NIL FUNCTION __dbDelim() ; RETURN NIL FUNCTION __dbJoin() ; RETURN NIL FUNCTION __dbSDF() ; RETURN NIL -FUNCTION __dbSort() ; RETURN NIL FUNCTION __dbTotal() ; RETURN NIL /* NOTE: Internal functions */ -FUNCTION __dbArrange() ; RETURN NIL FUNCTION __dbFList() ; RETURN {} FUNCTION __dbOpenSDF() ; RETURN NIL FUNCTION __dbTrans() ; RETURN NIL -FUNCTION __dbTransRec() ; RETURN NIL - +FUNCTION __dbTransRec() ; RETURN NIL \ No newline at end of file diff --git a/harbour/tests/Makefile b/harbour/tests/Makefile index 0a6aea0e3c..75b50a8820 100644 --- a/harbour/tests/Makefile +++ b/harbour/tests/Makefile @@ -114,9 +114,7 @@ PRG_SOURCES=\ test_all.prg \ testbrdb.prg \ testbrw.prg \ - testcdx.prg \ testcgi.prg \ - testdbf.prg \ testdecl.prg \ testerro.prg \ testfor.prg \ @@ -125,7 +123,6 @@ PRG_SOURCES=\ teststr.prg \ testpre.prg \ testread.prg \ - testrdd.prg \ testvars.prg \ testwarn.prg \ tstalias.prg \ @@ -136,6 +133,7 @@ PRG_SOURCES=\ version.prg \ vmasort.prg \ while.prg \ + newrdd.prg \ PRG_HEADERS=\ db_brows.ch \ @@ -179,6 +177,9 @@ BAD_PRG_SOURCES=\ testtok.prg \ tstprag.prg \ vec1.prg \ + testrdd.prg \ + testcdx.prg \ + testdbf.prg \ C_SOURCES=\ diff --git a/harbour/tests/newrdd.prg b/harbour/tests/newrdd.prg new file mode 100644 index 0000000000..6cd2e4c595 --- /dev/null +++ b/harbour/tests/newrdd.prg @@ -0,0 +1,361 @@ +function Main() + + local nI, aArray + + REQUEST _DBF + rddSetDefault( "DBF" ) + + SET EXCLUSIVE OFF + CLS + + dbUseArea( .T., "DBF", "Test", "TESTDBF", .T., .F. ) + ? "RecCount:", TESTDBF->( RecCount() ) + ? "Used:", TESTDBF->( Used() ) + ? "Select:", TESTDBF->( Select() ) + ? "RecSize:", TESTDBF->( RecSize() ) + ? "RecNo:", TESTDBF->( RecNo() ) + ? "NetErr:", TESTDBF->( NetErr() ) + + ? "Press any key to continue..." + InKey( 0 ) + CLS + + aArray := RddList( 0 ) + ? "Rdd's: " + for nI := 1 to Len( aArray ) + ?? aArray[ nI ], "" + next + ? "RddName:", TESTDBF->( RddName() ) + ? "lUpdate:", TESTDBF->( lUpdate() ) + ? "Header:", TESTDBF->( Header() ) + ? "FieldPos( 'LAST' ):", TESTDBF->( FieldPos( "LAST" ) ) + ? "FieldName( 2 ):", TESTDBF->( FieldName( 2 ) ) + ? "DBF():", TESTDBF->( DBF() ) + ? "Alias( 1 ):", Alias( 1 ) + ? "dbTableExt():", TESTDBF->( dbTableExt() ) + aArray := TESTDBF->( dbStruct() ) + ? "dbStruct:" + for nI := 1 to Len( aArray ) + ? PadR( aArray[ nI ][ 1 ], 10 ) , aArray[ nI ][ 2 ], aArray[ nI ][ 3 ], aArray[ nI ][ 4 ] + next + + ? "Press any key to continue..." + InKey( 0 ) + CLS + + ? "dbGoTop():" + dbGoTop() + ? "Bof Eof Found Deleted RecNo:", TESTDBF->( Bof() ), TESTDBF->( Eof() ), ; + TESTDBF->( Found() ), TESTDBF->( Deleted() ), TESTDBF->( Deleted() ), ; + TESTDBF->( RecNo() ) + ? "dbSkip( -1 ):" + dbSkip( -1 ) + ? "Bof Eof Found Deleted RecNo:", TESTDBF->( Bof() ), TESTDBF->( Eof() ), ; + TESTDBF->( Found() ), TESTDBF->( Deleted() ), TESTDBF->( Deleted() ), ; + TESTDBF->( RecNo() ) + ? "dbSkip( -1 ):" + dbSkip( -1 ) + ? "Bof Eof Found Deleted RecNo:", TESTDBF->( Bof() ), TESTDBF->( Eof() ), ; + TESTDBF->( Found() ), TESTDBF->( Deleted() ), TESTDBF->( Deleted() ), ; + TESTDBF->( RecNo() ) + ? "dbSkip( 1 ):" + dbSkip( 1 ) + ? "Bof Eof Found Deleted RecNo:", TESTDBF->( Bof() ), TESTDBF->( Eof() ), ; + TESTDBF->( Found() ), TESTDBF->( Deleted() ), TESTDBF->( Deleted() ), ; + TESTDBF->( RecNo() ) + ? "dbSkip( 1 ):" + dbSkip( 1 ) + ? "Bof Eof Found Deleted RecNo:", TESTDBF->( Bof() ), TESTDBF->( Eof() ), ; + TESTDBF->( Found() ), TESTDBF->( Deleted() ), TESTDBF->( Deleted() ), ; + TESTDBF->( RecNo() ) + ? "dbGoTop():" + dbGoTop() + ? "Bof Eof Found Deleted RecNo:", TESTDBF->( Bof() ), TESTDBF->( Eof() ), ; + TESTDBF->( Found() ), TESTDBF->( Deleted() ), TESTDBF->( Deleted() ), ; + TESTDBF->( RecNo() ) + ? "dbSkip( 1 ):" + dbSkip( 1 ) + ? "Bof Eof Found Deleted RecNo:", TESTDBF->( Bof() ), TESTDBF->( Eof() ), ; + TESTDBF->( Found() ), TESTDBF->( Deleted() ), TESTDBF->( Deleted() ), ; + TESTDBF->( RecNo() ) + ? "dbSkip( 1 ):" + dbSkip( 1 ) + ? "Bof Eof Found Deleted RecNo:", TESTDBF->( Bof() ), TESTDBF->( Eof() ), ; + TESTDBF->( Found() ), TESTDBF->( Deleted() ), TESTDBF->( Deleted() ), ; + TESTDBF->( RecNo() ) + ? "dbSkip( -1 ):" + dbSkip( -1 ) + ? "Bof Eof Found Deleted RecNo:", TESTDBF->( Bof() ), TESTDBF->( Eof() ), ; + TESTDBF->( Found() ), TESTDBF->( Deleted() ), TESTDBF->( Deleted() ), ; + TESTDBF->( RecNo() ) + ? "dbSkip( -1 ):" + dbSkip( -1 ) + ? "Bof Eof Found Deleted RecNo:", TESTDBF->( Bof() ), TESTDBF->( Eof() ), ; + TESTDBF->( Found() ), TESTDBF->( Deleted() ), TESTDBF->( Deleted() ), ; + TESTDBF->( RecNo() ) + InKey( 0 ) + CLS + + ? "dbGoBottom():" + dbGoBottom() + ? "Bof Eof Found Deleted RecNo:", TESTDBF->( Bof() ), TESTDBF->( Eof() ), ; + TESTDBF->( Found() ), TESTDBF->( Deleted() ), TESTDBF->( Deleted() ), ; + TESTDBF->( RecNo() ) + ? "dbSkip( 1 ):" + dbSkip( 1 ) + ? "Bof Eof Found Deleted RecNo:", TESTDBF->( Bof() ), TESTDBF->( Eof() ), ; + TESTDBF->( Found() ), TESTDBF->( Deleted() ), TESTDBF->( Deleted() ), ; + TESTDBF->( RecNo() ) + ? "dbSkip( 1 ):" + dbSkip( 1 ) + ? "Bof Eof Found Deleted RecNo:", TESTDBF->( Bof() ), TESTDBF->( Eof() ), ; + TESTDBF->( Found() ), TESTDBF->( Deleted() ), TESTDBF->( Deleted() ), ; + TESTDBF->( RecNo() ) + ? "dbSkip( -1 ):" + dbSkip( -1 ) + ? "Bof Eof Found Deleted RecNo:", TESTDBF->( Bof() ), TESTDBF->( Eof() ), ; + TESTDBF->( Found() ), TESTDBF->( Deleted() ), TESTDBF->( Deleted() ), ; + TESTDBF->( RecNo() ) + ? "dbSkip( -1 ):" + dbSkip( -1 ) + ? "Bof Eof Found Deleted RecNo:", TESTDBF->( Bof() ), TESTDBF->( Eof() ), ; + TESTDBF->( Found() ), TESTDBF->( Deleted() ), TESTDBF->( Deleted() ), ; + TESTDBF->( RecNo() ) + + ? "Press any key to continue..." + InKey( 0 ) + CLS + + ? "dbGoto( 490 ):" + dbGoto( 490 ) + ? "Bof Eof Found Deleted RecNo:", TESTDBF->( Bof() ), TESTDBF->( Eof() ), ; + TESTDBF->( Found() ), TESTDBF->( Deleted() ), TESTDBF->( Deleted() ), ; + TESTDBF->( RecNo() ) + ? "FCount:", TESTDBF->( FCount() ) + for nI := 1 to TESTDBF->( FCount() ) + ? "FieldGet( " + LTrim( Str( nI ) ) + " ):", TESTDBF->( FieldGet( nI ) ) + next + + ? "Press any key to continue..." + InKey( 0 ) + CLS + + ? "while !TESTDBF->( Eof() )" + ? " ? TESTDBF->FIRST, TESTDBF->( RecNo() )" + ? " TESTDBF->( dbSkip() )" + ? "end" + ? "" + while !TESTDBF->( Eof() ) + ? TESTDBF->FIRST, TESTDBF->( RecNo() ) + TESTDBF->( dbSkip() ) + end + + ? "Press any key to continue..." + InKey( 0 ) + CLS + + ? "SET FILTER TO TESTDBF->AGE == 21" + ? "? TESTDBF->( dbFilter() )" + ? "TESTDBF->( dbGoTop() )" + ? "while !TESTDBF->( Eof() )" + ? " ? TESTDBF->FIRST, TESTDBF->AGE, TESTDBF->( RecNo() )" + ? " TESTDBF->( dbSkip() )" + ? "end" + ? "SET FILTER TO" + ? "" + SET FILTER TO TESTDBF->AGE == 21 + ? TESTDBF->( dbFilter() ) + TESTDBF->( dbGoTop() ) + while !TESTDBF->( Eof() ) + ? TESTDBF->FIRST, TESTDBF->AGE, TESTDBF->( RecNo() ) + TESTDBF->( dbSkip() ) + end + SET FILTER TO + + ? "Press any key to continue..." + InKey( 0 ) + CLS + + ? "TESTDBF->( Found() )" + ? "LOCATE FOR TESTDBF->AGE == 23" + ? "while TESTDBF->( Found() )" + ? " ? TESTDBF->FIRST, TESTDBF->AGE, TESTDBF->( RecNo() )" + ? " CONTINUE" + ? "end" + TESTDBF->( Found() ) + LOCATE FOR TESTDBF->AGE == 23 + while TESTDBF->( Found() ) + ? TESTDBF->FIRST, TESTDBF->AGE, TESTDBF->( RecNo() ) + CONTINUE + end + + ? "Press any key to continue..." + InKey( 0 ) + CLS + + ? "TESTDBF->( dbEval( { || QOut( TESTDBF->FIRST, TESTDBF->AGE ) }, ;" + ? " { || TESTDBF->AGE == 23 } ) )" + ? "" + ? "dbCommit()" + TESTDBF->( dbEval( { || QOut( TESTDBF->FIRST, TESTDBF->AGE ) }, ; + { || TESTDBF->AGE == 23 } ) ) + TESTDBF->( dbCommit() ) + + ? "Press any key to continue..." + InKey( 0 ) + CLS + + ? 'dbCreate( "NewRdd", { { "First_Name", "C", 20, 0 }, ;' + ? ' { "Age", "N", 3, 0 }, ;' + ? ' { "Date", "D", 8, 0 }, ;' + ? ' { "Student", "L", 1, 0 } },, .T., "NEWRDD" )' + ? 'SET CENTURY ON' + dbCreate( "NewRdd", { { "First_Name", "C", 20, 0 }, ; + { "Age", "N", 3, 0 }, ; + { "Date", "D", 8, 0 }, ; + { "Rate", "N", 6, 2 }, ; + { "Student", "L", 1, 0 } },, .T., "NEWRDD" ) + SET CENTURY ON + ? "lUpdate:", NEWRDD->( lUpdate() ) + + ? "Press any key to continue..." + InKey( 0 ) + CLS + + ? 'Select( "TESTDBF" )' + ? "SET FILTER TO TESTDBF->SALARY > 120000" + ? "TESTDBF->( dbGoTop() )" + ? "while !TESTDBF->( Eof() )" + ? " NEWRDD->( dbAppend() )" + ? " NEWRDD->FIRST_NAME := TESTDBF->FIRST" + ? " NEWRDD->AGE := TESTDBF->AGE" + ? " NEWRDD->DATE := TESTDBF->HIREDATE" + ? " NEWRDD->RATE := Val( Right( LTrim( Str( Seconds() ) ), 5 ) )" + ? " NEWRDD->STUDENT := TESTDBF->MARRIED" + ? " TESTDBF->( dbSkip() )" + ? "end" + ? "SET FILTER TO" + ? "? NEWRDD->( RecCount() )" + ? "NEWRDD->( dbGoTop() )" + ? "NEWRDD->( dbRLock( 1 ) )" + ? "NEWRDD->( dbDelete() )" + ? "? NEWRDD->( Deleted() )" + ? "NEWRDD->( dbGoBottom() )" + ? "NEWRDD->( dbRLock() )" + ? "NEWRDD->( dbDelete() )" + ? "? NEWRDD->( Deleted() )" + ? "NEWRDD->( dbRLock( 3 ) )" + Select( "TESTDBF" ) + SET FILTER TO TESTDBF->SALARY > 120000 + TESTDBF->( dbGoTop() ) + while !TESTDBF->( Eof() ) + NEWRDD->( dbAppend() ) + NEWRDD->FIRST_NAME := TESTDBF->FIRST + NEWRDD->AGE := TESTDBF->AGE + NEWRDD->DATE := TESTDBF->HIREDATE + NEWRDD->RATE := Val( Right( LTrim( Str( Seconds() ) ), 5 ) ) + NEWRDD->STUDENT := TESTDBF->MARRIED + TESTDBF->( dbSkip() ) + end + SET FILTER TO + ? NEWRDD->( RecCount() ) + NEWRDD->( dbGoTop() ) + NEWRDD->( dbRLock( 1 ) ) + NEWRDD->( dbDelete() ) + ? NEWRDD->( Deleted() ) + NEWRDD->( dbGoBottom() ) + NEWRDD->( dbRLock() ) + NEWRDD->( dbDelete() ) + ? NEWRDD->( Deleted() ) + NEWRDD->( dbRLock( 3 ) ) + + ? "Press any key to continue..." + InKey( 0 ) + CLS + + aArray := NEWRDD->( dbRLockList() ) + ? "aArray := NEWRDD->( dbRLockList() )" + ? "for nI := 1 to Len( aArray )" + ? " ? aArray[ nI ]" + ? "next" + ? "dbRLockList(): " + for nI := 1 to Len( aArray ) + ? aArray[ nI ] + next + + ? "Press any key to continue..." + InKey( 0 ) + CLS + + ? 'NEWRDD->( dbCloseArea() )' + ? 'dbUseArea( .T., "DBF", "NewRdd", "NEWRDD", .F., .F. )' + ? 'nI := 1' + ? 'NEWRDD->( __dbPack( { || QOut( nI ), nI++ } ) )' + ? '? "RecCount:", NEWRDD->( RecCount() )' + ? "" + NEWRDD->( dbCloseArea() ) + dbUseArea( .T., "DBF", "NewRdd", "NEWRDD", .F., .F. ) + + ? "Press any key to continue..." + InKey( 0 ) + CLS + + nI := 1 + NEWRDD->( __dbPack( { || QOut( nI ), nI++ } ) ) + ? "RecCount:", NEWRDD->( RecCount() ) + + ? "Press any key to continue..." + InKey( 0 ) + CLS + + ? '? "RecCount:", NEWRDD->( RecCount() )' + ? 'NEWRDD->( __dbZap() )' + ? '? "RecCount:", NEWRDD->( RecCount() )' + ? "" + ? "RecCount:", NEWRDD->( RecCount() ) + NEWRDD->( __dbZap() ) + ? "RecCount:", NEWRDD->( RecCount() ) + + ? "Press any key to continue..." + InKey( 0 ) + CLS + + ? 'NEWRDD->( dbCloseArea() )' + ? 'SORT ON FIRST /DC, AGE /D TO NEWRDD' + ? 'dbUseArea( .T., "DBF", "NewRdd", "NEWRDD", .F., .F. )' + ? '? "RecCount:", NEWRDD->( RecCount() )' + ? 'for nI := 1 to 8' + ? ' ? NEWRDD->FIRST, NEWRDD->AGE' + ? ' NEWRDD->( dbSkip() )' + ? 'next' + ? '? "..."' + ? 'NEWRDD->( dbGoBottom() )' + ? 'NEWRDD->( dbSkip( -8 ) )' + ? 'for nI := 1 to 8' + ? ' ? NEWRDD->FIRST, NEWRDD->AGE' + ? ' NEWRDD->( dbSkip() )' + ? 'next' + + ? "Press any key to continue..." + InKey( 0 ) + CLS + + NEWRDD->( dbCloseArea() ) + Select( "TESTDBF" ) + SORT ON FIRST /DC, AGE /D TO NEWRDD + + dbUseArea( .T., "DBF", "NewRdd", "NEWRDD", .F., .F. ) + ? "RecCount:", NEWRDD->( RecCount() ) + for nI := 1 to 8 + ? NEWRDD->FIRST, NEWRDD->AGE + NEWRDD->( dbSkip() ) + next + ? "..." + NEWRDD->( dbGoBottom() ) + NEWRDD->( dbSkip( -8 ) ) + for nI := 1 to 8 + ? NEWRDD->FIRST, NEWRDD->AGE + NEWRDD->( dbSkip() ) + next + +return nil \ No newline at end of file