Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SEEK(),INDEXSEEK() or KeyMatch() or SELECT-SQL?
Message
 
 
À
13/04/2005 04:00:09
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Divers
Thread ID:
01002645
Message ID:
01004119
Vues:
37
Gregory,

Thanks. Yes, I figured this out yesterday and programmed accordingly. I think, I posted my latest version of the code.

>Think of this scenario
>
>Invoice 1:n Invoiceline
>
>Inserting something in InvoiceLine. Invoiceline needs a parent pointer, if not, we get an insert error
>
>Now suppose we have a cascade update, ie Id update on Invoice cascade updates InvoiceLine
>
>The update on InvoiceLine needs not check the parent pointer if it is a cascaded update from Invoice
>
>
>That is wat the code does
>
>If ( no cascadeparent or (cascasdeparent <> Contacts) )
>    If ( indexexpr changed )
>       check relation
>    endif
>endif
>
>
>>Bellow is the code I generated for a test database. You're right, that it has to be more robust. E.g. if triggerlevel <>1 I need to check, if it is the same parent initiated it.
>>But in this code I do not understand, why it is telling about Insert trigger violated while it is an Update trigger?
>>
>>********************************************************************************
>>procedure __RI_UPDATE_calls
>>** "Referential integrity update trigger for" calls
>>LOCAL llRetVal
>>llRetVal = .t.
>>PRIVATE pcParentDBF,pnParentRec,pcChildDBF,pnChildRec,pcParentID,pcChildID
>>PRIVATE pcParentExpr,pcChildExpr
>>STORE "" TO pcParentDBF,pcChildDBF,pcParentID,pcChildID,pcParentExpr,pcChildExpr
>>STORE 0 TO pnParentRec,pnChildRec
>>IF _triggerlevel=1
>>  BEGIN TRANSACTION
>>  PRIVATE pcRIcursors,pcRIwkareas,pcRIolderror,pnerror,;
>>  pcOldDele,pcOldExact,pcOldTalk,pcOldCompat,PcOldDBC
>>  pcOldTalk=SET("TALK")
>>  SET TALK OFF
>>  pcOldDele=SET("DELETED")
>>  pcOldExact=SET("EXACT")
>>  pcOldCompat=SET("COMPATIBLE")
>>  SET COMPATIBLE OFF
>>  SET DELETED ON
>>  SET EXACT OFF
>>  pcRIcursors=""
>>  pcRIwkareas=""
>>  pcRIolderror=ON("error")
>>  pnerror=0
>>  ON ERROR pnerror=rierror(ERROR(),message(),message(1),program())
>>  IF TYPE('gaErrors(1)')<>"U"
>>    release gaErrors
>>  ENDIF
>>  PUBLIC gaErrors(1,12)
>>  pcOldDBC=DBC()
>>  SET DATA TO ("CONTACTS")
>>ENDIF first trigger
>>LOCAL lcParentID && parent's value to be sought in child
>>LOCAL lcOldParentID && previous parent id value
>>LOCAL lcChildWkArea && child work area handle returned by riopen
>>LOCAL lcChildID && child's value to be sought in parent
>>LOCAL lcOldChildID && old child id value
>>LOCAL lcParentWkArea && parentwork area handle returned by riopen
>>LOCAL lcStartArea
>>lcStartArea=select()
>>llRetVal=.t.
>>lcChildWkArea=select()
>>IF _triggerlevel=1 or type("pccascadeparent")#"C" or (NOT pccascadeparent=="CONTACTS")
>>  SELECT (lcChildWkArea)
>>  lcChildID=CONTACT_ID
>>  lcOldChildID=oldval("CONTACT_ID")
>>  pcChildDBF=dbf(lcChildWkArea)
>>  pnChildRec=recno(lcChildWkArea)
>>  pcChildID=lcOldChildID
>>  pcChildExpr="CONTACT_ID"
>>  IF lcChildID<>lcOldChildID
>>    lcParentWkArea=riopen("contacts","contact_id")
>>    IF lcParentWkArea<=0
>>      IF _triggerlevel=1
>>        DO riend WITH .F.
>>      ENDIF at the end of the highest trigger level
>>      SELECT (lcStartArea)
>>      RETURN .F.
>>    ENDIF not able to open the child work area
>>    pcParentDBF=dbf(lcParentWkArea)
>>    llRetVal=SEEK(lcChildID,lcParentWkArea)
>>    pnParentRec=recno(lcParentWkArea)
>>    =rireuse("contacts",lcParentWkArea)
>>    IF NOT llRetVal
>>      pnError = rierror(-1,"Insert restrict rule violated.","","")
>>      IF _triggerlevel=1
>>        DO riend WITH llRetVal
>>      ENDIF at the end of the highest trigger level
>>      SELECT (lcStartArea)
>>      RETURN llRetVal
>>    ENDIF no parent
>>  ENDIF this value was changed
>>ENDIF not part of a cascade from "contacts"
>>lcParentWkArea=lcChildWkArea
>>IF _triggerlevel=1
>>  do riend with llRetVal
>>ENDIF at the end of the highest trigger level
>>SELECT (lcStartArea)
>>RETURN llRetVal
>>** "End of Referential integrity Update trigger for" calls
>>
>>
>[snip]
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform