25.01.2015 Views

Using Caché Objects - InterSystems Documentation

Using Caché Objects - InterSystems Documentation

Using Caché Objects - 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>Using</strong> <strong>Objects</strong> with <strong>Caché</strong> ObjectScript<br />

Set code = rset.Data("Code")<br />

You can also read data stored in the current row by specifying the column number as follows:<br />

Set data = rset.GetData(n)<br />

where data contains the data stored in column n.<br />

Alternately, you can read data for a specific column name by using the GetDataByName<br />

method:<br />

Set data = rset.GetDataByName(fieldname)<br />

where data contains the data in the column named fieldname. This is less efficient than using<br />

the Data property as a method call is slower than a property reference.<br />

Once all of the relevant data has been retrieved from one row, execute the Next method to<br />

move to the next row of data. You can progress through each row, using GetData or<br />

GetDataByName to retrieve the relevant data.<br />

10.7.5 Closing Queries<br />

Once you have processed all a result set's rows, close it as follows:<br />

Do rset.Close()<br />

Set sc = rset.Close()<br />

sc, in the second line of code, is a local variable where the method can return a status code<br />

containing error information.<br />

The Close method releases any resources held by the %ResultSet object. Once the result set<br />

is closed, you can use the %ResultSet object to run and process other queries by changing<br />

the value of the ClassName and QueryName properties.<br />

Calling the Close method is optional; when the %ResultSet object is destroyed (goes out of<br />

scope) it will be automatically closed.<br />

10.7.6 Example of <strong>Using</strong> a Class Query<br />

The following code shows how to use a %ResultSet object to execute a class query and process<br />

the results:<br />

86 <strong>Using</strong> <strong>Caché</strong> <strong>Objects</strong>

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

Saved successfully!

Ooh no, something went wrong!