Code: Select all
METHOD BuildIndex( )
// Description:
// Parameters :
// Returns :
LOCAL auStruct AS ARRAY
LOCAL aDir AS ARRAY
LOCAL cAppPath AS STRING
LOCAL cOrdExt AS STRING
LOCAL cWorkDir AS STRING
LOCAL cCurDrive AS STRING
LOCAL cDBFile AS STRING
LOCAL cIDXFile AS STRING
LOCAL cVal1 AS STRING
LOCAL iVal2 AS INT
LOCAL dToday AS DATE
LOCAL x AS DWORD
LOCAL cStart AS STRING
LOCAL cEnd AS STRING
LOCAL cElapsed AS STRING
LOCAL lSuccess AS LOGIC
LOCAL lVal3 AS LOGIC
LOCAL odbServer AS DBServer
cStart := Time( )
RddSetDefault( "DBFCDX" ) // Comix 3 ( CDX )
SetDeleted( .T. )
SetAnsi( TRUE )
RDDINFO( _SET_MEMOBLOCKSIZE, 1 )
RDDINFO( _SET_MEMOEXT, ".DBV" )
RDDINFO( _SET_OPTIMIZE, TRUE )
RDDINFO( _SET_STRICTREAD, TRUE )
SetExclusive( FALSE )
SetSoftSeek( TRUE )
SetCollation( #CLIPPER )
SetInternational( #CLIPPER )
SetPath( cAppPath )
SetDefault( cAppPath )
SetNatDLL( "ITALIAN.DLL" )
SetCentury( TRUE )
SetEpoch( 1990 )
SetDateCountry( ITALIAN )
SetDateFormat( "dd-mm-yyyy" )
SetDecimalSep( Asc( "," ) )
SetThousandSep( Asc( "." ) )
SetDecimal( 2 )
SetFloatDelta( 0.001 )
dToday := Today( )
cOrdExt := ORDBAGEXT( ) // index extension ( .CDX )
cCurDrive := CurDrive( )
cWorkDir := WorkDir( )
cAppPath := cWorkDir
cDBFile := cAppPath + "TestDBF"
SELF:oDCFixedText2:TextValue := "Running..."
SELF:oCCPBCancel:Disable( )
SELF:oCCPBOk:Disable( )
// delete existing .dbf and .cdx files
aDir := Directory( cAppPath + "TestDBF.*" )
AEval( aDir, { |aFile| FErase( cAppPath + aFile[ F_NAME ] ) } )
// create DBF file
auStruct := ArrayCreate( 4 )
auStruct[ 1 ] := { "Field1", "C", 20, 0 }
auStruct[ 2 ] := { "Field2", "N", 9, 0 }
auStruct[ 3 ] := { "Field3", "D", 8, 0 }
auStruct[ 4 ] := { "Field4", "L", 1, 0 }
lSuccess := DBCREATE( cDBFile, auStruct, "DBFCDX" )
IF lSuccess
// dbf creation successful, populate with random records
odbServer := DbServer{ cDBFile, .F., .F. }
FOR x := 1 UPTO 500000
cVal1 := "Test" + StrZero( x, 6 )
iVal2 := x
lVal3 := !lVal3
odbServer:Append( .T. )
odbServer:FIELDPUT( #Field1, cVal1 )
odbServer:FIELDPUT( #Field2, iVal2 )
odbServer:FIELDPUT( #Field3, dToday )
odbServer:FIELDPUT( #Field4, lVal3 )
NEXT
odbServer:Commit( )
odbServer:Unlock( )
cIDXFile := cDBFile + cOrdExt
IF !File( cIDXFile )
lSuccess := odbServer:SetOrderCondition( "Deleted() == .F. .And. Field4 == .F.", { || DELETED() == .F. .AND. odbServer:FIELDGET( #Field4 ) == .F. },,,,,,,,,,,,, )
IF lSuccess
lSuccess := odbServer:CreateOrder( "Order1", cIDXFile, "Field1 + '~' + DToS( Field3 )",, )
IF lSuccess
odbServer:Commit( )
ENDIF
ENDIF
lSuccess := odbServer:SetOrderCondition( "Deleted() == .F. .And. Field4 == .T.", { || DELETED() == .F. .AND. odbServer:FIELDGET( #Field4 ) == .T. },,,,,,,,,,,,, )
IF lSuccess
lSuccess := odbServer:CreateOrder( "Order2", cIDXFile, "Field1 + '~' + DToS( Field3 )",, )
IF lSuccess
odbServer:Commit( )
ENDIF
ENDIF
lSuccess := odbServer:SetOrderCondition( "Deleted() == .F.", { || DELETED() == .F. },,,,,,,,,,,,, )
IF lSuccess
lSuccess := odbServer:CreateOrder( "Order3", cIDXFile, "Field2",, )
IF lSuccess
odbServer:Commit( )
ENDIF
ENDIF
lSuccess := odbServer:SetOrderCondition( "Deleted() == .F. .And. Field4 == .F. ", { || DELETED() == .F. .AND. odbServer:FIELDGET( #Field4 ) == .F. },,,,,,,,,,,,, )
IF lSuccess
lSuccess := odbServer:CreateOrder( "Order4", cIDXFile, "Str( Field2, 7 ) + '~' + Field1 + '~' + DToS( Field3 )",, )
IF lSuccess
odbServer:Commit( )
ENDIF
ENDIF
lSuccess := odbServer:SetOrderCondition( "Deleted() == .F. .And. Field4 == .T. ", { || DELETED() == .F. .AND. odbServer:FIELDGET( #Field4 ) == .T. },,,,,,,,,,,,, )
IF lSuccess
lSuccess := odbServer:CreateOrder( "Order5", cIDXFile, "Str( Field2, 7 ) + '~' + Field1 + '~' + DToS( Field3 )",, )
IF lSuccess
odbServer:Commit( )
ENDIF
ENDIF
odbServer:Close( )
ENDIF
ENDIF
cEnd := Time( )
cElapsed := ElapTime( cStart, cEnd )
SELF:oDCFixedText2:TextValue := "Finished!"
SELF:oCCPBCancel:Enable( )
SELF:oCCPBOk:Enable( )
TextBox{ SELF, "TestDbf", "Elapsed: " + cElapsed + CRLF + "Build Index done!" }:Show( )
_Quit( )
RETURN NIL
1- in VO the time to create the dbf and the index file is much much shorter then in X#