HB_ISIZ hb_strAtTBM( const char * needle, HB_ISIZ m, const char * haystack, HB_ISIZ n ) { HB_ISIZ r = 0; HB_ISIZ bcShift, j, shift, u, v, turboShift; HB_ISIZ bmBc[ ASIZE ]; HB_ISIZ * bmGs; bmGs = ( HB_ISIZ * ) hb_xgrab( m * sizeof( HB_ISIZ ) ); /* Preprocessing */ preBmGs( needle, m, bmGs ); preBmBc( needle, m, bmBc ); /* Searching */ j = u = 0; shift = m; while( j <= n - m ) { HB_ISIZ i = m - 1; while( i >= 0 && needle[ i ] == haystack[ i + j ] ) { --i; if( u != 0 && i == m - 1 - shift ) i -= u; } if( i < 0 ) { r = j + 1; break; #if 0 /* To continue search */ shift = bmGs[ 0 ]; u = m - shift; #endif } else { v = m - 1 - i; turboShift = u - v; bcShift = bmBc[ ( HB_UCHAR ) haystack[ i + j ] ] - m + 1 + i; shift = HB_MAX( turboShift, bcShift ); shift = HB_MAX( shift, bmGs[ i ] ); if( shift == bmGs[ i ] ) u = HB_MIN( m - shift, v ); else { if( turboShift < bcShift ) shift = HB_MAX( shift, u + 1 ); u = 0; } } j += shift; } hb_xfree( bmGs ); return r; }
void hb_xexit( void ) { #ifdef HB_FM_STATISTICS if( s_nMemoryBlocks /* || hb_cmdargCheck( "INFO" ) */ ) { char szBuffer[ HB_MAX( 3 * HB_MEMSTR_BLOCK_MAX + 1, 100 ) ]; PHB_MEMINFO pMemBlock; int i; hb_conOutErr( hb_conNewLine(), 0 ); hb_conOutErr( "----------------------------------------", 0 ); hb_conOutErr( hb_conNewLine(), 0 ); hb_snprintf( szBuffer, sizeof( szBuffer ), "Total memory allocated: %" HB_PFS "u bytes (%" HB_PFS "u blocks)", s_nMemoryMaxConsumed, s_nMemoryMaxBlocks ); hb_conOutErr( szBuffer, 0 ); if( s_nMemoryBlocks ) { hb_conOutErr( hb_conNewLine(), 0 ); hb_snprintf( szBuffer, sizeof( szBuffer ), "WARNING! Memory allocated but not released: %" HB_PFS "u bytes (%" HB_PFS "u blocks)", s_nMemoryConsumed, s_nMemoryBlocks ); hb_conOutErr( szBuffer, 0 ); } hb_conOutErr( hb_conNewLine(), 0 ); for( i = 1, pMemBlock = s_pMemBlocks; pMemBlock; ++i, pMemBlock = pMemBlock->pNextBlock ) HB_TRACE( HB_TR_ERROR, ( "Block %i %p (size %" HB_PFS "u) \"%s\"", i, ( char * ) pMemBlock + HB_MEMINFO_SIZE, pMemBlock->nSize, hb_memToStr( szBuffer, ( char * ) pMemBlock + HB_MEMINFO_SIZE, pMemBlock->nSize ) ) ); } #endif }
static int s_sockexClose( PHB_SOCKEX pSock, HB_BOOL fClose ) { PHB_SOCKEX_BF pBF = HB_BFSOCK_GET( pSock ); int iResult = 0; if( pBF ) { if( pBF->sock ) s_sockexFlush( pSock, HB_MAX( 15000, pSock->iAutoFlush ), HB_TRUE ); if( pBF->sock ) { if( pSock->fShutDown ) pBF->sock->fShutDown = HB_TRUE; if( pSock->iAutoFlush != 0 && pBF->sock->iAutoFlush == 0 ) pBF->sock->iAutoFlush = pSock->iAutoFlush; iResult = hb_sockexClose( pBF->sock, fClose ); } memset( pBF, 0, sizeof( *pBF ) ); hb_xfree( pBF ); } /* call hb_sockexRawClear() with fClose = HB_FALSE because hb_sockexClose() already closed real socket */ hb_sockexRawClear( pSock, HB_FALSE ); hb_xfree( pSock ); return iResult; }
static long s_sockexRead( PHB_SOCKEX pSock, void * data, long len, HB_MAXINT timeout ) { long lRead = HB_MIN( pSock->inbuffer, len ); if( lRead > 0 ) { memcpy( data, pSock->buffer + pSock->posbuffer, lRead ); pSock->inbuffer -= lRead; if( pSock->inbuffer ) pSock->posbuffer += lRead; else pSock->posbuffer = 0; len -= lRead; if( len == 0 || pSock->sd == HB_NO_SOCKET ) return lRead; data = ( HB_BYTE * ) data + lRead; timeout = 0; } else if( pSock->sd == HB_NO_SOCKET ) { hb_socketSetError( HB_SOCKET_ERR_INVALIDHANDLE ); return -1; } len = pSock->cargo ? hb_znetRead( HB_ZNET_GET( pSock ), pSock->sd, data, len, timeout ) : hb_socketRecv( pSock->sd, data, len, 0, timeout ); return lRead > 0 ? HB_MAX( len, 0 ) + lRead : len; }
int hb_tracesysout( int new_sysout ) { int old_sysout = HB_MAX( s_sysout, 0 ); if( new_sysout == 0 || new_sysout == 1 ) s_sysout = new_sysout; return old_sysout; }
int hb_traceflush( int new_flush ) { int old_flush = HB_MAX( s_flush, 0 ); if( new_flush == 0 || new_flush == 1 ) s_flush = new_flush; return old_flush; }
static unsigned char *buf_append(unsigned char *buf, unsigned *buf_size, unsigned count, unsigned char c, unsigned *buf_len) { if (*buf_len + count > *buf_size) { *buf_size = HB_MAX(*buf_len + count, *buf_size + 32768); buf = (unsigned char *) hb_xrealloc(buf, *buf_size); } memset(buf + *buf_len, c, count); *buf_len += count; return buf; }
long hb_sockexWrite( PHB_SOCKEX pSock, const void * data, long len, HB_MAXINT timeout ) { len = pSock->pFilter->Write( pSock, data, len, timeout ); if( len >= 0 && pSock->iAutoFlush > 0 ) { if( timeout >= 0 ) timeout = HB_MAX( timeout, pSock->iAutoFlush ); hb_sockexFlush( pSock, timeout, HB_FALSE ); } return len; }
static HB_UCHAR * buf_append( HB_UCHAR * buf, HB_SIZE * buf_size, HB_SIZE count, HB_UCHAR c, HB_SIZE * buf_len ) { if( *buf_len + count > *buf_size ) { *buf_size = HB_MAX( *buf_len + count, *buf_size + 32768 ); buf = ( HB_UCHAR * ) hb_xrealloc( buf, *buf_size ); } memset( buf + *buf_len, c, count ); *buf_len += count; return buf; }
static long s_inetRecv( PHB_SOCKET_STRUCT socket, char * buffer, long size, HB_BOOL readahead ) { long rec = 0; if( readahead && socket->inbuffer == 0 && socket->readahead > size ) { if( socket->buffer == NULL ) socket->buffer = ( char * ) hb_xgrab( socket->readahead ); socket->posbuffer = 0; if( socket->recvFunc ) rec = socket->recvFunc( socket->stream, socket->sd, socket->buffer, socket->readahead, socket->iTimeout ); else rec = hb_socketRecv( socket->sd, socket->buffer, socket->readahead, 0, socket->iTimeout ); socket->inbuffer = HB_MAX( 0, rec ); } else readahead = HB_FALSE; if( socket->inbuffer > 0 ) { rec = HB_MIN( size, socket->inbuffer ); memcpy( buffer, socket->buffer + socket->posbuffer, rec ); socket->posbuffer += rec; socket->inbuffer -= rec; if( size > rec && ! readahead ) { if( socket->recvFunc ) rec = socket->recvFunc( socket->stream, socket->sd, buffer + rec, size - rec, socket->iTimeout ); else size = hb_socketRecv( socket->sd, buffer + rec, size - rec, 0, 0 ); if( size > 0 ) rec += size; } } else if( ! readahead ) { if( socket->recvFunc ) rec = socket->recvFunc( socket->stream, socket->sd, buffer, size, socket->iTimeout ); else rec = hb_socketRecv( socket->sd, buffer, size, 0, socket->iTimeout ); } return rec; }
static void hb_inetCloseStream( PHB_SOCKET_STRUCT socket ) { if( socket->flushFunc && socket->sd != HB_NO_SOCKET ) socket->flushFunc( socket->stream, socket->sd, HB_MAX( socket->iTimeout, 10000 ), HB_TRUE ); if( socket->cleanFunc ) socket->cleanFunc( socket->stream ); socket->recvFunc = NULL; socket->sendFunc = NULL; socket->flushFunc = NULL; socket->cleanFunc = NULL; socket->stream = NULL; }
static int s_sockexClose( PHB_SOCKEX pSock, HB_BOOL fClose ) { int iResult; if( pSock->cargo ) { if( pSock->sd != HB_NO_SOCKET ) hb_znetFlush( HB_ZNET_GET( pSock ), pSock->sd, HB_MAX( 15000, pSock->iAutoFlush ), HB_TRUE ); hb_znetClose( HB_ZNET_GET( pSock ) ); } iResult = hb_sockexRawClear( pSock, fClose ); hb_xfree( pSock ); return iResult; }
static HB_SIZE s_fileRead( PHB_FILE pFile, void * data, HB_SIZE nSize, HB_MAXINT timeout ) { HB_ERRCODE errcode; long lRead = 0; if( pFile->fRead ) { lRead = nSize > LONG_MAX ? LONG_MAX : ( long ) nSize; if( timeout == -1 ) timeout = pFile->timeout; lRead = hb_comRecv( pFile->port, data, lRead, timeout ); errcode = hb_comGetError( pFile->port ); } else errcode = HB_COM_ERR_ACCESS; hb_fsSetError( errcode ); return HB_MAX( lRead, 0 ); }
static HB_SIZE s_fileWrite( PHB_FILE pFile, const void * data, HB_SIZE nSize, HB_MAXINT timeout ) { HB_ERRCODE errcode; long lSent = 0; if( pFile->fWrite ) { lSent = nSize > LONG_MAX ? LONG_MAX : ( long ) nSize; if( timeout == -1 ) timeout = pFile->timeout; lSent = hb_comSend( pFile->port, data, lSent, timeout ); errcode = hb_comGetError( pFile->port ); } else errcode = HB_COM_ERR_ACCESS; hb_fsSetError( errcode ); return HB_MAX( 0, lSent ); }
static int s_sockexClose( PHB_SOCKEX pSock, HB_BOOL fClose ) { PHB_SOCKEX_Z pZ = HB_ZSOCK_GET( pSock ); int iResult = 0; if( pZ ) { if( pZ->sock ) s_sockexFlush( pSock, HB_MAX( 15000, pSock->iAutoFlush ), HB_TRUE ); if( pZ->fDecompressIn ) inflateEnd( &pZ->z_read ); if( pZ->rdbuf ) hb_xfree( pZ->rdbuf ); if( pZ->fCompressOut ) deflateEnd( &pZ->z_write ); if( pZ->wrbuf ) hb_xfree( pZ->wrbuf ); if( pZ->sock ) { if( pSock->fShutDown ) pZ->sock->fShutDown = HB_TRUE; if( pSock->iAutoFlush != 0 && pZ->sock->iAutoFlush == 0 ) pZ->sock->iAutoFlush = pSock->iAutoFlush; iResult = hb_sockexClose( pZ->sock, fClose ); } hb_xfree( pZ ); } /* call hb_sockexRawClear() with fClose = HB_FALSE because hb_sockexClose() already closed real socket */ hb_sockexRawClear( pSock, HB_FALSE ); hb_xfree( pSock ); return iResult; }
/* internal routine to do buffer skips. Passing a positive value performs a downward skip, a negative number does an upward skip. Passing 0 skips to the end of file. Returns a long indicating the number of records skipped */ static long _ft_skip( long iRecs ) { PFT_TEXT ft_text = ( PFT_TEXT ) hb_stackGetTSD( &s_ft_text ); HB_ISIZ iByteCount; HB_ISIZ iBytesRead, iBytesRemaining; char * cPtr; long iSkipped = 0; char * cBuff = ( char * ) hb_xgrab( BUFFSIZE ); HB_FOFFSET fpOffset = ft_text->offset[ ft_text->area ]; ft_text->isBof[ ft_text->area ] = HB_FALSE; ft_text->isEof[ ft_text->area ] = HB_FALSE; ft_text->error[ ft_text->area ] = 0; /* iRecs is zero if they want to find the EOF, start a top of file */ if( iRecs == 0 ) { fpOffset = 0; ft_text->recno[ ft_text->area ] = 1; } if( iRecs >= 0 ) { do { cPtr = cBuff; /* read a chunk */ if( ( iBytesRead = hb_fileResult( hb_fileReadAt( ft_text->handles[ ft_text->area ], cBuff, BUFFSIZE, fpOffset ) ) ) == 0 ) { /* buffer is empty thus EOF, set vars and quit */ ft_text->isEof[ ft_text->area ] = HB_TRUE; ft_text->last_rec[ ft_text->area ] = ft_text->recno[ ft_text->area ]; ft_text->last_off[ ft_text->area ] = ft_text->offset[ ft_text->area ]; ft_text->error[ ft_text->area ] = hb_fsError(); break; } iBytesRemaining = iBytesRead; /* parse the buffer while there's still stuff in it */ do { /* get count of chars in this line */ iByteCount = _findeol( cPtr, iBytesRemaining, NULL ); if( iByteCount > 0 && iByteCount != iBytesRemaining ) { /* found an EOL, iByteCount points to first char of next record */ iBytesRemaining -= iByteCount; fpOffset += iByteCount; cPtr += iByteCount; ft_text->offset[ ft_text->area ] = fpOffset; ft_text->recno[ ft_text->area ]++; iSkipped++; if( iRecs && ( iSkipped == iRecs ) ) iBytesRemaining = iBytesRead = 0; } else { /* no more EOLs in this buffer, or EOL is last chars in the buffer */ /* check for EOF */ if( iBytesRead != BUFFSIZE ) { /* buffer was not full, thus EOF, set vars and quit */ iBytesRemaining = 0; ft_text->last_rec[ ft_text->area ] = ft_text->recno[ ft_text->area ]; ft_text->last_off[ ft_text->area ] = ft_text->offset[ ft_text->area ]; if( iRecs ) ft_text->isEof[ ft_text->area ] = HB_TRUE; } else { /* buffer was full, so probably not EOF, but maybe EOL straddled end of buffer, so back up pointer a bit before doing the next read */ fpOffset = hb_fileSeek( ft_text->handles[ ft_text->area ], 0, FS_RELATIVE ) - 1; iBytesRemaining = 0; } } } while( iBytesRemaining > 0 ); } while( iBytesRead == BUFFSIZE ); } else { /* skip backwards */ iRecs = -iRecs; if( ft_text->recno[ ft_text->area ] > iRecs ) { do { /* calc offset to read area of file ahead of current pointer */ fpOffset = HB_MAX( ft_text->offset[ ft_text->area ] - BUFFSIZE, 0 ); /* read a chunk */ if( ( iBytesRead = hb_fileResult( hb_fileReadAt( ft_text->handles[ ft_text->area ], cBuff, BUFFSIZE, fpOffset ) ) ) == 0 ) { /* buffer is empty thus file is zero len, set vars and quit */ ft_text->isBof[ ft_text->area ] = HB_TRUE; ft_text->isEof[ ft_text->area ] = HB_TRUE; ft_text->recno[ ft_text->area ] = 0; ft_text->offset[ ft_text->area ] = 0; ft_text->last_rec[ ft_text->area ] = 0; ft_text->error[ ft_text->area ] = hb_fsError(); break; } /* set pointer within buffer */ iBytesRemaining = ( int ) ( ft_text->offset[ ft_text->area ] - fpOffset ); cPtr = cBuff + iBytesRemaining; /* parse the buffer while there's still stuff in it */ do { /* get count of chars in this line */ iByteCount = _findbol( cPtr, iBytesRemaining ); if( iByteCount > 0 ) { /* found an EOL, iByteCount points to first char of next record */ iBytesRemaining -= iByteCount; ft_text->offset[ ft_text->area ] -= iByteCount; cPtr -= iByteCount; fpOffset = ft_text->offset[ ft_text->area ]; ft_text->recno[ ft_text->area ]--; iSkipped++; if( iSkipped == iRecs ) iBytesRemaining = iBytesRead = 0; } else { /* no more EOLs in this buffer so we're either at BOF or record crosses buffer boundary */ /* check for BOF */ if( iBytesRead != BUFFSIZE ) { /* buffer was not full, thus BOF, set vars and quit */ iBytesRemaining = 0; ft_text->offset[ ft_text->area ] = 0; ft_text->recno[ ft_text->area ] = 1; ft_text->isBof[ ft_text->area ] = HB_TRUE; } else { /* buffer was full, so not BOF */ iBytesRemaining = 0; } } } while( iBytesRemaining > 0 ); } while( fpOffset > 0 && iBytesRead == BUFFSIZE ); } else { ft_text->offset[ ft_text->area ] = 0; ft_text->recno[ ft_text->area ] = 1; ft_text->isBof[ ft_text->area ] = HB_TRUE; } } hb_xfree( cBuff ); return iSkipped; }
static void s_inetSendInternal( HB_BOOL lAll ) { PHB_SOCKET_STRUCT socket = HB_PARSOCKET( 1 ); PHB_ITEM pBuffer = hb_param( 2, HB_IT_STRING ); const char * buffer; int iLen, iSent, iSend; long lLastSnd = 1; if( socket == NULL || pBuffer == NULL ) hb_inetErrRT(); else if( ! hb_inetIsOpen( socket ) ) hb_retni( -1 ); else { buffer = hb_itemGetCPtr( pBuffer ); iSend = ( int ) hb_itemGetCLen( pBuffer ); if( HB_ISNUM( 3 ) ) { iLen = hb_parni( 3 ); if( iLen < iSend ) iSend = iLen; } socket->iError = HB_INET_ERR_OK; iSent = iLen = 0; while( iSent < iSend ) { if( socket->sendFunc ) { iLen = socket->sendFunc( socket->stream, socket->sd, buffer + iSent, iSend - iSent, socket->iTimeout, &lLastSnd ); if( lLastSnd <= 0 && iLen > 0 ) { iSent += iLen; iLen = ( int ) lLastSnd; } } else iLen = hb_socketSend( socket->sd, buffer + iSent, iSend - iSent, 0, socket->iTimeout ); if( iLen > 0 ) { iSent += iLen; if( ! lAll ) break; } else { hb_inetGetError( socket ); break; } } socket->iCount = iSent; if( socket->flushFunc && ( lLastSnd > 0 || ( lLastSnd == -1 && socket->iTimeout >= 0 && socket->iTimeout < 10000 && s_inetIsTimeout( socket ) ) ) ) { /* TODO: safe information about unflushed data and try to call flush before entering receive wait sate */ socket->flushFunc( socket->stream, socket->sd, socket->iTimeout < 0 ? socket->iTimeout : HB_MAX( socket->iTimeout, 10000 ), HB_FALSE ); } hb_retni( iSent > 0 ? iSent : iLen ); } }
static PHB_FILE s_fileOpen( PHB_FILE_FUNCS pFuncs, const char * pszName, const char * pszDefExt, HB_FATTR nExFlags, const char * pPaths, PHB_ITEM pError ) { const char * pszHost = pszName + FILE_PREFIX_LEN, * ptr; PHB_FILE pFile = NULL; HB_ERRCODE errcode = 0; HB_SIZE nLen = 0; int iPort = 0; HB_MAXINT timeout = -1; HB_SYMBOL_UNUSED( pFuncs ); HB_SYMBOL_UNUSED( pszDefExt ); HB_SYMBOL_UNUSED( pPaths ); if( ( ptr = strchr( pszHost, ':' ) ) != NULL && ptr != pszHost ) { nLen = ptr - pszHost; ++ptr; while( HB_ISDIGIT( * ptr ) ) iPort = iPort * 10 + ( * ptr++ - '0' ); if( * ptr == ':' ) { ++ptr; while( HB_ISDIGIT( * ptr ) ) timeout = HB_MAX( timeout, 0 ) * 10 + ( * ptr++ - '0' ); } if( * ptr != 0 && * ptr != ':' ) iPort = 0; } if( iPort > 0 ) { char * pszAddr, * pszIpAddr; hb_socketAutoInit(); pszAddr = hb_strndup( pszHost, nLen ); pszIpAddr = hb_socketResolveAddr( pszAddr, HB_SOCKET_AF_INET ); hb_xfree( pszAddr ); if( pszIpAddr ) { HB_SOCKET sd = hb_socketOpen( HB_SOCKET_PF_INET, HB_SOCKET_PT_STREAM, 0 ); if( sd != HB_NO_SOCKET ) { void * pSockAddr; unsigned uiLen; if( hb_socketInetAddr( &pSockAddr, &uiLen, pszIpAddr, iPort ) ) { hb_socketSetKeepAlive( sd, HB_TRUE ); if( hb_socketConnect( sd, pSockAddr, uiLen, timeout ) == 0 ) { PHB_SOCKEX sock; switch( nExFlags & ( FO_READ | FO_WRITE | FO_READWRITE ) ) { case FO_READ: hb_socketShutdown( sd, HB_SOCKET_SHUT_WR ); break; case FO_WRITE: hb_socketShutdown( sd, HB_SOCKET_SHUT_RD ); break; } sock = hb_sockexNew( sd, NULL, NULL ); if( sock ) { hb_sockexSetShutDown( sock, HB_TRUE ); hb_sockexSetAutoFlush( sock, HB_TRUE ); pFile = s_fileNew( sock, timeout ); sd = HB_NO_SOCKET; } } hb_xfree( pSockAddr ); } if( sd != HB_NO_SOCKET ) { errcode = hb_socketGetError(); hb_socketClose( sd ); } } hb_xfree( pszIpAddr ); } if( errcode == 0 && pFile == NULL ) errcode = hb_socketGetError(); } else errcode = HB_SOCKET_ERR_WRONGADDR; hb_fsSetError( errcode ); if( pError ) { hb_errPutFileName( pError, pszName ); if( pFile == NULL ) { hb_errPutOsCode( pError, errcode ); hb_errPutGenCode( pError, ( HB_ERRCODE ) EG_OPEN ); } } return pFile; }
static HB_ERRCODE sqlite3Open( SQLBASEAREAP pArea ) { sqlite3 * pDb = ( ( SDDCONN * ) pArea->pConnection->pSDDConn )->pDb; sqlite3_stmt * st = NULL; SDDDATA * pSDDData; const char * pszQuery; HB_SIZE nQueryLen; void * hQuery; HB_USHORT uiFields, uiIndex; PHB_ITEM pItemEof, pItem, pName = NULL; HB_ERRCODE errCode; char * szError; HB_BOOL bError; pArea->pSDDData = memset( hb_xgrab( sizeof( SDDDATA ) ), 0, sizeof( SDDDATA ) ); pSDDData = ( SDDDATA * ) pArea->pSDDData; pItem = hb_itemPutC( NULL, pArea->szQuery ); pszQuery = S_HB_ITEMGETSTR( pItem, &hQuery, &nQueryLen ); if( sqlite3_prepare_v2( pDb, pszQuery, ( int ) nQueryLen, &st, NULL ) != SQLITE_OK ) { hb_strfree( hQuery ); hb_itemRelease( pItem ); szError = sqlite3GetError( pDb, &errCode ); hb_errRT_SQLT3DD( EG_OPEN, ESQLDD_INVALIDQUERY, szError, pArea->szQuery, errCode ); sqlite3_finalize( st ); hb_xfree( szError ); return HB_FAILURE; } else { hb_strfree( hQuery ); hb_itemRelease( pItem ); } if( sqlite3_step( st ) != SQLITE_ROW ) { szError = sqlite3GetError( pDb, &errCode ); hb_errRT_SQLT3DD( EG_OPEN, ESQLDD_INVALIDQUERY, szError, pArea->szQuery, errCode ); sqlite3_finalize( st ); hb_xfree( szError ); return HB_FAILURE; } uiFields = ( HB_USHORT ) sqlite3_column_count( st ); SELF_SETFIELDEXTENT( &pArea->area, uiFields ); errCode = 0; bError = HB_FALSE; pItemEof = hb_itemArrayNew( uiFields ); for( uiIndex = 0; uiIndex < uiFields; ++uiIndex ) { DBFIELDINFO dbFieldInfo; memset( &dbFieldInfo, 0, sizeof( dbFieldInfo ) ); pName = S_HB_ITEMPUTSTR( pName, sqlite3_column_name( st, uiIndex ) ); dbFieldInfo.atomName = hb_itemGetCPtr( pName ); dbFieldInfo.uiType = sqlite3DeclType( st, uiIndex ); pItem = hb_arrayGetItemPtr( pItemEof, uiIndex + 1 ); switch( dbFieldInfo.uiType ) { case HB_FT_STRING: { int iSize = sqlite3_column_bytes( st, uiIndex ); char * pStr; dbFieldInfo.uiLen = ( HB_USHORT ) HB_MAX( iSize, 10 ); pStr = ( char * ) hb_xgrab( ( HB_SIZE ) dbFieldInfo.uiLen + 1 ); memset( pStr, ' ', dbFieldInfo.uiLen ); hb_itemPutCLPtr( pItem, pStr, dbFieldInfo.uiLen ); break; } case HB_FT_BLOB: dbFieldInfo.uiLen = 4; hb_itemPutC( pItem, NULL ); break; case HB_FT_INTEGER: dbFieldInfo.uiLen = 8; hb_itemPutNInt( pItem, 0 ); break; case HB_FT_LONG: dbFieldInfo.uiLen = 20; dbFieldInfo.uiDec = ( HB_USHORT ) hb_setGetDecimals(); hb_itemPutNDDec( pItem, 0.0, dbFieldInfo.uiDec ); break; case HB_FT_ANY: dbFieldInfo.uiLen = 6; break; default: bError = HB_TRUE; } if( ! bError ) bError = ( SELF_ADDFIELD( &pArea->area, &dbFieldInfo ) == HB_FAILURE ); if( bError ) break; } hb_itemRelease( pName ); if( bError ) { hb_itemRelease( pItemEof ); sqlite3_finalize( st ); hb_errRT_SQLT3DD( EG_CORRUPTION, ESQLDD_INVALIDFIELD, "Invalid field type", pArea->szQuery, errCode ); return HB_FAILURE; } pArea->ulRecCount = 0; pArea->ulRecMax = SQLDD_ROWSET_INIT; pArea->pRow = ( void ** ) hb_xgrab( SQLDD_ROWSET_INIT * sizeof( void * ) ); pArea->pRowFlags = ( HB_BYTE * ) hb_xgrab( SQLDD_ROWSET_INIT * sizeof( HB_BYTE ) ); pArea->pRow[ 0 ] = pItemEof; pArea->pRowFlags[ 0 ] = SQLDD_FLAG_CACHED; pSDDData->pStmt = st; return HB_SUCCESS; }