Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Compare Tables
Message
De
22/08/2002 04:11:24
 
 
À
21/08/2002 13:49:09
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
Divers
Thread ID:
00692106
Message ID:
00692346
Vues:
27
>I am sure this must be in the achives somewhere, but is there a clean way to compare two tables or a table and a cursor to determine if they are identical?
>
>Bill

Bill,

Here is something I have found in my utility box. It works fast enough on a few hundred records.

I commented out the therm.
*---------------------------------------------------------------------------
#define TRUE .T.
#define FALSE .F.

procedure	CursorEqual(cursor1, cursor2, NeedTherm, ignorefilter)
	&& compare order must be set prior to calling this
	if( empty(Cursor1) or empty(Cursor2) )
		assert FALSE
		return	FALSE
	endif
	if( !(type('Cursor1') == T_CHARACTER) )
		assert FALSE
		return	FALSE
	endif
	if( !(type('Cursor2') == T_CHARACTER) )
		assert FALSE
		return	FALSE
	endif
	
	if( recsize(Cursor1) <> recsize(Cursor2) )
		return	FALSE
	endif
	if( fcount(Cursor1) <> fcount(Cursor2) )
		return	FALSE
	endif
	
	
	
	&& reccount
	local nrecs1, nrecs2
	nrecs1 = RecordCount(Cursor1, IgnoreFilter)
	nrecs2 = RecordCount(Cursor2, IgnoreFilter)
	if( nrecs1 <> nrecs2 )
		return FALSE
	endif
	
	&& now, compare record by record, order is set
	local s, r1, r2, sTalk
	s = select(0)
	r1 = recno(Cursor1)
	r2 = recno(Cursor2)
	sTalk = set('Talk')
	set Talk Off
	
	if( IgnoreFilter )
		local f1, f2
		f1 = filter(Cursor1)
		f2 = filter(Cursor2)
		select (Cursor1)
		set filter to
		select (Cursor2)
		set filter to
	endif
	
	go top in (Cursor1)
	go top in (Cursor2)
	
	local Failed, fc, c1, c2
	Failed = FALSE
	fc = fcount(Cursor1)
	if( NeedTherm )
		&& local t
		&& t = Therm(nrecs1)
	endif
	
	for i = 1 to nrecs1		
		&& =iif( NeedTherm and empty(mod(i,100)), t.Update(i), FALSE)
		
		select (Cursor1)
		scatter memo name c1
		select (Cursor2)
		scatter memo name c2
		Failed = !compobj(c1, c2)
		if( Failed )
			exit
		endif
	
		skip in (Cursor1)
		skip in (Cursor2)
	endfor
	
	if( IgnoreFilter )
		select (Cursor1)
		set filter to &f1
		select (Cursor2)
		set filter to &f2
	endif
	
	select (s)
	=RestoreRecordNumber(r1, Cursor1)
	=RestoreRecordNumber(r2, Cursor2)
	set Talk &sTalk
	
	return	!Failed
endproc
*---------------------------------------------------------------------------
procedure	RestoreRecordNumber(r, alias_)
	if( empty(alias_) )
		alias_ = alias()
	endif
	
	local sTalk
	sTalk = set('Talk')
	set Talk Off
	
	if( r <= reccount(alias_) )
		go r in (alias_)
	else	&& eof condi
		go bottom in (alias_)
		if( !eof(alias_) )
			skip in (alias_)
		endif
	endif
	
	set Talk &sTalk
endproc
*---------------------------------------------------------------------------
procedure	RecordCount(alias_, IgnoreFilter)
	if( empty(alias_) )
		alias_ = alias()
	endif
	
	if( set('Deleted') == 'OFF' )
		if( IgnoreFilter or empty(filter(alias_)) )
			return reccount(alias_)
		endif
	endif
		
	if( IgnoreFilter )
		local f
		f = filter(alias_)
	endif
	
	local s, sTalk, n, r
	s = select(0)
	r = recno(alias_)
	sTalk = set('Talk')
	set Talk Off
	select (alias_)
	if( IgnoreFilter )
		set filter to
	endif
	count to n	
	if( IgnoreFilter )
		set Filter to &f
	endif
	set Talk &sTalk
	select (s)
	=RestoreRecordNumber(r, alias_)
	
	return n
endproc
*---------------------------------------------------------------------------
Gregory
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform