>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>
>> >>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 ??>>
>> 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) >>endif &¬ used(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 >>>>