Using Caché Objects - InterSystems Documentation
Using Caché Objects - InterSystems Documentation
Using Caché Objects - InterSystems Documentation
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Class Queries<br />
8.1.3.2 About ROWSPEC<br />
A query's ROWSPEC provides information on the names, data types, headings, and order of<br />
the fields in each row. It is a quoted and comma-separated list of variable names and data<br />
types of the form:<br />
ROWSPEC = "Var1:%Type1,Var2:%Type2[:OptionalDescription]"<br />
The ROWSPEC specifies the order of fields as a comma-separated list. Each field's information<br />
consists of a colon-separated list of its name, its data type (if it is different than the property's<br />
assigned data type), and an optional heading. You can edit a ROWSPEC's code directly, or,<br />
for an existing query, by viewing the query Class Inspector window, expanding the list of<br />
parameters, and using the available dialog box.<br />
The number of elements in the ROWSPEC must match the number of fields in the query.<br />
Otherwise, <strong>Caché</strong> returns a “Cardinality Mismatch” error.<br />
8.1.3.3 A Class Query Specification Example<br />
The ByName query of the %Sample.Person sample class that comes with <strong>Caché</strong> has the following<br />
signature:<br />
Query ByName(name As %String = "")<br />
As %SQLQuery(CONTAINID = 1,<br />
ROWSPEC = "ID:%Integer,Name:%String(MAXLEN=30),DOB,SSN",<br />
SELECTMODE = "RUNTIME")<br />
[ SqlName = SP_Sample_By_Name, SqlProc ]<br />
{<br />
SELECT ID, Name, DOB, SSN<br />
FROM Sample.Person<br />
WHERE (Name %STARTSWITH :name)<br />
ORDER BY Name<br />
}<br />
Here, the CONTAINID parameter specifies that the first field is the ID (the default), and the<br />
first field specified in the SELECT statement is, respectively, ID. The ROWSPEC specifies<br />
that the fields are ID (treated as an integer), Name, DOB, and SSN; similarly, the SELECT<br />
statement contains the fields ID, Name, DOB, and SSN, in that order.<br />
8.2 User-Written Class Queries<br />
While simple %SQLQuery queries perform all result set management for you, this is not sufficient<br />
for certain applications. For such situations, <strong>Caché</strong> allows you to write queries in<br />
58 <strong>Using</strong> <strong>Caché</strong> <strong>Objects</strong>