Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Getting field name based on tag name
Message
 
 
À
29/09/2008 14:07:56
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 9 SP2
OS:
Windows XP
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01351504
Message ID:
01351551
Vues:
24
The select I posted was the exact one.

Anyway, here is what I have so far:
lnTables = ADBOBJECTS(laAllTables,"Relation")
ASORT(laAllTables)
*!*	A two-dimensional array is created when you specify RELATION for cSetting. 
*!*	Each row in the two-dimensional array corresponds to a relationship 
*!*	in the database. 
*!*	The first column in an array row contains the name of the child table and 
*!*	the second column in an array row contains the name of the parent table. 
*!*	The third column contains the name of the index tag for the child table and 
*!*	the fourth column contains the name of the index tag for the parent table. 

*!*	The fifth column in an array row contains referential integrity information. This column is empty if the relation has no referential integrity rules. If the relationship does have referential integrity rules, the column contains characters corresponding to the type of referential integrity rules for updates, deletions, and insertions. 

*!*	The first character indicates the type of update rule, the second character indicates the type of deletion rule, and the third character indicates the type of insertion rule. 

*!*	Possible values for updates and deletions are "C" for cascade, "R" for restrict, and "I" for ignore. Possible values for insertions are "R" for restrict, and "I" for ignore. For example, if a relation has cascaded updates, restricted deletions, and ignores insertion referential integrity rules, the column contains "CRI". 
LOCAL lcExprC as String, lcExprP as String, ;
      lcChild as String, lcParent as String, lnRecs as Integer 
      
CREATE CURSOR curOrphans (PK char (100), Parent_T char(100), ;
                          Child_T char(100), Parent_E char(100), ;
                          Child_E char(100), NumOrphans  I)    
FOR lnI = 1 TO lnTables
   TRY
     lcChild = laAllTables[lnI,1]
     USE (lcChild) IN 0 SHARED ALIAS Child AGAIN 
     lcExprC = KEY(TAGNO(laAllTables[lnI,3],"",'Child'), 'Child')
     lcParent = laAllTables[lnI,2]
     USE (lcParent) IN 0 SHARED ALIAS ParentT again
     lcExprP = KEY(TAGNO(laAllTables[lnI,4],"", 'ParentT'), 'ParentT')
     SELECT TRANSFORM(&lcExprC) as ChildField, ;
     lcParent as Parent_T, lcChild as Child_T, ;
     lcExprP as Parent_E, lcExprC as Child_E ;
     FROM (lcParent) ParentP ;
     RIGHT JOIN (lcChild) Child ON ;
     ParentP.&lcExprP = Child.&lcExprC ;
     WHERE (ParentP.&lcExprP) IS NULL INTO CURSOR curOr nofilter
     lnRecs = _tally
     IF lnRecs == 0
        INSERT INTO curOrphans VALUES ("", lcParent, lcChild, lcExprP, lcExprC, 0)
     else
     	INSERT INTO curOrphans SELECT *, lnRecs as NumOrphans FROM curOr
     endif
   CATCH TO loSkip
      * we're skipping this table
      =ErrorMsg(Log_Error(loSkip))
    FINALLY
      USE IN SELECT('Child')           
      USE IN SELECT('ParentT')           
      USE IN SELECT('curOr')
   ENDTRY
next         
SELECT curOrphans
browse
>>>The second parameter is the CDX file name, not the alias of the table
>>>
>>>try
>>>
>>>
>>>use myTable alias myAliasName in 0
>>>? Sys(14, TagNo('myKeyName', Forceext(Dbf('myAliasName'), 'CDX'), 'myAliasName'))
>>>
>>
>>Thanks again. KEY function seems to work, so I used it.
>>
>>Anyway, now two new questions.
>>
>>1. Do you see a problem with this statement
>>
>>
>>SELECT TRANSFORM(&lcExprC) as ChildField, ;
>>     lcParent as Parent_T, lcChild as Child_T, ;
>>     lcExprP as Parent_E, lcExprC as Child_E ;
>>     FROM (lcParent) ParentP ;
>>     RIGHT JOIN (lcChild) Child ON ;
>>     ParentP.&lcExprP = Child.&lcExprC ;
>>     WHERE (ParentP.&lcExprP) IS NULL INTO CURSOR curOr nofilter
>>
>>Looks like it selecting a lot of records, while I would expect to have just few orphans.
>>
>>Also I'm doing these selects in a loop. Is there a way to gracefully interrupt it?
>>
>>Thanks again.
>
>I see one:
>TRANSFORM(&lcExprC)
>that is a variable length field and if the first has the shortest value you will end up with that length :-)
>
>Could you post the full select?
If it's not broken, fix it until it is.


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

Click here to load this message in the networking platform