File: ResultSet.html

package info (click to toggle)
sqlite3-ruby 1.1.0-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 904 kB
  • ctags: 753
  • sloc: ruby: 4,099; makefile: 59
file content (397 lines) | stat: -rw-r--r-- 18,719 bytes parent folder | download
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <title>Class: SQLite3::ResultSet</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <meta http-equiv="Content-Script-Type" content="text/javascript" />
    <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />

    <script type="text/javascript" language="JavaScript">
      <!--
        function toggleSource( id )
        {
          var elem
          var link

          if( document.all )
          {
            elem = eval( "document.all." + id )
            link = eval( "document.all.l_" + id )
          }
          else
          {
            elem = document.getElementById( id )
            link = document.getElementById( "l_" + id )
          }

          if( elem.style.display == "block" )
          {
            elem.style.display = "none"
            link.innerHTML = "show source"
          }
          else
          {
            elem.style.display = "block"
            link.innerHTML = "hide source"
          }
        }

        function openCode( url )
        {
          window.open( url, "SOURCE_CODE", "width=400,height=400,scrollbars=yes" )
        }
      //-->
    </script>
  </head>

  <body>


<table width="100%" border='0' cellpadding='0' cellspacing='0' class='banner'><tr>
  <td class="file-title"><span class="file-title-prefix">Class</span><br />SQLite3::ResultSet</td>
  <td align="right">
    <table cellspacing=0 cellpadding=2>
      <tr valign="top">
        <td>In:</td>
        <td>
<a href="../../files/lib/sqlite3/resultset_rb.html">lib/sqlite3/resultset.rb</a>
        </td>
      </tr>
    <tr>
      <td>Parent:</td>
      <td>
Object
     </td>
   </tr>
         </table>
        </td>
        </tr>
      </table>
  <!-- banner header -->

  <div id="bodyContent">

  <div id="content">
  <div id="contextContent">

  <div class="description"><p>
The <a href="ResultSet.html">ResultSet</a> object encapsulates the
enumerability of a query&#8217;s output. It is a simple cursor over the
data that the query returns. It will very rarely (if ever) be instantiated
directly. Instead, client&#8217;s should obtain a <a
href="ResultSet.html">ResultSet</a> instance via <a
href="Statement.html#M000079">Statement#execute</a>.
</p>
</div>



  <div class="sectiontitle">Methods</div>
  <ul>
  <li><a href="#M000088">close</a></li>
  <li><a href="#M000089">closed?</a></li>
  <li><a href="#M000091">columns</a></li>
  <li><a href="#M000087">each</a></li>
  <li><a href="#M000085">eof?</a></li>
  <li><a href="#M000083">new</a></li>
  <li><a href="#M000086">next</a></li>
  <li><a href="#M000084">reset</a></li>
  <li><a href="#M000090">types</a></li>
  </ul>
 </div>

<div class="sectiontitle">Included Modules</div>
<ul>
  <li>Enumerable</li>
</ul>

    <div id="section">



  <div class="sectiontitle">Classes and Modules</div>
  Module <a href="ResultSet/FieldsContainer.html" class="link">SQLite3::ResultSet::FieldsContainer</a><br />
Module <a href="ResultSet/TypesContainer.html" class="link">SQLite3::ResultSet::TypesContainer</a><br />


<div class="sectiontitle">Public Class methods</div>
<div class="method">
  <div class="title">
    <a name="M000083"></a><b>new</b>( db, stmt )
  </div>
  <div class="description">
  <p>
Create a new <a href="ResultSet.html">ResultSet</a> attached to the given
database, using the given sql text.
</p>
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000083-source')" id="l_M000083-source">show source</a> ]</p>
  <div id="M000083-source" class="dyn-source">
<pre>
    <span class="ruby-comment cmt"># File lib/sqlite3/resultset.rb, line 57</span>
57:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>( <span class="ruby-identifier">db</span>, <span class="ruby-identifier">stmt</span> )
58:       <span class="ruby-ivar">@db</span> = <span class="ruby-identifier">db</span>
59:       <span class="ruby-ivar">@driver</span> = <span class="ruby-ivar">@db</span>.<span class="ruby-identifier">driver</span>
60:       <span class="ruby-ivar">@stmt</span> = <span class="ruby-identifier">stmt</span>
61:       <span class="ruby-identifier">commence</span>
62:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="sectiontitle">Public Instance methods</div>
<div class="method">
  <div class="title">
    <a name="M000088"></a><b>close</b>()
  </div>
  <div class="description">
  <p>
Closes the statement that spawned this result set. <em>Use with
caution!</em> Closing a result set will automatically close any other
result sets that were spawned from the same statement.
</p>
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000088-source')" id="l_M000088-source">show source</a> ]</p>
  <div id="M000088-source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File lib/sqlite3/resultset.rb, line 168</span>
168:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">close</span>
169:       <span class="ruby-ivar">@stmt</span>.<span class="ruby-identifier">close</span>
170:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000089"></a><b>closed?</b>()
  </div>
  <div class="description">
  <p>
Queries whether the underlying statement has been closed or not.
</p>
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000089-source')" id="l_M000089-source">show source</a> ]</p>
  <div id="M000089-source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File lib/sqlite3/resultset.rb, line 173</span>
173:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">closed?</span>
174:       <span class="ruby-ivar">@stmt</span>.<span class="ruby-identifier">closed?</span>
175:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000091"></a><b>columns</b>()
  </div>
  <div class="description">
  <p>
Returns the names of the columns returned by this result set.
</p>
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000091-source')" id="l_M000091-source">show source</a> ]</p>
  <div id="M000091-source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File lib/sqlite3/resultset.rb, line 183</span>
183:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">columns</span>
184:       <span class="ruby-ivar">@stmt</span>.<span class="ruby-identifier">columns</span>
185:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000087"></a><b>each</b>() {|row| ...}
  </div>
  <div class="description">
  <p>
Required by the Enumerable mixin. Provides an internal iterator over the
rows of the result set.
</p>
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000087-source')" id="l_M000087-source">show source</a> ]</p>
  <div id="M000087-source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File lib/sqlite3/resultset.rb, line 159</span>
159:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">each</span>
160:       <span class="ruby-keyword kw">while</span> <span class="ruby-identifier">row</span>=<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">next</span>
161:         <span class="ruby-keyword kw">yield</span> <span class="ruby-identifier">row</span>
162:       <span class="ruby-keyword kw">end</span>
163:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000085"></a><b>eof?</b>()
  </div>
  <div class="description">
  <p>
Query whether the cursor has reached the end of the result set or not.
</p>
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000085-source')" id="l_M000085-source">show source</a> ]</p>
  <div id="M000085-source" class="dyn-source">
<pre>
    <span class="ruby-comment cmt"># File lib/sqlite3/resultset.rb, line 91</span>
91:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">eof?</span>
92:       <span class="ruby-ivar">@eof</span>
93:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000086"></a><b>next</b>()
  </div>
  <div class="description">
  <p>
Obtain the next row from the cursor. If there are no more rows to be had,
this will return <tt>nil</tt>. If type translation is active on the
corresponding database, the values in the row will be translated according
to their types.
</p>
<p>
The returned value will be an array, unless Database#results_as_hash has
been set to <tt>true</tt>, in which case the returned value will be a hash.
</p>
<p>
For arrays, the column names are accessible via the <tt>fields</tt>
property, and the column types are accessible via the <tt>types</tt>
property.
</p>
<p>
For hashes, the column names are the keys of the hash, and the column types
are accessible via the <tt>types</tt> property.
</p>
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000086-source')" id="l_M000086-source">show source</a> ]</p>
  <div id="M000086-source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File lib/sqlite3/resultset.rb, line 108</span>
108:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">next</span>
109:       <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@eof</span>
110: 
111:       <span class="ruby-ivar">@stmt</span>.<span class="ruby-identifier">must_be_open!</span>
112: 
113:       <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@first_row</span>
114:         <span class="ruby-identifier">result</span> = <span class="ruby-ivar">@driver</span>.<span class="ruby-identifier">step</span>( <span class="ruby-ivar">@stmt</span>.<span class="ruby-identifier">handle</span> )
115:         <span class="ruby-identifier">check</span> <span class="ruby-identifier">result</span>
116:       <span class="ruby-keyword kw">end</span>
117: 
118:       <span class="ruby-ivar">@first_row</span> = <span class="ruby-keyword kw">false</span>
119: 
120:       <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@eof</span>
121:         <span class="ruby-identifier">row</span> = []
122:         <span class="ruby-ivar">@driver</span>.<span class="ruby-identifier">data_count</span>( <span class="ruby-ivar">@stmt</span>.<span class="ruby-identifier">handle</span> ).<span class="ruby-identifier">times</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">column</span><span class="ruby-operator">|</span>
123:           <span class="ruby-keyword kw">case</span> <span class="ruby-ivar">@driver</span>.<span class="ruby-identifier">column_type</span>( <span class="ruby-ivar">@stmt</span>.<span class="ruby-identifier">handle</span>, <span class="ruby-identifier">column</span> )
124:             <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Constants</span><span class="ruby-operator">::</span><span class="ruby-constant">ColumnType</span><span class="ruby-operator">::</span><span class="ruby-constant">NULL</span> <span class="ruby-keyword kw">then</span>
125:               <span class="ruby-identifier">row</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-keyword kw">nil</span>
126:             <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Constants</span><span class="ruby-operator">::</span><span class="ruby-constant">ColumnType</span><span class="ruby-operator">::</span><span class="ruby-constant">BLOB</span> <span class="ruby-keyword kw">then</span>
127:               <span class="ruby-identifier">row</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-ivar">@driver</span>.<span class="ruby-identifier">column_blob</span>( <span class="ruby-ivar">@stmt</span>.<span class="ruby-identifier">handle</span>, <span class="ruby-identifier">column</span> )
128:             <span class="ruby-keyword kw">else</span>
129:               <span class="ruby-identifier">row</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-ivar">@driver</span>.<span class="ruby-identifier">column_text</span>( <span class="ruby-ivar">@stmt</span>.<span class="ruby-identifier">handle</span>, <span class="ruby-identifier">column</span> )
130:           <span class="ruby-keyword kw">end</span>
131:         <span class="ruby-keyword kw">end</span>
132: 
133:         <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@db</span>.<span class="ruby-identifier">type_translation</span>
134:           <span class="ruby-identifier">row</span> = <span class="ruby-ivar">@stmt</span>.<span class="ruby-identifier">types</span>.<span class="ruby-identifier">zip</span>( <span class="ruby-identifier">row</span> ).<span class="ruby-identifier">map</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">type</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
135:             <span class="ruby-ivar">@db</span>.<span class="ruby-identifier">translator</span>.<span class="ruby-identifier">translate</span>( <span class="ruby-identifier">type</span>, <span class="ruby-identifier">value</span> )
136:           <span class="ruby-keyword kw">end</span>
137:         <span class="ruby-keyword kw">end</span>
138: 
139:         <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@db</span>.<span class="ruby-identifier">results_as_hash</span>
140:           <span class="ruby-identifier">new_row</span> = <span class="ruby-constant">Hash</span>[ <span class="ruby-operator">*</span>( <span class="ruby-ivar">@stmt</span>.<span class="ruby-identifier">columns</span>.<span class="ruby-identifier">zip</span>( <span class="ruby-identifier">row</span> ).<span class="ruby-identifier">flatten</span> ) ]
141:           <span class="ruby-identifier">row</span>.<span class="ruby-identifier">each_with_index</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">value</span>,<span class="ruby-identifier">idx</span><span class="ruby-operator">|</span> <span class="ruby-identifier">new_row</span>[<span class="ruby-identifier">idx</span>] = <span class="ruby-identifier">value</span> }
142:           <span class="ruby-identifier">row</span> = <span class="ruby-identifier">new_row</span>
143:         <span class="ruby-keyword kw">else</span>
144:           <span class="ruby-identifier">row</span>.<span class="ruby-identifier">extend</span> <span class="ruby-constant">FieldsContainer</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">row</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:fields</span>)
145:           <span class="ruby-identifier">row</span>.<span class="ruby-identifier">fields</span> = <span class="ruby-ivar">@stmt</span>.<span class="ruby-identifier">columns</span>
146:         <span class="ruby-keyword kw">end</span>
147: 
148:         <span class="ruby-identifier">row</span>.<span class="ruby-identifier">extend</span> <span class="ruby-constant">TypesContainer</span>
149:         <span class="ruby-identifier">row</span>.<span class="ruby-identifier">types</span> = <span class="ruby-ivar">@stmt</span>.<span class="ruby-identifier">types</span>
150: 
151:         <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">row</span>
152:       <span class="ruby-keyword kw">end</span>
153: 
154:       <span class="ruby-keyword kw">nil</span>
155:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000084"></a><b>reset</b>( *bind_params )
  </div>
  <div class="description">
  <p>
Reset the cursor, so that a result set which has reached end-of-file can be
rewound and reiterated.
</p>
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000084-source')" id="l_M000084-source">show source</a> ]</p>
  <div id="M000084-source" class="dyn-source">
<pre>
    <span class="ruby-comment cmt"># File lib/sqlite3/resultset.rb, line 82</span>
82:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">reset</span>( <span class="ruby-operator">*</span><span class="ruby-identifier">bind_params</span> )
83:       <span class="ruby-ivar">@stmt</span>.<span class="ruby-identifier">must_be_open!</span>
84:       <span class="ruby-ivar">@driver</span>.<span class="ruby-identifier">reset</span>( <span class="ruby-ivar">@stmt</span>.<span class="ruby-identifier">handle</span> )
85:       <span class="ruby-ivar">@stmt</span>.<span class="ruby-identifier">bind_params</span>( <span class="ruby-operator">*</span><span class="ruby-identifier">bind_params</span> )
86:       <span class="ruby-ivar">@eof</span> = <span class="ruby-keyword kw">false</span>
87:       <span class="ruby-identifier">commence</span>
88:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000090"></a><b>types</b>()
  </div>
  <div class="description">
  <p>
Returns the types of the columns returned by this result set.
</p>
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000090-source')" id="l_M000090-source">show source</a> ]</p>
  <div id="M000090-source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File lib/sqlite3/resultset.rb, line 178</span>
178:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">types</span>
179:       <span class="ruby-ivar">@stmt</span>.<span class="ruby-identifier">types</span>
180:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>