Example #1
0
static PHB_FILE s_fileOpen( PHB_FILE_FUNCS pFuncs, const char * pszName,
                            const char * pszDefExt, HB_USHORT uiExFlags,
                            const char * pPaths, PHB_ITEM pError )
{
   PHB_IOUSR pIO = ( PHB_IOUSR ) pFuncs;
   PHB_FILE pFile = NULL;
   PHB_ITEM pFileItm;

   s_pushMethod( pIO, IOUSR_OPEN );
   hb_vmPushString( pszName, strlen( pszName ) );
   if( pszDefExt )
      hb_vmPushString( pszDefExt, strlen( pszDefExt ) );
   else
      hb_vmPushNil();
   hb_vmPushInteger( uiExFlags );
   if( pPaths )
      hb_vmPushString( pPaths, strlen( pPaths ) );
   else
      hb_vmPushNil();
   if( pError )
      hb_vmPush( pError );
   else
      hb_vmPushNil();

   hb_vmDo( 5 );

   pFileItm = hb_stackReturnItem();
   if( ! HB_IS_NIL( pFileItm ) )
      pFile = s_fileNew( pIO, hb_itemNew( pFileItm ) );

   return pFile;
}
Example #2
0
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;
}
Example #3
0
HB_ERRCODE hb_rddCreateTable( const char * szFileName, const char * szDriver,
                              HB_USHORT uiArea, const char * szAlias,
                              HB_BOOL fKeepOpen,
                              const char * szCpId, HB_ULONG ulConnection,
                              PHB_ITEM pStruct, PHB_ITEM pDelim )
{
   char szDriverBuffer[ HB_RDD_MAX_DRIVERNAME_LEN + 1 ];
   DBOPENINFO pInfo;
   HB_ERRCODE errCode;
   HB_USHORT uiPrevArea;
   AREAP pArea;

   if( ! szFileName )
   {
      hb_errRT_DBCMD( EG_ARG, EDBCMD_DBCMDBADPARAMETER, NULL, HB_ERR_FUNCNAME );
      return HB_FAILURE;
   }

   if( szDriver && szDriver[ 0 ] )
   {
      hb_strncpyUpper( szDriverBuffer, szDriver, sizeof( szDriverBuffer ) - 1 );
      szDriver = szDriverBuffer;
   }
   else
      szDriver = hb_rddDefaultDrv( NULL );

   uiPrevArea = ( HB_AREANO ) hb_rddGetCurrentWorkAreaNumber();

   /* 0 means chose first available in hb_rddInsertAreaNode() */
   hb_rddSelectWorkAreaNumber( uiArea );
   if( uiArea )
      hb_rddReleaseCurrentArea();

   /* Create a new WorkArea node */
   if( ! hb_rddInsertAreaNode( szDriver ) )
   {
      hb_rddSelectWorkAreaNumber( uiPrevArea );
      hb_errRT_DBCMD( EG_ARG, EDBCMD_BADPARAMETER, NULL, HB_ERR_FUNCNAME );
      return HB_FAILURE;
   }
   pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer();

   /* Fill pInfo structure */
   pInfo.uiArea = pArea->uiArea;
   pInfo.abName = szFileName;
   pInfo.atomAlias = szAlias;
   pInfo.fShared = HB_FALSE;
   pInfo.fReadonly = HB_FALSE;
   pInfo.cdpId = szCpId ? szCpId : hb_setGetDBCODEPAGE();
   pInfo.ulConnection = ulConnection;
   pInfo.lpdbHeader = NULL;

   if( pDelim && ! HB_IS_NIL( pDelim ) )
      errCode = SELF_INFO( pArea, DBI_SETDELIMITER, pDelim );
   else
      errCode = HB_SUCCESS;

   if( errCode == HB_SUCCESS )
   {
      errCode = SELF_CREATEFIELDS( pArea, pStruct );
      if( errCode == HB_SUCCESS )
         errCode = SELF_CREATE( pArea, &pInfo );
   }

   if( ! fKeepOpen || errCode != HB_SUCCESS )
   {
      hb_rddReleaseCurrentArea();
      hb_rddSelectWorkAreaNumber( uiPrevArea );
   }

   return errCode;
}
Example #4
0
HB_ERRCODE hb_rddOpenTable( const char * szFileName, const char * szDriver,
                            HB_USHORT uiArea, const char * szAlias,
                            HB_BOOL fShared, HB_BOOL fReadonly,
                            const char * szCpId, HB_ULONG ulConnection,
                            PHB_ITEM pStruct, PHB_ITEM pDelim )
{
   char szDriverBuffer[ HB_RDD_MAX_DRIVERNAME_LEN + 1 ];
   DBOPENINFO pInfo;
   HB_ERRCODE errCode;
   AREAP pArea;

   /* uiArea = 0 in hb_rddInsertAreaNode() means chose first
    * available free area, otherwise we should close table in
    * current WA and it should be done before parameter validation
    * RT errors below. This breaks xHarbour like MT code which
    * shares WA between threads so dbUseArea() should be covered
    * by external mutex to make lNewArea MT safe, [druzus]
    */
   if( uiArea )
   {
      hb_rddSelectWorkAreaNumber( uiArea );
      hb_rddReleaseCurrentArea();
   }
   else
      hb_rddSelectFirstAvailable();

   /* Clipper clears NETERR flag before parameter validation, [druzus]
    */
   hb_rddSetNetErr( HB_FALSE );

   /* Now check parameters, first RDD name.
    * Clipper seems to make sth like:
    *    if( szDriver && strlen( szDriver ) > 1 )
    * but I do not think we should replicate it, [druzus]
    */
   if( szDriver && szDriver[ 0 ] )
   {
      hb_strncpyUpper( szDriverBuffer, szDriver, sizeof( szDriverBuffer ) - 1 );
      szDriver = szDriverBuffer;
   }
   else
      szDriver = hb_rddDefaultDrv( NULL );

   /* First try to create new are node and validate RDD name */
   if( ! hb_rddInsertAreaNode( szDriver ) )
   {
      hb_errRT_DBCMD( EG_ARG, EDBCMD_BADPARAMETER, NULL, HB_ERR_FUNCNAME );
      return HB_FAILURE;
   }

   /* Then check if valid file name was given - Clipper allows to use empty
    * ("") file name
    */
   if( ! szFileName )
   {
      hb_rddReleaseCurrentArea();
      hb_errRT_DBCMD( EG_ARG, EDBCMD_USE_BADPARAMETER, NULL, HB_ERR_FUNCNAME );
      return HB_FAILURE;
   }

   pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer();

   /* Fill pInfo structure */
   pInfo.uiArea = pArea->uiArea;
   pInfo.abName = szFileName;
   pInfo.atomAlias = szAlias;
   pInfo.fShared = fShared;
   pInfo.fReadonly = fReadonly;
   pInfo.cdpId = szCpId ? szCpId : hb_setGetDBCODEPAGE();
   pInfo.ulConnection = ulConnection;
   pInfo.lpdbHeader = NULL;

   errCode = pStruct ? SELF_CREATEFIELDS( pArea, pStruct ) : HB_SUCCESS;
   if( errCode == HB_SUCCESS )
   {
      if( pDelim && ! HB_IS_NIL( pDelim ) )
         errCode = SELF_INFO( pArea, DBI_SETDELIMITER, pDelim );
      if( errCode == HB_SUCCESS )
         /* Open file */
         errCode = SELF_OPEN( pArea, &pInfo );
   }

   if( errCode != HB_SUCCESS )
      hb_rddReleaseCurrentArea();

   return errCode;
}
Example #5
0
static void _hb_jsonEncode( PHB_ITEM pValue, PHB_JSON_ENCODE_CTX pCtx,
                            HB_SIZE nLevel, HB_BOOL fEOL )
{
   /* Protection against recursive structures */
   if( ( HB_IS_ARRAY( pValue ) || HB_IS_HASH( pValue ) ) && hb_itemSize( pValue ) > 0 )
   {
      void * id = HB_IS_HASH( pValue ) ? hb_hashId( pValue ) : hb_arrayId( pValue );
      HB_SIZE nIndex;

      for( nIndex = 0; nIndex < nLevel; nIndex++ )
      {
         if( pCtx->pId[ nIndex ] == id )
         {
            if( ! fEOL && pCtx->fHuman )
               _hb_jsonCtxAddIndent( pCtx, nLevel * INDENT_SIZE );
            _hb_jsonCtxAdd( pCtx, "null", 4 );
            return;
         }
      }
      if( nLevel >= pCtx->nAllocId )
      {
         pCtx->nAllocId += 8;
         pCtx->pId = ( void ** ) hb_xrealloc( pCtx->pId, sizeof( void * ) * pCtx->nAllocId );
      }
      pCtx->pId[ nLevel ] = id;
   }

   if( fEOL )
   {
      --pCtx->pHead;
      _hb_jsonCtxAdd( pCtx, pCtx->szEol, pCtx->iEolLen );
   }

   if( HB_IS_STRING( pValue ) )
   {
      const char * szString = hb_itemGetCPtr( pValue );
      HB_SIZE nPos, nPos2, nLen = hb_itemGetCLen( pValue );

      _hb_jsonCtxAdd( pCtx, "\"", 1 );

      nPos = 0;
      while( nPos < nLen )
      {
         nPos2 = nPos;
         while( *( ( const unsigned char * ) szString + nPos2 ) >= ' ' &&
                szString[ nPos2 ] != '\\' && szString[ nPos2 ] != '\"' )
            nPos2++;
         if( nPos2 > nPos )
         {
            _hb_jsonCtxAdd( pCtx, szString + nPos, nPos2 - nPos );
            nPos = nPos2;
            continue;
         }

         switch( szString[ nPos ] )
         {
            case '\\':
               _hb_jsonCtxAdd( pCtx, "\\\\", 2 );
               break;
            case '\"':
               _hb_jsonCtxAdd( pCtx, "\\\"", 2 );
               break;
            case '\b':
               _hb_jsonCtxAdd( pCtx, "\\b", 2 );
               break;
            case '\f':
               _hb_jsonCtxAdd( pCtx, "\\f", 2 );
               break;
            case '\n':
               _hb_jsonCtxAdd( pCtx, "\\n", 2 );
               break;
            case '\r':
               _hb_jsonCtxAdd( pCtx, "\\r", 2 );
               break;
            case '\t':
               _hb_jsonCtxAdd( pCtx, "\\t", 2 );
               break;
            default:
            {
               char buf[ 8 ];
               hb_snprintf( buf, sizeof( buf ), "\\u00%02X", ( unsigned char ) szString[ nPos ] );
               _hb_jsonCtxAdd( pCtx, buf, 6 );
               break;
            }
         }
         nPos++;
      }
      _hb_jsonCtxAdd( pCtx, "\"", 1 );
   }
   else if( HB_IS_NUMINT( pValue ) )
   {
      char buf[ 32 ];

      hb_snprintf( buf, sizeof( buf ), "%" PFHL "d", hb_itemGetNInt( pValue ) );
      _hb_jsonCtxAdd( pCtx, buf, strlen( buf ) );
   }
   else if( HB_IS_NUMERIC( pValue ) )
   {
      char buf[ 64 ];
      int iDec;
      double dblValue = hb_itemGetNDDec( pValue, &iDec );

      hb_snprintf( buf, sizeof( buf ), "%.*f", iDec, dblValue );
      _hb_jsonCtxAdd( pCtx, buf, strlen( buf ) );
   }
   else if( HB_IS_NIL( pValue ) )
   {
      _hb_jsonCtxAdd( pCtx, "null", 4 );
   }
   else if( HB_IS_LOGICAL( pValue ) )
   {
      if( hb_itemGetL( pValue ) )
         _hb_jsonCtxAdd( pCtx, "true", 4 );
      else
         _hb_jsonCtxAdd( pCtx, "false", 5 );

   }
   else if( HB_IS_DATE( pValue ) )
   {
      char szBuffer[ 10 ];

      hb_itemGetDS( pValue, szBuffer + 1 );
      szBuffer[ 0 ] = '\"';
      szBuffer[ 9 ] = '\"';
      _hb_jsonCtxAdd( pCtx, szBuffer, 10 );
   }
   else if( HB_IS_TIMESTAMP( pValue ) )
   {
      char szBuffer[ 19 ];
      hb_itemGetTS( pValue, szBuffer + 1 );
      szBuffer[ 0 ] = '\"';
      szBuffer[ 18 ] = '\"';
      _hb_jsonCtxAdd( pCtx, szBuffer, 19 );
   }
   else if( HB_IS_ARRAY( pValue ) )
   {
      HB_SIZE nLen = hb_itemSize( pValue );

      if( nLen )
      {
         HB_SIZE nIndex;

         if( pCtx->fHuman )
            _hb_jsonCtxAddIndent( pCtx, nLevel * INDENT_SIZE );

         _hb_jsonCtxAdd( pCtx, "[", 1 );

         for( nIndex = 1; nIndex <= nLen; nIndex++ )
         {
            PHB_ITEM pItem = hb_arrayGetItemPtr( pValue, nIndex );

            if( nIndex > 1 )
               _hb_jsonCtxAdd( pCtx, ",", 1 );

            if( pCtx->fHuman )
               _hb_jsonCtxAdd( pCtx, pCtx->szEol, pCtx->iEolLen );

            if( pCtx->fHuman &&
                ! ( ( HB_IS_ARRAY( pItem ) || HB_IS_HASH( pItem ) ) &&
                    hb_itemSize( pItem ) > 0 ) )
               _hb_jsonCtxAddIndent( pCtx, ( nLevel + 1 ) * INDENT_SIZE );

            _hb_jsonEncode( pItem, pCtx, nLevel + 1, HB_FALSE );
         }
         if( pCtx->fHuman )
         {
            _hb_jsonCtxAdd( pCtx, pCtx->szEol, pCtx->iEolLen );
            _hb_jsonCtxAddIndent( pCtx, nLevel * INDENT_SIZE );
         }
         _hb_jsonCtxAdd( pCtx, "]", 1 );
      }
      else
         _hb_jsonCtxAdd( pCtx, "[]", 2 );
   }
   else if( HB_IS_HASH( pValue ) )
   {
      HB_SIZE nLen = hb_hashLen( pValue );

      if( nLen )
      {
         HB_SIZE nIndex;

         if( pCtx->fHuman )
            _hb_jsonCtxAddIndent( pCtx, nLevel * INDENT_SIZE );

         _hb_jsonCtxAdd( pCtx, "{", 1 );

         for( nIndex = 1; nIndex <= nLen; nIndex++ )
         {
            PHB_ITEM pKey = hb_hashGetKeyAt( pValue, nIndex );

            if( HB_IS_STRING( pKey ) )
            {
               PHB_ITEM pItem = hb_hashGetValueAt( pValue, nIndex );
               HB_BOOL fEOL = HB_FALSE;

               if( nIndex > 1 )
                  _hb_jsonCtxAdd( pCtx, ",", 1 );

               if( pCtx->fHuman )
               {
                  _hb_jsonCtxAdd( pCtx, pCtx->szEol, pCtx->iEolLen );
                  _hb_jsonCtxAddIndent( pCtx, ( nLevel + 1 ) * INDENT_SIZE );
               }
               _hb_jsonEncode( pKey, pCtx, nLevel + 1, HB_FALSE );

               if( pCtx->fHuman )
               {
                  _hb_jsonCtxAdd( pCtx, ": ", 2 );
                  fEOL = ( HB_IS_ARRAY( pItem ) || HB_IS_HASH( pItem ) ) && hb_itemSize( pItem ) > 0;
               }
               else
                  _hb_jsonCtxAdd( pCtx, ":", 1 );

               _hb_jsonEncode( pItem, pCtx, nLevel + 1, fEOL );
            }
         }
         if( pCtx->fHuman )
         {
            _hb_jsonCtxAdd( pCtx, pCtx->szEol, pCtx->iEolLen );
            _hb_jsonCtxAddIndent( pCtx, nLevel * INDENT_SIZE );
         }
         _hb_jsonCtxAdd( pCtx, "}", 1 );
      }
      else
         _hb_jsonCtxAdd( pCtx, "{}", 2 );
   }
   else
   {
      /* All unsupported types are replacd by null */
      _hb_jsonCtxAdd( pCtx, "null", 4 );
   }
}
Example #6
0
static void _hb_jsonEncode( PHB_ITEM pValue, PHB_JSON_ENCODE_CTX pCtx,
                            HB_SIZE nLevel, HB_BOOL fEOL, PHB_CODEPAGE cdp )
{
   /* Protection against recursive structures */
   if( ( HB_IS_ARRAY( pValue ) || HB_IS_HASH( pValue ) ) && hb_itemSize( pValue ) > 0 )
   {
      void * id = HB_IS_HASH( pValue ) ? hb_hashId( pValue ) : hb_arrayId( pValue );
      HB_SIZE nIndex;

      for( nIndex = 0; nIndex < nLevel; nIndex++ )
      {
         if( pCtx->pId[ nIndex ] == id )
         {
            if( ! fEOL && pCtx->fHuman )
               _hb_jsonCtxAddIndent( pCtx, nLevel * INDENT_SIZE );
            _hb_jsonCtxAdd( pCtx, "null", 4 );
            return;
         }
      }
      if( nLevel >= pCtx->nAllocId )
      {
         pCtx->nAllocId += 8;
         pCtx->pId = ( void ** ) hb_xrealloc( pCtx->pId, sizeof( void * ) * pCtx->nAllocId );
      }
      pCtx->pId[ nLevel ] = id;
   }

   if( fEOL )
   {
      --pCtx->pHead;
      _hb_jsonCtxAdd( pCtx, pCtx->szEol, pCtx->iEolLen );
   }

   if( HB_IS_STRING( pValue ) )
   {
      HB_SIZE nPos, nLen = hb_itemGetCLen( pValue );
      const char * szString = hb_itemGetCPtr( pValue );
      char buf[ 8 ];

      _hb_jsonCtxAdd( pCtx, "\"", 1 );

      if( cdp )
      {
         HB_WCHAR wc;

         nPos = 0;
         while( HB_CDPCHAR_GET( cdp, szString, nLen, &nPos, &wc ) )
         {
            if( wc >= ' ' && wc < 0x7F && wc != '\\' && wc != '\"' )
            {
               buf[ 0 ] = ( char ) wc;
               _hb_jsonCtxAdd( pCtx, buf, 1 );
               continue;
            }
            switch( wc )
            {
               case '\\':
                  _hb_jsonCtxAdd( pCtx, "\\\\", 2 );
                  break;
               case '\"':
                  _hb_jsonCtxAdd( pCtx, "\\\"", 2 );
                  break;
               case '\b':
                  _hb_jsonCtxAdd( pCtx, "\\b", 2 );
                  break;
               case '\f':
                  _hb_jsonCtxAdd( pCtx, "\\f", 2 );
                  break;
               case '\n':
                  _hb_jsonCtxAdd( pCtx, "\\n", 2 );
                  break;
               case '\r':
                  _hb_jsonCtxAdd( pCtx, "\\r", 2 );
                  break;
               case '\t':
                  _hb_jsonCtxAdd( pCtx, "\\t", 2 );
                  break;
               default:
                  hb_snprintf( buf, sizeof( buf ), "\\u%04X", wc );
                  _hb_jsonCtxAdd( pCtx, buf, 6 );
                  break;
            }
         }
      }
      else
      {
         nPos = 0;
         while( nPos < nLen )
         {
            unsigned char uch = szString[ nPos ];
            HB_SIZE nPos2 = nPos;
            while( uch >= ' ' && uch != '\\' && uch != '\"' )
               uch = szString[ ++nPos2 ];
            if( nPos2 > nPos )
            {
               _hb_jsonCtxAdd( pCtx, szString + nPos, nPos2 - nPos );
               if( nPos2 >= nLen )
                  break;
               nPos = nPos2;
            }

            switch( uch )
            {
               case '\\':
                  _hb_jsonCtxAdd( pCtx, "\\\\", 2 );
                  break;
               case '\"':
                  _hb_jsonCtxAdd( pCtx, "\\\"", 2 );
                  break;
               case '\b':
                  _hb_jsonCtxAdd( pCtx, "\\b", 2 );
                  break;
               case '\f':
                  _hb_jsonCtxAdd( pCtx, "\\f", 2 );
                  break;
               case '\n':
                  _hb_jsonCtxAdd( pCtx, "\\n", 2 );
                  break;
               case '\r':
                  _hb_jsonCtxAdd( pCtx, "\\r", 2 );
                  break;
               case '\t':
                  _hb_jsonCtxAdd( pCtx, "\\t", 2 );
                  break;
               default:
                  hb_snprintf( buf, sizeof( buf ), "\\u00%02X", uch );
                  _hb_jsonCtxAdd( pCtx, buf, 6 );
                  break;
            }
            nPos++;
         }
      }
      _hb_jsonCtxAdd( pCtx, "\"", 1 );
   }
   else if( HB_IS_NUMINT( pValue ) )
   {
      char buf[ 24 ];
      HB_MAXINT nVal = hb_itemGetNInt( pValue );
      HB_BOOL fNeg = nVal < 0;
      int i = 0;

      if( fNeg )
         nVal = -nVal;
      do
         buf[ sizeof( buf ) - ++i ] = ( nVal % 10 ) + '0';
      while( ( nVal /= 10 ) != 0 );
      if( fNeg )
         buf[ sizeof( buf ) - ++i ] = '-';
      _hb_jsonCtxAdd( pCtx, &buf[ sizeof( buf ) - i ], i );
   }
   else if( HB_IS_NUMERIC( pValue ) )
   {
      char buf[ 64 ];
      int iDec;
      double dblValue = hb_itemGetNDDec( pValue, &iDec );

      hb_snprintf( buf, sizeof( buf ), "%.*f", iDec, dblValue );
      _hb_jsonCtxAdd( pCtx, buf, strlen( buf ) );
   }
   else if( HB_IS_NIL( pValue ) )
   {
      _hb_jsonCtxAdd( pCtx, "null", 4 );
   }
   else if( HB_IS_LOGICAL( pValue ) )
   {
      if( hb_itemGetL( pValue ) )
         _hb_jsonCtxAdd( pCtx, "true", 4 );
      else
         _hb_jsonCtxAdd( pCtx, "false", 5 );

   }
   else if( HB_IS_DATE( pValue ) )
   {
      char szBuffer[ 10 ];

      hb_itemGetDS( pValue, szBuffer + 1 );
      szBuffer[ 0 ] = '\"';
      szBuffer[ 9 ] = '\"';
      _hb_jsonCtxAdd( pCtx, szBuffer, 10 );
   }
   else if( HB_IS_TIMESTAMP( pValue ) )
   {
      char szBuffer[ 19 ];
      hb_itemGetTS( pValue, szBuffer + 1 );
      szBuffer[ 0 ] = '\"';
      szBuffer[ 18 ] = '\"';
      _hb_jsonCtxAdd( pCtx, szBuffer, 19 );
   }
   else if( HB_IS_ARRAY( pValue ) )
   {
      HB_SIZE nLen = hb_itemSize( pValue );

      if( nLen )
      {
         HB_SIZE nIndex;

         if( pCtx->fHuman )
            _hb_jsonCtxAddIndent( pCtx, nLevel * INDENT_SIZE );

         _hb_jsonCtxAdd( pCtx, "[", 1 );

         for( nIndex = 1; nIndex <= nLen; nIndex++ )
         {
            PHB_ITEM pItem = hb_arrayGetItemPtr( pValue, nIndex );

            if( nIndex > 1 )
               _hb_jsonCtxAdd( pCtx, ",", 1 );

            if( pCtx->fHuman )
               _hb_jsonCtxAdd( pCtx, pCtx->szEol, pCtx->iEolLen );

            if( pCtx->fHuman &&
                ! ( ( HB_IS_ARRAY( pItem ) || HB_IS_HASH( pItem ) ) &&
                    hb_itemSize( pItem ) > 0 ) )
               _hb_jsonCtxAddIndent( pCtx, ( nLevel + 1 ) * INDENT_SIZE );

            _hb_jsonEncode( pItem, pCtx, nLevel + 1, HB_FALSE, cdp );
         }
         if( pCtx->fHuman )
         {
            _hb_jsonCtxAdd( pCtx, pCtx->szEol, pCtx->iEolLen );
            _hb_jsonCtxAddIndent( pCtx, nLevel * INDENT_SIZE );
         }
         _hb_jsonCtxAdd( pCtx, "]", 1 );
      }
      else
         _hb_jsonCtxAdd( pCtx, "[]", 2 );
   }
   else if( HB_IS_HASH( pValue ) )
   {
      HB_SIZE nLen = hb_hashLen( pValue );

      if( nLen )
      {
         HB_SIZE nIndex;

         if( pCtx->fHuman )
            _hb_jsonCtxAddIndent( pCtx, nLevel * INDENT_SIZE );

         _hb_jsonCtxAdd( pCtx, "{", 1 );

         for( nIndex = 1; nIndex <= nLen; nIndex++ )
         {
            PHB_ITEM pKey = hb_hashGetKeyAt( pValue, nIndex );

            if( HB_IS_STRING( pKey ) )
            {
               PHB_ITEM pItem = hb_hashGetValueAt( pValue, nIndex );

               if( nIndex > 1 )
                  _hb_jsonCtxAdd( pCtx, ",", 1 );

               if( pCtx->fHuman )
               {
                  _hb_jsonCtxAdd( pCtx, pCtx->szEol, pCtx->iEolLen );
                  _hb_jsonCtxAddIndent( pCtx, ( nLevel + 1 ) * INDENT_SIZE );
               }
               _hb_jsonEncode( pKey, pCtx, nLevel + 1, HB_FALSE, cdp );

               if( pCtx->fHuman )
               {
                  _hb_jsonCtxAdd( pCtx, ": ", 2 );
                  fEOL = ( HB_IS_ARRAY( pItem ) || HB_IS_HASH( pItem ) ) && hb_itemSize( pItem ) > 0;
               }
               else
               {
                  _hb_jsonCtxAdd( pCtx, ":", 1 );
                  fEOL = HB_FALSE;
               }

               _hb_jsonEncode( pItem, pCtx, nLevel + 1, fEOL, cdp );
            }
         }
         if( pCtx->fHuman )
         {
            _hb_jsonCtxAdd( pCtx, pCtx->szEol, pCtx->iEolLen );
            _hb_jsonCtxAddIndent( pCtx, nLevel * INDENT_SIZE );
         }
         _hb_jsonCtxAdd( pCtx, "}", 1 );
      }
      else
         _hb_jsonCtxAdd( pCtx, "{}", 2 );
   }
   else
   {
      /* All unsupported types are replacd by null */
      _hb_jsonCtxAdd( pCtx, "null", 4 );
   }
}