Created
December 17, 2010 15:29
-
-
Save mccrackend/745107 to your computer and use it in GitHub Desktop.
Using %ResultSet.SQL Objects for query results. Written in Intersystems Cache Object Script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ResultSetSample() | |
// Build query string | |
Set sql = "Select Value, DateTimeStamp From Spectrum_Support_Metrics.EnsPerformanceMetricsData Where " _ | |
"CheckType = 'datasize' AND " _ | |
"Detail = '/ensemble/mgr/PROD/' AND " _ | |
"DateTimeStamp > '201012170930'" | |
// Create new resultSet object to work with called "rs". It's basically a cursor. | |
// This %Prepare command executes the query contained in "sql", sets the result to "rs", and gives an "error" flag back. | |
Set rs = ##class(%ResultSet.SQL).%Prepare(sql,.error,"") | |
// Check to see that the query executed without error. | |
If $IsObject(error) { | |
// In here is where you do something if you get an error. | |
Write "Error = " _ error | |
Quit 0 | |
} | |
// Lets use a While statement to loop over each row returned from the query. | |
// The %Next command on the result set loads in the first row, and parses over the rest. | |
While (rs.%Next()) { | |
// Use the %Get command to get the value of the column specified, in this case, "Value". | |
Write "Value = " _ rs.%Get("Value") _ " at " _ rs.%Get("DateTimeStamp") _ " date/time.", ! | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment