示例#1
0
/* update counters for autoinc and rowver fields */
HB_ERRCODE hb_dbTransCounters( LPDBTRANSINFO lpdbTransInfo )
{
   PHB_ITEM pItem = hb_itemNew( NULL );
   HB_USHORT uiCount;

   for( uiCount = 0; uiCount < lpdbTransInfo->uiItemCount; ++uiCount )
   {
      LPDBTRANSITEM lpdbTransItem = &lpdbTransInfo->lpTransItems[ uiCount ];

      if( SELF_FIELDINFO( lpdbTransInfo->lpaSource, lpdbTransItem->uiSource,
                          DBS_COUNTER, pItem ) == HB_SUCCESS &&
          SELF_FIELDINFO( lpdbTransInfo->lpaDest, lpdbTransItem->uiDest,
                          DBS_COUNTER, pItem ) == HB_SUCCESS )
      {
         hb_itemClear( pItem );
         if( SELF_FIELDINFO( lpdbTransInfo->lpaSource, lpdbTransItem->uiSource,
                             DBS_STEP, pItem ) == HB_SUCCESS )
             SELF_FIELDINFO( lpdbTransInfo->lpaDest, lpdbTransItem->uiDest,
                             DBS_STEP, pItem );
      }
      hb_itemClear( pItem );
   }
   hb_itemRelease( pItem );

   return HB_SUCCESS;
}
示例#2
0
/* This function releases all memory occupied by a memvar variable and
 * assigns NIL value - it releases variables created in current
 * procedure only.
 * The scope of released variables are specified using passed name's mask
 */
static void hb_memvarReleaseWithMask( const char * szMask, HB_BOOL bInclude )
{
   HB_STACK_TLS_PRELOAD
   HB_SIZE nBase, nCount;
   PHB_DYNS pDynVar;
   PHB_ITEM pMemvar;

   HB_TRACE( HB_TR_DEBUG, ( "hb_memvarReleaseWithMask(%s, %d)", szMask, ( int ) bInclude ) );

   nCount = hb_stackGetPrivateStack()->count;
   nBase = hb_stackBaseItem()->item.asSymbol.stackstate->nPrivateBase;
   while( nCount-- > nBase )
   {
      pDynVar = hb_stackGetPrivateStack()->stack[ nCount ].pDynSym;
      /* reset current value to NIL - the overriden variables will be
       * visible after exit from current procedure
       */
      pMemvar = hb_dynsymGetMemvar( pDynVar );
      if( pMemvar )
      {
         HB_BOOL fMatch = hb_strMatchCaseWildExact( pDynVar->pSymbol->szName, szMask );
         if( bInclude ? fMatch : ! fMatch )
            hb_itemClear( pMemvar );
      }
   }
}
示例#3
0
PHB_ITEM hb_oleAxControlNew( PHB_ITEM pItem, HWND hWnd )
{
   IUnknown *  pUnk  = NULL;
   IDispatch * pDisp = NULL;

   if( pItem )
      hb_itemClear( pItem );

   if( ! hb_oleAxInit() || ! s_pAtlAxGetControl )
   {
      hb_oleSetError( S_OK );
      hb_errRT_OLE( EG_UNSUPPORTED, 1010, 0, "ActiveX not initialized", HB_ERR_FUNCNAME );
   }
   else
   {
      HRESULT lOleError = ( *s_pAtlAxGetControl )( hWnd, &pUnk );

      if( lOleError == S_OK )
      {
         lOleError = HB_VTBL( pUnk )->QueryInterface( HB_THIS_( pUnk ) HB_ID_REF( IID_IDispatch ), ( void ** ) ( void * ) &pDisp );

         if( lOleError == S_OK )
            pItem = hb_oleItemPut( pItem, pDisp );

         HB_VTBL( pUnk )->Release( HB_THIS( pUnk ) );
      }

      hb_oleSetError( lOleError );

      if( lOleError != S_OK )
         hb_errRT_OLE( EG_ARG, 1011, ( HB_ERRCODE ) lOleError, NULL, HB_ERR_FUNCNAME );
   }

   return pItem;
}
示例#4
0
/*
 * Obtain the current value of a field.
 */
HB_ERRCODE hb_rddGetFieldValue( PHB_ITEM pItem, PHB_SYMB pFieldSymbol )
{
   HB_ERRCODE errCode;

   HB_TRACE( HB_TR_DEBUG, ( "hb_rddGetFieldValue(%p, %p)", pItem, pFieldSymbol ) );

   errCode = hb_rddFieldGet( pItem, pFieldSymbol );

   if( errCode == HB_FAILURE && hb_vmRequestQuery() == 0 )
   {
      /*
       * generate an error with retry possibility
       * (user created error handler can make this field accessible)
       */
      PHB_ITEM pError;

      pError = hb_errRT_New( ES_ERROR, NULL, EG_NOVAR, EDBCMD_NOVAR,
                             NULL, pFieldSymbol->szName, 0, EF_CANRETRY );
      hb_itemClear( pItem );

      while( hb_errLaunch( pError ) == E_RETRY )
      {
         errCode = hb_rddFieldGet( pItem, pFieldSymbol );

         if( errCode == HB_SUCCESS || hb_vmRequestQuery() != 0 )
            break;
      }
      hb_itemRelease( pError );
   }

   return errCode;
}
示例#5
0
void hb_rddsqlSetError( HB_ERRCODE errCode, const char * szError, const char * szQuery, PHB_ITEM pItem, unsigned long ulAffectedRows )
{
   s_errCode = errCode;

   if( s_szError )
   {
      hb_xfree( s_szError );
      s_szError = NULL;
   }
   if( szError )
      s_szError = hb_strdup( szError );

   if( s_szQuery )
   {
      hb_xfree( s_szQuery );
      s_szQuery = NULL;
   }
   if( szQuery )
      s_szQuery = hb_strdup( szQuery );

   if( pItem )
      hb_itemCopy( s_pItemNewID, pItem );
   else
      hb_itemClear( s_pItemNewID );

   s_ulAffectedRows = ulAffectedRows;
}
示例#6
0
/*
 * This function decreases the number of references to passed global value.
 * If it is the last reference then this value is deleted.
 */
void hb_memvarValueDecRef( PHB_ITEM pMemvar )
{
   HB_TRACE( HB_TR_DEBUG, ( "hb_memvarValueDecRef(%p)", pMemvar ) );

   if( hb_xRefDec( pMemvar ) )
   {
      if( HB_IS_COMPLEX( pMemvar ) )
         hb_itemClear( pMemvar );
      hb_xfree( pMemvar );
   }
}
示例#7
0
文件: tcpio.c 项目: jiangxilong/core
static HB_BOOL s_fileConfigure( PHB_FILE pFile, int iIndex, PHB_ITEM pValue )
{
   switch( iIndex )
   {
      case HB_VF_TIMEOUT:
      {
         HB_MAXINT timeout = pFile->timeout;

         if( HB_IS_NUMERIC( pValue ) )
            pFile->timeout = hb_itemGetNInt( pValue );
         hb_itemPutNInt( pValue, timeout );
         return HB_TRUE;
      }
      case HB_VF_SHUTDOWN:
      {
         HB_SOCKET sd = hb_sockexGetHandle( pFile->sock );

         if( HB_IS_NUMERIC( pValue ) && sd != HB_NO_SOCKET )
         {
            switch( hb_itemGetNI( pValue ) )
            {
               case FO_READ:
                  hb_socketShutdown( sd, HB_SOCKET_SHUT_RD );
                  break;
               case FO_WRITE:
                  hb_socketShutdown( sd, HB_SOCKET_SHUT_WR );
                  break;
               case FO_READWRITE:
                  hb_socketShutdown( sd, HB_SOCKET_SHUT_RDWR );
                  break;
            }
         }
         hb_itemClear( pValue );
         return HB_TRUE;
      }
      case HB_VF_RDHANDLE:
      case HB_VF_WRHANDLE:
         hb_itemPutNInt( pValue, ( HB_NHANDLE ) hb_sockexGetHandle( pFile->sock ) );
         return HB_TRUE;
   }

   return HB_FALSE;
}
示例#8
0
static BOOL xwt_gtk_menu_getall( PXWT_WIDGET widget, PHB_ITEM pProps )
{
   HB_ITEM hbValue;
   XWT_GTK_MENU *wSelf = (PXWT_GTK_MENU) widget->widget_data;
   const char *szPropVal;

   hbValue.type = HB_IT_NIL;
   
   if ( xwt_gtk_base_getall( widget, pProps ) )
   {   
      szPropVal = gtk_label_get_label( GTK_LABEL( wSelf->label ));
      hb_itemPutCRawStatic( &hbValue, (char*)szPropVal, strlen( szPropVal ) );
      hb_hashAddChar( pProps, "text", &hbValue );
      
      hb_itemClear( &hbValue );
      
      return TRUE;
   }

   return FALSE;
}
示例#9
0
/* This function releases all memory occupied by a memvar variable
 * It also restores the value that was hidden if there is another
 * PRIVATE variable with the same name.
 */
static void hb_memvarRelease( PHB_ITEM pMemvar )
{
   HB_TRACE( HB_TR_DEBUG, ( "hb_memvarRelease(%p)", pMemvar ) );

   if( HB_IS_STRING( pMemvar ) )
   {
      PHB_DYNS pDynSymbol = hb_memvarFindSymbol( pMemvar->item.asString.value,
                                                 pMemvar->item.asString.length );

      if( pDynSymbol && hb_dynsymGetMemvar( pDynSymbol ) )
      {
         HB_STACK_TLS_PRELOAD
         HB_SIZE nBase = hb_stackGetPrivateStack()->count;

         /* Find the variable with a requested name that is currently visible
          * Start from the top of the stack.
          */
         while( nBase > 0 )
         {
            if( pDynSymbol == hb_stackGetPrivateStack()->stack[ --nBase ].pDynSym )
            {
               /* reset current value to NIL - the overriden variables will be
                * visible after exit from current procedure
                */
               pMemvar = hb_dynsymGetMemvar( pDynSymbol );
               if( pMemvar )
                  hb_itemClear( pMemvar );
               return;
            }
         }

         /* No match found for PRIVATEs - it's PUBLIC so let's remove it.
          */
         hb_memvarDetachDynSym( pDynSymbol, NULL );
      }
   }
   else
      hb_errRT_BASE( EG_ARG, 3008, NULL, "RELEASE", HB_ERR_ARGS_BASEPARAMS );
}
示例#10
0
BOOL xwt_gtk_align_getall( PXWT_WIDGET widget, PHB_ITEM pProps )
{
   HB_ITEM hbValue;
   XWT_GTK_ALIGN* wMain = (XWT_GTK_ALIGN*) widget->widget_data;

   hbValue.type = HB_IT_NIL;

   if (! xwt_gtk_base_getall( widget, pProps ) )
   {
      return FALSE;
   }

   // Vertical alignment
   switch( wMain->iVAlign )
   {
      case XWT_ALIGN_TOP: hb_itemPutC( &hbValue, "top"); break;
      case XWT_ALIGN_CENTER: hb_itemPutC( &hbValue, "center"); break;
      case XWT_ALIGN_BOTTOM: hb_itemPutC( &hbValue, "bottom"); break;
      default: return FALSE;
   }
   hb_hashAddChar( pProps, "valign", &hbValue );

   // Horizontal alignment
   switch( wMain->iHAlign )
   {
      case XWT_ALIGN_LEFT: hb_itemPutC( &hbValue, "left"); break;
      case XWT_ALIGN_CENTER: hb_itemPutC( &hbValue, "center"); break;
      case XWT_ALIGN_RIGHT: hb_itemPutC( &hbValue, "right"); break;
      default: return FALSE;
   }
   hb_hashAddChar( pProps, "align", &hbValue );


   // clear the item in case it is a complex value;
   // to be removed after developement stage if this is not the case
   hb_itemClear( &hbValue );
   return TRUE;
}
示例#11
0
void hb_gcGripDrop( HB_ITEM_PTR pItem )
{

   HB_TRACE( HB_TR_DEBUG, ( "hb_gcGripDrop(%p)", pItem ) );

   if( hb_gc_bReleaseAll )
   {
      HB_TRACE( HB_TR_DEBUG, ( "Aborted - hb_gcGripDrop(%p)", pItem ) );
      return;
   }

   if( pItem )
   {
      HB_GARBAGE_PTR pAlloc = ( HB_GARBAGE_PTR ) pItem;
      --pAlloc;

      HB_TRACE( HB_TR_INFO, ( "Drop %p %p", pItem, pAlloc ) );

      if( pAlloc->pFunc == hb_gcGripRelease )
      {
         if( HB_IS_COMPLEX( pItem ) )
         {
            hb_itemClear( pItem );    /* clear value stored in this item */
         }
      }

      HB_CRITICAL_LOCK( hb_garbageAllocMutex );

      hb_gcUnlink( &s_pLockedBlock, pAlloc );

      HB_CRITICAL_UNLOCK( hb_garbageAllocMutex );

      HB_GARBAGE_FREE( pAlloc );
   }

}
示例#12
0
void hb_memvarGetValue( PHB_ITEM pItem, PHB_SYMB pMemvarSymb )
{
   HB_TRACE( HB_TR_DEBUG, ( "hb_memvarGetValue(%p, %p)", pItem, pMemvarSymb ) );

   if( hb_memvarGet( pItem, pMemvarSymb ) == HB_FAILURE )
   {
      /* Generate an error with retry possibility
       * (user created error handler can create this variable)
       */
      PHB_ITEM pError;

      pError = hb_errRT_New( ES_ERROR, NULL, EG_NOVAR, 1003,
                             NULL, pMemvarSymb->szName, 0, EF_CANRETRY );
      hb_itemClear( pItem );

      while( hb_errLaunch( pError ) == E_RETRY )
      {
         if( hb_memvarGet( pItem, pMemvarSymb ) == HB_SUCCESS )
            break;
      }

      hb_errRelease( pError );
   }
}
示例#13
0
/*
 * Obtain the current value of a field.
 */
static HB_ERRCODE hb_delimGetValue( DELIMAREAP pArea, USHORT uiIndex, PHB_ITEM pItem )
{
   LPFIELD pField;

   HB_TRACE(HB_TR_DEBUG, ("hb_delimGetValue(%p, %hu, %p)", pArea, uiIndex, pItem));

   --uiIndex;
   pField = pArea->lpFields + uiIndex;
   switch( pField->uiType )
   {
      case HB_FT_STRING:
#ifndef HB_CDP_SUPPORT_OFF
         if( pArea->cdPage != hb_cdppage() )
         {
            char * pVal = ( char * ) hb_xgrab( pField->uiLen + 1 );
            memcpy( pVal, pArea->pRecord + pArea->pFieldOffset[ uiIndex ], pField->uiLen );
            pVal[ pField->uiLen ] = '\0';
            hb_cdpnTranslate( pVal, pArea->cdPage, hb_cdppage(), pField->uiLen );
            hb_itemPutCPtr( pItem, pVal, pField->uiLen );
         }
         else
#endif
         {
            hb_itemPutCL( pItem, ( char * ) pArea->pRecord + pArea->pFieldOffset[ uiIndex ],
                          pField->uiLen );
         }
         break;

      case HB_FT_LOGICAL:
         switch( pArea->pRecord[ pArea->pFieldOffset[ uiIndex ] ] )
         {
            case 'T':
            case 't':
            case 'Y':
            case 'y':
               hb_itemPutL( pItem, TRUE );
               break;
            default:
               hb_itemPutL( pItem, FALSE );
               break;
         }
         break;

      case HB_FT_DATE:
         hb_itemPutDS( pItem, ( char * ) pArea->pRecord + pArea->pFieldOffset[ uiIndex ] );
         break;

      case HB_FT_LONG:
         {
            HB_LONG lVal;
            double dVal;
            BOOL fDbl;

            fDbl = hb_strnToNum( (const char *) pArea->pRecord + pArea->pFieldOffset[ uiIndex ],
                                 pField->uiLen, &lVal, &dVal );


            if( pField->uiDec )
            {
               hb_itemPutNDLen( pItem, fDbl ? dVal : ( double ) lVal,
                                ( int ) ( pField->uiLen - pField->uiDec - 1 ),
                                ( int ) pField->uiDec );
            }
            else if( fDbl )
            {
               hb_itemPutNDLen( pItem, dVal, ( int ) pField->uiLen, 0 );
            }
            else
            {
               hb_itemPutNIntLen( pItem, lVal, ( int ) pField->uiLen );
            }
         }
         break;

      case HB_FT_MEMO:
         hb_itemPutC( pItem, "" );
         break;

      case HB_FT_NONE:
         hb_itemClear( pItem );
         break;

      default:
      {
         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, EDBF_DATATYPE );
         SELF_ERROR( ( AREAP ) pArea, pError );
         hb_itemRelease( pError );
         return HB_FAILURE;
      }
   }

   return HB_SUCCESS;
}
示例#14
0
static HB_ERRCODE sqlbaseCreate( SQLBASEAREAP pArea, LPDBOPENINFO pOpenInfo )
{
   PHB_ITEM  pItemEof, pItem;
   HB_USHORT uiCount;
   HB_BOOL   bError;

   pArea->ulConnection = pOpenInfo->ulConnection ? pOpenInfo->ulConnection : s_ulConnectionCurrent;

   if( pArea->ulConnection > s_ulConnectionCount ||
       ( pArea->ulConnection && ! s_pConnection[ pArea->ulConnection - 1 ] ) )
   {
      hb_errRT_SQLBASE( EG_OPEN, ESQLDD_NOTCONNECTED, "Not connected", NULL );
      return HB_FAILURE;
   }

   if( pArea->ulConnection )
   {
      pArea->pConnection = s_pConnection[ pArea->ulConnection - 1 ];
      pArea->pConnection->uiAreaCount++;
      pArea->pSDD = pArea->pConnection->pSDD;
   }
   else
      pArea->pSDD = &sddNull;

   pItemEof = hb_itemArrayNew( pArea->area.uiFieldCount );

   bError = HB_FALSE;
   for( uiCount = 0; uiCount < pArea->area.uiFieldCount; uiCount++ )
   {
      LPFIELD pField = pArea->area.lpFields + uiCount;

      switch( pField->uiType )
      {
         case HB_FT_STRING:
         {
            char * pStr;

            pStr = ( char * ) hb_xgrab( pField->uiLen + 1 );
            memset( pStr, ' ', pField->uiLen );
            pStr[ pField->uiLen ] = '\0';

            pItem = hb_itemPutCL( NULL, pStr, pField->uiLen );
            hb_xfree( pStr );
            break;
         }

         case HB_FT_MEMO:
            pItem = hb_itemPutC( NULL, NULL );
            break;

         case HB_FT_INTEGER:
            if( pField->uiDec )
               pItem = hb_itemPutND( NULL, 0.0 );
            else
               pItem = hb_itemPutNI( NULL, 0 );
            break;

         case HB_FT_LONG:
            if( pField->uiDec )
               pItem = hb_itemPutND( NULL, 0.0 );
            else
               pItem = hb_itemPutNL( NULL, 0 );
            break;

         case HB_FT_FLOAT:
            pItem = hb_itemPutND( NULL, 0.0 );
            break;

         case HB_FT_DOUBLE:
            pItem = hb_itemPutND( NULL, 0.0 );
            break;

         case HB_FT_DATE:
            pItem = hb_itemPutDS( NULL, NULL );
            break;

         case HB_FT_LOGICAL:
            pItem = hb_itemPutL( NULL, HB_FALSE );
            break;

         default:
            pItem  = hb_itemNew( NULL );
            bError = HB_TRUE;
            break;
      }

      hb_arraySetForward( pItemEof, uiCount + 1, pItem );
      hb_itemRelease( pItem );

      if( bError )
         break;
   }

   if( bError )
   {
      hb_itemClear( pItemEof );
      hb_itemRelease( pItemEof );
      hb_errRT_SQLBASE( EG_CORRUPTION, ESQLDD_INVALIDFIELD, "Invalid field type", NULL );
      SELF_CLOSE( ( AREAP ) pArea );
      return HB_FAILURE;
   }

   pArea->ulRecCount = 0;

   pArea->pRow      = ( void ** ) hb_xalloc( SQLDD_ROWSET_RESIZE * sizeof( void * ) );
   pArea->pRowFlags = ( HB_BYTE * ) hb_xalloc( SQLDD_ROWSET_RESIZE * sizeof( HB_BYTE ) );
   pArea->ulRecMax  = SQLDD_ROWSET_RESIZE;

   *( pArea->pRow )      = pItemEof;
   pArea->pRowFlags[ 0 ] = SQLDD_FLAG_CACHED;
   pArea->fFetched       = HB_TRUE;

   if( SUPER_CREATE( ( AREAP ) pArea, pOpenInfo ) != HB_SUCCESS )
   {
      SELF_CLOSE( ( AREAP ) pArea );
      return HB_FAILURE;
   }

   return SELF_GOTOP( ( AREAP ) pArea );
}
示例#15
0
static HB_ERRCODE ocilibOpen( SQLBASEAREAP pArea )
{
   OCI_Statement * st = OCI_StatementCreate( ( ( SDDCONN * ) pArea->pConnection->pSDDConn )->pConn );
   OCI_Resultset * rs;
   SDDDATA *       pSDDData;
   void *          hQuery;
   HB_USHORT       uiFields, uiIndex;
   PHB_ITEM        pItemEof, pItem;
   HB_ERRCODE      errCode;
   char *          szError;
   HB_BOOL         bError;

   pArea->pSDDData = memset( hb_xgrab( sizeof( SDDDATA ) ), 0, sizeof( SDDDATA ) );
   pSDDData        = ( SDDDATA * ) pArea->pSDDData;

   if( ! st )
   {
      szError = ocilibGetError( &errCode );
      hb_errRT_OCIDD( EG_OPEN, ESQLDD_STMTALLOC, szError, pArea->szQuery, errCode );
      hb_xfree( szError );
      return HB_FAILURE;
   }

   pItem = hb_itemPutC( NULL, pArea->szQuery );

   if( ! OCI_ExecuteStmt( st, M_HB_ITEMGETSTR( pItem, &hQuery, NULL ) ) )
   {
      hb_strfree( hQuery );
      hb_itemRelease( pItem );
      szError = ocilibGetError( &errCode );
      OCI_StatementFree( st );
      hb_errRT_OCIDD( EG_OPEN, ESQLDD_INVALIDQUERY, szError, pArea->szQuery, errCode );
      hb_xfree( szError );
      return HB_FAILURE;
   }
   else
   {
      hb_strfree( hQuery );
      hb_itemRelease( pItem );
   }

   rs = OCI_GetResultset( st );

   uiFields = ( HB_USHORT ) OCI_GetColumnCount( rs );
   SELF_SETFIELDEXTENT( ( AREAP ) pArea, uiFields );

   pItemEof = hb_itemArrayNew( uiFields );
   pItem    = hb_itemNew( NULL );

#if 0
   HB_TRACE( HB_TR_ALWAYS, ( "fieldcount=%d", iNameLen ) );
#endif

   errCode = 0;
   bError  = HB_FALSE;
   for( uiIndex = 0; uiIndex < uiFields; ++uiIndex )
   {
      DBFIELDINFO pFieldInfo;

      PHB_ITEM pName;

      OCI_Column * col = OCI_GetColumn( rs, uiIndex + 1 );

      unsigned int uiDataType;
      unsigned int uiSize;
      int          iDec;
      HB_BOOL      bNullable;

      if( ! col )
      {
         hb_itemRelease( pItemEof );
         hb_itemRelease( pItem );
         szError = ocilibGetError( NULL );
         OCI_StatementFree( st );
         hb_errRT_OCIDD( EG_OPEN, ESQLDD_STMTDESCR + 1001, szError, pArea->szQuery, 0 );
         hb_xfree( szError );
         return HB_FAILURE;
      }

      pName = D_HB_ITEMPUTSTR( NULL, OCI_ColumnGetName( col ) );
      pFieldInfo.atomName = hb_itemGetCPtr( pName );

      uiDataType = OCI_ColumnGetType( col );
      uiSize     = OCI_ColumnGetSize( col );
      iDec       = OCI_ColumnGetPrecision( col );
      bNullable  = ( HB_BOOL ) OCI_ColumnGetNullable( col );

      if( bNullable )
         pFieldInfo.uiFlags |= HB_FF_NULLABLE;

      pFieldInfo.uiLen = ( HB_USHORT ) uiSize;
      pFieldInfo.uiDec = ( HB_USHORT ) iDec;

#if 0
      HB_TRACE( HB_TR_ALWAYS, ( "field: name=%s type=%d len=%d dec=%d nullable=%d %d %d %d %d", pFieldInfo.atomName, uiDataType, uiSize, iDec, bNullable, OCI_ColumnGetScale( col ), OCI_ColumnGetPrecision( col ), OCI_ColumnGetFractionalPrecision( col ), OCI_ColumnGetLeadingPrecision( col ) ) );
#endif

      switch( uiDataType )
      {
         case OCI_CDT_TEXT:
            pFieldInfo.uiType = HB_FT_STRING;
            break;

         case OCI_CDT_NUMERIC:
            pFieldInfo.uiType = HB_FT_LONG;
            /* For plain 'NUMERIC', precision is zero and scale is -127 */
            if( OCI_ColumnGetPrecision( col ) > 0 )
               pFieldInfo.uiLen = ( HB_USHORT ) OCI_ColumnGetPrecision( col );
            if( OCI_ColumnGetScale( col ) >= 0 )
               pFieldInfo.uiDec = ( HB_USHORT ) OCI_ColumnGetScale( col );
            else
               pFieldInfo.uiDec = ( HB_USHORT ) hb_setGetDecimals();
            break;

         case OCI_CDT_LONG:
            pFieldInfo.uiType = HB_FT_VARLENGTH;
            break;

         case OCI_CDT_RAW:
            pFieldInfo.uiType = HB_FT_BLOB;
            break;

         case OCI_CDT_DATETIME:
         case OCI_CDT_TIMESTAMP:
         case OCI_CDT_INTERVAL:
            pFieldInfo.uiType = HB_FT_TIME;
            break;

         default:
#if 0
            HB_TRACE( HB_TR_ALWAYS, ( "new sql type=%d", uiDataType ) );
#endif
            bError  = HB_TRUE;
            errCode = ( HB_ERRCODE ) uiDataType;
            pFieldInfo.uiType = 0;
            pFieldInfo.uiType = HB_FT_STRING;
            break;
      }

      if( ! bError )
      {
         switch( pFieldInfo.uiType )
         {
            case HB_FT_STRING:
            {
               char * pStr = ( char * ) hb_xgrab( ( HB_SIZE ) pFieldInfo.uiLen + 1 );
               memset( pStr, ' ', pFieldInfo.uiLen );
               pStr[ pFieldInfo.uiLen ] = '\0';

               hb_itemPutCLPtr( pItem, pStr, pFieldInfo.uiLen );
               break;
            }
            case HB_FT_MEMO:
            case HB_FT_VARLENGTH:
            case HB_FT_BLOB:
               hb_itemPutC( pItem, NULL );
               break;

            case HB_FT_INTEGER:
               hb_itemPutNI( pItem, 0 );
               break;

            case HB_FT_LONG:
               if( pFieldInfo.uiDec == 0 )
                  hb_itemPutNLLen( pItem, 0, pFieldInfo.uiLen );
               else
                  hb_itemPutNDLen( pItem, 0.0, pFieldInfo.uiLen, pFieldInfo.uiDec );
               break;

            case HB_FT_DOUBLE:
               hb_itemPutNDLen( pItem, 0.0, pFieldInfo.uiLen, pFieldInfo.uiDec );
               break;

            case HB_FT_LOGICAL:
               hb_itemPutL( pItem, HB_FALSE );
               break;

            case HB_FT_DATE:
               hb_itemPutDL( pItem, 0 );
               break;

            case HB_FT_TIME:
            case HB_FT_TIMESTAMP:
               hb_itemPutTDT( pItem, 0, 0 );
               break;

            default:
               hb_itemClear( pItem );
               bError = HB_TRUE;
         }

         hb_arraySetForward( pItemEof, uiIndex + 1, pItem );

         if( ! bError )
            bError = ( SELF_ADDFIELD( ( AREAP ) pArea, &pFieldInfo ) == HB_FAILURE );
      }

      hb_itemRelease( pName );

      if( bError )
         break;
   }

   hb_itemRelease( pItem );

   if( bError )
   {
      hb_itemRelease( pItemEof );
      OCI_StatementFree( st );
      hb_errRT_OCIDD( 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 * ) );
   memset( pArea->pRow, 0, SQLDD_ROWSET_INIT * sizeof( void * ) );
   pArea->pRowFlags = ( HB_BYTE * ) hb_xgrab( SQLDD_ROWSET_INIT * sizeof( HB_BYTE ) );
   memset( pArea->pRowFlags, 0, SQLDD_ROWSET_INIT * sizeof( HB_BYTE ) );

   pArea->pRow[ 0 ]      = pItemEof;
   pArea->pRowFlags[ 0 ] = SQLDD_FLAG_CACHED;

   pSDDData->pStmt = st;
   return HB_SUCCESS;
}
示例#16
0
文件: garbage.c 项目: JamesLinus/core
static HB_GARBAGE_FUNC( hb_gcGripRelease )
{
   if( HB_IS_COMPLEX( ( PHB_ITEM ) Cargo ) )
      hb_itemClear( ( PHB_ITEM ) Cargo );
}
示例#17
0
BOOL xwt_gtk_base_getall( PXWT_WIDGET widget, PHB_ITEM pRet )
{
   HB_ITEM hbValue;
   XWT_GTK_BASE *wSelf = (PXWT_GTK_BASE) widget->widget_data;
   GtkWidget *wTop = wSelf->top_widget( widget );

   hbValue.type = HB_IT_NIL;

   hb_hashAddChar( pRet, "x", hb_itemPutNI( &hbValue, wSelf->x ) );
   hb_hashAddChar( pRet, "y", hb_itemPutNI( &hbValue, wSelf->y ) );
   hb_hashAddChar( pRet, "width", hb_itemPutNI( &hbValue, wSelf->width ) );
   hb_hashAddChar( pRet, "height", hb_itemPutNI( &hbValue, wSelf->height ) );
   hb_hashAddChar( pRet, "id", hb_itemPutNI( &hbValue, wSelf->nId ) );
   hb_hashAddChar( pRet, "broadcast", hb_itemPutL( &hbValue, wSelf->bBroadcast ) );
   if (!wSelf->fgColor )
   {
   hb_hashAddChar( pRet, "fgcolor", hb_itemPutC( &hbValue, "" ) ) ;
   }
   else
   {
      hb_hashAddChar( pRet, "fgcolor", hb_itemPutCPtr( &hbValue, wSelf->fgColor, 7 ) );
   }
   if(wSelf->baseColor  != NULL )
   {
      hb_hashAddChar( pRet, "basecolor", hb_itemPutCPtr( &hbValue, wSelf->baseColor, 7) );
   }
   else
   {
      hb_hashAddChar( pRet, "basecolor", hb_itemPutC( &hbValue, "" ) );
   }
   if( wSelf->textColor != NULL )
   {
      hb_hashAddChar( pRet, "textcolor", hb_itemPutCPtr( &hbValue, wSelf->textColor, 7 ) );   
   }
   else
   {
      hb_hashAddChar( pRet, "textcolor", hb_itemPutC( &hbValue, "" ) );      
   }
   if(  wSelf->bgColor  )
   {
      hb_hashAddChar( pRet, "bgcolor", hb_itemPutCPtr( &hbValue, wSelf->bgColor, 7 ) );   
   }
   else
   {
      hb_hashAddChar( pRet, "bgcolor", hb_itemPutC( &hbValue,  ""  ) );   
   }
   if ( GTK_WIDGET_VISIBLE(wTop) )
   {
      hb_itemPutCRawStatic( &hbValue, "visible", 7 );
   }
   else
   {
      hb_itemPutCRawStatic( &hbValue, "hidden", 6 );
   }
   hb_hashAddChar( pRet, "visibility", &hbValue );
   hb_hashAddChar( pRet, "focus", hb_itemPutL( &hbValue, gtk_widget_is_focus( wTop )) );

   hb_itemClear( &hbValue );

   return TRUE;
}
示例#18
0
static HB_ERRCODE mysqlGetValue( SQLBASEAREAP pArea, HB_USHORT uiIndex, PHB_ITEM pItem )
{
   SDDDATA * pSDDData = ( SDDDATA * ) pArea->pSDDData;
   LPFIELD   pField;
   char *    pValue;
   char      szBuffer[ 64 ];
   HB_BOOL   bError;
   PHB_ITEM  pError;
   HB_SIZE   ulLen;

   bError = HB_FALSE;
   uiIndex--;
   pField = pArea->area.lpFields + uiIndex;

   pValue = pSDDData->pNatRecord[ uiIndex ];
   ulLen  = pSDDData->pNatLength[ uiIndex ];

   /* NULL => NIL (?) */
   if( ! pValue )
   {
      hb_itemClear( pItem );
      return HB_SUCCESS;
   }

   switch( pField->uiType )
   {
      case HB_FT_STRING:
      {
#if 0
         char * pStr;

         /* Expand strings to field length */
         pStr = ( char * ) hb_xgrab( pField->uiLen + 1 );
         if( pValue )
            memcpy( pStr, pValue, ulLen );

         if( ( HB_SIZE ) pField->uiLen > ulLen )
            memset( pStr + ulLen, ' ', pField->uiLen - ulLen );

         pStr[ pField->uiLen ] = '\0';
         hb_itemPutCRaw( pItem, pStr, pField->uiLen );
#else
         /* Do not expand strings */
         if( pValue )
            hb_itemPutCL( pItem, pValue, ulLen );
         else
            hb_itemPutC( pItem, NULL );
#endif
         break;
      }

      case HB_FT_MEMO:
         if( pValue )
            hb_itemPutCL( pItem, pValue, ulLen );
         else
            hb_itemPutC( pItem, NULL );

         hb_itemSetCMemo( pItem );
         break;

      case HB_FT_INTEGER:
      case HB_FT_LONG:
      case HB_FT_DOUBLE:
         if( pValue )
         {
            hb_strncpy( szBuffer, pValue, sizeof( szBuffer ) - 1 );

            if( pField->uiDec )
            {
               hb_itemPutNDLen( pItem, atof( szBuffer ),
                                ( int ) pField->uiLen - ( ( int ) pField->uiDec + 1 ),
                                ( int ) pField->uiDec );
            }
            else
               hb_itemPutNLLen( pItem, atol( szBuffer ), ( int ) pField->uiLen );
         }
         else
         {
            if( pField->uiDec )
               hb_itemPutNDLen( pItem, 0.0,
                                ( int ) pField->uiLen - ( ( int ) pField->uiDec + 1 ),
                                ( int ) pField->uiDec );
            else
               hb_itemPutNLLen( pItem, 0, ( int ) pField->uiLen );
         }
         break;

      case HB_FT_DATE:
      {
         char szDate[ 9 ];

         szDate[ 0 ] = pValue[ 0 ];
         szDate[ 1 ] = pValue[ 1 ];
         szDate[ 2 ] = pValue[ 2 ];
         szDate[ 3 ] = pValue[ 3 ];
         szDate[ 4 ] = pValue[ 5 ];
         szDate[ 5 ] = pValue[ 6 ];
         szDate[ 6 ] = pValue[ 8 ];
         szDate[ 7 ] = pValue[ 9 ];
         szDate[ 8 ] = '\0';
         hb_itemPutDS( pItem, szDate );
         break;
      }

      case HB_FT_TIMESTAMP:
      {
         char szTimeStamp[ 15 ];

         szTimeStamp[ 0 ] = pValue[ 0 ];
         szTimeStamp[ 1 ] = pValue[ 1 ];
         szTimeStamp[ 2 ] = pValue[ 2 ];
         szTimeStamp[ 3 ] = pValue[ 3 ];
         szTimeStamp[ 4 ] = pValue[ 5 ];
         szTimeStamp[ 5 ] = pValue[ 6 ];
         szTimeStamp[ 6 ] = pValue[ 8 ];
         szTimeStamp[ 7 ] = pValue[ 9 ];

         szTimeStamp[ 8 ]  = pValue[ 11 ];
         szTimeStamp[ 9 ]  = pValue[ 12 ];
         szTimeStamp[ 10 ] = pValue[ 14 ];
         szTimeStamp[ 11 ] = pValue[ 15 ];
         szTimeStamp[ 12 ] = pValue[ 17 ];
         szTimeStamp[ 13 ] = pValue[ 18 ];
         szTimeStamp[ 14 ] = '\0';
         hb_itemPutTS( pItem, szTimeStamp );
         break;
      }

      case HB_FT_TIME:
      {
         char szTimeStamp[ 15 ];

         szTimeStamp[ 0 ] = '0';
         szTimeStamp[ 1 ] = '0';
         szTimeStamp[ 2 ] = '0';
         szTimeStamp[ 3 ] = '0';
         szTimeStamp[ 4 ] = '0';
         szTimeStamp[ 5 ] = '0';
         szTimeStamp[ 6 ] = '0';
         szTimeStamp[ 7 ] = '0';

         szTimeStamp[ 8 ]  = pValue[ 0 ];
         szTimeStamp[ 9 ]  = pValue[ 1 ];
         szTimeStamp[ 10 ] = pValue[ 3 ];
         szTimeStamp[ 11 ] = pValue[ 4 ];
         szTimeStamp[ 12 ] = pValue[ 6 ];
         szTimeStamp[ 13 ] = pValue[ 7 ];
         szTimeStamp[ 14 ] = '\0';
         hb_itemPutTS( pItem, szTimeStamp );
         break;
      }

      default:
         bError = HB_TRUE;
         break;
   }

   if( bError )
   {
      pError = hb_errNew();
      hb_errPutGenCode( pError, EG_DATATYPE );
      hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_DATATYPE ) );
      hb_errPutSubCode( pError, EDBF_DATATYPE );
      SELF_ERROR( ( AREAP ) pArea, pError );
      hb_itemRelease( pError );
      return HB_FAILURE;
   }
   return HB_SUCCESS;
}
示例#19
0
文件: sddpg.c 项目: ggargano/hbtest2
static HB_ERRCODE pgsqlOpen( SQLBASEAREAP pArea )
{
   PGconn *       pConn = ( ( SDDCONN * ) pArea->pConnection->pSDDConn )->pConn;
   SDDDATA *      pSDDData;
   PGresult *     pResult;
   ExecStatusType status;
   PHB_ITEM       pItemEof, pItem;
   HB_USHORT      uiFields, uiCount;
   HB_BOOL        bError;
   DBFIELDINFO    pFieldInfo;

   pArea->pSDDData = memset( hb_xgrab( sizeof( SDDDATA ) ), 0, sizeof( SDDDATA ) );
   pSDDData        = ( SDDDATA * ) pArea->pSDDData;

   pResult = PQexec( pConn, pArea->szQuery );
   if( ! pResult )
   {
      hb_errRT_PostgreSQLDD( EG_OPEN, ESQLDD_LOWMEMORY, "Query failed", NULL, 0 );  /* Low memory, etc */
      return HB_FAILURE;
   }

   status = PQresultStatus( pResult );
   if( status != PGRES_TUPLES_OK && status != PGRES_COMMAND_OK )
   {
      hb_errRT_PostgreSQLDD( EG_OPEN, ESQLDD_INVALIDQUERY, PQresultErrorMessage( pResult ), pArea->szQuery, ( HB_ERRCODE ) status );
      PQclear( pResult );
      return HB_FAILURE;
   }

   pSDDData->pResult = pResult;

   uiFields = ( HB_USHORT ) PQnfields( pResult );
   SELF_SETFIELDEXTENT( ( AREAP ) pArea, uiFields );

   pItemEof = hb_itemArrayNew( uiFields );
   pItem    = hb_itemNew( NULL );

   bError = HB_FALSE;
   for( uiCount = 0; uiCount < uiFields; uiCount++ )
   {
      pFieldInfo.atomName = PQfname( pResult, ( int ) uiCount );
      pFieldInfo.uiDec    = 0;

      switch( PQftype( pResult, ( int ) uiCount ) )
      {
         case BPCHAROID:
         case VARCHAROID:
            pFieldInfo.uiType = HB_FT_STRING;
            pFieldInfo.uiLen  = ( HB_USHORT ) PQfmod( pResult, uiCount ) - 4;
            break;

         case TEXTOID:
            pFieldInfo.uiType = HB_FT_MEMO;
            pFieldInfo.uiLen  = 10;
            break;

         case NUMERICOID:
            pFieldInfo.uiType = HB_FT_DOUBLE;
            pFieldInfo.uiLen  = ( PQfmod( pResult, uiCount ) - 4 ) >> 16;
            pFieldInfo.uiDec  = ( PQfmod( pResult, uiCount ) - 4 ) & 0xFFFF;
            break;

         case INT2OID:
            pFieldInfo.uiType = HB_FT_INTEGER;
            pFieldInfo.uiLen  = 6;
            break;

         case INT4OID:
            pFieldInfo.uiType = HB_FT_INTEGER;
            pFieldInfo.uiLen  = 11;
            break;

         case INT8OID:
         case OIDOID:
            pFieldInfo.uiType = HB_FT_LONG;
            pFieldInfo.uiLen  = 20;
            break;

         case FLOAT4OID:
         case FLOAT8OID:
         case CASHOID:  /* TODO: ??? */
            pFieldInfo.uiType = HB_FT_DOUBLE;
            pFieldInfo.uiLen  = 16;
            pFieldInfo.uiDec  = 2;   /* TODO: hb_set.SET_DECIMALS ??? */
            break;

         case BOOLOID:
            pFieldInfo.uiType = HB_FT_LOGICAL;
            pFieldInfo.uiLen  = 1;
            break;

         case DATEOID:
            pFieldInfo.uiType = HB_FT_DATE;
            pFieldInfo.uiLen  = 8;
            break;

         case INETOID:
            pFieldInfo.uiType = HB_FT_STRING;
            pFieldInfo.uiLen  = 29;
            break;

         case CIDROID:
            pFieldInfo.uiType = HB_FT_STRING;
            pFieldInfo.uiLen  = 32;
            break;

         case MACADDROID:
            pFieldInfo.uiType = HB_FT_STRING;
            pFieldInfo.uiLen  = 17;
            break;

         case BITOID:
         case VARBITOID:
            pFieldInfo.uiType = HB_FT_STRING;
            pFieldInfo.uiLen  = ( HB_USHORT ) PQfsize( pResult, uiCount );
            break;

         case TIMEOID:
            pFieldInfo.uiType = HB_FT_STRING;
            pFieldInfo.uiLen  = 12;
            break;

         case TIMESTAMPOID:
            pFieldInfo.uiType = HB_FT_STRING;
            pFieldInfo.uiLen  = 23;
            break;

         case TIMETZOID:
            pFieldInfo.uiType = HB_FT_STRING;
            pFieldInfo.uiLen  = 15;
            break;

         case TIMESTAMPTZOID:
            pFieldInfo.uiType = HB_FT_STRING;
            pFieldInfo.uiLen  = 26;
            break;

         case NAMEOID:
            pFieldInfo.uiType = HB_FT_STRING;
            pFieldInfo.uiLen  = 63;
            break;

         case BYTEAOID:
            pFieldInfo.uiType = HB_FT_STRING;
            pFieldInfo.uiLen  = 0;
            break;

         default:
            pFieldInfo.uiType = 0;
            pFieldInfo.uiLen  = 0;
            bError = HB_TRUE;
            break;
      }
      /* 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 )
      {
         switch( pFieldInfo.uiType )
         {
            case HB_FT_STRING:
            {
               char * pStr;

               pStr = ( char * ) hb_xgrab( pFieldInfo.uiLen + 1 );
               memset( pStr, ' ', pFieldInfo.uiLen );
               pStr[ pFieldInfo.uiLen ] = '\0';

               hb_itemPutCL( pItem, pStr, pFieldInfo.uiLen );
               hb_xfree( pStr );
               break;
            }
            case HB_FT_MEMO:
               hb_itemPutC( pItem, NULL );
               hb_itemSetCMemo( pItem );
               break;

            case HB_FT_INTEGER:
               hb_itemPutNI( pItem, 0 );
               break;

            case HB_FT_LONG:
               hb_itemPutNL( pItem, 0 );
               break;

            case HB_FT_DOUBLE:
               hb_itemPutND( pItem, 0.0 );
               break;

            case HB_FT_LOGICAL:
               hb_itemPutL( pItem, HB_FALSE );
               break;

            case HB_FT_DATE:
               hb_itemPutDS( pItem, NULL );
               break;

            default:
               hb_itemClear( pItem );
               bError = HB_TRUE;
               break;
         }

         hb_arraySetForward( pItemEof, uiCount + 1, pItem );

/*       if( pFieldInfo.uiType == HB_IT_DOUBLE || pFieldInfo.uiType == HB_IT_INTEGER )
            pFieldInfo.uiType = HB_IT_LONG;
 */

         if( ! bError )
            bError = ( SELF_ADDFIELD( ( AREAP ) pArea, &pFieldInfo ) == HB_FAILURE );
      }

      if( bError )
         break;
   }

   hb_itemRelease( pItem );

   if( bError )
   {
      hb_itemClear( pItemEof );
      hb_itemRelease( pItemEof );
      hb_errRT_PostgreSQLDD( EG_CORRUPTION, ESQLDD_INVALIDFIELD, "Invalid field type", pArea->szQuery, 0 );
      return HB_FAILURE;
   }

   pArea->ulRecCount = ( HB_ULONG ) PQntuples( pResult );

   pArea->pRow      = ( void ** ) hb_xgrab( ( pArea->ulRecCount + 1 ) * sizeof( void * ) );
   pArea->pRowFlags = ( HB_BYTE * ) hb_xgrab( ( pArea->ulRecCount + 1 ) * sizeof( HB_BYTE ) );
   memset( pArea->pRowFlags, 0, ( pArea->ulRecCount + 1 ) * sizeof( HB_BYTE ) );

   *pArea->pRow = pItemEof;
   pArea->pRowFlags[ 0 ] = SQLDD_FLAG_CACHED;
   pArea->fFetched       = HB_TRUE;

   return HB_SUCCESS;
}
示例#20
0
void hb_memvarGetRefer( PHB_ITEM pItem, PHB_SYMB pMemvarSymb )
{
   PHB_DYNS pDyn;

   HB_TRACE( HB_TR_DEBUG, ( "hb_memvarGetRefer(%p, %p)", pItem, pMemvarSymb ) );

   pDyn = ( PHB_DYNS ) pMemvarSymb->pDynSym;
   if( pDyn )
   {
      PHB_ITEM pMemvar;

      pMemvar = hb_dynsymGetMemvar( pDyn );

      HB_TRACE( HB_TR_INFO, ( "Memvar item (%p)(%s) referenced", pMemvar, pMemvarSymb->szName ) );

      if( pMemvar )
      {
         if( HB_IS_BYREF( pMemvar ) && ! HB_IS_ENUM( pMemvar ) )
            hb_itemCopy( pItem, pMemvar );
         else
         {
            /* value is already created */
            pItem->type = HB_IT_BYREF | HB_IT_MEMVAR;
            pItem->item.asMemvar.value = pMemvar;
            hb_xRefInc( pMemvar );
         }
      }
      else
      {
         /* Generate an error with retry possibility
          * (user created error handler can make this variable accessible)
          */
         PHB_ITEM pError;

         pError = hb_errRT_New( ES_ERROR, NULL, EG_NOVAR, 1003,
                                NULL, pMemvarSymb->szName, 0, EF_CANRETRY );
         hb_itemClear( pItem );

         while( hb_errLaunch( pError ) == E_RETRY )
         {
            pMemvar = hb_dynsymGetMemvar( pDyn );
            if( pMemvar )
            {
               if( HB_IS_BYREF( pMemvar ) && ! HB_IS_ENUM( pMemvar ) )
                  hb_itemCopy( pItem, pMemvar );
               else
               {
                  /* value is already created */
                  pItem->type = HB_IT_BYREF | HB_IT_MEMVAR;
                  pItem->item.asMemvar.value = pMemvar;
                  hb_xRefInc( pMemvar );
               }
               break;
            }
         }
         hb_errRelease( pError );
      }
   }
   else
      hb_errInternal( HB_EI_MVBADSYMBOL, NULL, pMemvarSymb->szName, NULL );
}
示例#21
0
//-----------------------------------------------------------------------=
                                                        // ÚÄ1ra Col.a Pintar
                                                        // ³
static void near PaintTheLine( HDC hDC, RECT * rct, WORD wIndex,
                               PCLIPVAR pAtext, PCLIPVAR pAsizes,
                               HPEN hWhitePen, HPEN hGrayPen, BOOL bTree,
                               PCLIPVAR pAJustify, WORD wPressed,
                               BOOL bHeader, WORD nStyle,
                               WORD wFocus, BOOL bFocused,
                               PCLIPVAR pTextColor, PCLIPVAR pBkColor,
                               WORD wRowPos, WORD nHeightCtrl,
                               LONG nClrLine, BOOL bFooter,
                               BOOL bSelect, PCLIPVAR pFont,
                               BOOL bDrawFocusRect )
{
   RECT box, wholebox, rctadj;
   int iMaxRight = rct->right;

   WORD wLenJust = 0 ;
   #ifndef __HARBOUR__
   WORD wLen     = _VARRAYLEN( pAtext );
   CLV_WORD lJustify;
   #else
   WORD wLen     = hb_arrayLen( pAtext );
   PHB_ITEM uElem = hb_itemNew( NULL );
   #endif
   WORD wType, wcLen;
   LONG lValue;
   char * cValue;
   HPEN hOldPen, hPen;
   BITMAP bmp;
   WORD wRow, wCol;
   LONG lColor ;
   HBRUSH hBrush;
   LONG lTextColorOld = -1 ; // CeSoTech
   LONG lBkColorOld   = -1 ; // CeSoTech
   PCLIPVAR pEvalOld ;
   HFONT hFont ; // CeSoTech
   WORD wAlign ; // CeSoTech

   // CeSoTech
   LONG nClrLineC = ( nStyle == 2 || nStyle == 6 || nStyle == 8 ||
                      nStyle == 10 ) ? GetSysColor( COLOR_BTNSHADOW ) : 0 ;

   // CeSoTech
   if ( nClrLine >= 0 )   // Desde Clipper manda color especifico linea
      nClrLineC = nClrLine ;

   if ( ! bDrawHeaders )
      bHeader = FALSE ;

   if ( bFooter )
      bHeader = TRUE ; //-> Para que lo pinte con similar aspecto

   //CeSoTech
   // Si es un estilo sin separadores horizontales, pintar uno mas arriba
   //CeSoTech para que que bien completa el area !!!
   if ( ! (bHeader) && (nStyle == 0 || nStyle == 5 || nStyle == 6 ||
                        nStyle == 9 || nStyle == 10) )
      rct->top--       ;

   wholebox.top    = rct->top+1;
   wholebox.left   = rct->left;
   wholebox.bottom = rct->bottom;
   wholebox.right  = rct->right;

   rct->right  = 0;

   box.top    = rct->top ;
   box.bottom = rct->bottom - 1;

   if( !wIndex | wIndex > wLen )
       wIndex = 1;

   if ( pAJustify )
      #ifndef __HARBOUR__
         wLenJust = _VARRAYLEN( pAJustify );
      #else
         wLenJust = hb_arrayLen( pAJustify );
      #endif

   while( wIndex <= wLen )
   {

        rct->left   = rct->right;

        rct->right  = ( wIndex == wLen ? iMaxRight
                                      : rct->left + GetInt( pAsizes, wIndex ) );
        // CeSoTech // Cuando estoy estoy en la ultima celda, NO pintar hasta
                    // el final si no existe ajuste de ultima columna.
        if ( ( wIndex == wLen ) && ( ! bAdjLastCol )  )
        {
           rct->right  = rct->left + GetInt( pAsizes, wIndex ) +(bHeader ? 1: 0) ;
           if ( !bAdjBrowse )
              wholebox.right = rct->right ; // Tambien ajusto el borde focus

        }
        // CeSoTech //


        wAlign = HA_LEFT | VA_CENTER ;  // Alineacion por defecto
        wcLen = 0;
        ///////// INICIO Toma de datos celda !!!

        #ifndef __HARBOUR__
           if ( wIndex <= wLenJust )
           {
             _cAt( pAJustify, wIndex, 0xFFFF, ( PCLIPVAR ) &lJustify );
             wAlign = lJustify.wWord ;
           }
           _cAt( pAtext, wIndex, 0xFFFF, ++_tos );
           wType = _tos->wType;
           if ( wType & NUMERIC )
              lValue = (LONG) _tos->pPointer1;
           if ( wType & CHARACTER )
           {
              cValue = _VSTR( _tos );
              wcLen = _tos->w2;
           }
        #else

           if ( wIndex <= wLenJust )
           {
              hb_arrayGet( pAJustify, wIndex, uElem );
              if ( ( hb_itemType( uElem ) & LOGICAL ) && hb_itemGetL( uElem ) )
                 wAlign = HA_RIGHT | VA_CENTER ;
              else
                 wAlign = hb_itemGetNL( uElem );

			        hb_itemClear( uElem );
           }

           // uElem.type = HB_IT_NIL;
           hb_arrayGet( pAtext, wIndex, uElem );
           wType = hb_itemType( uElem );
           if ( wType & NUMERIC )
              lValue = hb_itemGetNL( uElem );
           if ( wType & CHARACTER )
           {
//              cValue = hb_itemGetC( uElem );
				cValue = hb_itemGetCPtr( uElem );
                wcLen = strlen( cValue );
           }

        #endif
        ///////// FIN Toma de datos celda !!!



        if( wFocus > 0 && wIndex != wFocus )
        {
           #ifndef __HARBOUR__
              _tos--;
           #endif

           if( rct->right >= iMaxRight )
           {
               wIndex = wLen + 1;   // ya no pintamos m s
           }
           else
              ++wIndex;
           continue;
        }

        if( bTree ||
            (GetInt( pAsizes, wIndex ) > 0) ) //Si NO es columna oculta (x Freeze)
        {                                     //(Es lo mismo no hacer esto,
                                              // pero es para evitar hacer trabajar
                                              // al codigo sin sentido !!! )

           if( (wType & NUMERIC) && bTree )
           {
               if( lValue )
               {
                  FillRect( hDC, rct, hBrush = CreateSolidBrush( GetPixel( hDC, rct->left, rct->top ) ) );
                  DrawMasked( hDC, (HBITMAP) lValue, rct->top, rct->left );
                  DeleteObject( hBrush );
               }

           }
           else  // Si es Numerico Bmp no Tree, o , es Character !!!!
           {

               if ( pBkColor )  // Bloque de Color Fondo Celda
               {
                  _PutSym( _SymEval );
                  _xPushM( pBkColor );
                  _PutLN( wRowPos );
                  _PutLN( wIndex );
                  _PutLN( bFooter ? 2 : ( bHeader ? 1 : ( bSelect ? 3 : 0 ) ) );
                  _xEval( 3 ) ;
                  if ( _parinfo( -1 ) & NUMERIC )
                    lBkColorOld = SetBkColor( hDC, _parnl( - 1 ) ) ;
               }

               if( pTextColor ) // Bloque de Color Texto Celda
               {
                  _PutSym( _SymEval );
                  _xPushM( pTextColor );
                  _PutLN( wRowPos );
                  _PutLN( wIndex );
                  _PutLN( bFooter ? 2 : ( bHeader ? 1 : ( bSelect ? 3 : 0 ) ) );
                  _xEval( 3 ) ;
                  if ( _parinfo( -1 ) & NUMERIC )
                    lTextColorOld = SetTextColor( hDC, _parnl( - 1 ) ) ;
               }

               hFont = 0 ;
               if( pFont )      // Bloque de Font Celda
               {
                  _PutSym( _SymEval );
                  _xPushM( pFont );
                  _PutLN( wRowPos );
                  _PutLN( wIndex );
                  _PutLN( bFooter ? 2 : ( bHeader ? 1 : ( bSelect ? 3 : 0 ) ) );
                  _xEval( 3 ) ;
                  if ( _parinfo( -1 ) & NUMERIC )
                     hFont = (HFONT) _parnl( - 1 ) ;
               }


               /////// CeSoTech ///////
               if (!bHeader) rct->top ++;


               if( wType & NUMERIC )   // Es un BitMap
               {
                  FW_DrawBitmapCenter( hDC, (HBITMAP) lValue, rct, nStyle, bSelect );
               }
               else                    // Es una Cadena
               {
                  FW_DrawText( hDC, rct,
                               ( wType & CHARACTER ) ? cValue : "",
                               wAlign, wcLen, hFont, bHeader ) ;
               }


               /////// CeSoTech restauracion de colores //////
               if ( lTextColorOld >= 0 )
               {
                  SetTextColor( hDC, lTextColorOld ) ;
                  lTextColorOld = -1 ;
               }
               if ( lBkColorOld >= 0 )
               {
                  SetBkColor( hDC, lBkColorOld ) ;
                  lBkColorOld = -1 ;
               }


               /// CeSoTech ///
               // Si hay modalidad ajustar el Browse y no hay ajuste de ultima
               // columna, deber‚ pintar hasta el final hasta cubrir toda
               // el area, hasta llegar a la derecha del control. (Col.Ficticia)
               if ( bAdjBrowse && wIndex == wLen && !bAdjLastCol &&
                    rct->right <= iMaxRight )
               {
                  rctadj.top    = rct->top;
                  rctadj.left   = rct->right ;
                  rctadj.bottom = rct->bottom;
                  rctadj.right  = wholebox.right  ;

                  if ( nStyle == 3 )
                     rctadj.top--;

                  if ( wFocus == 0 )  // Si No es CellStyle (Pinto hasta final)
                     ExtTextOut( hDC, 0, rct->top, ETO_OPAQUE, &rctadj, "", 0, 0 );

                  if ( bHeader && nStyle==3 ) // Pinto Bordes Header Falso
                   {
                      rctadj.right  = wholebox.right - 2  ;
                      rctadj.bottom = rctadj.bottom - 2 ;
                      WndDrawBox( hDC, &rctadj, hWhitePen, hGrayPen );
                      rctadj.bottom++  ;
                      rctadj.right++  ;
                      WndDrawBox( hDC, &rctadj, hWhitePen, GetStockObject( BLACK_PEN ) );

                      if ( bFooter ) // Si es Footer (Linea Negra de Arriba Foot)
                      {
                        hPen = GetStockObject( BLACK_PEN );
                        hOldPen = SelectObject( hDC, hPen );
                        MoveTo( hDC, rctadj.left-1, rctadj.top-1 );
                        LineTo( hDC, rctadj.right+1, rctadj.top-1 );
                        SelectObject( hDC, hOldPen );
                      }

                  }

               }
               /// CeSoTech Fin ///

               if (!bHeader) rct->top --;
           }

           box.left   = rct->left;

           box.right  = ( wIndex < wLen && rct->right <= iMaxRight ?
                                                        rct->right - 1 :
                                                        iMaxRight - 1 );

           // CeSoTech // El Borde derecho de Box de la ultima columna,
                       // no estirarlo cuando no exista ajuste de ultima columna
                       // PERO cuando nLineStyle (nStyle) es 7/8 (Lineas Horiz)
                       // queda anti-estetico cortar los renglones, cuando no hay
                       // ajuste ult.col. y hay ajuste de browse. Por ello
                       // se verificara que para cortar el borde no se de esta
                       // condicion.
           if ( ( wIndex == wLen ) && ( ! bAdjLastCol ) )
           {
              if (! (!bHeader && (nStyle==7 || nStyle==8) && !bAdjLastCol && bAdjBrowse) )
               box.right  = rct->left + GetInt( pAsizes, wIndex ) - 1 ;
           }
           // CeSoTech //



           if( ! bTree )
           {
              if( wPressed && ( wIndex == wPressed ) )
              {
                WndDrawBox( hDC, &box, hGrayPen, hWhitePen );
              }
              else
/////////////  if(!bHeader)
               if(!bHeader || (bHeader && nStyle!=3) )
               {
                  switch( nStyle )
                  {
                     case 0:
                        break;
                     case 1:
                    //  hOldPen = SelectObject( hDC, GetStockObject( BLACK_PEN ) );
                        hPen = CreatePen(PS_SOLID, 0, nClrLineC );
                        hOldPen = SelectObject( hDC, hPen);
                        MoveTo( hDC, box.left, box.bottom+1 );
                        LineTo( hDC, box.left, box.top );
                        LineTo( hDC, box.right+1, box.top );
                        LineTo( hDC, box.right+1,  box.bottom+1 );
                        LineTo( hDC, box.left, box.bottom+1 );
                        SelectObject( hDC, hOldPen );
                        DeleteObject( hPen);
                        break;
                     case 2:
                        hPen = CreatePen(PS_SOLID, 0, nClrLineC );
                        hOldPen = SelectObject( hDC, hPen);
                        MoveTo( hDC, box.left, box.bottom+1 );
                        LineTo( hDC, box.left, box.top );
                        LineTo( hDC, box.right+1, box.top );
                        LineTo( hDC, box.right+1,  box.bottom+1 );
                        LineTo( hDC, box.left, box.bottom+1 );
                        SelectObject( hDC, hOldPen );
                        DeleteObject( hPen);
                        break;
                     case 3:
                        WndDrawBox( hDC, &box, hWhitePen, hGrayPen );
                        break;
                     case 4:
                        box.bottom ++;
                        box.right ++;
                        FrameDot( hDC, &box );
                        box.bottom --;
                        box.right --;
                        break;
                     case 7:
                     case 8:
                        hPen = CreatePen(PS_SOLID, 0, nClrLineC );
                        hOldPen = SelectObject( hDC, hPen);
                        MoveTo( hDC, box.left, box.top );
                        LineTo( hDC, box.right+1, box.top );
                        MoveTo( hDC, box.right+1,  box.bottom+1 );
                        LineTo( hDC, box.left, box.bottom+1 );
                        SelectObject( hDC, hOldPen );
                        DeleteObject( hPen);
                        break;
                     case 5:
                     case 6:
                     case 9:
                     case 10:
                        hPen = CreatePen(PS_SOLID, 0, nClrLineC);
                        hOldPen = SelectObject( hDC, hPen);
                        if (box.left>1)
                        {
                           MoveTo( hDC, box.left, box.bottom+1 );
                           LineTo( hDC, box.left, box.top );
                        }
                        MoveTo( hDC, box.right+1, box.top );

                        if ( bDrawFooters && nStyle >= 9 )
                        {
                        LineTo( hDC, box.right+1,
                                     nHeightCtrl - (wFooterHeight+1) ) ;
                        } else {
                          LineTo( hDC, box.right+1,
                                     nStyle < 9 ? box.bottom+1 : nHeightCtrl );
                        }

                        SelectObject( hDC, hOldPen );
                        DeleteObject( hPen);
                        break;
                  }
               }
               else  // Box para Headers !!!
               {
                  box.left ++;

                  // CeSoTech
                  if ( bFooter ) // Linea negra sobre el Footer
                  {
                    hPen = GetStockObject( BLACK_PEN );
                    hOldPen = SelectObject( hDC, hPen );
                    MoveTo( hDC, box.left-1, box.top-1 );
                    LineTo( hDC, box.right+1, box.top-1 );
                    SelectObject( hDC, hOldPen );
                  }

                  box.right--  ;
                  box.bottom-- ;
                  WndDrawBox( hDC, &box, hWhitePen, hGrayPen );
                  box.bottom++  ;
                  box.right++  ;
                  WndDrawBox( hDC, &box, hWhitePen, GetStockObject( BLACK_PEN ) );

                  box.left --;

               }
           }
           else
           {
              if( ! ( wType & NUMERIC ) )
              {
                 box.left -= 16;
              }
           }

          // CeSoTech if( bFocused && wFocus > 0 && wIndex == wFocus )
           if( bDrawFocusRect && bFocused && wFocus > 0 &&
               wIndex == wFocus && nStyle != 3)
           {
            rct->left++;
            rct->top++;
            DrawFocusRect( hDC, rct );
            rct->left--;
            rct->top--;
           }

        }

        #ifndef __HARBOUR__
           _tos--;
        #endif

        if( rct->right >= iMaxRight )
        {
            wIndex = wLen + 1;   // ya no pintamos m s
        }
        else
           ++wIndex;


   }

   if (bDrawFocusRect && !bTree && bFocused && wFocus==0 && nStyle!=3) // CeSoTech
      DrawFocusRect( hDC, &wholebox );

  hb_itemRelease( uElem );
}
示例#22
0
文件: core.c 项目: NaldoDj/core
static HB_ERRCODE odbcOpen( SQLBASEAREAP pArea )
{
   SDDCONN *   pSDDConn = ( SDDCONN * ) pArea->pConnection->pSDDConn;
   SDDDATA *   pSDDData;
   O_HB_CHAR * pchQuery;
   SQLHSTMT    hStmt;
   SQLSMALLINT iNameLen;
   PHB_ITEM    pItemEof, pItem;
   HB_BOOL     bError;
   HB_USHORT   uiFields, uiIndex;
   HB_ERRCODE  errCode;
   char *      szError;
   SQLRETURN   result;

   pArea->pSDDData = memset( hb_xgrab( sizeof( SDDDATA ) ), 0, sizeof( SDDDATA ) );
   pSDDData        = ( SDDDATA * ) pArea->pSDDData;

#if ODBCVER >= 0x0300
   if( ! SQL_SUCCEEDED( SQLAllocHandle( SQL_HANDLE_STMT, pSDDConn->hConn, &hStmt ) ) )
#else
   if( ! SQL_SUCCEEDED( SQLAllocStmt( pSDDConn->hConn, &hStmt ) ) )
#endif
   {
      szError = odbcGetError( pSDDConn->hEnv, pSDDConn->hConn, SQL_NULL_HSTMT, &errCode );
      hb_errRT_ODBCDD( EG_OPEN, ESQLDD_STMTALLOC, szError, pArea->szQuery, errCode );
      hb_xfree( szError );
      return HB_FAILURE;
   }

   pchQuery = O_HB_CHARDUP( pArea->szQuery );
   result = SQLExecDirect( hStmt,
                           ( SQLTCHAR * ) HB_UNCONST( pchQuery ),
                           ( SQLINTEGER ) O_HB_STRLEN( pchQuery ) );
   hb_xfree( pchQuery );

   if( ! SQL_SUCCEEDED( result ) )
   {
      szError = odbcGetError( pSDDConn->hEnv, pSDDConn->hConn, hStmt, &errCode );
#if ODBCVER >= 0x0300
      SQLFreeHandle( SQL_HANDLE_STMT, hStmt );
#else
      SQLFreeStmt( hStmt, SQL_DROP );
#endif
      hb_errRT_ODBCDD( EG_OPEN, ESQLDD_INVALIDQUERY, szError, pArea->szQuery, errCode );
      hb_xfree( szError );
      return HB_FAILURE;
   }

   if( ! SQL_SUCCEEDED( SQLNumResultCols( hStmt, &iNameLen ) ) )
   {
      szError = odbcGetError( pSDDConn->hEnv, pSDDConn->hConn, hStmt, &errCode );
#if ODBCVER >= 0x0300
      SQLFreeHandle( SQL_HANDLE_STMT, hStmt );
#else
      SQLFreeStmt( hStmt, SQL_DROP );
#endif
      hb_errRT_ODBCDD( EG_OPEN, ESQLDD_STMTDESCR + 1000, szError, pArea->szQuery, errCode );
      hb_xfree( szError );
      return HB_FAILURE;
   }

   uiFields = ( HB_USHORT ) iNameLen;
   SELF_SETFIELDEXTENT( &pArea->area, uiFields );

   pItemEof = hb_itemArrayNew( uiFields );
   pItem = hb_itemNew( NULL );

#if 0
   HB_TRACE( HB_TR_ALWAYS, ( "fieldcount=%d", iNameLen ) );
#endif

   errCode = 0;
   bError  = HB_FALSE;
   for( uiIndex = 0; uiIndex < uiFields; uiIndex++ )
   {
      DBFIELDINFO dbFieldInfo;
      char *      pszName;
      SQLTCHAR    cName[ 256 ];
      SQLULEN     uiSize;
      SQLSMALLINT iDataType, iDec, iNull;

      if( ! SQL_SUCCEEDED( SQLDescribeCol( hStmt, ( SQLSMALLINT ) uiIndex + 1,
                           cName, HB_SIZEOFARRAY( cName ),
                           &iNameLen, &iDataType, &uiSize, &iDec, &iNull ) ) )
      {
         hb_itemRelease( pItemEof );
         hb_itemRelease( pItem );
         szError = odbcGetError( pSDDConn->hEnv, pSDDConn->hConn, hStmt, NULL );
#if ODBCVER >= 0x0300
         SQLFreeHandle( SQL_HANDLE_STMT, hStmt );
#else
         SQLFreeStmt( hStmt, SQL_DROP );
#endif
         hb_errRT_ODBCDD( EG_OPEN, ESQLDD_STMTDESCR + 1001, szError, pArea->szQuery, 0 );
         hb_xfree( szError );
         return HB_FAILURE;
      }

      memset( &dbFieldInfo, 0, sizeof( dbFieldInfo ) );

      dbFieldInfo.atomName = pszName = O_HB_OSSTRDUP( ( O_HB_CHAR * ) cName );

      /*
         We do mapping of many SQL types to one Harbour field type here, so, we need store
         real SQL type in uiTypeExtended. SQL types are signed, so, HB_USHORT type casting
         is a little hackish. We need to remember use this casting also in expressions like
         this:
            if( pField->uiTypeExtended == ( HB_USHORT ) SQL_BIGINT )
         or introduce our own unsigned SQL types.
         [Mindaugas]
       */
      dbFieldInfo.uiTypeExtended = ( HB_USHORT ) iDataType;
      dbFieldInfo.uiLen = ( HB_USHORT ) uiSize;
      dbFieldInfo.uiDec = iDec;
      if( iNull == SQL_NULLABLE )
         dbFieldInfo.uiFlags |= HB_FF_NULLABLE;

#if 0
      HB_TRACE( HB_TR_ALWAYS, ( "field: name=%s type=%d len=%d dec=%d null=%d", dbFieldInfo.atomName, iDataType, uiSize, iDec, iNull ) );
#endif

      switch( iDataType )
      {
         case SQL_CHAR:
         case SQL_VARCHAR:
         case SQL_LONGVARCHAR:
            dbFieldInfo.uiType = HB_FT_STRING;
            break;

         case SQL_WCHAR:
         case SQL_WVARCHAR:
         case SQL_WLONGVARCHAR:
            dbFieldInfo.uiType = HB_FT_STRING;
            dbFieldInfo.uiFlags |= HB_FF_UNICODE;
            break;

         case SQL_BINARY:
         case SQL_VARBINARY:
         case SQL_LONGVARBINARY:
            dbFieldInfo.uiType = HB_FT_STRING;
            dbFieldInfo.uiFlags |= HB_FF_BINARY;
            break;

         case SQL_TINYINT:
         case SQL_SMALLINT:
         case SQL_INTEGER:
         case SQL_BIGINT:
            dbFieldInfo.uiType = HB_FT_INTEGER;
            break;

         case SQL_DECIMAL:
         case SQL_NUMERIC:
            dbFieldInfo.uiType = HB_FT_LONG;
            break;

         case SQL_REAL:
         case SQL_FLOAT:
         case SQL_DOUBLE:
            dbFieldInfo.uiType = HB_FT_DOUBLE;
            break;

         case SQL_BIT:
            dbFieldInfo.uiType = HB_FT_LOGICAL;
            break;

         case SQL_DATE:
#if ODBCVER >= 0x0300
         case SQL_TYPE_DATE:
#endif
            dbFieldInfo.uiType = HB_FT_DATE;
            break;

         case SQL_TIME:
#if ODBCVER >= 0x0300
         case SQL_TYPE_TIME:
#endif
            dbFieldInfo.uiType = HB_FT_TIME;
            break;

         /* SQL_DATETIME = SQL_DATE = 9 */
         case SQL_TIMESTAMP:
#if ODBCVER >= 0x0300
         case SQL_TYPE_TIMESTAMP:
#endif
            dbFieldInfo.uiType = HB_FT_TIMESTAMP;
            break;

         default:
#if 0
            HB_TRACE( HB_TR_ALWAYS, ( "new sql type=%d", iDataType ) );
#endif
            bError  = HB_TRUE;
            errCode = ( HB_ERRCODE ) iDataType;
            break;
      }

      if( ! bError )
      {
         switch( dbFieldInfo.uiType )
         {
            case HB_FT_STRING:
            {
               char * pStr;

               pStr = ( char * ) hb_xgrab( ( HB_SIZE ) dbFieldInfo.uiLen + 1 );
               memset( pStr, ' ', dbFieldInfo.uiLen );
               pStr[ dbFieldInfo.uiLen ] = '\0';

               hb_itemPutCL( pItem, pStr, dbFieldInfo.uiLen );
               hb_xfree( pStr );
               break;
            }

            case HB_FT_MEMO:
               hb_itemPutC( pItem, NULL );
               break;

            case HB_FT_INTEGER:
               hb_itemPutNI( pItem, 0 );
               break;

            case HB_FT_LONG:
               if( dbFieldInfo.uiDec == 0 )
                  hb_itemPutNLLen( pItem, 0, dbFieldInfo.uiLen );
               else
                  hb_itemPutNDLen( pItem, 0.0, dbFieldInfo.uiLen, dbFieldInfo.uiDec );
               break;

            case HB_FT_DOUBLE:
               hb_itemPutNDLen( pItem, 0.0, dbFieldInfo.uiLen, dbFieldInfo.uiDec );
               break;

            case HB_FT_LOGICAL:
               hb_itemPutL( pItem, HB_FALSE );
               break;

            case HB_FT_DATE:
               hb_itemPutDL( pItem, 0 );
               break;

            case HB_FT_TIME:
               hb_itemPutTDT( pItem, 0, 0 );
               break;

            case HB_FT_TIMESTAMP:
               hb_itemPutTDT( pItem, 0, 0 );
               break;

            default:
               hb_itemClear( pItem );
               bError = HB_TRUE;
               break;
         }

         hb_arraySetForward( pItemEof, uiIndex + 1, pItem );

         if( ! bError )
            bError = ( SELF_ADDFIELD( &pArea->area, &dbFieldInfo ) == HB_FAILURE );

         hb_xfree( pszName );
      }

      if( bError )
         break;
   }
   hb_itemRelease( pItem );

   if( bError )
   {
      hb_itemRelease( pItemEof );
#if ODBCVER >= 0x0300
      SQLFreeHandle( SQL_HANDLE_STMT, hStmt );
#else
      SQLFreeStmt( hStmt, SQL_DROP );
#endif
      hb_errRT_ODBCDD( 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->hStmt = hStmt;
   return HB_SUCCESS;
}
示例#23
0
文件: core.c 项目: NaldoDj/core
static HB_ERRCODE odbcGoTo( SQLBASEAREAP pArea, HB_ULONG ulRecNo )
{
   SQLHSTMT  hStmt;
   SQLRETURN res;
   SQLLEN    iLen;
   PHB_ITEM  pArray, pItem;
   LPFIELD   pField;
   HB_USHORT ui;

   /* No pArea->pSDDData for DBCreate() area...
    * though pArea->fFetched == HB_TRUE for them
    */
   hStmt = pArea->pSDDData ? ( ( SDDDATA * ) pArea->pSDDData )->hStmt : NULL;

   while( ulRecNo > pArea->ulRecCount && ! pArea->fFetched )
   {
      if( ! SQL_SUCCEEDED( SQLFetch( hStmt ) ) )
      {
         pArea->fFetched = HB_TRUE;
         break;
      }

      pArray = hb_itemArrayNew( pArea->area.uiFieldCount );
      pItem  = NULL;
      for( ui = 1; ui <= pArea->area.uiFieldCount; ui++ )
      {
         iLen   = SQL_NULL_DATA;
         res    = 0;
         pField = pArea->area.lpFields + ui - 1;
         switch( pField->uiType )
         {
            case HB_FT_STRING:
               if( pField->uiType & HB_FF_BINARY )
               {
                  char buffer[ 1 ];

                  iLen = 0;
                  if( SQL_SUCCEEDED( res = SQLGetData( hStmt, ui, SQL_C_BINARY, buffer, 0, &iLen ) ) )
                  {
                     if( iLen >= 0 )
                     {
                        char * val = ( char * ) hb_xgrab( iLen + 1 );
                        if( SQL_SUCCEEDED( res = SQLGetData( hStmt, ui, SQL_C_BINARY, val, iLen + 1, &iLen ) ) )
                           pItem = hb_itemPutCLPtr( pItem, val, ( HB_SIZE ) iLen );
                        else
                           hb_xfree( val );
                     }
                  }
               }
               else
               {
                  O_HB_CHAR buffer[ 1 ];
#if defined( UNICODE )
                  SQLSMALLINT iTargetType = SQL_C_WCHAR;
#else
                  SQLSMALLINT iTargetType = SQL_C_CHAR;
#endif

                  iLen = 0;
                  if( SQL_SUCCEEDED( res = SQLGetData( hStmt, ui, iTargetType, buffer, 0, &iLen ) ) )
                  {
                     if( iLen >= 0 )
                     {
                        O_HB_CHAR * val = ( O_HB_CHAR * ) hb_xgrab( iLen + sizeof( O_HB_CHAR ) );
                        if( SQL_SUCCEEDED( res = SQLGetData( hStmt, ui, iTargetType, val, iLen + sizeof( O_HB_CHAR ), &iLen ) ) )
                        {
#if defined( UNICODE )
                           iLen >>= 1;
#endif
                           pItem = O_HB_ITEMPUTSTRLEN( pItem, val, ( HB_SIZE ) iLen );
                        }
                        hb_xfree( val );
                     }
                  }
               }
               break;

            case HB_FT_INTEGER:
#if ODBCVER >= 0x0300
               if( pField->uiTypeExtended == ( HB_USHORT ) SQL_BIGINT )
               {
                  HB_I64 val = 0;
                  /* NOTE: SQL_C_SBIGINT not available before ODBC 3.0 */
                  if( SQL_SUCCEEDED( res = SQLGetData( hStmt, ui, SQL_C_SBIGINT, &val, sizeof( val ), &iLen ) ) )
                     pItem = hb_itemPutNIntLen( pItem, val, pField->uiLen );
               }
               else
#endif
               {
                  SQLINTEGER val = 0;
                  if( SQL_SUCCEEDED( res = SQLGetData( hStmt, ui, SQL_C_LONG, &val, sizeof( val ), &iLen ) ) )
                     pItem = hb_itemPutNLLen( pItem, val, pField->uiLen );
               }
               break;

            case HB_FT_LONG:
               if( pField->uiDec == 0 && pField->uiLen < 10 )
               {
                  SQLINTEGER val = 0;
                  if( SQL_SUCCEEDED( res = SQLGetData( hStmt, ui, SQL_C_LONG, &val, sizeof( val ), &iLen ) ) )
                     pItem = hb_itemPutNLLen( pItem, val, pField->uiLen );
               }
               else
               {
                  double val = 0.0;
                  if( SQL_SUCCEEDED( res = SQLGetData( hStmt, ui, SQL_C_DOUBLE, &val, sizeof( val ), &iLen ) ) )
                     pItem = hb_itemPutNDLen( pItem, val, pField->uiLen, pField->uiDec );
               }
               break;

            case HB_FT_DOUBLE:
            {
               double val = 0.0;
               if( SQL_SUCCEEDED( res = SQLGetData( hStmt, ui, SQL_C_DOUBLE, &val, sizeof( val ), &iLen ) ) )
                  pItem = hb_itemPutNDLen( pItem, val, pField->uiLen, pField->uiDec );
               break;
            }

            case HB_FT_LOGICAL:
            {
               unsigned char val = 0;
               if( SQL_SUCCEEDED( res = SQLGetData( hStmt, ui, SQL_C_BIT, &val, sizeof( val ), &iLen ) ) )
                  pItem = hb_itemPutL( pItem, val != 0 );
               break;
            }

            case HB_FT_DATE:
            {
               DATE_STRUCT val = { 0, 0, 0 };
               if( SQL_SUCCEEDED( res = SQLGetData( hStmt, ui, SQL_C_DATE, &val, sizeof( val ), &iLen ) ) )
                  pItem = hb_itemPutD( pItem, val.year, val.month, val.day );
               break;
            }

            case HB_FT_TIME:
            {
               TIME_STRUCT val = { 0, 0, 0 };
               if( SQL_SUCCEEDED( res = SQLGetData( hStmt, ui, SQL_C_TIME, &val, sizeof( val ), &iLen ) ) )
                  pItem = hb_itemPutTDT( pItem, 0, hb_timeEncode( val.hour, val.minute, val.second, 0 ) );
               break;
            }

            case HB_FT_TIMESTAMP:
            {
               TIMESTAMP_STRUCT val = { 0, 0, 0, 0, 0, 0, 0 };
               if( SQL_SUCCEEDED( res = SQLGetData( hStmt, ui, SQL_C_TIMESTAMP, &val, sizeof( val ), &iLen ) ) )
                  pItem = hb_itemPutTDT( pItem, hb_dateEncode( val.year, val.month, val.day ),
                                         hb_timeEncode( val.hour, val.minute, val.second, val.fraction / 1000000 ) );
               break;
            }
         }

         /* TODO: check SQL_SUCCEEDED( res ) */
         /* TODO: check for SQL_NO_TOTAL. What does this mean? */
         HB_SYMBOL_UNUSED( res );

         if( pItem )
         {
            /* NULL -> NIL */
            if( iLen == SQL_NULL_DATA )
               hb_itemClear( pItem );
            else
               hb_arraySetForward( pArray, ui, pItem );
         }
      }
      if( pItem )
         hb_itemRelease( pItem );

      if( pArea->ulRecCount + 1 >= pArea->ulRecMax )
      {
         pArea->pRow      = ( void ** ) hb_xrealloc( pArea->pRow, ( pArea->ulRecMax + SQLDD_ROWSET_RESIZE ) * sizeof( void * ) );
         pArea->pRowFlags = ( HB_BYTE * ) hb_xrealloc( pArea->pRowFlags, ( pArea->ulRecMax + SQLDD_ROWSET_RESIZE ) * sizeof( HB_BYTE ) );
         pArea->ulRecMax += SQLDD_ROWSET_RESIZE;
      }

      pArea->ulRecCount++;
      pArea->pRow[ pArea->ulRecCount ]      = pArray;
      pArea->pRowFlags[ pArea->ulRecCount ] = SQLDD_FLAG_CACHED;
   }
示例#24
0
static const char * _hb_jsonDecode( const char * szSource, PHB_ITEM pValue )
{
   if( *szSource == '\"' )
   {
      char * szDest, * szHead;
      HB_SIZE nAlloc = 16;

      szHead = szDest = ( char * ) hb_xgrab( nAlloc );
      szSource++;
      while( *szSource != '\"' )
      {
         if( szHead + 6 >= szDest + nAlloc )
         {
            HB_SIZE nLen = szHead - szDest;
            nAlloc += nAlloc << 1;
            szDest = ( char * ) hb_xrealloc( szDest, nAlloc );
            szHead = szDest + nLen;
         }
         if( *szSource == '\\' )
         {
            szSource++;
            switch( *szSource )
            {
               case '\"':
                  *szHead++ = '\"';
                  break;
               case '\\':
                  *szHead++ = '\\';
                  break;
               case '/':
                  *szHead++ = '/';
                  break;
               case 'b':
                  *szHead++ = '\b';
                  break;
               case 'f':
                  *szHead++ = '\f';
                  break;
               case 'n':
                  *szHead++ = '\n';
                  break;
               case 'r':
                  *szHead++ = '\r';
                  break;
               case 't':
                  *szHead++ = '\t';
                  break;
               case 'u':
               {
                  HB_WCHAR wc = 0;
                  int i;

                  for( i = 0; i < 4; i++ )
                  {
                     char c = *++szSource;
                     wc <<= 4;
                     if( c >= '0' && c <= '9' )
                        wc += c - '0';
                     else if( c >= 'A' && c <= 'F' )
                        wc += c - 'A' + 10;
                     else if( c >= 'a' && c <= 'f' )
                        wc += c - 'a' + 10;
                     else
                     {
                        hb_xfree( szDest );
                        return NULL;
                     }
                  }
                  szHead += hb_cdpU16ToStr( hb_vmCDP(), HB_CDP_ENDIAN_NATIVE,
                                            &wc, 1,
                                            szHead, szDest + nAlloc - szHead );
                  break;
               }
               default:
                  hb_xfree( szDest );
                  return NULL;
            }
            szSource++;
         }
         else if( *( const unsigned char * ) szSource >= ' ' )
            *szHead++ = *szSource++;
         else
         {
            hb_xfree( szDest );
            return NULL;
         }
      }
      hb_itemPutCL( pValue, szDest, szHead - szDest );
      hb_xfree( szDest );
      return szSource + 1;
   }
   else if( *szSource == '-' || ( *szSource >= '0' && *szSource <= '9' ) )
   {
      /* NOTE: this function is much less strict to number format than
               JSON syntax definition. This is allowed behaviour [Mindaugas] */
      HB_MAXINT nValue = 0;
      double dblValue = 0;
      HB_BOOL fNeg, fDbl = HB_FALSE;
      int iDec = 0;

      fNeg = *szSource == '-';
      if( fNeg )
         szSource++;

      while( *szSource >= '0' && *szSource <= '9' )
      {
         nValue = nValue * 10 + *szSource - '0';
         szSource++;
      }
      if( *szSource == '.' )
      {
         double mult = 1;

         dblValue = ( double ) nValue;
         fDbl = HB_TRUE;
         szSource++;
         while( *szSource >= '0' && *szSource <= '9' )
         {
            mult /= 10;
            dblValue += ( ( double ) ( *szSource - '0' ) ) * mult;
            szSource++;
            iDec++;
         }
      }
      if( *szSource == 'e' || *szSource == 'E' )
      {
         HB_BOOL fNegExp;
         int iExp = 0;

         szSource++;
         fNegExp = *szSource == '-';
         if( fNegExp )
            szSource++;

         while( *szSource >= '0' && *szSource <= '9' )
         {
            iExp = iExp * 10 + *szSource - '0';
            szSource++;
         }
         if( ! fDbl )
         {
            dblValue = ( double ) nValue;
            fDbl = HB_TRUE;
         }
         if( fNegExp )
            iDec += iExp;
         dblValue = hb_numExpConv( dblValue, fNegExp ? iExp : -iExp );
      }

      if( fDbl )
         hb_itemPutNDDec( pValue, hb_numRound( fNeg ? -dblValue : dblValue, iDec ), iDec );
      else
         hb_itemPutNInt( pValue, fNeg ? -nValue : nValue );
      return szSource;
   }
   else if( ! strncmp( szSource, "null", 4 ) )
   {
      hb_itemClear( pValue );
      return szSource + 4;
   }
   else if( ! strncmp( szSource, "true", 4 ) )
   {
      hb_itemPutL( pValue, HB_TRUE );
      return szSource + 4;
   }
   else if( ! strncmp( szSource, "false", 5 ) )
   {
      hb_itemPutL( pValue, HB_FALSE );
      return szSource + 5;
   }
   else if( *szSource == '[' )
   {
      hb_arrayNew( pValue, 0 );
      szSource = _skipws( szSource + 1 );
      if( *szSource != ']' )
      {
         PHB_ITEM pItem = hb_itemNew( NULL );

         for( ;; )
         {
            szSource = _hb_jsonDecode( szSource, pItem );
            if( ! szSource )
            {
               hb_itemRelease( pItem );
               return NULL;
            }
            hb_arrayAddForward( pValue, pItem );

            szSource = _skipws( szSource );
            if( *szSource == ',' )
            {
               szSource = _skipws( szSource + 1 );
               continue;
            }
            else if( *szSource == ']' )
               break;
            else
            {
               hb_itemRelease( pItem );
               return NULL;
            }
         }
         hb_itemRelease( pItem );
      }
      return szSource + 1;
   }
   else if( *szSource == '{' )
   {
      hb_hashNew( pValue );
      szSource = _skipws( szSource + 1 );
      if( *szSource != '}' )
      {
         PHB_ITEM pItemKey = hb_itemNew( NULL );
         PHB_ITEM pItemValue = hb_itemNew( NULL );

         for( ;; )
         {
            /* Do we need to check if key does not exist yet? */
            if( ( szSource = _hb_jsonDecode( szSource, pItemKey ) ) == NULL ||
                ! HB_IS_STRING( pItemKey ) ||
                * ( szSource = _skipws( szSource ) ) != ':' ||
                ( szSource = _hb_jsonDecode( _skipws( szSource + 1 ), pItemValue ) ) == NULL)
            {
               hb_itemRelease( pItemKey );
               hb_itemRelease( pItemValue );
               return NULL;
            }

            hb_hashAdd( pValue, pItemKey, pItemValue );
            szSource = _skipws( szSource );
            if( *szSource == ',' )
            {
               szSource = _skipws( szSource + 1 );
               continue;
            }
            else if( *szSource == '}' )
               break;
            else
            {
               hb_itemRelease( pItemKey );
               hb_itemRelease( pItemValue );
               return NULL;
            }
         }
         hb_itemRelease( pItemKey );
         hb_itemRelease( pItemValue );
      }
      return szSource + 1;
   }
   return NULL;
}
示例#25
0
文件: sdf1.c 项目: AmericoBalboa/core
/*
 * Obtain the current value of a field.
 */
static HB_ERRCODE hb_sdfGetValue( SDFAREAP pArea, HB_USHORT uiIndex, PHB_ITEM pItem )
{
   LPFIELD pField;

   HB_TRACE( HB_TR_DEBUG, ( "hb_sdfGetValue(%p, %hu, %p)", pArea, uiIndex, pItem ) );

   if( --uiIndex >= pArea->area.uiFieldCount )
      return HB_FAILURE;

   pField = pArea->area.lpFields + uiIndex;
   switch( pField->uiType )
   {
      case HB_FT_STRING:
         if( ( pField->uiFlags & HB_FF_BINARY ) == 0 )
         {
            HB_SIZE nLen = pField->uiLen;
            char * pszVal = hb_cdpnDup( ( const char * ) pArea->pRecord + pArea->pFieldOffset[ uiIndex ],
                                        &nLen, pArea->area.cdPage, hb_vmCDP() );
            hb_itemPutCLPtr( pItem, pszVal, nLen );
         }
         else
         {
            hb_itemPutCL( pItem, ( char * ) pArea->pRecord + pArea->pFieldOffset[ uiIndex ],
                          pField->uiLen );
         }
         break;

      case HB_FT_LOGICAL:
         switch( pArea->pRecord[ pArea->pFieldOffset[ uiIndex ] ] )
         {
            case 'T':
            case 't':
            case 'Y':
            case 'y':
               hb_itemPutL( pItem, HB_TRUE );
               break;
            default:
               hb_itemPutL( pItem, HB_FALSE );
               break;
         }
         break;

      case HB_FT_DATE:
         hb_itemPutDS( pItem, ( char * ) pArea->pRecord + pArea->pFieldOffset[ uiIndex ] );
         break;

      case HB_FT_TIMESTAMP:
      {
         long lJulian, lMilliSec;
         HB_BYTE * pFieldPtr = pArea->pRecord + pArea->pFieldOffset[ uiIndex ], bChar;

         bChar = pFieldPtr[ pField->uiLen ];
         pFieldPtr[ pField->uiLen ] = 0;
         hb_timeStampStrGetDT( ( const char * ) pFieldPtr, &lJulian, &lMilliSec );
         pFieldPtr[ pField->uiLen ] = bChar;
         hb_itemPutTDT( pItem, lJulian, lMilliSec );
         break;
      }

      case HB_FT_LONG:
      {
         HB_MAXINT lVal;
         double    dVal;
         HB_BOOL   fDbl;

         fDbl = hb_strnToNum( ( const char * ) pArea->pRecord + pArea->pFieldOffset[ uiIndex ],
                              pField->uiLen, &lVal, &dVal );

         if( pField->uiDec )
         {
            hb_itemPutNDLen( pItem, fDbl ? dVal : ( double ) lVal,
                             ( int ) ( pField->uiLen - pField->uiDec - 1 ),
                             ( int ) pField->uiDec );
         }
         else if( fDbl )
         {
            hb_itemPutNDLen( pItem, dVal, ( int ) pField->uiLen, 0 );
         }
         else
         {
            hb_itemPutNIntLen( pItem, lVal, ( int ) pField->uiLen );
         }
      }
      break;

      case HB_FT_MEMO:
         hb_itemPutC( pItem, NULL );
         break;

      case HB_FT_NONE:
         hb_itemClear( pItem );
         break;

      default:
      {
         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, EDBF_DATATYPE );
         SELF_ERROR( &pArea->area, pError );
         hb_itemRelease( pError );
         return HB_FAILURE;
      }
   }

   return HB_SUCCESS;
}