;Example of bdbfs plugin file.
;Appends from another base all records absent in current.
;The tables must have the same structure.
;The CRC32-algorithm is used for comparing. See also mark_dbl.ini.
;Uses also some elements of bdbfs visual interface.

#include clipper.ch
#include bdbfs.ch

LOCAL nRec, nApp, crc1, crc2

cCodePage:='cp866'
IF !FileExist("OTHER.DBF")
	SHOW 'OTHER.DBF is absent'
	#BREAK
ENDIF

nRec:=RECNO()
nApp:=0

SELECT 2
USE HERE other
START SEARCH
WHILE !EOF() .AND. CheckEsc()	//Esc=Abort
	crc2:=''
	=For(1, FCOUNT(), {|i| crc2:=crc2+XTOC(FieldGet(i)) })

	SELECT 1
	DBGOTO( 2->(RECNO()) )

	crc1:=''
	=For(1, FCOUNT(), {|i| crc1:=crc1+XTOC(FieldGet(i)) })
//Another (slower) way
;	LOCAL i
;	FOR i:=1 TO FCOUNT()
;		crc1:=crc1+XTOC(FieldGet(i))
;	NEXT	

	SELECT 2
	IF CRC32(crc1) <> CRC32(crc2)
		Scatter()
		SELECT 1
		APPEND BLANK
		IF RLOCK()
			Gather()
		ENDIF
		nApp:=nApp+1
	ENDIF
	SELECT 2
	SKIP
ENDWHILE

END METER
SHOW WITH BELL NTRIM(nApp)+' records appended'

CLOSE 2

SELECT 1
DBGOTO(nRec)

DISABLE REOPEN		//Disable main file Re-Open
