From a5baeb0cb0dd09000e4541ef592de573ae91415c Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Tue, 13 Mar 2012 12:53:47 +0000 Subject: [PATCH] 2012-03-13 13:53 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * harbour/contrib/sddpg/sddpg.c * harbour/contrib/sddsqlt3/sddsqlt3.c * harbour/contrib/sddmy/sddmy.c * harbour/contrib/sddfb/sddfb.c * harbour/contrib/sddodbc/sddodbc.c * harbour/contrib/sddoci/sddoci.c * removed redundant fieldname conversions ; I left one TOFIX note in sddfb.c - It's not critical but I'd like to ask someone with FB experience to verify it. --- harbour/ChangeLog | 11 +++++++++++ harbour/contrib/sddfb/sddfb.c | 19 +++++++++---------- harbour/contrib/sddmy/sddmy.c | 12 +----------- harbour/contrib/sddoci/sddoci.c | 10 ++-------- harbour/contrib/sddodbc/sddodbc.c | 10 ++-------- harbour/contrib/sddpg/sddpg.c | 15 ++------------- harbour/contrib/sddsqlt3/sddsqlt3.c | 9 ++------- 7 files changed, 29 insertions(+), 57 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 7379abd70b..baeab61c30 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,17 @@ The license applies to all entries newer than 2009-04-28. */ +2012-03-13 13:53 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) + * harbour/contrib/sddpg/sddpg.c + * harbour/contrib/sddsqlt3/sddsqlt3.c + * harbour/contrib/sddmy/sddmy.c + * harbour/contrib/sddfb/sddfb.c + * harbour/contrib/sddodbc/sddodbc.c + * harbour/contrib/sddoci/sddoci.c + * removed redundant fieldname conversions + ; I left one TOFIX note in sddfb.c - It's not critical but I'd like + to ask someone with FB experience to verify it. + 2012-03-13 12:55 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * harbour/package/harbour.spec ! added missing attribute for harbour.ld.conf file diff --git a/harbour/contrib/sddfb/sddfb.c b/harbour/contrib/sddfb/sddfb.c index bc3369f524..b42eb2e14c 100644 --- a/harbour/contrib/sddfb/sddfb.c +++ b/harbour/contrib/sddfb/sddfb.c @@ -213,7 +213,6 @@ static HB_ERRCODE fbOpen( SQLBASEAREAP pArea ) PHB_ITEM pItemEof, pItem; DBFIELDINFO pFieldInfo; HB_BOOL bError; - char * pBuffer; HB_USHORT uiFields, uiCount; int iType; @@ -276,16 +275,16 @@ static HB_ERRCODE fbOpen( SQLBASEAREAP pArea ) pItemEof = hb_itemArrayNew( uiFields ); - pBuffer = ( char * ) hb_xgrab( MAX_FIELD_NAME + 1 ); - bError = HB_FALSE; for ( uiCount = 0, pVar = pSqlda->sqlvar; uiCount < uiFields; uiCount++, pVar++ ) { - hb_cdpnDup2Upper( hb_vmCDP(), - pVar->sqlname, pVar->sqlname_length, - pBuffer, MAX_FIELD_NAME + 1 ); - pBuffer[ MAX_FIELD_NAME ] = '\0'; - pFieldInfo.atomName = pBuffer; + /* FIXME: if pVar->sqlname is ended with 0 byte then this hb_strndup() + * and hb_xfree() bewlow is redundant and + * pFieldInfo.atomName = pVar->sqlname; + * is enough. + */ + char * szOurName = hb_strndup( pVar->sqlname, pVar->sqlname_length ); + pFieldInfo.atomName = szOurName; pFieldInfo.uiDec = 0; @@ -400,12 +399,12 @@ static HB_ERRCODE fbOpen( SQLBASEAREAP pArea ) bError = ( SELF_ADDFIELD( ( AREAP ) pArea, &pFieldInfo ) == HB_FAILURE ); } + hb_xfree( szOurName ); + if ( bError ) break; } - hb_xfree( pBuffer ); - if ( bError ) { hb_itemClear( pItemEof ); diff --git a/harbour/contrib/sddmy/sddmy.c b/harbour/contrib/sddmy/sddmy.c index f64d216e09..4d0edd504e 100644 --- a/harbour/contrib/sddmy/sddmy.c +++ b/harbour/contrib/sddmy/sddmy.c @@ -235,7 +235,6 @@ static HB_ERRCODE mysqlOpen( SQLBASEAREAP pArea ) HB_USHORT uiFields, uiCount; HB_ERRCODE errCode = 0; HB_BOOL bError; - char * pBuffer; DBFIELDINFO pFieldInfo; MYSQL_FIELD * pMyField; void ** pRow; @@ -262,19 +261,12 @@ static HB_ERRCODE mysqlOpen( SQLBASEAREAP pArea ) pItemEof = hb_itemArrayNew( uiFields ); - pBuffer = ( char * ) hb_xgrab( MAX_FIELD_NAME + 1 ); - bError = HB_FALSE; for ( uiCount = 0; uiCount < uiFields; uiCount++ ) { pMyField = mysql_fetch_field_direct( pSDDData->pResult, uiCount ); - hb_cdpnDup2Upper( hb_vmCDP(), - pMyField->name, strlen( pMyField->name ), - pBuffer, MAX_FIELD_NAME + 1 ); - pBuffer[ MAX_FIELD_NAME ] = '\0'; - pFieldInfo.atomName = pBuffer; - + pFieldInfo.atomName = pMyField->name; pFieldInfo.uiLen = ( HB_USHORT ) pMyField->length; pFieldInfo.uiDec = 0; @@ -405,8 +397,6 @@ static HB_ERRCODE mysqlOpen( SQLBASEAREAP pArea ) break; } - hb_xfree( pBuffer ); - if ( bError ) { hb_itemRelease( pItemEof ); diff --git a/harbour/contrib/sddoci/sddoci.c b/harbour/contrib/sddoci/sddoci.c index 7df38fcbb9..9f75f9e245 100644 --- a/harbour/contrib/sddoci/sddoci.c +++ b/harbour/contrib/sddoci/sddoci.c @@ -342,7 +342,6 @@ static HB_ERRCODE ocilibOpen( SQLBASEAREAP pArea ) DBFIELDINFO pFieldInfo; PHB_ITEM pName; - char * szOurName; OCI_Column * col = OCI_GetColumn( rs, uiIndex + 1 ); @@ -363,12 +362,7 @@ static HB_ERRCODE ocilibOpen( SQLBASEAREAP pArea ) } pName = D_HB_ITEMPUTSTR( NULL, OCI_ColumnGetName( col ) ); - - szOurName = hb_cdpnDupUpper( hb_vmCDP(), hb_itemGetCPtr( pName ), NULL ); - hb_itemRelease( pName ); - if( strlen( szOurName ) > MAX_FIELD_NAME ) - szOurName[ MAX_FIELD_NAME ] = '\0'; - pFieldInfo.atomName = szOurName; + pFieldInfo.atomName = hb_itemGetCPtr( pName ); uiDataType = OCI_ColumnGetType( col ); uiSize = OCI_ColumnGetSize( col ); @@ -481,7 +475,7 @@ static HB_ERRCODE ocilibOpen( SQLBASEAREAP pArea ) bError = ( SELF_ADDFIELD( ( AREAP ) pArea, &pFieldInfo ) == HB_FAILURE ); } - hb_xfree( szOurName ); + hb_itemRelease( pName ); if( bError ) break; diff --git a/harbour/contrib/sddodbc/sddodbc.c b/harbour/contrib/sddodbc/sddodbc.c index 4bbb23102d..333b1ffe5c 100644 --- a/harbour/contrib/sddodbc/sddodbc.c +++ b/harbour/contrib/sddodbc/sddodbc.c @@ -381,7 +381,6 @@ static HB_ERRCODE odbcOpen( SQLBASEAREAP pArea ) DBFIELDINFO pFieldInfo; PHB_ITEM pName; - char * szOurName; SQLTCHAR cName[ 256 ]; SQLULEN uiSize; @@ -398,12 +397,7 @@ static HB_ERRCODE odbcOpen( SQLBASEAREAP pArea ) } pName = O_HB_ITEMPUTSTRLEN( NULL, ( O_HB_CHAR * ) cName, iNameLen ); - - szOurName = hb_cdpnDupUpper( hb_vmCDP(), hb_itemGetCPtr( pName ), NULL ); - hb_itemRelease( pName ); - if( strlen( szOurName ) > MAX_FIELD_NAME ) - szOurName[ MAX_FIELD_NAME ] = '\0'; - pFieldInfo.atomName = szOurName; + pFieldInfo.atomName = hb_itemGetCPtr( pName ); /* We do mapping of many SQL types to one Harbour field type here, so, we need store @@ -549,7 +543,7 @@ static HB_ERRCODE odbcOpen( SQLBASEAREAP pArea ) bError = ( SELF_ADDFIELD( ( AREAP ) pArea, &pFieldInfo ) == HB_FAILURE ); } - hb_xfree( szOurName ); + hb_itemRelease( pName ); if ( bError ) break; diff --git a/harbour/contrib/sddpg/sddpg.c b/harbour/contrib/sddpg/sddpg.c index 1c48acbc7d..684565150c 100644 --- a/harbour/contrib/sddpg/sddpg.c +++ b/harbour/contrib/sddpg/sddpg.c @@ -239,7 +239,6 @@ static HB_ERRCODE pgsqlOpen( SQLBASEAREAP pArea ) PHB_ITEM pItemEof, pItem; HB_USHORT uiFields, uiCount; HB_BOOL bError; - char* pBuffer; DBFIELDINFO pFieldInfo; pArea->pSDDData = memset( hb_xgrab( sizeof( SDDDATA ) ), 0, sizeof( SDDDATA ) ); @@ -268,18 +267,10 @@ static HB_ERRCODE pgsqlOpen( SQLBASEAREAP pArea ) pItemEof = hb_itemArrayNew( uiFields ); pItem = hb_itemNew( NULL ); - pBuffer = ( char * ) hb_xgrab( MAX_FIELD_NAME + 1 ); - bError = HB_FALSE; for ( uiCount = 0; uiCount < uiFields; uiCount++ ) { - char * pszName = PQfname( pResult, ( int ) uiCount ); - hb_cdpnDup2Upper( hb_vmCDP(), - pszName, strlen( pszName ), - pBuffer, MAX_FIELD_NAME + 1 ); - pBuffer[ MAX_FIELD_NAME ] = '\0'; - pFieldInfo.atomName = pBuffer; - + pFieldInfo.atomName = PQfname( pResult, ( int ) uiCount ); pFieldInfo.uiDec = 0; switch( PQftype( pResult, ( int ) uiCount ) ) @@ -392,7 +383,7 @@ static HB_ERRCODE pgsqlOpen( SQLBASEAREAP pArea ) bError = HB_TRUE; break; } - /* printf( "field:%s \ttype:%d \tsize:%d \tformat:%d \tmod:%d err=%d\n", pBuffer, PQftype( pResult, ( int ) uiCount ), PQfsize( pResult, uiCount ), PQfformat( pResult, uiCount ) , PQfmod( pResult, uiCount ), bError ); */ + /* printf( "field:%s \ttype:%d \tsize:%d \tformat:%d \tmod:%d err=%d\n", pFieldInfo.atomName, PQftype( pResult, ( int ) uiCount ), PQfsize( pResult, uiCount ), PQfformat( pResult, uiCount ) , PQfmod( pResult, uiCount ), bError ); */ if ( ! bError ) { @@ -456,8 +447,6 @@ static HB_ERRCODE pgsqlOpen( SQLBASEAREAP pArea ) break; } - hb_xfree( pBuffer ); - hb_itemRelease( pItem ); if ( bError ) diff --git a/harbour/contrib/sddsqlt3/sddsqlt3.c b/harbour/contrib/sddsqlt3/sddsqlt3.c index a01ae2d0e8..532f341ee4 100644 --- a/harbour/contrib/sddsqlt3/sddsqlt3.c +++ b/harbour/contrib/sddsqlt3/sddsqlt3.c @@ -295,18 +295,13 @@ static HB_ERRCODE sqlite3Open( SQLBASEAREAP pArea ) DBFIELDINFO pFieldInfo; PHB_ITEM pName; - char * szOurName; int iDataType; int iSize; int iDec; pName = S_HB_ITEMPUTSTR( NULL, sqlite3_column_name( st, uiIndex ) ); - szOurName = hb_cdpnDupUpper( hb_vmCDP(), hb_itemGetCPtr( pName ), NULL ); - hb_itemRelease( pName ); - if( strlen( szOurName ) > MAX_FIELD_NAME ) - szOurName[ MAX_FIELD_NAME ] = '\0'; - pFieldInfo.atomName = szOurName; + pFieldInfo.atomName = hb_itemGetCPtr( pName ); iDataType = sqlite3_column_type( st, uiIndex ); @@ -378,7 +373,7 @@ static HB_ERRCODE sqlite3Open( SQLBASEAREAP pArea ) bError = ( SELF_ADDFIELD( ( AREAP ) pArea, &pFieldInfo ) == HB_FAILURE ); } - hb_xfree( szOurName ); + hb_itemRelease( pName ); if( bError ) break;