home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 16 / CD_ASCQ_16_0994.iso / news / 4611 / fw16d.ins / SOURCE / CLASSES / DATABASE.OLD < prev    next >
Text File  |  1994-06-09  |  6KB  |  147 lines

  1. // Clase realizada por Jose Mariano
  2. // Warning: Under construction
  3.  
  4. #include "FiveWin.ch"
  5.  
  6. //----------------------------------------------------------------------------//
  7.  
  8. CLASS TDataBase
  9.  
  10.   DATA   cAlias, cFile, cDriver
  11.   DATA   aField, aIndex
  12.   DATA   nIndex, nArea
  13.   DATA   lReadOnly, cScope
  14.  
  15.   METHOD New( cAlias, oDbm ) CONSTRUCTOR
  16.  
  17.   METHOD AddIndex( xIndex, cTag )
  18.   METHOD Append()         INLINE ( ::cAlias )->( DbAppend() )
  19.   METHOD Bof()            INLINE ( ::cAlias )->( Bof() )
  20.  
  21.   METHOD Close()          INLINE ( ::cAlias )->( DbCloseArea() ), ::nArea:= 0
  22.   METHOD CloseInd()       INLINE ( ::cAlias )->( DbClearIndex() ), ::nIndex:= 0
  23.  
  24.   METHOD Commit()         INLINE ( ::cAlias )->( DbCommit() )
  25.   METHOD Delete()         INLINE ( ::cAlias )->( DbDelete() )
  26.   METHOD DeleteTag( cTag, cFile ) INLINE ( ::cAlias )->( Sx_TagDelete( cTag, cFile ) )
  27.   METHOD Eof()            INLINE ( ::cAlias )->( Eof() )
  28.   METHOD FieldWBlock( cCampo ) INLINE FieldWBlock( cCampo, ::nArea )
  29.   METHOD FieldGet( n )
  30.   METHOD FieldPut( n, xVal )
  31.   METHOD Flock()          INLINE ( ::cAlias )->( Flock() )
  32.   METHOD Found()          INLINE ( ::cAlias )->( Found() )
  33.   METHOD GoBottom()       INLINE ( ::cAlias )->( DbGoBottom() )
  34.   METHOD GoTo( nReg )     INLINE ( ::cAlias )->( DbGoto( nReg ) )
  35.   METHOD GoTop()          INLINE ( ::cAlias )->( DbGoTop() )
  36.   METHOD KeyCount()       INLINE ( ::cAlias )->( Sx_KeyCount() )
  37.   METHOD KeyGoto( nKey )  INLINE ( ::cAlias )->( Sx_KeyGoto( nKey ) )
  38.   METHOD KeyNum()         INLINE ( ::cAlias )->( Sx_KeyNo() )
  39.   METHOD LastRec()        INLINE ( ::cAlias )->( LastRec() )
  40.  
  41.   METHOD Locate( bWhile, bFor, nNext )
  42.  
  43.   METHOD NumTags( cIndex ) INLINE ( ::cAlias )->( Sx_TagCount( cIndex ) )
  44.   METHOD NumOrder()        INLINE ( ::cAlias )->( Sx_OrderCount() )
  45.   METHOD Open()            INLINE ::OpenDb(), ::AddIndex()
  46.   METHOD OpenDb()
  47.   METHOD Seek( xValor, lSoftSeek ) INLINE (::cAlias)->( DbSeek( xValor, lSoftSeek ) )
  48.   METHOD SetOrder( nOrd ) INLINE (::cAlias)->( Sx_SetTagOrder( ::nIndex := nOrd ) )
  49.   METHOD SetScope( xInf, xSup )
  50.   METHOD SetTagNo( nTag ) INLINE ( ::cAlias )->( Sx_SetTagNo( nTag ) )
  51.   METHOD SetTag( cTag, cIndex ) INLINE ( ::cAlias )->( Sx_SetTagOrder( cTag, cIndex ) )
  52.   METHOD Skip( nReg )     INLINE ( ::cAlias )->( DbSkip( nReg ) )
  53.   METHOD UnLock()         INLINE ( ::cAlias )->( DbUnLock() )
  54.  
  55. ENDCLASS
  56.  
  57. //----------------------------------------------------------------------------//
  58.  
  59. METHOD New( cAlias, oDbm ) CLASS TDataBase
  60.  
  61.     if IS_NIL( oDbm ) THEN oDbm:= oDbms
  62.        ::cAlias    := Upper( cAlias )
  63.        ::nIndex    := 0
  64.        ::nArea     := 0
  65.        ::lReadOnly := FALSE
  66.        // Otra chapuza... para que inicialice cFile, aField y aIndex.
  67.     oDbm:Db( Self )
  68.  
  69. RETURN Self
  70.  
  71. //----------------------------------------------------------------------------//
  72.  
  73. METHOD OpenDb() CLASS TDataBase
  74.        if Empty( ::nArea )
  75.           DbUseArea( .T., ::cDriver, ::cFile, ::cAlias,, ::lReadOnly )
  76.           ::nArea:= Select()
  77.          else
  78.           DbSelectArea( ::nArea )
  79.        end
  80. RETURN
  81.  
  82. //----------------------------------------------------------------------------//
  83.  
  84. METHOD AddIndex( xIndex, cTag ) CLASS TDataBase
  85.        if IS_ARRAY( xIndex ) THEN aEval( xIndex, {|e| ::AddIndex( e ) } )
  86.        DbSelectArea( ::nArea )
  87.        if IS_NIL( xIndex )
  88.           aEval( ::aIndex, {|a| DbSetIndex( a[1] ) } )
  89.          else
  90.           // Busca cIndex y/o cTag para ver si existe.
  91.           if ( aScan( ::aIndex, { |a| a[1] == Upper( xIndex ) } ) <> 0 ) .and. ;
  92.              ( IS_NIL( cTag ) .or. aScan( ::aIndex, { |a| a[1] == Upper( cTag ) } ) <> 0 )
  93.              * OrdListAdd( cIndex, cTag )
  94.              DbSetIndex( xIndex )
  95.             else
  96.              Warning( "El fichero Indice o el tag no existe" )
  97.           end
  98.        end
  99.        ::nIndex := IndexOrd() // ???
  100. RETURN
  101.  
  102. //----------------------------------------------------------------------------//
  103.  
  104. METHOD FieldGet( xCampo ) CLASS TDataBase
  105.        if valtype( xCampo ) == "C" THEN xCampo:= (::cAlias)->( fieldpos( xCampo ) )
  106. RETURN ( ::cAlias )->( fieldget( xCampo ) )
  107.  
  108. //----------------------------------------------------------------------------//
  109.  
  110. METHOD FieldPut( xCampo, xVal ) CLASS TDataBase
  111.        if valtype( xCampo ) == "C" THEN xCampo:= (::cAlias)->( fieldpos( xCampo ) )
  112. RETURN ( ::cAlias )->( fieldput( xCampo, xVal ) )
  113.  
  114. //----------------------------------------------------------------------------//
  115.  
  116. METHOD SetScope( xInf, xSup ) CLASS TDataBase
  117.        local nCont:= PCount()
  118.        Switch nCont
  119.         case 0: if Empty( ::Scope ) THEN Sx_ClrScope() ELSE nCont:=1; xInf:= ::Scope
  120.         case 1: Sx_SetScope( 0, xInf ); Sx_SetScope( 1, xInf )
  121.         case 2: Sx_SetScope( 0, xInf ); Sx_SetScope( 1, xSup )
  122.        endSwitch
  123. RETURN
  124.  
  125. //----------------------------------------------------------------------------//
  126.  
  127. METHOD Locate( For, While, Next ) CLASS TDataBase
  128.        static bWhile, bFor, nNext
  129.        DbSelectArea( ::nArea )
  130.        //Si es un mensaje Locate.
  131.        if( For != NIL .or. While != NIL .or. Next != NIL )
  132.          DEFAULT bWhile = {|| .T. }
  133.          DEFAULT nNext  = 4000000000
  134.          bFor := For
  135.        end
  136.        //Si es un mensaje Continue:
  137.        while eval( bWhile ) .and. nNext-- > 0
  138.              if eval( bFor ) THEN RETURN
  139.              ::SKip()
  140.        end
  141.        //Provocar eof() si no encontrado
  142.        ::GoBottom()
  143.        ::Skip()
  144. RETURN
  145.  
  146. //----------------------------------------------------------------------------//
  147.