예제 #1
0
파일: wafunc.c 프로젝트: AmericoBalboa/core
/*
 * Obtain the current value of a field.
 */
HB_ERRCODE hb_rddFieldGet( PHB_ITEM pItem, PHB_SYMB pFieldSymbol )
{
   AREAP pArea;

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

   pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer();
   if( pArea )
   {
      HB_USHORT uiField = 1;
      LPFIELD pField = pArea->lpFields;
      PHB_DYNS pDynSym = pFieldSymbol->pDynSym;

      while( pField )
      {
         if( ( PHB_DYNS ) pField->sym == pDynSym )
         {
            return SELF_GETVALUE( pArea, uiField, pItem );
         }
         ++uiField;
         pField = pField->lpfNext;
      }
   }
   return HB_FAILURE;
}
예제 #2
0
static HB_ERRCODE sqlbaseGoHot( SQLBASEAREAP pArea )
{
   PHB_ITEM  pArray, pItem;
   HB_USHORT us;

   pArray = hb_itemArrayNew( pArea->area.uiFieldCount );
   for( us = 1; us <= pArea->area.uiFieldCount; us++ )
   {
      pItem = hb_itemNew( NULL );
      if( SELF_GETVALUE( ( AREAP ) pArea, us, pItem ) == HB_SUCCESS )
         hb_arraySetForward( pArray, us, pItem );
      hb_itemRelease( pItem );
   }
   pArea->pRecord        = pArray;
   pArea->bRecordFlags  |= SQLDD_FLAG_CACHED;
   pArea->fRecordChanged = HB_TRUE;
   return HB_SUCCESS;
}
예제 #3
0
파일: dbsql.c 프로젝트: cwanderlei/hbtest3
/* Export DBF content to a SQL script file */
static HB_ULONG hb_db2Sql( AREAP pArea, PHB_ITEM pFields, HB_MAXINT llNext,
                           PHB_ITEM pWhile, PHB_ITEM pFor,
                           const char * szDelim, const char * szSep,
                           const char * szEsc, const char * szTable,
                           HB_FHANDLE hFile, HB_BOOL fInsert, HB_BOOL fRecno )
{
   PHB_FILEBUF pFileBuf;
   HB_ULONG ulRecords = 0;
   HB_USHORT uiFields = 0, ui;
   PHB_ITEM pTmp;
   HB_BOOL fWriteSep = HB_FALSE;
   const char * szNewLine = hb_conNewLine();
   char * szInsert = NULL;
   HB_BOOL fEof = HB_TRUE;
   HB_BOOL fNoFieldPassed = ( pFields == NULL || hb_arrayLen( pFields ) == 0 );

   if( SELF_FIELDCOUNT( pArea, &uiFields ) != HB_SUCCESS )
      return 0;

   if( fInsert && szTable )
      szInsert = hb_xstrcpy( NULL, "INSERT INTO ", szTable, " VALUES ( ", NULL );

   pFileBuf = hb_createFBuffer( hFile, HB_FILE_BUF_SIZE );
   pTmp = hb_itemNew( NULL );

   while( llNext-- > 0 )
   {
      if( pWhile )
      {
         if( SELF_EVALBLOCK( pArea, pWhile ) != HB_SUCCESS ||
             ! hb_itemGetL( pArea->valResult ) )
            break;
      }

      if( SELF_EOF( pArea, &fEof ) != HB_SUCCESS || fEof )
         break;

      if( pFor )
      {
         if( SELF_EVALBLOCK( pArea, pFor ) != HB_SUCCESS )
            break;
      }
      if( ! pFor || hb_itemGetL( pArea->valResult ) )
      {
         ++ulRecords;

         if( szInsert )
            hb_addStrToFBuffer( pFileBuf, szInsert );

         if( fRecno )
         {
            HB_ULONG ulRec = ulRecords;
            char szRecno[ 13 ], * szVal;

            szVal = szRecno + sizeof( szRecno );
            *--szVal = 0;
            do
            {
               *--szVal = ( char ) ( ulRec % 10 ) + '0';
               ulRec /= 10;
            }
            while( ulRec );
            hb_addStrToFBuffer( pFileBuf, szVal );
            hb_addStrToFBuffer( pFileBuf, szSep );
         }

         if( fNoFieldPassed )
         {
            for( ui = 1; ui <= uiFields; ui++ )
            {
               if( SELF_GETVALUE( pArea, ui, pTmp ) != HB_SUCCESS )
                  break;
               if( fWriteSep )
                  hb_addStrToFBuffer( pFileBuf, szSep );
               fWriteSep = hb_exportBufSqlVar( pFileBuf, pTmp, szDelim, szEsc );
            }
            if( ui <= uiFields )
               break;
         }
         else
         {
            /* TODO: exporting only some fields */
         }

         if( szInsert )
            hb_addStrToFBuffer( pFileBuf, " );" );
         hb_addStrToFBuffer( pFileBuf, szNewLine );
         fWriteSep = HB_FALSE;
      }

      if( SELF_SKIP( pArea, 1 ) != HB_SUCCESS )
         break;

      if( ( llNext % 10000 ) == 0 )
         hb_inkeyPoll();
   }

   if( szInsert )
      hb_xfree( szInsert );
   hb_destroyFBuffer( pFileBuf );
   hb_itemRelease( pTmp );

   /* Writing EOF */
   /* hb_fsWrite( hFile, "\x1A", 1 ); */

   return ulRecords;
}