Example #1
0
HB_ERRCODE hb_rddTransRecords( AREAP pArea,
                               const char * szFileName, const char * szDriver,
                               HB_ULONG ulConnection,
                               PHB_ITEM pFields, HB_BOOL fExport,
                               PHB_ITEM pCobFor, PHB_ITEM pStrFor,
                               PHB_ITEM pCobWhile, PHB_ITEM pStrWhile,
                               PHB_ITEM pNext, PHB_ITEM pRecID,
                               PHB_ITEM pRest,
                               const char * szCpId,
                               PHB_ITEM pDelim )
{
   AREAP lpaClose = NULL;
   PHB_ITEM pStruct = NULL;
   DBTRANSINFO dbTransInfo;
   HB_USHORT uiPrevArea, uiCount, uiSwap;
   HB_ERRCODE errCode;

   memset( &dbTransInfo, 0, sizeof( dbTransInfo ) );
   uiPrevArea = ( HB_AREANO ) hb_rddGetCurrentWorkAreaNumber();

   if( szDriver == NULL )
      /* szDriver = SELF_RDDNODE( pArea )->szName; */
      szDriver = hb_rddDefaultDrv( NULL );

   if( fExport )
   {
      errCode = hb_dbTransStruct( pArea, NULL, &dbTransInfo,
                                  &pStruct, pFields );
      if( errCode == HB_SUCCESS )
      {
         errCode = hb_rddCreateTable( szFileName, szDriver, 0, "",
                                      HB_TRUE,
                                      szCpId, ulConnection, pStruct, pDelim );
         if( errCode == HB_SUCCESS )
            dbTransInfo.lpaDest = lpaClose =
                                 ( AREAP ) hb_rddGetCurrentWorkAreaPointer();
      }
   }
   else
   {
      LPRDDNODE pRddNode = hb_rddFindNode( szDriver, NULL );

      if( ! pRddNode )
      {
         hb_errRT_DBCMD( EG_ARG, EDBCMD_USE_BADPARAMETER, NULL, HB_ERR_FUNCNAME );
         return HB_FAILURE;
      }

      if( pRddNode->uiType == RDT_TRANSFER )
      {
         errCode = hb_dbTransStruct( pArea, NULL, &dbTransInfo,
                                     &pStruct, pFields );

         /* revert area and items */
         dbTransInfo.lpaDest = dbTransInfo.lpaSource;
         for( uiCount = 0; uiCount < dbTransInfo.uiItemCount; ++uiCount )
         {
            uiSwap = dbTransInfo.lpTransItems[ uiCount ].uiSource;
            dbTransInfo.lpTransItems[ uiCount ].uiSource =
                                    dbTransInfo.lpTransItems[ uiCount ].uiDest;
            dbTransInfo.lpTransItems[ uiCount ].uiDest = uiSwap;
         }

         if( errCode == HB_SUCCESS )
         {
            errCode = hb_rddOpenTable( szFileName, szDriver, 0, "", HB_TRUE, HB_TRUE,
                                       szCpId, ulConnection, pStruct, pDelim );
            if( errCode == HB_SUCCESS )
            {
               lpaClose = dbTransInfo.lpaSource =
                                 ( AREAP ) hb_rddGetCurrentWorkAreaPointer();
            }
         }
      }
      else
      {
         errCode = hb_rddOpenTable( szFileName, szDriver, 0, "", HB_TRUE, HB_TRUE,
                                    szCpId, ulConnection, NULL, pDelim );
         if( errCode == HB_SUCCESS )
         {
            lpaClose = ( AREAP ) hb_rddGetCurrentWorkAreaPointer();
            errCode = hb_dbTransStruct( lpaClose, pArea, &dbTransInfo,
                                        NULL, pFields );
         }
      }
   }

   if( pStruct )
      hb_itemRelease( pStruct );

   if( errCode == HB_SUCCESS )
   {
      PHB_ITEM pTransItm;

      hb_rddSelectWorkAreaNumber( dbTransInfo.lpaSource->uiArea );

      dbTransInfo.dbsci.itmCobFor   = pCobFor;
      dbTransInfo.dbsci.lpstrFor    = pStrFor;
      dbTransInfo.dbsci.itmCobWhile = pCobWhile;
      dbTransInfo.dbsci.lpstrWhile  = pStrWhile;
      dbTransInfo.dbsci.lNext       = pNext;
      dbTransInfo.dbsci.itmRecID    = pRecID;
      dbTransInfo.dbsci.fRest       = pRest;

      dbTransInfo.dbsci.fIgnoreFilter     = HB_TRUE;
      dbTransInfo.dbsci.fIncludeDeleted   = HB_TRUE;
      dbTransInfo.dbsci.fLast             = HB_FALSE;
      dbTransInfo.dbsci.fIgnoreDuplicates = HB_FALSE;
      dbTransInfo.dbsci.fBackward         = HB_FALSE;

      pTransItm = hb_dbTransInfoPut( NULL, &dbTransInfo );
      errCode = SELF_INFO( dbTransInfo.lpaDest, DBI_TRANSREC, pTransItm );
      if( errCode == HB_SUCCESS )
      {
         errCode = dbTransInfo.uiItemCount == 0 ? HB_FAILURE :
                   SELF_TRANS( dbTransInfo.lpaSource, &dbTransInfo );
         /* we always call DBI_TRANSREC second time after TRANS() method
          * even if TRANS() failed - it's for RDDs which may need to store
          * pointer to dbTransInfo in first call and then release it and/or
          * clean some structures allocated for transfer operation [druzus]
          */
         SELF_INFO( dbTransInfo.lpaDest, DBI_TRANSREC, pTransItm );
         if( errCode == HB_SUCCESS && ( dbTransInfo.uiFlags & DBTF_CPYCTR ) )
            errCode = hb_dbTransCounters( &dbTransInfo );
      }
      hb_itemRelease( pTransItm );
   }

   if( dbTransInfo.lpTransItems )
      hb_xfree( dbTransInfo.lpTransItems );
   if( lpaClose )
   {
      hb_rddSelectWorkAreaNumber( lpaClose->uiArea );
      hb_rddReleaseCurrentArea();
   }
   hb_rddSelectWorkAreaNumber( uiPrevArea );

   return errCode;
}
Example #2
0
File: wafunc.c Project: CsBela/core
HB_ERRCODE hb_rddTransRecords( AREAP pArea,
                               const char * szFileName, const char * szDriver,
                               HB_ULONG ulConnection,
                               PHB_ITEM pFields, HB_BOOL fExport,
                               PHB_ITEM pCobFor, PHB_ITEM pStrFor,
                               PHB_ITEM pCobWhile, PHB_ITEM pStrWhile,
                               PHB_ITEM pNext, PHB_ITEM pRecID,
                               PHB_ITEM pRest,
                               const char * szCpId,
                               PHB_ITEM pDelim )
{
   AREAP lpaClose = NULL;
   PHB_ITEM pStruct = NULL;
   DBTRANSINFO dbTransInfo;
   HB_USHORT uiPrevArea, uiCount, uiSwap;
   HB_ERRCODE errCode;

   memset( &dbTransInfo, 0, sizeof( dbTransInfo ) );
   uiPrevArea = ( HB_AREANO ) hb_rddGetCurrentWorkAreaNumber();

   if( szDriver == NULL )
      /* szDriver = SELF_RDDNODE( pArea )->szName; */
      szDriver = hb_rddDefaultDrv( NULL );

   if( fExport )
   {
      errCode = hb_dbTransStruct( pArea, NULL, &dbTransInfo,
                                  &pStruct, pFields );
      if( errCode == HB_SUCCESS )
      {
         errCode = hb_rddCreateTable( szFileName, szDriver, 0, "",
                                      HB_TRUE,
                                      szCpId, ulConnection, pStruct, pDelim );
         if( errCode == HB_SUCCESS )
         {
            dbTransInfo.lpaDest = lpaClose =
                                 ( AREAP ) hb_rddGetCurrentWorkAreaPointer();
         }
      }
   }
   else
   {
      LPRDDNODE pRddNode = hb_rddFindNode( szDriver, NULL );

      if( ! pRddNode )
      {
         hb_errRT_DBCMD( EG_ARG, EDBCMD_USE_BADPARAMETER, NULL, HB_ERR_FUNCNAME );
         return HB_FAILURE;
      }

      if( pRddNode->uiType == RDT_TRANSFER )
      {
         errCode = hb_dbTransStruct( pArea, NULL, &dbTransInfo,
                                     &pStruct, pFields );

         /* revert area and items */
         dbTransInfo.lpaDest = dbTransInfo.lpaSource;
         for( uiCount = 0; uiCount < dbTransInfo.uiItemCount; ++uiCount )
         {
            uiSwap = dbTransInfo.lpTransItems[ uiCount ].uiSource;
            dbTransInfo.lpTransItems[ uiCount ].uiSource =
                                    dbTransInfo.lpTransItems[ uiCount ].uiDest;
            dbTransInfo.lpTransItems[ uiCount ].uiDest = uiSwap;
         }

         if( errCode == HB_SUCCESS )
         {
            errCode = hb_rddOpenTable( szFileName, szDriver, 0, "", HB_TRUE, HB_TRUE,
                                       szCpId, ulConnection, pStruct, pDelim );
            if( errCode == HB_SUCCESS )
            {
               lpaClose = dbTransInfo.lpaSource =
                                 ( AREAP ) hb_rddGetCurrentWorkAreaPointer();
            }
         }
      }
      else
      {
         errCode = hb_rddOpenTable( szFileName, szDriver, 0, "", HB_TRUE, HB_TRUE,
                                    szCpId, ulConnection, NULL, pDelim );
         if( errCode == HB_SUCCESS )
         {
            lpaClose = ( AREAP ) hb_rddGetCurrentWorkAreaPointer();
            errCode = hb_dbTransStruct( lpaClose, pArea, &dbTransInfo,
                                        NULL, pFields );
         }
      }
   }

   if( pStruct )
      hb_itemRelease( pStruct );

   if( errCode == HB_SUCCESS )
   {
      hb_rddSelectWorkAreaNumber( dbTransInfo.lpaSource->uiArea );

      dbTransInfo.dbsci.itmCobFor   = pCobFor;
      dbTransInfo.dbsci.lpstrFor    = pStrFor;
      dbTransInfo.dbsci.itmCobWhile = pCobWhile;
      dbTransInfo.dbsci.lpstrWhile  = pStrWhile;
      dbTransInfo.dbsci.lNext       = pNext;
      dbTransInfo.dbsci.itmRecID    = pRecID;
      dbTransInfo.dbsci.fRest       = pRest;

      dbTransInfo.dbsci.fIgnoreFilter     = HB_TRUE;
      dbTransInfo.dbsci.fIncludeDeleted   = HB_TRUE;
      dbTransInfo.dbsci.fLast             = HB_FALSE;
      dbTransInfo.dbsci.fIgnoreDuplicates = HB_FALSE;
      dbTransInfo.dbsci.fBackward         = HB_FALSE;

      errCode = SELF_TRANS( dbTransInfo.lpaSource, &dbTransInfo );
   }

   if( dbTransInfo.lpTransItems )
      hb_xfree( dbTransInfo.lpTransItems );
   if( lpaClose )
   {
      hb_rddSelectWorkAreaNumber( lpaClose->uiArea );
      hb_rddReleaseCurrentArea();
   }
   hb_rddSelectWorkAreaNumber( uiPrevArea );

   return errCode;
}