-
Notifications
You must be signed in to change notification settings - Fork 2
/
FirstLookObjectScript.xml
105 lines (94 loc) · 3 KB
/
FirstLookObjectScript.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?xml version="1.0" encoding="UTF-8"?>
<Export generator="IRIS" version="26" zv="IRIS for Windows (x86-64) 2020.1 (Build 215U)" ts="2021-06-30 10:36:08">
<Class name="FirstLook.ObjectScript">
<Description>
ObjectScript First Look</Description>
<TimeChanged>65178,54157.597904</TimeChanged>
<TimeCreated>65127,45967.546529</TimeCreated>
<Method name="Iterate">
<Description><![CDATA[
Iterate over global ^testglobal<br>
To call from Terminal:<br>
do ##class(FirstLook.ObjectScript).Iterate()]]></Description>
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[
// Start by setting subscript to ""
set subscript = ""
// "Argumentless" for loop
for {
// Get the next subscript
set subscript = $order(^testglobal(subscript))
// When we get to the end, quit the for loop
quit:(subscript = "")
// Otherwise, write the subscript and the value
// stored at ^testglobal(subscript)
write !, "subscript=", subscript, ", value=", ^testglobal(subscript)
}
]]></Implementation>
</Method>
</Class>
<Class name="FirstLook.Person">
<Description><![CDATA[
Person class for ObjectScript FirstLook<br>]]></Description>
<Super>%Persistent</Super>
<TimeChanged>65925,38158.350022</TimeChanged>
<TimeCreated>65127,42843.235733</TimeCreated>
<Property name="FirstName">
<Type>%String</Type>
<Required>1</Required>
</Property>
<Property name="LastName">
<Type>%String</Type>
<Required>1</Required>
</Property>
<Method name="WriteName">
<Description><![CDATA[
Given an instance of a person, write person's name<br>
To call from Terminal:<br>
do person.WriteName()]]></Description>
<Implementation><![CDATA[
write "The name of this person is:"
write !, ..FirstName
write !, ..LastName
]]></Implementation>
</Method>
<Query name="Select">
<Description><![CDATA[
Query for all stored names<br>
Called from ClassMethod WriteAllNames()<br>
To call from Terminal:<br>
do ##class(%ResultSet).RunQuery("FirstLook.Person", "Select")]]></Description>
<Type>%SQLQuery</Type>
<SqlProc>1</SqlProc>
<SqlQuery> SELECT %ID, FirstName, LastName
FROM Person
ORDER By LastName, FirstName</SqlQuery>
</Query>
<Method name="WriteAllNames">
<Description><![CDATA[
Run select query and write all names in result set<br>
To call from Terminal:<br>
do ##class(FirstLook.Person).WriteAllNames()]]></Description>
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[
// Create a new %SQL.Statement object
set stmt = ##class(%SQL.Statement).%New()
// Prepare the class query to execute by passing in
// the ClassName and QueryName.
set status = stmt.%PrepareClassQuery("FirstLook.Person", "Select")
// Handle any errors
if $$$ISERR(status) {
do $system.OBJ.DisplayError(status)
quit
}
// Execute the query
set resultSet = stmt.%Execute()
// Iterate over results
while (resultSet.%Next()) {
// Write person's first and last name
write !, resultSet.%Get("FirstName"), " ", resultSet.%Get("LastName")
}
]]></Implementation>
</Method>
</Class>
</Export>