static HB_ERRCODE sqlbasePutValue( SQLBASEAREAP pArea, HB_USHORT uiIndex, PHB_ITEM pItem ) { LPFIELD pField; HB_ERRCODE errCode; if( uiIndex == 0 || uiIndex > pArea->area.uiFieldCount ) return HB_FAILURE; if( ! pArea->fPositioned ) return HB_SUCCESS; if( ! pArea->fRecordChanged && SELF_GOHOT( ( AREAP ) pArea ) == HB_FAILURE ) return HB_FAILURE; errCode = HB_SUCCESS; pField = pArea->area.lpFields + ( uiIndex - 1 ); if( ( ( HB_IS_MEMO( pItem ) || HB_IS_STRING( pItem ) ) && ( pField->uiType == HB_FT_STRING || pField->uiType == HB_FT_MEMO ) ) || ( HB_IS_DATE( pItem ) && pField->uiType == HB_FT_DATE ) || ( HB_IS_TIMESTAMP( pItem ) && pField->uiType == HB_FT_TIMESTAMP ) || ( HB_IS_NUMBER( pItem ) && ( pField->uiType == HB_FT_INTEGER || pField->uiType == HB_FT_LONG || pField->uiType == HB_FT_FLOAT || pField->uiType == HB_FT_DOUBLE ) ) || ( HB_IS_LOGICAL( pItem ) && pField->uiType == HB_FT_LOGICAL ) || HB_IS_NIL( pItem ) ) { hb_arraySet( ( PHB_ITEM ) pArea->pRecord, uiIndex, pItem ); } else { PHB_ITEM pError; pError = hb_errNew(); hb_errPutGenCode( pError, EG_DATATYPE ); hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_DATATYPE ) ); hb_errPutOperation( pError, hb_dynsymName( ( PHB_DYNS ) pField->sym ) ); hb_errPutSubCode( pError, errCode ); hb_errPutFlags( pError, EF_CANDEFAULT ); errCode = SELF_ERROR( ( AREAP ) pArea, pError ); hb_itemRelease( pError ); return errCode == E_DEFAULT ? HB_SUCCESS : HB_FAILURE; } return HB_SUCCESS; }
/* * Assign a value to a field. */ static HB_ERRCODE hb_delimPutValue( DELIMAREAP pArea, USHORT uiIndex, PHB_ITEM pItem ) { char szBuffer[ 256 ]; HB_ERRCODE uiError; LPFIELD pField; USHORT uiSize; HB_TRACE(HB_TR_DEBUG, ("hb_delimPutValue(%p,%hu,%p)", pArea, uiIndex, pItem)); if( !pArea->fPositioned ) return HB_SUCCESS; if( !pArea->fRecordChanged ) return HB_FAILURE; uiError = HB_SUCCESS; --uiIndex; pField = pArea->lpFields + uiIndex; if( pField->uiType != HB_FT_MEMO && pField->uiType != HB_FT_NONE ) { if( HB_IS_MEMO( pItem ) || HB_IS_STRING( pItem ) ) { if( pField->uiType == HB_FT_STRING ) { uiSize = ( USHORT ) hb_itemGetCLen( pItem ); if( uiSize > pField->uiLen ) uiSize = pField->uiLen; memcpy( pArea->pRecord + pArea->pFieldOffset[ uiIndex ], hb_itemGetCPtr( pItem ), uiSize ); #ifndef HB_CDP_SUPPORT_OFF hb_cdpnTranslate( (char *) pArea->pRecord + pArea->pFieldOffset[ uiIndex ], hb_cdppage(), pArea->cdPage, uiSize ); #endif memset( pArea->pRecord + pArea->pFieldOffset[ uiIndex ] + uiSize, ' ', pField->uiLen - uiSize ); } else uiError = EDBF_DATATYPE; } else if( HB_IS_DATE( pItem ) ) { if( pField->uiType == HB_FT_DATE ) { hb_itemGetDS( pItem, szBuffer ); memcpy( pArea->pRecord + pArea->pFieldOffset[ uiIndex ], szBuffer, 8 ); } else uiError = EDBF_DATATYPE; } else if( HB_IS_NUMBER( pItem ) ) { if( pField->uiType == HB_FT_LONG ) { if( hb_itemStrBuf( szBuffer, pItem, pField->uiLen, pField->uiDec ) ) { memcpy( pArea->pRecord + pArea->pFieldOffset[ uiIndex ], szBuffer, pField->uiLen ); } else { uiError = EDBF_DATAWIDTH; memset( pArea->pRecord + pArea->pFieldOffset[ uiIndex ], '*', pField->uiLen ); } } else uiError = EDBF_DATATYPE; } else if( HB_IS_LOGICAL( pItem ) ) { if( pField->uiType == HB_FT_LOGICAL ) pArea->pRecord[ pArea->pFieldOffset[ uiIndex ] ] = hb_itemGetL( pItem ) ? 'T' : 'F'; else uiError = EDBF_DATATYPE; } else uiError = EDBF_DATATYPE; } if( uiError != HB_SUCCESS ) { PHB_ITEM pError= hb_errNew(); USHORT uiGenCode = uiError == EDBF_DATAWIDTH ? EG_DATAWIDTH : EDBF_DATATYPE; hb_errPutGenCode( pError, uiGenCode ); hb_errPutDescription( pError, hb_langDGetErrorDesc( uiGenCode ) ); hb_errPutOperation( pError, hb_dynsymName( ( PHB_DYNS ) pField->sym ) ); hb_errPutSubCode( pError, uiError ); hb_errPutFlags( pError, EF_CANDEFAULT ); uiError = SELF_ERROR( ( AREAP ) pArea, pError ); hb_itemRelease( pError ); return uiError == E_DEFAULT ? HB_SUCCESS : HB_FAILURE; } return HB_SUCCESS; }
/* * Assign a value to a field. */ static HB_ERRCODE hb_sdfPutValue( SDFAREAP pArea, HB_USHORT uiIndex, PHB_ITEM pItem ) { char szBuffer[ 256 ]; HB_ERRCODE errCode; LPFIELD pField; HB_SIZE nSize; HB_TRACE( HB_TR_DEBUG, ( "hb_sdfPutValue(%p,%hu,%p)", pArea, uiIndex, pItem ) ); if( ! pArea->fPositioned ) return HB_SUCCESS; if( ! pArea->fRecordChanged ) return HB_FAILURE; if( --uiIndex >= pArea->area.uiFieldCount ) return HB_FAILURE; errCode = HB_SUCCESS; pField = pArea->area.lpFields + uiIndex; if( pField->uiType != HB_FT_MEMO && pField->uiType != HB_FT_NONE ) { if( HB_IS_MEMO( pItem ) || HB_IS_STRING( pItem ) ) { if( pField->uiType == HB_FT_STRING ) { if( ( pField->uiFlags & HB_FF_BINARY ) == 0 ) { nSize = pField->uiLen; hb_cdpnDup2( hb_itemGetCPtr( pItem ), hb_itemGetCLen( pItem ), ( char * ) pArea->pRecord + pArea->pFieldOffset[ uiIndex ], &nSize, hb_vmCDP(), pArea->area.cdPage ); } else { nSize = hb_itemGetCLen( pItem ); if( nSize > ( HB_SIZE ) pField->uiLen ) nSize = pField->uiLen; memcpy( pArea->pRecord + pArea->pFieldOffset[ uiIndex ], hb_itemGetCPtr( pItem ), nSize ); } if( nSize < ( HB_SIZE ) pField->uiLen ) memset( pArea->pRecord + pArea->pFieldOffset[ uiIndex ] + nSize, ' ', pField->uiLen - nSize ); } else errCode = EDBF_DATATYPE; } else if( HB_IS_DATETIME( pItem ) ) { if( pField->uiType == HB_FT_DATE ) { hb_itemGetDS( pItem, szBuffer ); memcpy( pArea->pRecord + pArea->pFieldOffset[ uiIndex ], szBuffer, 8 ); } else if( pField->uiType == HB_FT_TIMESTAMP && ( pField->uiLen == 12 || pField->uiLen == 23 ) ) { long lDate, lTime; hb_itemGetTDT( pItem, &lDate, &lTime ); if( pField->uiLen == 12 ) hb_timeStr( szBuffer, lTime ); else hb_timeStampStr( szBuffer, lDate, lTime ); memcpy( pArea->pRecord + pArea->pFieldOffset[ uiIndex ], szBuffer, pField->uiLen ); } else errCode = EDBF_DATATYPE; } else if( HB_IS_NUMBER( pItem ) ) { if( pField->uiType == HB_FT_LONG ) { if( hb_itemStrBuf( szBuffer, pItem, pField->uiLen, pField->uiDec ) ) { memcpy( pArea->pRecord + pArea->pFieldOffset[ uiIndex ], szBuffer, pField->uiLen ); } else { errCode = EDBF_DATAWIDTH; memset( pArea->pRecord + pArea->pFieldOffset[ uiIndex ], '*', pField->uiLen ); } } else errCode = EDBF_DATATYPE; } else if( HB_IS_LOGICAL( pItem ) ) { if( pField->uiType == HB_FT_LOGICAL ) pArea->pRecord[ pArea->pFieldOffset[ uiIndex ] ] = hb_itemGetL( pItem ) ? 'T' : 'F'; else errCode = EDBF_DATATYPE; } else errCode = EDBF_DATATYPE; } if( errCode != HB_SUCCESS ) { PHB_ITEM pError = hb_errNew(); HB_ERRCODE errGenCode = errCode == EDBF_DATAWIDTH ? EG_DATAWIDTH : EDBF_DATATYPE; hb_errPutGenCode( pError, errGenCode ); hb_errPutDescription( pError, hb_langDGetErrorDesc( errGenCode ) ); hb_errPutOperation( pError, hb_dynsymName( ( PHB_DYNS ) pField->sym ) ); hb_errPutSubCode( pError, errCode ); hb_errPutFlags( pError, EF_CANDEFAULT ); errCode = SELF_ERROR( &pArea->area, pError ); hb_itemRelease( pError ); return errCode == E_DEFAULT ? HB_SUCCESS : HB_FAILURE; } return HB_SUCCESS; }