*Init
Clear
Close tables All
Try
MkDir c:\temp
Catch
*
EndTry
Erase c:\temp\test.dbf
Erase c:\temp\testchild.dbf
Create Table c:\temp\test.dbf (iID I autoinc, lBool L)
Create Table c:\temp\testchild.dbf (iID I autoinc, iTestID I, cChildtext C(10)) && iTestID = foreign key to test.iid
Select test
* Index on field of the child table
Index on testchild.cchildtext Tag xChildText
* Close all newly generated tables to reset
Close Tables All
* start testing
Set Multilocks On
CursorSetProp("Buffering",5,0)
* testchild has to be opened first (try reversing, you'll see)
Use c:\temp\testchild.dbf In 0
Use c:\temp\test.dbf In 0
Insert Into test (lBool) values (.T.)
Insert Into testchild (iTestID, cChildtext) Values (1,"aaa")
* first experiment, seek in test:
? "Seeking aaa, expect .T., really get ",Seek("aaa","test","xChildText")
* for comparison: Seek bbb
? "Seeking bbb, expect .F., really get ",Seek("bbb","test","xChildText")
* Now update child data only
Update testchild set cChildtext = "bbb"
* second experiment, seek in test, index not yet updated:
? "Seeking aaa, expect .T., really get ",Seek("aaa","test","xChildText")
* for comparison: Seek bbb
? "Seeking bbb, expect .F., really get ",Seek("bbb","test","xChildText")
* Causing index update in parent table (hopefully)
SetFldState("lBool",4,"test")
TableUpdate(2,.t.,"test")
* third experiment, seek in test, index should have been updated:
? "Seeking aaa, expect .F., really get ",Seek("aaa","test","xChildText")
* for comparison: Seek bbb
? "Seeking bbb, expect .T., really get ",Seek("bbb","test","xChildText")
? "Is everything as expected? Especially the last two Seeks? Then we had success!"