Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SEEK(),INDEXSEEK() or KeyMatch() or SELECT-SQL?
Message
 
 
To
14/04/2005 10:08:38
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01002645
Message ID:
01004648
Views:
40
>Nadya,
>
>There's a point that Thomas is saying and I wrote it too (message#1004128).
>
>This is one you have to address
>____________________________________________________________
Thomas already did it for me < g > by opening table again.


>>Thomas,
>>
>>Thanks a lot for doing by job for me :)
>>
>>BTW, this piece of code
>>
>>if not alltrim(ParentKey) == m.lcParentKeyExp && So it would calculate it only once
>>					lcParentKeyExp = alltrim(ParentKey)
>>					luOldKey       = oldval(m.lcParentKeyExp, m.lcAlias)
>>					luNewKey       = evaluate(IIF("."$m.lcParentKeyExp, "", m.lcAlias + ".") + m.lcParentKeyExp )
>>				endif
>>
>>will not work, if we're using compound keys [though in our system we don't] - this was pointed out by Gregory Adam, that's why I select initial alias, evaluate, then switch back.
>>
>>>Well,
>>>
>>>my first look possible problem would be the 2 scans. perhaps
>>>
>>>Index on upper(ChildTB) = m.lcSearch + Padl(InsTrigger, 2, "0") and
>>>lcScanSearch = m.lcSearch + "01"
>>>scan  upper(ChildTB)+ Padl(InsTrigger, 2, "0") = lcScanSearch and !plError ??
>>>
>>>or even seek()-scan rest ?
>>>
>>>Otherwise just at first glance:
>>>You added more lines code - work the other way!
>>>Therefore the individual cascade/restrict functions should be slower...
>>>
>>>You went from the memory objects to a table (in its own datasession ?) Is the "Currentrecord" in RIDefinitions guaranteed to stay even when triggers maybe call RI recursively inside each function ?
>>>
>>>If so, changing along the lines of
>>>  case m.lcTriggerType = 'DELETE'
>>>   if RIDefinitions.DelTrigger > 0
>>>     if not alltrim(ParentKey) == m.lcParentKeyExp && So it would calculate it only once
>>>       *-- iif can be eliminated/replaced by concat if no alias is ever present in parentkey...
>>>         luKey = evaluate(IIF("."$ParentKey, "", m.lcAlias + ".") + alltrim(ParentKey))
>>>     endif
>>>				
>>>     = ICASE(isnull(m.luKey), .f., ;
>>>	 RIDefinitions.DelTrigger = 2, Cascade_Delete(m.luKey, alltrim(RIDefinitions.ChildKey)), ;
>>>	 RIDefinitions.DelTrigger = 1, Restrict_Delete(m.luKey) )
>>>    endif
>>>   endcase
>>>
>>>function Cascade_Delete
>>>lparameters tuOldKey, tcChildKey
>>>
>>>delete ;
>>>	from (RIDefinitions.ChildTB) ;
>>>	where &tcChildKey = m.tuOldKey
>>>
>>>if m.plError
>>>	local laError[1] &&, tcParentTable, tcParentKey
>>>	aerror(laError)
>>>
>>>	LogRIError(laError[1], laError[2], 'Cascade Delete', ;
>>>		alltrim(RIDefinitions.ParentTB), ;
>>>                iif(used(alltrim(RIDefinitions.ParentTB)),recno(alltrim(RIDefinitions.ParentTB)),0), ;
>>>		alltrim(RIDefinitions.ParentKey), m.tuOldKey, ;
>>>		alltrim(RIDefinitions.ChildTB), 0, m.tcChildKey, m.tuOldKey)
>>>endif && plError
>>>RETURN
>>>
>>>function Restrict_Delete
>>>lparameters tuKey
>>>>*!*	(tcParentTable, ;
>>>>*!*		tcChildTable, ;
>>>>*!*		tcParentKey, ;
>>>>*!*		tcChildKey, ;
>>>>*!*		tuKey, tcTag)
>>>>
>>>local lcTable
>>>lcTable = strtran(alltrim(RIDefinitions.ChildTB), ' ', '_')
>>>
>>>if not used(m.lcTable)
>>>	use (alltrim(RIDefinitions.ChildTB)) again in 0 shared alias (m.lcTable)
>>>endifused(lcTable)
>>>
>>>**** WHERE IS m.tcTag coming from now ??? was commented out but not in the new code ??
>>>if indexseek(m.tuKey, .f., m.lcTable, m.tcTag) && Record exists
>>>*	if keymatch(m.tuKey,tagno(m.tcTag, '', m.lcTable), m.lcTable) && Record exists
>>>	plError = .t.
>>>	#define cnERR_TRIGGER_FAILED 1539
>>>	LogRIError(cnERR_TRIGGER_FAILED, 'Trigger Failed', 'Restrict Delete', ;
>>>		alltrim(RIDefinitions.ParentTB), ;
>>>                iif(used(alltrim(RIDefinitions.ParentTB),recno(alltrim(RIDefinitions.ParentTB),0), ;
>>>		alltrim(RIDefinitions.ParentKey), m.tuKey, ;
>>>		alltrim(RIDefinitions.ChildTB), 0, alltrim(RIDefinitions.ChildKey), m.tuKey)
>>>endif &&_tally > 0
>>>RETURN
>>>
>>>
>>>might give some speed back and point you in the right direction. Check the comment line on the missing tcTag... I am certain that eliminating one line of code buffering the trimmed table field si slower than 2 or 3 accesses to the field. If there is no error, which should be the normal state of affairs, the line of code is eliminated without penalty and lead to quicker running time. Change other code accordingly.
>>>
>>>regards
>>>
>>>thomas
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform