Subject:Recursive function error Author:Rusty Manesiya Date:05 Mar 2007 09:59 AM
I have a simple function that returns relations to the party, but fails with an error on second attempt to call the same function.
The function getParty gets recursively called inside the getPartyRelationship. I get the error when function tries call
[DataDirect][XQuery][err:XPTY0004]Error at line 6, column 21. Static type error. Types 'element(ID, DECIMAL_10_0)' and 'element(ID, xs:anyType)*' are invalid argument types for binary operator '='.
If i were to remove the code
"return local:getParty($relatedParty treat as element(PARTY))" from the getPartyRelationship function it works fine b/c there is no recursion happening.
declare function local:getParty($INPARTY as element(PARTY)) as element()*{
for $PARTY in collection("PARTY")/PARTY
where $PARTY/ID = $INPARTY/ID
return
<a:id>
{$PARTY/ID/text()}
</a:id>
union
<a:listOfRelationship>
{local:getPartyRelationship($INPARTY)}
</a:listOfRelationship>
};
declare function local:getPartyRelationship($INPARTY as element(PARTY))
as element(a:partyRelationship){
for $PARTYRELATIONSHIP in collection("PARTYRELATIONSHIP")/PARTYRELATIONSHIP
where $PARTYRELATIONSHIP/PARTY2ID = $INPARTY/ID
return
<a:partyRelationship>
<a:id>
{$PARTYRELATIONSHIP/PARTY2ID/text()}
</a:id>
<a:relatedParty>
{
let $relatedParty := collection("PARTY")/PARTY[ID = $INPARTY/ID]
return local:getParty($relatedParty treat as element(PARTY))
}
</a:relatedParty>
</a:partyRelationship>
};
Subject:Recursive function error Author:(Deleted User) Date:05 Mar 2007 12:20 PM
Hi Rusty,
the error occurs because the static typing of the ID sub-element of PARTY is not identical to the one coming from the collection (and in particular, its cardinality is zero-or-more).
You could try either adding /text() to both sides of the comparison, or changing $INPARTY/ID to be ($INPARTY/ID treat as element(ID)).