Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How can I use Globally Unique IDentifier (GUID)
Message
From
04/11/2004 11:13:42
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00958008
Message ID:
00958136
Views:
15
>Thanks for the reply Gregory,
>if you have a time would like to give a sample via which is containing tables of fields myguid,mydtime . i need a prototype for situation 1 - 2 and 3
>
>(1) in tableA and not in TableB
>>>> insert into tableB
>
>(2) in tableB and not in TableA
>>>> insert into tableA
>
>(3) exists in both tableA and tableB
>
>TIA

Soykan,

I believe that offline views are the better as Cetin says

This is a sample with the 3 conditions. You may want to change condition 3
*--------------------------------------------------------------------------
function do_it()

	=SampleCursors()

	=CursorCompare('CursorOne', 'CursorTwo')
	
endfunc
*--------------------------------------------------------------------------
function CursorCompare(CursorName1, CursorName2)

	local s
	s = select(0)
	
	select	c1_Id	as	key_1, ;
		recno() as	rec_1 ;
		from (CursorName1) ;
		into cursor tmp1
	
	select	c1_Id	as	key_2, ;
		recno() as	rec_2 ;
		from (CursorName2) ;
		into cursor tmp2

	select * ;
		from tmp1 ;
		full join tmp2 on Key_1 == Key_2 ;
		into cursor tmp
	
	use in tmp1
	use in tmp2
	
	select tmp
	
	local obj1, obj2
	scan all
		
		do case
		case isnull(rec_2)
			select (CursorName1)
			go (tmp.rec_1)
			scatter memo name obj1
			select (CursorName2)
			append blank
			gather name obj1 memo
		
		case isnull(rec_1)
			select (CursorName2)
			go (tmp.rec_2)
			scatter memo name obj2
			select (CursorName1)
			append blank
			gather name obj2 memo
		
		otherwise
			select (CursorName1)
			go (tmp.rec_1)
			scatter memo name obj1
			
			select (CursorName2)
			go (tmp.rec_2)
			scatter memo name obj2
	
			do case
			case compobj(m.obj1, m.obj2)
				&& same
		
			&& 1 more recent than 2
			case m.obj1.c1_dt > m.obj2.c1_dt
				select (CursorName2)
				gather name obj1 memo
			
			otherwise
				select (CursorName1)
				gather name obj2 memo
			
			endcase
		endcase
		
		select tmp
	endscan
	use in tmp
	select (m.s)
endfunc
*--------------------------------------------------------------------------
function SampleCursors()

	Create Cursor CursorOne ;
		(	c1_Id	C(32)	default '', ;
			c1_dt	T		default {}, ;
			c1_f2	I		default 0, ;
			c1_f3	c(10)	default '', ;
			c1_f4	M		default '' ;
		)
	
	index on c1_id tag Id candidate
	=CursorFill('CursorOne', 10)
	
	Create Cursor CursorTwo ;
		(	c1_Id	C(32)	default '', ;
			c1_dt	T		default {}, ;
			c1_f2	I		default 0, ;
			c1_f3	c(10)	default '', ;
			c1_f4	M		default '' ;
		)
	index on c1_id tag Id candidate
	=CursorFill('CursorTwo', 15)
	
	&& Copy some records from One to Two
	=CursorCopyRecords('CursorOne', 'CursorTwo')
endfunc
*--------------------------------------------------------------------------
function CursorFill(CursorName, HowMany)

	local i
	for i = 1 to m.HowMany
		insert into (m.CursorName) ;
			( c1_Id, c1_dt, c1_f2, c1_f3, c1_f4) ;
			values ;
			( Guid_String(), dateTime() - int(rand()*100), m.i, sys(2015), sys(2015) )
			
	endfor

endfunc
*--------------------------------------------------------------------------
function CursorCopyRecords(CursorFrom, CursorTo)
	
	local obj
	&& copy records 3 and 5
	select (CursorFrom)
	go 3
	scatter memo name obj
	select (CursorTo)
	append blank
	obj.c1_f3 = sys(2015)	&& change a field
	obj.c1_f4 = sys(2015)	&& change a field
	gather name obj memo
	
	select (CursorFrom)
	go 5
	scatter memo name obj
	select (CursorTo)
	append blank
        obj.c1_dt = obj.c1_dt + 10
	obj.c1_f3 = sys(2015)	&& change a field
	obj.c1_f4 = sys(2015)	&& change a field
	gather name obj memo
endfunc
*--------------------------------------------------------------------------
Function Guid_String()

	declare integer CoCreateGuid in ole32 string @	
	declare integer StringFromGUID2 in ole32 string,string @,integer 
	
	local guid, guidString, n, s
	guid = space(16)
	do case
	case empty(CoCreateGuid(@guid))
		guidString = space(78)
		n = StringFromGUID2(guid, @guidString,len(guidString))
		do case
		case n = len(guidString)/2
			s = chrtran(guidString, chr(0) + '-{}', '')
			return s
		otherwise
			assert FALSE
			return Null
		endcase
	
	otherwise
		assert FALSE
		return Null
	endcase

endfunc
*--------------------------------------------------------------------------
Gregory
Previous
Reply
Map
View

Click here to load this message in the networking platform