Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
New FAQ - Merge data
Message
From
24/07/2007 13:01:53
Mike Yearwood
Toronto, Ontario, Canada
 
 
To
24/07/2007 11:45:13
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01243120
Message ID:
01243232
Views:
35
>>Hey all
>>
>>Check out FAQ#33156
>
>Hi Mike,
>Maybe you'd want to change the explanation on "or". Unfortunately comparison in SQL doesn't work the same way in other places that we call 'shortcut'. Interestingly if it's only field3 that has changed then there would be more calls vs if all those foelds were changed.

Hi Cetin! How are you?

I did something like this test to prove the shortcut once before, but since you asked... :)

I created 3 records. Only Record 1 has a difference in Field3.

The output of the following programming is this:

I'm assuming this is some kind of setup: It remained constant no matter how many records.
2 field3a
2 field3a
2 field3a
2 field3a
2 field2
2 field2
2 field1
2 field1

I believe it gets interesting here:
2 field3a
1 field1
1 field2
1 field3a

That seems to be it detecting a difference in only field3 and not firing the test for field1 and field2. That's the shortcut I expected. It immediately updates fields 1, 2 and 3.

Then it seems to proceed to check all fields in record 2, of course, since there were no differences.

Then it seems to check all fields in record 3 again since there were no differences.

It will not have to check all fields in all records. That's what I'd expect in SQL or VFP. I was referring to the savings to be had when lots of records have a change in the certain fields. These can be updated quickly because the conditions won't be checked.
CLEAR
SET TALK OFF
CREATE TABLE TARGET_TABLE FREE ;
	(pk i, ;
	FIELD1 C(10),;
	FIELD2 C(10),;
	FIELD3 C(10))

INSERT INTO target_table ;
	(pk, ;
	field1, ;
	field2, ;
	field3) ;
	VALUES ;
	(1, ;
	"field1",;
	"field2",;
	"field3")

INSERT INTO target_table ;
	(pk, ;
	field1, ;
	field2, ;
	field3) ;
	VALUES ;
	(2, ;
	"field1",;
	"field2",;
	"field3")

INSERT INTO target_table ;
	(pk, ;
	field1, ;
	field2, ;
	field3) ;
	VALUES ;
	(3, ;
	"field1",;
	"field2",;
	"field3")

CREATE TABLE SOURCE_TABLE FREE ;
	(pk i, ;
	FIELD1 C(10),;
	FIELD2 C(10),;
	FIELD3 C(10))

INSERT INTO source_table ;
	(pk, ;
	field1, ;
	field2, ;
	field3) ;
	VALUES ;
	(1, ;
	"field1",;
	"field2",;
	"field3a")

INSERT INTO source_table ;
	(pk, ;
	field1, ;
	field2, ;
	field3) ;
	VALUES ;
	(2, ;
	"field1",;
	"field2",;
	"field3")

INSERT INTO source_table ;
	(pk, ;
	field1, ;
	field2, ;
	field3) ;
	VALUES ;
	(3, ;
	"field1",;
	"field2",;
	"field3")

UPDATE t ;
	SET ;
		t.field1 = MYUDF(S.field1,1), ;
		t.field2 = MYUDF(S.field2,1), ;
		t.field3 = MYUDF(s.field3,1) ;
	FROM ;
		source_table s ;
		inner join target_table t ;
		on t.pk = s.pk ;
	WHERE t.field3 # myudf(s.field3,2) ;
		OR t.field2 # myudf(s.field2,2) ;
		OR t.field1 # myudf(s.field1,2)
RETURN

FUNCTION MYUDF
LPARAMETERS m.tcField, m.tnMode
?m.tnMode,m.tcField
RETURN m.tcField
ENDFUNC
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform