diff --git a/ChangeLog.txt b/ChangeLog.txt index 3ab5cba1eb..cc625d1224 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -10,6 +10,19 @@ * Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment */ +2015-03-04 09:18 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) + * src/rdd/dbf1.c + * src/rtl/hbinet.c + * pacified warnings (Thanks to Grigory) + + * src/rdd/dbcmd.c + * src/rdd/wafunc.c + * small code simplification and cleanup + ! protection against GPF when wrong parameters are passed to __dbArrange() + + added support for transferring records using __dbArrange() to area with + different fields order (low level driver may refuse to finish such + operation but not it's possible. + 2015-03-03 16:26 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * contrib/rddads/ads1.c ! use AdsSetLongLong() (if available) instead of AdsSetDouble() to not diff --git a/src/rdd/dbcmd.c b/src/rdd/dbcmd.c index e606937d4c..a59ea863e3 100644 --- a/src/rdd/dbcmd.c +++ b/src/rdd/dbcmd.c @@ -1820,126 +1820,115 @@ HB_FUNC( DBSETRELATION ) HB_FUNC( __DBARRANGE ) { - AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); + AREAP pArea, pDestArea; + PHB_ITEM pStruct; - if( pArea ) + pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer(); + pDestArea = ( AREAP ) hb_rddGetWorkAreaPointer( ( HB_AREANO ) hb_parni( 1 ) ); + + /* Fields structure of source WorkArea */ + pStruct = hb_param( 2, HB_IT_ARRAY ); + + /* TODO: check what Clipper does when pDestArea == NULL or pArea == pDestArea */ + if( pArea && pDestArea && pArea != pDestArea && pStruct ) { - HB_USHORT uiCount, uiDest; - HB_AREANO uiNewArea; - HB_SIZE nSize; - char * szFieldLine, * szPos; - PHB_ITEM pStruct, pFields; DBSORTINFO dbSortInfo; + HB_USHORT uiCount, uiDest; memset( &dbSortInfo, 0, sizeof( dbSortInfo ) ); - dbSortInfo.dbtri.uiFlags = DBTF_PUTREC; - uiNewArea = ( HB_AREANO ) hb_parni( 1 ); - /* Fields structure of source WorkArea */ - pStruct = hb_param( 2, HB_IT_ARRAY ); - if( pStruct ) + dbSortInfo.dbtri.uiFlags = DBTF_PUTREC; + dbSortInfo.dbtri.lpaSource = pArea; + dbSortInfo.dbtri.lpaDest = pDestArea; + + 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_ISNIL( 6 ) ? NULL : hb_param( 6, HB_IT_ANY ); + dbSortInfo.dbtri.dbsci.fRest = hb_param( 7, HB_IT_LOGICAL ); + + dbSortInfo.dbtri.dbsci.fIgnoreFilter = + dbSortInfo.dbtri.dbsci.fLast = + dbSortInfo.dbtri.dbsci.fIgnoreDuplicates = + dbSortInfo.dbtri.dbsci.fBackward = + dbSortInfo.dbtri.dbsci.fOptimized = HB_FALSE; + dbSortInfo.dbtri.dbsci.fIncludeDeleted = HB_TRUE; + + dbSortInfo.dbtri.uiItemCount = ( HB_USHORT ) hb_arrayLen( pStruct ); + if( dbSortInfo.dbtri.uiItemCount > 0 ) { - dbSortInfo.dbtri.uiItemCount = ( HB_USHORT ) hb_arrayLen( pStruct ); - if( dbSortInfo.dbtri.uiItemCount > 0 ) + dbSortInfo.dbtri.lpTransItems = ( LPDBTRANSITEM ) + hb_xgrab( dbSortInfo.dbtri.uiItemCount * sizeof( DBTRANSITEM ) ); + for( uiCount = 0; uiCount < dbSortInfo.dbtri.uiItemCount; ++uiCount ) { - dbSortInfo.dbtri.lpTransItems = ( LPDBTRANSITEM ) - hb_xgrab( dbSortInfo.dbtri.uiItemCount * - sizeof( DBTRANSITEM ) ); - for( uiCount = 0; uiCount < dbSortInfo.dbtri.uiItemCount; ++uiCount ) + const char * szName = hb_arrayGetCPtr( hb_arrayGetItemPtr( pStruct, + uiCount + 1 ), 1 ); + dbSortInfo.dbtri.lpTransItems[ uiCount ].uiSource = + hb_rddFieldIndex( pArea, szName ); + dbSortInfo.dbtri.lpTransItems[ uiCount ].uiDest = + hb_rddFieldIndex( pDestArea, szName ); + if( dbSortInfo.dbtri.lpTransItems[ uiCount ].uiSource == 0 || + dbSortInfo.dbtri.lpTransItems[ uiCount ].uiDest == 0 ) { - pFields = hb_arrayGetItemPtr( pStruct, uiCount + 1 ); - if( HB_IS_ARRAY( pFields ) && hb_arrayLen( pFields ) > 0 ) - { - dbSortInfo.dbtri.lpTransItems[ uiCount ].uiSource = - dbSortInfo.dbtri.lpTransItems[ uiCount ].uiDest = - hb_rddFieldIndex( pArea, hb_arrayGetCPtr( pFields, 1 ) ); - } - else - { - hb_xfree( dbSortInfo.dbtri.lpTransItems ); - dbSortInfo.dbtri.lpTransItems = NULL; - dbSortInfo.dbtri.uiItemCount = 0; - break; - } + dbSortInfo.dbtri.uiItemCount = 0; + break; } } } - 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_ISNIL( 6 ) ? NULL : hb_param( 6, HB_IT_ANY ); - dbSortInfo.dbtri.dbsci.fRest = hb_param( 7, HB_IT_LOGICAL ); - dbSortInfo.dbtri.dbsci.fIgnoreFilter = - dbSortInfo.dbtri.dbsci.fLast = - dbSortInfo.dbtri.dbsci.fIgnoreDuplicates = - dbSortInfo.dbtri.dbsci.fBackward = - dbSortInfo.dbtri.dbsci.fOptimized = HB_FALSE; - dbSortInfo.dbtri.dbsci.fIncludeDeleted = HB_TRUE; - - pFields = hb_param( 8, HB_IT_ARRAY ); - dbSortInfo.uiItemCount = pFields ? ( HB_USHORT ) hb_arrayLen( pFields ) : 0; - if( dbSortInfo.uiItemCount > 0 ) + if( dbSortInfo.dbtri.uiItemCount > 0 ) { - dbSortInfo.lpdbsItem = ( LPDBSORTITEM ) hb_xgrab( dbSortInfo.uiItemCount * sizeof( DBSORTITEM ) ); - nSize = 0; - for( uiCount = 1; uiCount <= dbSortInfo.uiItemCount; ++uiCount ) + PHB_ITEM pFields = hb_param( 8, HB_IT_ARRAY ); + + dbSortInfo.uiItemCount = pFields ? ( HB_USHORT ) hb_arrayLen( pFields ) : 0; + if( dbSortInfo.uiItemCount > 0 ) { - HB_SIZE nLine = hb_arrayGetCLen( pFields, uiCount ); - if( nLine > nSize ) - nSize = nLine; - } - szFieldLine = ( char * ) hb_xgrab( nSize + 1 ); - for( uiCount = uiDest = 0; uiCount < dbSortInfo.uiItemCount; ++uiCount ) - { - dbSortInfo.lpdbsItem[ uiDest ].uiFlags = 0; - hb_strncpyUpper( szFieldLine, hb_arrayGetCPtr( pFields, uiCount + 1 ), - hb_arrayGetCLen( pFields, uiCount + 1 ) ); - szPos = strchr( szFieldLine, '/' ); - if( szPos ) + char * szFieldLine, * szPos; + HB_SIZE nSize = 0; + + dbSortInfo.lpdbsItem = ( LPDBSORTITEM ) hb_xgrab( dbSortInfo.uiItemCount * sizeof( DBSORTITEM ) ); + for( uiCount = 1; uiCount <= dbSortInfo.uiItemCount; ++uiCount ) { - *szPos++ = 0; - if( strchr( szPos, 'D' ) > strchr( szPos, 'A' ) ) - dbSortInfo.lpdbsItem[ uiDest ].uiFlags |= SF_DESCEND; + HB_SIZE nLine = hb_arrayGetCLen( pFields, uiCount ); + if( nLine > nSize ) + nSize = nLine; + } + szFieldLine = ( char * ) hb_xgrab( nSize + 1 ); + for( uiDest = 0, uiCount = 1; uiCount <= dbSortInfo.uiItemCount; ++uiCount ) + { + dbSortInfo.lpdbsItem[ uiDest ].uiFlags = 0; + hb_strncpyUpper( szFieldLine, hb_arrayGetCPtr( pFields, uiCount ), + hb_arrayGetCLen( pFields, uiCount ) ); + szPos = strchr( szFieldLine, '/' ); + if( szPos ) + { + *szPos++ = 0; + if( strchr( szPos, 'D' ) > strchr( szPos, 'A' ) ) + dbSortInfo.lpdbsItem[ uiDest ].uiFlags |= SF_DESCEND; + else + dbSortInfo.lpdbsItem[ uiDest ].uiFlags |= SF_ASCEND; + if( strchr( szPos, 'C' ) != NULL ) + dbSortInfo.lpdbsItem[ uiDest ].uiFlags |= SF_CASE; + } else dbSortInfo.lpdbsItem[ uiDest ].uiFlags |= SF_ASCEND; - if( strchr( szPos, 'C' ) != NULL ) - dbSortInfo.lpdbsItem[ uiDest ].uiFlags |= SF_CASE; - } - else - { - dbSortInfo.lpdbsItem[ uiDest ].uiFlags |= SF_ASCEND; - } - dbSortInfo.lpdbsItem[ uiDest ].uiField = hb_rddFieldExpIndex( pArea, szFieldLine ); - - /* Field found */ - if( dbSortInfo.lpdbsItem[ uiDest ].uiField != 0 ) - { - ++uiDest; + dbSortInfo.lpdbsItem[ uiDest ].uiField = hb_rddFieldExpIndex( pArea, szFieldLine ); + /* Field found */ + if( dbSortInfo.lpdbsItem[ uiDest ].uiField != 0 ) + ++uiDest; } + dbSortInfo.uiItemCount = uiDest; + hb_xfree( szFieldLine ); } - dbSortInfo.uiItemCount = uiDest; - hb_xfree( szFieldLine ); + + if( dbSortInfo.uiItemCount == 0 ) + SELF_TRANS( pArea, &dbSortInfo.dbtri ); + else + SELF_SORT( pArea, &dbSortInfo ); } - dbSortInfo.dbtri.lpaSource = pArea; - dbSortInfo.dbtri.lpaDest = ( AREAP ) hb_rddGetWorkAreaPointer( uiNewArea ); - /* TODO: check what Clipper does when lpaDest == NULL or lpaDest == lpaSource */ - - if( dbSortInfo.uiItemCount == 0 ) - SELF_TRANS( pArea, &dbSortInfo.dbtri ); - else - SELF_SORT( pArea, &dbSortInfo ); - /* Free items */ if( dbSortInfo.lpdbsItem ) hb_xfree( dbSortInfo.lpdbsItem ); @@ -1985,11 +1974,12 @@ HB_FUNC( __DBTRANS ) dbTransInfo.dbsci.itmRecID = HB_ISNIL( 6 ) ? NULL : hb_param( 6, HB_IT_ANY ); dbTransInfo.dbsci.fRest = hb_param( 7, HB_IT_LOGICAL ); - dbTransInfo.dbsci.fIgnoreFilter = HB_TRUE; + dbTransInfo.dbsci.fIgnoreFilter = + dbTransInfo.dbsci.fLast = + dbTransInfo.dbsci.fIgnoreDuplicates = + dbTransInfo.dbsci.fBackward = + dbTransInfo.dbsci.fOptimized = HB_FALSE; dbTransInfo.dbsci.fIncludeDeleted = HB_TRUE; - dbTransInfo.dbsci.fLast = HB_FALSE; - dbTransInfo.dbsci.fIgnoreDuplicates = HB_FALSE; - dbTransInfo.dbsci.fBackward = HB_FALSE; pTransItm = hb_itemPutL( NULL, HB_TRUE ); SELF_INFO( dbTransInfo.lpaDest, DBI_TRANSREC, pTransItm ); diff --git a/src/rdd/dbf1.c b/src/rdd/dbf1.c index a1f33e8bcb..ba62e0b6c7 100644 --- a/src/rdd/dbf1.c +++ b/src/rdd/dbf1.c @@ -3786,7 +3786,6 @@ static HB_ERRCODE hb_dbfFieldInfo( DBFAREAP pArea, HB_USHORT uiIndex, HB_USHORT case DBS_COUNTER: if( hb_dbfIsAutoIncField( pArea->area.lpFields + uiIndex - 1 ) != HB_AUTOINC_NONE ) { - nValue = 0; fLck = HB_FALSE; if( pArea->fShared && ! pArea->fFLocked && ! pArea->fHeaderLocked ) { @@ -3810,7 +3809,6 @@ static HB_ERRCODE hb_dbfFieldInfo( DBFAREAP pArea, HB_USHORT uiIndex, HB_USHORT case DBS_STEP: if( hb_dbfIsAutoIncField( pArea->area.lpFields + uiIndex - 1 ) != HB_AUTOINC_NONE ) { - iValue = 0; if( HB_IS_NUMERIC( pItem ) ) { fLck = HB_FALSE; diff --git a/src/rdd/wafunc.c b/src/rdd/wafunc.c index befbb9b630..cd84b013a5 100644 --- a/src/rdd/wafunc.c +++ b/src/rdd/wafunc.c @@ -162,40 +162,29 @@ HB_ERRCODE hb_rddGetTempAlias( char * szAliasTmp ) */ void * hb_rddAllocWorkAreaAlias( const char * szAlias, int iArea ) { - PHB_DYNS pSymAlias; int iDummyArea; HB_TRACE( HB_TR_DEBUG, ( "hb_rddAllocWorkAreaAlias(%s, %d)", szAlias, iArea ) ); /* Verify if the alias name is valid symbol */ if( hb_rddVerifyAliasName( szAlias ) != HB_SUCCESS ) - { hb_errRT_DBCMD_Ext( EG_BADALIAS, EDBCMD_BADALIAS, NULL, szAlias, EF_CANDEFAULT ); - return NULL; - } /* Verify if the alias is already in use */ - if( hb_rddGetAliasNumber( szAlias, &iDummyArea ) == HB_SUCCESS ) - { + else if( hb_rddGetAliasNumber( szAlias, &iDummyArea ) == HB_SUCCESS ) hb_errRT_DBCMD_Ext( EG_DUPALIAS, EDBCMD_DUPALIAS, NULL, szAlias, EF_CANDEFAULT ); - return NULL; - } - - pSymAlias = hb_dynsymGet( szAlias ); - if( hb_dynsymAreaHandle( pSymAlias ) != 0 ) - { - pSymAlias = NULL; - } else { - hb_dynsymSetAreaHandle( pSymAlias, iArea ); - } + PHB_DYNS pSymAlias = hb_dynsymGet( szAlias ); - if( ! pSymAlias ) - { + if( hb_dynsymAreaHandle( pSymAlias ) == 0 ) + { + hb_dynsymSetAreaHandle( pSymAlias, iArea ); + return pSymAlias; + } hb_errRT_DBCMD_Ext( EG_DUPALIAS, EDBCMD_DUPALIAS, NULL, szAlias, EF_CANDEFAULT ); } - return pSymAlias; + return NULL; } /* diff --git a/src/rtl/hbinet.c b/src/rtl/hbinet.c index f7167d86e5..c7f4879d3c 100644 --- a/src/rtl/hbinet.c +++ b/src/rtl/hbinet.c @@ -717,7 +717,7 @@ static void s_inetRecvInternal( int iMode ) hb_retni( -1 ); else { - int iLen, iMaxLen, iReceived = 0, iTimeElapsed = 0; + int iLen, iMaxLen, iReceived, iTimeElapsed; char * buffer; HB_SIZE nLen; @@ -740,8 +740,7 @@ static void s_inetRecvInternal( int iMode ) else iMaxLen = iLen; - iReceived = 0; - iTimeElapsed = 0; + iReceived = iTimeElapsed = 0; socket->iError = HB_INET_ERR_OK; do {