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 >
Wrap
Text File
|
1994-06-09
|
6KB
|
147 lines
// Clase realizada por Jose Mariano
// Warning: Under construction
#include "FiveWin.ch"
//----------------------------------------------------------------------------//
CLASS TDataBase
DATA cAlias, cFile, cDriver
DATA aField, aIndex
DATA nIndex, nArea
DATA lReadOnly, cScope
METHOD New( cAlias, oDbm ) CONSTRUCTOR
METHOD AddIndex( xIndex, cTag )
METHOD Append() INLINE ( ::cAlias )->( DbAppend() )
METHOD Bof() INLINE ( ::cAlias )->( Bof() )
METHOD Close() INLINE ( ::cAlias )->( DbCloseArea() ), ::nArea:= 0
METHOD CloseInd() INLINE ( ::cAlias )->( DbClearIndex() ), ::nIndex:= 0
METHOD Commit() INLINE ( ::cAlias )->( DbCommit() )
METHOD Delete() INLINE ( ::cAlias )->( DbDelete() )
METHOD DeleteTag( cTag, cFile ) INLINE ( ::cAlias )->( Sx_TagDelete( cTag, cFile ) )
METHOD Eof() INLINE ( ::cAlias )->( Eof() )
METHOD FieldWBlock( cCampo ) INLINE FieldWBlock( cCampo, ::nArea )
METHOD FieldGet( n )
METHOD FieldPut( n, xVal )
METHOD Flock() INLINE ( ::cAlias )->( Flock() )
METHOD Found() INLINE ( ::cAlias )->( Found() )
METHOD GoBottom() INLINE ( ::cAlias )->( DbGoBottom() )
METHOD GoTo( nReg ) INLINE ( ::cAlias )->( DbGoto( nReg ) )
METHOD GoTop() INLINE ( ::cAlias )->( DbGoTop() )
METHOD KeyCount() INLINE ( ::cAlias )->( Sx_KeyCount() )
METHOD KeyGoto( nKey ) INLINE ( ::cAlias )->( Sx_KeyGoto( nKey ) )
METHOD KeyNum() INLINE ( ::cAlias )->( Sx_KeyNo() )
METHOD LastRec() INLINE ( ::cAlias )->( LastRec() )
METHOD Locate( bWhile, bFor, nNext )
METHOD NumTags( cIndex ) INLINE ( ::cAlias )->( Sx_TagCount( cIndex ) )
METHOD NumOrder() INLINE ( ::cAlias )->( Sx_OrderCount() )
METHOD Open() INLINE ::OpenDb(), ::AddIndex()
METHOD OpenDb()
METHOD Seek( xValor, lSoftSeek ) INLINE (::cAlias)->( DbSeek( xValor, lSoftSeek ) )
METHOD SetOrder( nOrd ) INLINE (::cAlias)->( Sx_SetTagOrder( ::nIndex := nOrd ) )
METHOD SetScope( xInf, xSup )
METHOD SetTagNo( nTag ) INLINE ( ::cAlias )->( Sx_SetTagNo( nTag ) )
METHOD SetTag( cTag, cIndex ) INLINE ( ::cAlias )->( Sx_SetTagOrder( cTag, cIndex ) )
METHOD Skip( nReg ) INLINE ( ::cAlias )->( DbSkip( nReg ) )
METHOD UnLock() INLINE ( ::cAlias )->( DbUnLock() )
ENDCLASS
//----------------------------------------------------------------------------//
METHOD New( cAlias, oDbm ) CLASS TDataBase
if IS_NIL( oDbm ) THEN oDbm:= oDbms
::cAlias := Upper( cAlias )
::nIndex := 0
::nArea := 0
::lReadOnly := FALSE
// Otra chapuza... para que inicialice cFile, aField y aIndex.
oDbm:Db( Self )
RETURN Self
//----------------------------------------------------------------------------//
METHOD OpenDb() CLASS TDataBase
if Empty( ::nArea )
DbUseArea( .T., ::cDriver, ::cFile, ::cAlias,, ::lReadOnly )
::nArea:= Select()
else
DbSelectArea( ::nArea )
end
RETURN
//----------------------------------------------------------------------------//
METHOD AddIndex( xIndex, cTag ) CLASS TDataBase
if IS_ARRAY( xIndex ) THEN aEval( xIndex, {|e| ::AddIndex( e ) } )
DbSelectArea( ::nArea )
if IS_NIL( xIndex )
aEval( ::aIndex, {|a| DbSetIndex( a[1] ) } )
else
// Busca cIndex y/o cTag para ver si existe.
if ( aScan( ::aIndex, { |a| a[1] == Upper( xIndex ) } ) <> 0 ) .and. ;
( IS_NIL( cTag ) .or. aScan( ::aIndex, { |a| a[1] == Upper( cTag ) } ) <> 0 )
* OrdListAdd( cIndex, cTag )
DbSetIndex( xIndex )
else
Warning( "El fichero Indice o el tag no existe" )
end
end
::nIndex := IndexOrd() // ???
RETURN
//----------------------------------------------------------------------------//
METHOD FieldGet( xCampo ) CLASS TDataBase
if valtype( xCampo ) == "C" THEN xCampo:= (::cAlias)->( fieldpos( xCampo ) )
RETURN ( ::cAlias )->( fieldget( xCampo ) )
//----------------------------------------------------------------------------//
METHOD FieldPut( xCampo, xVal ) CLASS TDataBase
if valtype( xCampo ) == "C" THEN xCampo:= (::cAlias)->( fieldpos( xCampo ) )
RETURN ( ::cAlias )->( fieldput( xCampo, xVal ) )
//----------------------------------------------------------------------------//
METHOD SetScope( xInf, xSup ) CLASS TDataBase
local nCont:= PCount()
Switch nCont
case 0: if Empty( ::Scope ) THEN Sx_ClrScope() ELSE nCont:=1; xInf:= ::Scope
case 1: Sx_SetScope( 0, xInf ); Sx_SetScope( 1, xInf )
case 2: Sx_SetScope( 0, xInf ); Sx_SetScope( 1, xSup )
endSwitch
RETURN
//----------------------------------------------------------------------------//
METHOD Locate( For, While, Next ) CLASS TDataBase
static bWhile, bFor, nNext
DbSelectArea( ::nArea )
//Si es un mensaje Locate.
if( For != NIL .or. While != NIL .or. Next != NIL )
DEFAULT bWhile = {|| .T. }
DEFAULT nNext = 4000000000
bFor := For
end
//Si es un mensaje Continue:
while eval( bWhile ) .and. nNext-- > 0
if eval( bFor ) THEN RETURN
::SKip()
end
//Provocar eof() si no encontrado
::GoBottom()
::Skip()
RETURN
//----------------------------------------------------------------------------//