sakai-info 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@
2
2
  # SakaiInfo::Announcement library
3
3
  #
4
4
  # Created 2012-02-16 daveadams@gmail.com
5
- # Last updated 2012-02-16 daveadams@gmail.com
5
+ # Last updated 2012-02-24 daveadams@gmail.com
6
6
  #
7
7
  # https://github.com/daveadams/sakai-info
8
8
  #
@@ -18,19 +18,16 @@ module SakaiInfo
18
18
 
19
19
  def self.find(id)
20
20
  if @@cache[id].nil?
21
- next_id = nil
22
21
  xml = ""
23
- DB.connect.exec("select next_id, xml from announcement_channel " +
24
- "where channel_id = :id", id) do |row|
25
- nextid = row[0].to_i
26
- REXML::Document.new(row[1].read).write(xml, 2)
27
- end
28
- if nextid.nil?
22
+ row = DB.connect[:announcement_channel].filter(:channel_id => id).first
23
+ if row.nil?
29
24
  raise ObjectNotFoundException.new(AnnouncementChannel, id)
30
25
  end
31
- new_announcement = AnnouncementChannel.new(id, nextid, xml)
32
- @@cache[id] = new_announcement
33
- @@site_cache[new_announcement.site_id] = new_announcement
26
+ nextid = row[:next_id].to_i
27
+ REXML::Document.new(row[:xml].read).write(xml, 2)
28
+ channel = AnnouncementChannel.new(id, nextid, xml)
29
+ @@cache[id] = channel
30
+ @@site_cache[channel.site_id] = channel
34
31
  end
35
32
  @@cache[id]
36
33
  end
@@ -91,22 +88,21 @@ module SakaiInfo
91
88
  @@cache = {}
92
89
  def self.find(id)
93
90
  if @@cache[id].nil?
94
- channel = draft = pubview = owner = date = nil
95
91
  xml = ""
96
- DB.connect.exec("select channel_id, draft, pubview, owner, " +
97
- "to_char(message_date,'YYYY-MM-DD HH24:MI:SS'), xml " +
98
- "from announcement_message " +
99
- "where message_id = :id", id) do |row|
100
- channel = AnnouncementChannel.find(row[0])
101
- draft = row[1]
102
- pubview = row[2]
103
- owner = User.find(row[3])
104
- date = row[4]
105
- REXML::Document.new(row[5].read).write(xml, 2)
106
- end
107
- if date.nil?
92
+ row = DB.connect.fetch("select channel_id, draft, pubview, owner, xml, " +
93
+ "to_char(message_date,'YYYY-MM-DD HH24:MI:SS') as message_date " +
94
+ "from announcement_message " +
95
+ "where message_id = ?", id).first
96
+ if row.nil?
108
97
  raise ObjectNotFoundException.new(Announcement, id)
109
98
  end
99
+
100
+ channel = AnnouncementChannel.find(row[:channel_id])
101
+ draft = row[:draft]
102
+ pubview = row[:pubview]
103
+ owner = User.find(row[:owner])
104
+ date = row[:message_date]
105
+ REXML::Document.new(row[:xml].read).write(xml, 2)
110
106
  @@cache[id] = Announcement.new(id, channel, draft, pubview, owner, date, xml)
111
107
  end
112
108
  @@cache[id]
@@ -129,17 +125,17 @@ module SakaiInfo
129
125
  announcements = []
130
126
  channel = AnnouncementChannel.find(channel_id)
131
127
 
132
- DB.connect.exec("select message_id, draft, pubview, owner, " +
133
- "to_char(message_date,'YYYY-MM-DD HH24:MI:SS'), xml " +
134
- "from announcement_message " +
135
- "where channel_id = :channel_id", channel_id) do |row|
128
+ DB.connect.fetch("select message_id, draft, pubview, owner, xml, " +
129
+ "to_char(message_date,'YYYY-MM-DD HH24:MI:SS') as message_date " +
130
+ "from announcement_message " +
131
+ "where channel_id = ?", channel_id) do |row|
136
132
  xml = ""
137
- id = row[0]
138
- draft = row[1]
139
- pubview = row[2]
140
- owner = User.find(row[3])
141
- date = row[4]
142
- REXML::Document.new(row[5].read).write(xml, 2)
133
+ id = row[:message_id]
134
+ draft = row[:draft]
135
+ pubview = row[:pubview]
136
+ owner = User.find(row[:owner])
137
+ REXML::Document.new(row[:xml].read).write(xml, 2)
138
+ date = row[:message_date]
143
139
 
144
140
  @@cache[id] = Announcement.new(id, channel, draft, pubview, owner, date, xml)
145
141
  announcements << @@cache[id]
@@ -2,7 +2,7 @@
2
2
  # SakaiInfo::Assignment library
3
3
  #
4
4
  # Created 2012-02-17 daveadams@gmail.com
5
- # Last updated 2012-02-17 daveadams@gmail.com
5
+ # Last updated 2012-02-24 daveadams@gmail.com
6
6
  #
7
7
  # https://github.com/daveadams/sakai-info
8
8
  #
@@ -16,16 +16,13 @@ module SakaiInfo
16
16
  @@cache = {}
17
17
  def self.find(id)
18
18
  if @@cache[id].nil?
19
- site = nil
20
19
  xml = ""
21
- DB.connect.exec("select context, xml from assignment_assignment " +
22
- "where assignment_id = :id", id) do |row|
23
- site = Site.find(row[0])
24
- REXML::Document.new(row[1].read).write(xml, 2)
25
- end
26
- if site.nil?
20
+ row = DB.connect[:assignment_assigment].filter(:assignment_id => id).first
21
+ if row.nil?
27
22
  raise ObjectNotFoundException.new(Assignment, id)
28
23
  end
24
+ site = Site.find(row[:context])
25
+ REXML::Document.new(row[:xml].read).write(xml, 2)
29
26
  @@cache[id] = Assignment.new(id, site, xml)
30
27
  end
31
28
  @@cache[id]
@@ -42,24 +39,18 @@ module SakaiInfo
42
39
  # set lookup
43
40
  def self.find_by_site_id(site_id)
44
41
  assignments = []
45
- DB.connect.exec("select assignment_id, context, xml from assignment_assignment " +
46
- "where context = :site_id", site_id) do |row|
47
- id = row[0]
48
- site = Site.find(row[1])
42
+ site = Site.find(site_id)
43
+ DB.connect[:assignment_assignment].filter(:context => site_id).all.each do |row|
44
+ id = row[:assignment_id]
49
45
  xml = ""
50
- REXML::Document.new(row[2].read).write(xml, 2)
46
+ REXML::Document.new(row[:xml].read).write(xml, 2)
51
47
  assignments << Assignment.new(id, site, xml)
52
48
  end
53
49
  return assignments
54
50
  end
55
51
 
56
52
  def self.count_by_site_id(site_id)
57
- assignment_count = 0
58
- DB.connect.exec("select count(*) from assignment_assignment " +
59
- "where context = :site_id", site_id) do |row|
60
- assignment_count = row[0].to_i
61
- end
62
- return assignment_count
53
+ DB.connect[:assignment_assignment].filter(:context => site_id).count
63
54
  end
64
55
 
65
56
  # getters
@@ -115,19 +106,17 @@ module SakaiInfo
115
106
  if @@cache[id].nil?
116
107
  assignment = submitter = submitted_at = submitted = graded = nil
117
108
  xml = ""
118
- DB.connect.exec("select context, xml, submitter_id, " +
119
- "submitted, graded from assignment_submission " +
120
- "where submission_id = :id", id) do |row|
121
- assignment = Assignment.find(row[0])
122
- xml = ""
123
- REXML::Document.new(row[1].read).write(xml, 2)
124
- submitter = User.find(row[2])
125
- submitted = (row[3] == "true")
126
- graded = (row[4] == "true")
127
- end
128
- if assignment.nil?
109
+ row = DB.connect[:assignment_submission].filter(:submission_id => id).first
110
+ if row.nil?
129
111
  raise ObjectNotFoundException.new(AssignmentSubmission, id)
130
112
  end
113
+
114
+ assignment = Assignment.find(row[:context])
115
+ REXML::Document.new(row[:xml].read).write(xml, 2)
116
+ submitter = User.find(row[:submitter_id])
117
+ submitted = (row[:submitted] == "true")
118
+ graded = (row[:graded] == "true")
119
+
131
120
  @@cache[id] = AssignmentSubmission.new(id, assignment, xml, submitter, submitted, graded)
132
121
  end
133
122
  @@cache[id]
@@ -147,54 +136,40 @@ module SakaiInfo
147
136
 
148
137
  def self.find_by_assignment_id(assignment_id)
149
138
  submissions = []
150
- DB.connect.exec("select submission_id, context, xml, submitter_id, " +
151
- "submitted, graded from assignment_submission " +
152
- "where context = :assignment_id", assignment_id) do |row|
153
- id = row[0]
154
- assignment = Assignment.find(row[1])
139
+ assignment = Assignment.find(assignment_id)
140
+ DB.connect[:assignment_submission].filter(:context => assignment_id).all.each do |row|
141
+ id = row[:submission_id]
155
142
  xml = ""
156
- REXML::Document.new(row[2].read).write(xml, 2)
157
- submitter = User.find(row[3])
158
- submitted = (row[4] == "true")
159
- graded = (row[5] == "true")
143
+ REXML::Document.new(row[:xml].read).write(xml, 2)
144
+ submitter = User.find(row[:submitter_id])
145
+ submitted = (row[:submitted] == "true")
146
+ graded = (row[:graded] == "true")
160
147
  submissions << AssignmentSubmission.new(id, assignment, xml, submitter, submitted, graded)
161
148
  end
162
149
  return submissions
163
150
  end
164
151
 
165
152
  def self.count_by_assignment_id(assignment_id)
166
- submission_count = 0
167
- DB.connect.exec("select count(*) from assignment_submission " +
168
- "where context = :assignment_id", assignment_id) do |row|
169
- submission_count = row[0].to_i
170
- end
171
- return submission_count
153
+ DB.connect[:assignment_submission].filter(:context => assignment_id).count
172
154
  end
173
155
 
174
156
  def self.find_by_user_id(user_id)
175
157
  submissions = []
176
- DB.connect.exec("select submission_id, context, xml, submitter_id, " +
177
- "submitted, graded from assignment_submission " +
178
- "where submitter_id = :user_id", user_id) do |row|
179
- id = row[0]
180
- assignment = Assignment.find(row[1])
158
+ submitter = User.find(user_id)
159
+ DB.connect[:assignment_submission].filter(:submitter_id => user_id).all.each do |row|
160
+ id = row[:submission_id]
161
+ assignment = Assignment.find(row[:context])
181
162
  xml = ""
182
- REXML::Document.new(row[2].read).write(xml, 2)
183
- submitter = User.find(row[3])
184
- submitted = (row[4] == "true")
185
- graded = (row[5] == "true")
163
+ REXML::Document.new(row[:xml].read).write(xml, 2)
164
+ submitted = (row[:submitted] == "true")
165
+ graded = (row[:graded] == "true")
186
166
  submissions << AssignmentSubmission.new(id, assignment, xml, submitter, submitted, graded)
187
167
  end
188
168
  return submissions
189
169
  end
190
170
 
191
171
  def self.count_by_user_id(user_id)
192
- submission_count = 0
193
- DB.connect.exec("select count(*) from assignment_submission " +
194
- "where submitter_id = :user_id", user_id) do |row|
195
- submission_count = row[0].to_i
196
- end
197
- return submission_count
172
+ DB.connect[:assignment_submission].filter(:submitter_id => user_id).count
198
173
  end
199
174
 
200
175
  # yaml/json serialization
@@ -236,41 +211,31 @@ module SakaiInfo
236
211
  @@cache = {}
237
212
  def self.find(id)
238
213
  if @@cache[id].nil?
239
- context = nil
240
- xml = ""
241
- DB.connect.exec("select context, xml from assignment_content " +
242
- "where content_id = :id", id) do |row|
243
- context = row[0]
244
- REXML::Document.new(row[1].read).write(xml, 2)
245
- end
246
- if context.nil?
214
+ row = DB.connect[:assignment_content].filter(:content_id => id).first
215
+ if row.nil?
247
216
  raise ObjectNotFoundException.new(AssignmentContent, id)
248
217
  end
249
- @@cache[id] = AssignmentContent.new(id, context, xml)
218
+ xml = ""
219
+ REXML::Document.new(row[:xml].read).write(xml, 2)
220
+ @@cache[id] = AssignmentContent.new(id, row[:context], xml)
250
221
  end
251
222
  @@cache[id]
252
223
  end
253
224
 
254
225
  def self.find_by_user_id(user_id)
255
226
  contents = []
256
- DB.connect.exec("select content_id, context, xml from assignment_content " +
257
- "where context = :user_id", user_id) do |row|
258
- id = row[0]
259
- context = row[1]
227
+ DB.connect[:assignment_content].filter(:context => user_id).all.each do |row|
228
+ id = row[:content_id]
229
+ context = row[:context]
260
230
  xml = ""
261
- REXML::Document.new(row[2].read).write(xml, 2)
231
+ REXML::Document.new(row[:xml].read).write(xml, 2)
262
232
  contents << AssignmentContent.new(id, context, xml)
263
233
  end
264
234
  return contents
265
235
  end
266
236
 
267
237
  def self.count_by_user_id(user_id)
268
- content_count = 0
269
- DB.connect.exec("select count(*) from assignment_content " +
270
- "where context = :user_id", user_id) do |row|
271
- content_count = row[0].to_i
272
- end
273
- content_count
238
+ DB.connect[:assignment_content].filter(:context => user_id).count
274
239
  end
275
240
 
276
241
  # getters
@@ -26,15 +26,12 @@ module SakaiInfo
26
26
  def self.find_by_id(id)
27
27
  id = id.to_s
28
28
  if @@cache[id].nil?
29
- name = nil
30
- DB.connect.exec("select role_name from sakai_realm_role " +
31
- "where role_key = :id", id.to_i) do |row|
32
- name = row[0]
33
- end
34
- if name.nil?
29
+ row = DB.connect.fetch("select role_name from sakai_realm_role " +
30
+ "where role_key = ?", id.to_i).first
31
+ if row.nil?
35
32
  raise ObjectNotFoundException.new(AuthzRole, id)
36
33
  end
37
- @@cache[id] = AuthzRole.new(id, name)
34
+ @@cache[id] = AuthzRole.new(id, row[:role_name])
38
35
  @@cache[name] = @@cache[id]
39
36
  end
40
37
  @@cache[id]
@@ -45,14 +42,12 @@ module SakaiInfo
45
42
  raise ObjectNotFoundException.new(AuthzRole, "")
46
43
  end
47
44
  if @@cache[name].nil?
48
- id = nil
49
- DB.connect.exec("select role_key from sakai_realm_role " +
50
- "where role_name = :name", name) do |row|
51
- id = row[0].to_i.to_s
52
- end
53
- if id.nil?
45
+ row = DB.connect.fetch("select role_key from sakai_realm_role " +
46
+ "where role_name = ?", name).first
47
+ if row.nil?
54
48
  raise ObjectNotFoundException.new(AuthzRole, name)
55
49
  end
50
+ id = row[:role_key].to_i.to_s
56
51
  @@cache[name] = AuthzRole.new(id, name)
57
52
  @@cache[id] = @@cache[name]
58
53
  end
@@ -76,13 +71,13 @@ module SakaiInfo
76
71
 
77
72
  def self.find_by_realm_id_and_function_id(realm_id, function_id)
78
73
  roles = []
79
- DB.connect.exec("select role_key, role_name from " +
80
- "sakai_realm_role where role_key in " +
81
- "(select role_key from sakai_realm_rl_fn " +
82
- "where realm_key=:realm_id and function_key=:function_id) " +
83
- "order by role_name", realm_id, function_id) do |row|
84
- role_id = row[0].to_i.to_s
85
- role_name = row[1]
74
+ DB.connect.fetch("select role_key, role_name from " +
75
+ "sakai_realm_role where role_key in " +
76
+ "(select role_key from sakai_realm_rl_fn " +
77
+ "where realm_key=? and function_key=?) " +
78
+ "order by role_name", realm_id, function_id) do |row|
79
+ role_id = row[:role_key].to_i.to_s
80
+ role_name = row[:role_name]
86
81
  roles << AuthzRole.new(role_id, role_name)
87
82
  end
88
83
  roles
@@ -105,16 +100,13 @@ module SakaiInfo
105
100
  def self.find_by_id(id)
106
101
  id = id.to_s
107
102
  if @@cache[id].nil?
108
- name = nil
109
- DB.connect.exec("select function_name from sakai_realm_function " +
110
- "where function_key = :id", id.to_i) do |row|
111
- name = row[0]
112
- end
113
- if name.nil?
103
+ row = DB.connect.fetch("select function_name from sakai_realm_function " +
104
+ "where function_key = ?", id.to_i).first
105
+ if row.nil?
114
106
  raise ObjectNotFoundException.new(AuthzFunction, id)
115
107
  end
116
- @@cache[id] = AuthzFunction.new(id, name)
117
- @@cache[name] = @@cache[id]
108
+ @@cache[id] = AuthzFunction.new(id, row[:function_name])
109
+ @@cache[row[:function_name]] = @@cache[id]
118
110
  end
119
111
  @@cache[id]
120
112
  end
@@ -122,13 +114,12 @@ module SakaiInfo
122
114
  def self.find_by_name(name)
123
115
  if @@cache[name].nil?
124
116
  id = nil
125
- DB.connect.exec("select function_key from sakai_realm_function " +
126
- "where function_name = :name", name) do |row|
127
- id = row[0].to_i.to_s
128
- end
129
- if id.nil?
117
+ row = DB.connect.fetch("select function_key from sakai_realm_function " +
118
+ "where function_name = ?", name).first
119
+ if row.nil?
130
120
  raise ObjectNotFoundException.new(AuthzFunction, name)
131
121
  end
122
+ id = row[:function_key].to_i.to_s
132
123
  @@cache[name] = AuthzFunction.new(id, name)
133
124
  @@cache[id] = @@cache[name]
134
125
  end
@@ -151,24 +142,19 @@ module SakaiInfo
151
142
  end
152
143
 
153
144
  def self.count_by_realm_id_and_role_id(realm_id, role_id)
154
- count = 0
155
- DB.connect.exec("select count(*) from sakai_realm_rl_fn " +
156
- "where realm_key=:realm_id and role_key=:role_id",
157
- realm_id, role_id) do |row|
158
- count = row[0].to_i
159
- end
160
- count
145
+ DB.connect[:sakai_realm_rl_fn].
146
+ filter(:realm_key => realm_id, :role_key => role_id).count
161
147
  end
162
148
 
163
149
  def self.find_by_realm_id_and_role_id(realm_id, role_id)
164
150
  functions = []
165
- DB.connect.exec("select function_key, function_name from " +
166
- "sakai_realm_function where function_key in " +
167
- "(select function_key from sakai_realm_rl_fn " +
168
- "where realm_key=:realm_id and role_key=:role_id) " +
169
- "order by function_name", realm_id, role_id) do |row|
170
- function_id = row[0].to_i.to_s
171
- function_name = row[1]
151
+ DB.connect.fetch("select function_key, function_name from " +
152
+ "sakai_realm_function where function_key in " +
153
+ "(select function_key from sakai_realm_rl_fn " +
154
+ "where realm_key=? and role_key=?) " +
155
+ "order by function_name", realm_id, role_id) do |row|
156
+ function_id = row[:function_key].to_i.to_s
157
+ function_name = row[:function_name]
172
158
  functions << AuthzFunction.new(function_id, function_name)
173
159
  end
174
160
  functions
@@ -209,21 +195,21 @@ module SakaiInfo
209
195
  def self.find_by_id(id)
210
196
  id = id.to_s
211
197
  if @@cache[id].nil?
212
- name = providers = maintain_role = nil
213
- DB.connect.exec("select realm_id, provider_id, maintain_role " +
214
- "from sakai_realm " +
215
- "where realm_key = :id", id.to_i) do |row|
216
- name = row[0]
217
- providers = row[1]
218
- if row[2].nil? or row[2] == ""
219
- maintain_role = nil
220
- else
221
- maintain_role = AuthzRole.find_by_id(row[2].to_i)
222
- end
223
- end
224
- if name.nil?
198
+ row = DB.connect.fetch("select realm_id, provider_id, maintain_role " +
199
+ "from sakai_realm " +
200
+ "where realm_key = ?", id.to_i).first
201
+ if row.nil?
225
202
  raise ObjectNotFoundException.new(AuthzRealm, id)
226
203
  end
204
+
205
+ name = row[:realm_id]
206
+ providers = row[:provider_id]
207
+ maintain_role = nil
208
+ if row[:maintain_role].nil? or row[:maintain_role] == ""
209
+ maintain_role = nil
210
+ else
211
+ maintain_role = AuthzRole.find_by_id(row[:maintain_role].to_i)
212
+ end
227
213
  @@cache[id] = AuthzRealm.new(id, name, providers, maintain_role)
228
214
  @@cache[name] = @@cache[id]
229
215
  end
@@ -232,21 +218,21 @@ module SakaiInfo
232
218
 
233
219
  def self.find_by_name(name)
234
220
  if @@cache[name].nil?
235
- id = providers = maintain_role = nil
236
- DB.connect.exec("select realm_key, provider_id, maintain_role " +
237
- "from sakai_realm " +
238
- "where realm_id = :name", name) do |row|
239
- id = row[0].to_i.to_s
240
- providers = row[1]
241
- if row[2].nil? or row[2] == ""
242
- maintain_role = nil
243
- else
244
- maintain_role = AuthzRole.find_by_id(row[2].to_i)
245
- end
246
- end
247
- if id.nil?
221
+ row = DB.connect.fetch("select realm_key, provider_id, maintain_role " +
222
+ "from sakai_realm " +
223
+ "where realm_id = ?", name).first
224
+ if row.nil?
248
225
  raise ObjectNotFoundException.new(AuthzRealm, name)
249
226
  end
227
+
228
+ id = row[:realm_key].to_i.to_s
229
+ providers = row[:provider_id]
230
+ maintain_role = nil
231
+ if row[:maintain_role].nil? or row[:maintain_role] == ""
232
+ maintain_role = nil
233
+ else
234
+ maintain_role = AuthzRole.find_by_id(row[:maintain_role].to_i)
235
+ end
250
236
  @@cache[name] = AuthzRealm.new(id, name, providers, maintain_role)
251
237
  @@cache[id] = @@cache[name]
252
238
  end
@@ -304,11 +290,11 @@ module SakaiInfo
304
290
  def self.find_by_realm_id(realm_id)
305
291
  realm_roles = []
306
292
  realm = AuthzRealm.find_by_id(realm_id)
307
- DB.connect.exec("select distinct role_key from " +
308
- "sakai_realm_rl_fn where " +
309
- "realm_key = :realm_id", realm_id) do |row|
293
+ DB.connect.fetch("select distinct role_key from " +
294
+ "sakai_realm_rl_fn where " +
295
+ "realm_key = ?", realm_id) do |row|
310
296
  begin
311
- role = AuthzRole.find_by_id(row[0].to_i)
297
+ role = AuthzRole.find_by_id(row[:role_key].to_i)
312
298
  realm_roles << AuthzRealmRole.new(realm, role)
313
299
  rescue AuthzRoleNotFoundException
314
300
  end
@@ -345,32 +331,29 @@ module SakaiInfo
345
331
 
346
332
  def self.find_by_realm_id(realm_id)
347
333
  results = []
348
- DB.connect.exec("select srrg.user_id, srr.role_name " +
349
- "from sakai_realm_rl_gr srrg, sakai_realm_role srr " +
350
- "where srrg.role_key = srr.role_key " +
351
- "and srrg.realm_key = :realm_id", realm_id) do |row|
352
- results << AuthzRealmMembership.new(realm_id, row[0], row[1])
334
+ DB.connect.fetch("select srrg.user_id as user_id, " +
335
+ "srr.role_name as role_name " +
336
+ "from sakai_realm_rl_gr srrg, sakai_realm_role srr " +
337
+ "where srrg.role_key = srr.role_key " +
338
+ "and srrg.realm_key = ?", realm_id) do |row|
339
+ results << AuthzRealmMembership.new(realm_id, row[:user_id], row[:role_name])
353
340
  end
354
341
  results
355
342
  end
356
343
 
357
344
  def self.count_by_realm_id(realm_id)
358
- count = 0
359
- DB.connect.exec("select count(*) from sakai_realm_rl_gr " +
360
- "where realm_key = :realm_id", realm_id) do |row|
361
- count = row[0].to_i
362
- end
363
- count
345
+ DB.connect[:sakai_realm_rl_gr].filter(:realm_key => realm_id).count
364
346
  end
365
347
 
366
348
  def self.find_by_user_id(user_id)
367
349
  results = []
368
- DB.connect.exec("select sr.realm_id, srr.role_name " +
369
- "from sakai_realm_rl_gr srrg, sakai_realm_role srr, sakai_realm sr " +
370
- "where srrg.role_key = srr.role_key " +
371
- "and srrg.realm_key = sr.realm_key " +
372
- "and srrg.user_id = :user_id", user_id) do |row|
373
- results << AuthzRealmMembership.new(row[0], user_id, row[1])
350
+ DB.connect.fetch("select sr.realm_id as realm_id, " +
351
+ "srr.role_name as role_name " +
352
+ "from sakai_realm_rl_gr srrg, sakai_realm_role srr, sakai_realm sr " +
353
+ "where srrg.role_key = srr.role_key " +
354
+ "and srrg.realm_key = sr.realm_key " +
355
+ "and srrg.user_id = ?", user_id) do |row|
356
+ results << AuthzRealmMembership.new(row[:realm_id], user_id, row[:role_name])
374
357
  end
375
358
  results
376
359
  end