11.07.2015 Views

Caché ObjectScript Reference - InterSystems Documentation

Caché ObjectScript Reference - InterSystems Documentation

Caché ObjectScript Reference - InterSystems Documentation

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Caché</strong> <strong>ObjectScript</strong> FunctionsValue^client(4,1,3)^client(4,2)^client(5)null string ("")Returned by the $QUERY Function If...If ^client(4,1,3) exists and contains data.If ^client(4,1,3) does not exist or does not contain data and if^client(4,2) does exist and contains data.If ^client(4,1,3) and ^client(4,2) do not exist or do not contain data andif ^client(5) does exist and contains data.If none of the previous global references exist or contain data; $QUERYhas reached the end of the array.With a direction value of -1, $QUERY can traverse an entire array in reverse order in rightto-left,bottom-to-top fashion.$QUERY Compared to $ORDER$QUERY differs from the $ORDER function in that $QUERY returns a full global reference,while $ORDER returns only the subscript of the next node. $ORDER proceeds along onlythe horizontal axis, across nodes at one level.$QUERY also differs from $ORDER in that it selects only those existing nodes that containdata. $ORDER selects existing nodes, regardless of whether or not they contain data. Where$ORDER performs an implicit test for existence ($DATA'=0), $QUERY performs an implicittest for both existence and data ($DATA'=0 and $DATA'=10). Note, however, that $QUERYdoes not distinguish between pointer nodes ($DATA=11) and terminal nodes ($DATA=1)that contain data. To make this distinction, you must include appropriate $DATA tests inyour code.Like $ORDER, $QUERY is typically used with loop processing to traverse the nodes in asparse array. A sparse array is an array that can contain undefined nodes on any given level.$QUERY simply skips undefined or empty nodes to return the global reference of the nextexisting node. $QUERY provides very compact code for accessing global arrays.Like the $NAME and $ORDER functions, $QUERY can be used with a naked global reference,which is specified without the array name and designates the most recently executedglobal reference. For example:SET a=^client(1)SET x=2SET z=$QUERY(^(x))The first SET command establishes the current global reference, including the level for thereference. The second SET command sets up a variable for use with subscripts. The $QUERY292 <strong>Caché</strong> <strong>ObjectScript</strong> <strong>Reference</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!