dbmlite3 1.0.0 → 2.0.0.pre.alpha.3
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.
- checksums.yaml +4 -4
- data/README.md +70 -19
- data/Rakefile +5 -4
- data/dbmlite3.gemspec +32 -10
- data/extras/benchmark.rb +172 -0
- data/lib/dbmlite3.rb +9 -949
- data/lib/internal_lite3/dbm.rb +542 -0
- data/lib/internal_lite3/error.rb +27 -0
- data/lib/internal_lite3/handle.rb +284 -0
- data/lib/internal_lite3/sql.rb +87 -0
- data/spec/dbmlite3_spec.rb +113 -72
- metadata +30 -29
- data/doc/Lite3/DBM.html +0 -2653
- data/doc/Lite3/Error.html +0 -135
- data/doc/Lite3/SQL.html +0 -390
- data/doc/Lite3.html +0 -117
- data/doc/_index.html +0 -152
- data/doc/class_list.html +0 -51
- data/doc/css/common.css +0 -1
- data/doc/css/full_list.css +0 -58
- data/doc/css/style.css +0 -496
- data/doc/file.README.html +0 -212
- data/doc/file_list.html +0 -56
- data/doc/frames.html +0 -17
- data/doc/index.html +0 -212
- data/doc/js/app.js +0 -314
- data/doc/js/full_list.js +0 -216
- data/doc/js/jquery.js +0 -4
- data/doc/method_list.html +0 -307
- data/doc/top-level-namespace.html +0 -110
data/doc/Lite3/DBM.html
DELETED
@@ -1,2653 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<meta charset="utf-8">
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
-
<title>
|
7
|
-
Class: Lite3::DBM
|
8
|
-
|
9
|
-
— Documentation by YARD 0.9.25
|
10
|
-
|
11
|
-
</title>
|
12
|
-
|
13
|
-
<link rel="stylesheet" href="../css/style.css" type="text/css" />
|
14
|
-
|
15
|
-
<link rel="stylesheet" href="../css/common.css" type="text/css" />
|
16
|
-
|
17
|
-
<script type="text/javascript">
|
18
|
-
pathId = "Lite3::DBM";
|
19
|
-
relpath = '../';
|
20
|
-
</script>
|
21
|
-
|
22
|
-
|
23
|
-
<script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
|
24
|
-
|
25
|
-
<script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
|
26
|
-
|
27
|
-
|
28
|
-
</head>
|
29
|
-
<body>
|
30
|
-
<div class="nav_wrap">
|
31
|
-
<iframe id="nav" src="../class_list.html?1"></iframe>
|
32
|
-
<div id="resizer"></div>
|
33
|
-
</div>
|
34
|
-
|
35
|
-
<div id="main" tabindex="-1">
|
36
|
-
<div id="header">
|
37
|
-
<div id="menu">
|
38
|
-
|
39
|
-
<a href="../_index.html">Index (D)</a> »
|
40
|
-
<span class='title'><span class='object_link'><a href="../Lite3.html" title="Lite3 (module)">Lite3</a></span></span>
|
41
|
-
»
|
42
|
-
<span class="title">DBM</span>
|
43
|
-
|
44
|
-
</div>
|
45
|
-
|
46
|
-
<div id="search">
|
47
|
-
|
48
|
-
<a class="full_list_link" id="class_list_link"
|
49
|
-
href="../class_list.html">
|
50
|
-
|
51
|
-
<svg width="24" height="24">
|
52
|
-
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
-
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
54
|
-
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
55
|
-
</svg>
|
56
|
-
</a>
|
57
|
-
|
58
|
-
</div>
|
59
|
-
<div class="clear"></div>
|
60
|
-
</div>
|
61
|
-
|
62
|
-
<div id="content"><h1>Class: Lite3::DBM
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
</h1>
|
67
|
-
<div class="box_info">
|
68
|
-
|
69
|
-
<dl>
|
70
|
-
<dt>Inherits:</dt>
|
71
|
-
<dd>
|
72
|
-
<span class="inheritName">Object</span>
|
73
|
-
|
74
|
-
<ul class="fullTree">
|
75
|
-
<li>Object</li>
|
76
|
-
|
77
|
-
<li class="next">Lite3::DBM</li>
|
78
|
-
|
79
|
-
</ul>
|
80
|
-
<a href="#" class="inheritanceTree">show all</a>
|
81
|
-
|
82
|
-
</dd>
|
83
|
-
</dl>
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
<dl>
|
91
|
-
<dt>Includes:</dt>
|
92
|
-
<dd>Enumerable</dd>
|
93
|
-
</dl>
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
<dl>
|
101
|
-
<dt>Defined in:</dt>
|
102
|
-
<dd>lib/dbmlite3.rb</dd>
|
103
|
-
</dl>
|
104
|
-
|
105
|
-
</div>
|
106
|
-
|
107
|
-
<h2>Overview</h2><div class="docstring">
|
108
|
-
<div class="discussion">
|
109
|
-
<p>Lite3::DBM encapsulates a single table in a single SQLite3
|
110
|
-
database file and lets you access it as easily as a Hash:</p>
|
111
|
-
|
112
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>dbmlite3</span><span class='tstring_end'>'</span></span>
|
113
|
-
|
114
|
-
<span class='id identifier rubyid_db'>db</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="../Lite3.html" title="Lite3 (module)">Lite3</a></span></span><span class='op'>::</span><span class='const'>DBM</span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="#initialize-instance_method" title="Lite3::DBM#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>database.sqlite3</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>table</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
115
|
-
<span class='id identifier rubyid_db'>db</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>speed</span><span class='tstring_end'>"</span></span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='int'>88</span>
|
116
|
-
<span class='id identifier rubyid_db'>db</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>date</span><span class='tstring_end'>"</span></span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='const'>Date</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='int'>1955</span><span class='comma'>,</span> <span class='int'>11</span><span class='comma'>,</span> <span class='int'>5</span><span class='rparen'>)</span>
|
117
|
-
<span class='id identifier rubyid_db'>db</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>power_threshold</span><span class='tstring_end'>"</span></span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='float'>2.2</span>
|
118
|
-
|
119
|
-
<span class='id identifier rubyid_db'>db</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span><span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_k'>k</span><span class='comma'>,</span> <span class='id identifier rubyid_v'>v</span><span class='op'>|</span> <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_k'>k</span><span class='embexpr_end'>}</span><span class='tstring_content'> -> </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_v'>v</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='rbrace'>}</span>
|
120
|
-
|
121
|
-
<span class='id identifier rubyid_double_speed'>double_speed</span> <span class='op'>=</span> <span class='id identifier rubyid_db'>db</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>speed</span><span class='tstring_end'>"</span></span><span class='rbracket'>]</span> <span class='op'>*</span> <span class='int'>2</span>
|
122
|
-
|
123
|
-
<span class='id identifier rubyid_db'>db</span><span class='period'>.</span><span class='id identifier rubyid_close'>close</span>
|
124
|
-
</code></pre>
|
125
|
-
|
126
|
-
<p>Note that keys must be Strings. As a special exception, Symbols
|
127
|
-
are also allowed but are transparently converted to Strings
|
128
|
-
first. This means that while something like this will work:</p>
|
129
|
-
|
130
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_db'>db</span><span class='lbracket'>[</span><span class='symbol'>:foo</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='int'>42</span>
|
131
|
-
</code></pre>
|
132
|
-
|
133
|
-
<p>a subseqent</p>
|
134
|
-
|
135
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_db'>db</span><span class='period'>.</span><span class='id identifier rubyid_keys'>keys</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='symbol'>:foo</span><span class='rparen'>)</span> <span class='kw'>or</span> <span class='id identifier rubyid_raise'>raise</span> <span class='const'>AbjectFailure</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
|
136
|
-
</code></pre>
|
137
|
-
|
138
|
-
<p>will raise an exception because the key <code>:foo</code> was turned into a
|
139
|
-
string. you will need to do this instead:</p>
|
140
|
-
|
141
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_db'>db</span><span class='period'>.</span><span class='id identifier rubyid_keys'>keys</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>foo</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='kw'>or</span> <span class='id identifier rubyid_raise'>raise</span> <span class='const'>AbjectFailure</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
|
142
|
-
</code></pre>
|
143
|
-
|
144
|
-
<p>Unlike DBM, values may (optionally) be any serializable Ruby type.</p>
|
145
|
-
|
146
|
-
<p>You can select the serialization method with an optional third
|
147
|
-
constructor argument. Options are YAML (the default), <code>Marshal</code>
|
148
|
-
or simple string conversion with <code>to_s</code>. Each of these methods
|
149
|
-
will have their own pros and cons.</p>
|
150
|
-
|
151
|
-
<p><strong>WARNING:</strong> Both YAML and Marshal serialization have the usual
|
152
|
-
security caveats as described in the documentation for <code>Marshal</code>
|
153
|
-
and <code>Psych</code>. If you are going to let an untrusted entity modify
|
154
|
-
the database, you should not use these methods and instead stick
|
155
|
-
to string conversion.</p>
|
156
|
-
|
157
|
-
<p>The table name must be a valid name identifier (i.e. matches
|
158
|
-
/^[a-zA-Z_]\w*$/).</p>
|
159
|
-
|
160
|
-
<p>Lite3::DBM also provides access to SQLite3 transactions with the
|
161
|
-
<code>transaction</code> method:</p>
|
162
|
-
|
163
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_db'>db</span><span class='period'>.</span><span class='id identifier rubyid_transaction'>transaction</span> <span class='lbrace'>{</span>
|
164
|
-
<span class='lparen'>(</span><span class='int'>1</span><span class='op'>..</span><span class='int'>1000</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span><span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_n'>n</span><span class='op'>|</span> <span class='id identifier rubyid_db'>db</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>key_</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_n'>n</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='id identifier rubyid_n'>n</span><span class='comma'>,</span> <span class='id identifier rubyid_n'>n</span><span class='op'>*</span><span class='int'>2</span><span class='comma'>,</span> <span class='id identifier rubyid_n'>n</span><span class='op'>-</span><span class='int'>1</span><span class='rbracket'>]</span> <span class='rbrace'>}</span>
|
165
|
-
<span class='rbrace'>}</span>
|
166
|
-
</code></pre>
|
167
|
-
|
168
|
-
<p>Outside of a transaction statement, each Lite3::DBM method that accesses
|
169
|
-
the database does so in a single transaction.</p>
|
170
|
-
|
171
|
-
<p>Note that if you need to do a large number of database operations,
|
172
|
-
there is often a significant performance advantage to grouping them
|
173
|
-
together in a transaction.</p>
|
174
|
-
|
175
|
-
<p>The underlying table will have the given name prefixed with the
|
176
|
-
string <code>dbmlite3_</code>. In addition, the table <code>meta_dbmlite3</code> holds
|
177
|
-
some related metadata. If your program also uses the SQLite3 gem to
|
178
|
-
access the database directly, you should not touch these tables or
|
179
|
-
expect their format to remain consistant.</p>
|
180
|
-
|
181
|
-
|
182
|
-
</div>
|
183
|
-
</div>
|
184
|
-
<div class="tags">
|
185
|
-
|
186
|
-
|
187
|
-
</div>
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
<h2>
|
196
|
-
Class Method Summary
|
197
|
-
<small><a href="#" class="summary_toggle">collapse</a></small>
|
198
|
-
</h2>
|
199
|
-
|
200
|
-
<ul class="summary">
|
201
|
-
|
202
|
-
<li class="public ">
|
203
|
-
<span class="summary_signature">
|
204
|
-
|
205
|
-
<a href="#open-class_method" title="open (class method)">.<strong>open</strong>(filename, tablename, serializer = :yaml, &block) ⇒ Object </a>
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
</span>
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
<span class="summary_desc"><div class='inline'><p>Identical to <code>initialize</code> except that if a block is provided, it is evaluated with a new Lite3::DBM which is then closed afterward.</p>
|
220
|
-
</div></span>
|
221
|
-
|
222
|
-
</li>
|
223
|
-
|
224
|
-
|
225
|
-
</ul>
|
226
|
-
|
227
|
-
<h2>
|
228
|
-
Instance Method Summary
|
229
|
-
<small><a href="#" class="summary_toggle">collapse</a></small>
|
230
|
-
</h2>
|
231
|
-
|
232
|
-
<ul class="summary">
|
233
|
-
|
234
|
-
<li class="public ">
|
235
|
-
<span class="summary_signature">
|
236
|
-
|
237
|
-
<a href="#[]-instance_method" title="#[] (instance method)">#<strong>[]</strong>(key) ⇒ Object </a>
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
</span>
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
<span class="summary_desc"><div class='inline'><p>Retrieve the value associated with <code>key</code> from the database or nil if it is not present.</p>
|
252
|
-
</div></span>
|
253
|
-
|
254
|
-
</li>
|
255
|
-
|
256
|
-
|
257
|
-
<li class="public ">
|
258
|
-
<span class="summary_signature">
|
259
|
-
|
260
|
-
<a href="#[]=-instance_method" title="#[]= (instance method)">#<strong>[]=</strong>(key, value) ⇒ Object </a>
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
(also: #store)
|
265
|
-
|
266
|
-
</span>
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
<span class="summary_desc"><div class='inline'><p>Store <code>value</code> at <code>key</code> in the database.</p>
|
277
|
-
</div></span>
|
278
|
-
|
279
|
-
</li>
|
280
|
-
|
281
|
-
|
282
|
-
<li class="public ">
|
283
|
-
<span class="summary_signature">
|
284
|
-
|
285
|
-
<a href="#clear-instance_method" title="#clear (instance method)">#<strong>clear</strong> ⇒ Object </a>
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
</span>
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
<span class="summary_desc"><div class='inline'><p>Delete all entries from the table.</p>
|
300
|
-
</div></span>
|
301
|
-
|
302
|
-
</li>
|
303
|
-
|
304
|
-
|
305
|
-
<li class="public ">
|
306
|
-
<span class="summary_signature">
|
307
|
-
|
308
|
-
<a href="#close-instance_method" title="#close (instance method)">#<strong>close</strong> ⇒ Object </a>
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
</span>
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
<span class="summary_desc"><div class='inline'><p>Close <code>self</code>.</p>
|
323
|
-
</div></span>
|
324
|
-
|
325
|
-
</li>
|
326
|
-
|
327
|
-
|
328
|
-
<li class="public ">
|
329
|
-
<span class="summary_signature">
|
330
|
-
|
331
|
-
<a href="#closed%3F-instance_method" title="#closed? (instance method)">#<strong>closed?</strong> ⇒ Boolean </a>
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
</span>
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
<span class="summary_desc"><div class='inline'><p>Test if this object has been closed.</p>
|
346
|
-
</div></span>
|
347
|
-
|
348
|
-
</li>
|
349
|
-
|
350
|
-
|
351
|
-
<li class="public ">
|
352
|
-
<span class="summary_signature">
|
353
|
-
|
354
|
-
<a href="#delete-instance_method" title="#delete (instance method)">#<strong>delete</strong>(key) ⇒ Object </a>
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
</span>
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
<span class="summary_desc"><div class='inline'><p>Remove <code>key</code> and its associated value from <code>self</code>.</p>
|
369
|
-
</div></span>
|
370
|
-
|
371
|
-
</li>
|
372
|
-
|
373
|
-
|
374
|
-
<li class="public ">
|
375
|
-
<span class="summary_signature">
|
376
|
-
|
377
|
-
<a href="#delete_if-instance_method" title="#delete_if (instance method)">#<strong>delete_if</strong> {|value| ... } ⇒ Object </a>
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
(also: #reject!)
|
382
|
-
|
383
|
-
</span>
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
<span class="summary_desc"><div class='inline'><p>Evaluate the block on each key-value pair in <code>self</code> end delete each entry for which the block returns true.</p>
|
394
|
-
</div></span>
|
395
|
-
|
396
|
-
</li>
|
397
|
-
|
398
|
-
|
399
|
-
<li class="public ">
|
400
|
-
<span class="summary_signature">
|
401
|
-
|
402
|
-
<a href="#each-instance_method" title="#each (instance method)">#<strong>each</strong> {|key, value| ... } ⇒ Object </a>
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
(also: #each_pair)
|
407
|
-
|
408
|
-
</span>
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
<span class="summary_desc"><div class='inline'><p>Calls the given block with each key-value pair in the usual order, then return self.</p>
|
419
|
-
</div></span>
|
420
|
-
|
421
|
-
</li>
|
422
|
-
|
423
|
-
|
424
|
-
<li class="public ">
|
425
|
-
<span class="summary_signature">
|
426
|
-
|
427
|
-
<a href="#each_key-instance_method" title="#each_key (instance method)">#<strong>each_key</strong> {|key| ... } ⇒ Object </a>
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
</span>
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
<span class="summary_desc"><div class='inline'><p>Calls the given block with each key; returns self.</p>
|
442
|
-
</div></span>
|
443
|
-
|
444
|
-
</li>
|
445
|
-
|
446
|
-
|
447
|
-
<li class="public ">
|
448
|
-
<span class="summary_signature">
|
449
|
-
|
450
|
-
<a href="#each_value-instance_method" title="#each_value (instance method)">#<strong>each_value</strong> {|value| ... } ⇒ Object </a>
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
</span>
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
<span class="summary_desc"><div class='inline'><p>Calls the given block with each value; returns self.</p>
|
465
|
-
</div></span>
|
466
|
-
|
467
|
-
</li>
|
468
|
-
|
469
|
-
|
470
|
-
<li class="public ">
|
471
|
-
<span class="summary_signature">
|
472
|
-
|
473
|
-
<a href="#empty%3F-instance_method" title="#empty? (instance method)">#<strong>empty?</strong> ⇒ Boolean </a>
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
</span>
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
<span class="summary_desc"><div class='inline'><p>Test if <code>self</code> is empty.</p>
|
488
|
-
</div></span>
|
489
|
-
|
490
|
-
</li>
|
491
|
-
|
492
|
-
|
493
|
-
<li class="public ">
|
494
|
-
<span class="summary_signature">
|
495
|
-
|
496
|
-
<a href="#fetch-instance_method" title="#fetch (instance method)">#<strong>fetch</strong>(key, *args) {|key| ... } ⇒ Object </a>
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
</span>
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
<span class="summary_desc"><div class='inline'><p>Retrieve the value associated with <code>key</code>.</p>
|
511
|
-
</div></span>
|
512
|
-
|
513
|
-
</li>
|
514
|
-
|
515
|
-
|
516
|
-
<li class="public ">
|
517
|
-
<span class="summary_signature">
|
518
|
-
|
519
|
-
<a href="#handle_closed%3F-instance_method" title="#handle_closed? (instance method)">#<strong>handle_closed?</strong> ⇒ Boolean </a>
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
</span>
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
<span class="summary_desc"><div class='inline'><p>Test if the underlying <code>SQLite3::Database</code> is closed.</p>
|
534
|
-
</div></span>
|
535
|
-
|
536
|
-
</li>
|
537
|
-
|
538
|
-
|
539
|
-
<li class="public ">
|
540
|
-
<span class="summary_signature">
|
541
|
-
|
542
|
-
<a href="#has_key%3F-instance_method" title="#has_key? (instance method)">#<strong>has_key?</strong>(key) ⇒ Boolean </a>
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
(also: #include?, #member?, #key?)
|
547
|
-
|
548
|
-
</span>
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
<span class="summary_desc"><div class='inline'><p>Return <code>true</code> if the table contains <code>key</code>; otherwise, return <code>false</code>.</p>
|
559
|
-
</div></span>
|
560
|
-
|
561
|
-
</li>
|
562
|
-
|
563
|
-
|
564
|
-
<li class="public ">
|
565
|
-
<span class="summary_signature">
|
566
|
-
|
567
|
-
<a href="#has_value%3F-instance_method" title="#has_value? (instance method)">#<strong>has_value?</strong>(val) ⇒ Boolean </a>
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
(also: #value?)
|
572
|
-
|
573
|
-
</span>
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
<span class="summary_desc"><div class='inline'><p>Test if <code>val</code> is one of the values in this table.</p>
|
584
|
-
</div></span>
|
585
|
-
|
586
|
-
</li>
|
587
|
-
|
588
|
-
|
589
|
-
<li class="public ">
|
590
|
-
<span class="summary_signature">
|
591
|
-
|
592
|
-
<a href="#initialize-instance_method" title="#initialize (instance method)">#<strong>initialize</strong>(filename, tablename, serializer = :yaml) ⇒ DBM </a>
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
</span>
|
597
|
-
|
598
|
-
|
599
|
-
<span class="note title constructor">constructor</span>
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
<span class="summary_desc"><div class='inline'><p>Create a new <code>Lite3::DBM</code> object that opens database file <code>filename</code> and performs subsequent operations on <code>table</code>.</p>
|
609
|
-
</div></span>
|
610
|
-
|
611
|
-
</li>
|
612
|
-
|
613
|
-
|
614
|
-
<li class="public ">
|
615
|
-
<span class="summary_signature">
|
616
|
-
|
617
|
-
<a href="#invert-instance_method" title="#invert (instance method)">#<strong>invert</strong> ⇒ Object </a>
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
</span>
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
<span class="summary_desc"><div class='inline'><p>Return a <code>Hash</code> whose keys are the table's values and whose values are the table's keys.</p>
|
632
|
-
</div></span>
|
633
|
-
|
634
|
-
</li>
|
635
|
-
|
636
|
-
|
637
|
-
<li class="public ">
|
638
|
-
<span class="summary_signature">
|
639
|
-
|
640
|
-
<a href="#keys-instance_method" title="#keys (instance method)">#<strong>keys</strong> ⇒ Object </a>
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
</span>
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
<span class="summary_desc"><div class='inline'><p>Return an <code>Array</code> of all of the keys in the table.</p>
|
655
|
-
</div></span>
|
656
|
-
|
657
|
-
</li>
|
658
|
-
|
659
|
-
|
660
|
-
<li class="public ">
|
661
|
-
<span class="summary_signature">
|
662
|
-
|
663
|
-
<a href="#shift-instance_method" title="#shift (instance method)">#<strong>shift</strong> ⇒ Object </a>
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
</span>
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
<span class="summary_desc"><div class='inline'><p>Remove the first key/value pair from <code>self</code> and return it.</p>
|
678
|
-
</div></span>
|
679
|
-
|
680
|
-
</li>
|
681
|
-
|
682
|
-
|
683
|
-
<li class="public ">
|
684
|
-
<span class="summary_signature">
|
685
|
-
|
686
|
-
<a href="#size-instance_method" title="#size (instance method)">#<strong>size</strong> ⇒ Object </a>
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
(also: #length)
|
691
|
-
|
692
|
-
</span>
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
<span class="summary_desc"><div class='inline'><p>Return the number of entries (key-value pairs) in <code>self</code>.</p>
|
703
|
-
</div></span>
|
704
|
-
|
705
|
-
</li>
|
706
|
-
|
707
|
-
|
708
|
-
<li class="public ">
|
709
|
-
<span class="summary_signature">
|
710
|
-
|
711
|
-
<a href="#to_a-instance_method" title="#to_a (instance method)">#<strong>to_a</strong> ⇒ Object </a>
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
</span>
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
<span class="summary_desc"><div class='inline'><p>Returns an <code>Array</code> of 2-element <code>Array</code> objects each containing a key-value pair from <code>self</code>.</p>
|
726
|
-
</div></span>
|
727
|
-
|
728
|
-
</li>
|
729
|
-
|
730
|
-
|
731
|
-
<li class="public ">
|
732
|
-
<span class="summary_signature">
|
733
|
-
|
734
|
-
<a href="#to_hash-instance_method" title="#to_hash (instance method)">#<strong>to_hash</strong> ⇒ Object </a>
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
</span>
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
<span class="summary_desc"><div class='inline'><p>Copies the table into a <code>Hash</code> and returns it.</p>
|
749
|
-
</div></span>
|
750
|
-
|
751
|
-
</li>
|
752
|
-
|
753
|
-
|
754
|
-
<li class="public ">
|
755
|
-
<span class="summary_signature">
|
756
|
-
|
757
|
-
<a href="#to_s-instance_method" title="#to_s (instance method)">#<strong>to_s</strong> ⇒ Object </a>
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
(also: #inspect)
|
762
|
-
|
763
|
-
</span>
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
<span class="summary_desc"><div class='inline'></div></span>
|
774
|
-
|
775
|
-
</li>
|
776
|
-
|
777
|
-
|
778
|
-
<li class="public ">
|
779
|
-
<span class="summary_signature">
|
780
|
-
|
781
|
-
<a href="#transaction-instance_method" title="#transaction (instance method)">#<strong>transaction</strong> {|db| ... } ⇒ Object </a>
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
</span>
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
<span class="summary_desc"><div class='inline'><p>Begins a transaction, evaluates the given block and then ends the transaction.</p>
|
796
|
-
</div></span>
|
797
|
-
|
798
|
-
</li>
|
799
|
-
|
800
|
-
|
801
|
-
<li class="public ">
|
802
|
-
<span class="summary_signature">
|
803
|
-
|
804
|
-
<a href="#transaction_active%3F-instance_method" title="#transaction_active? (instance method)">#<strong>transaction_active?</strong> ⇒ Boolean </a>
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
</span>
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
<span class="summary_desc"><div class='inline'><p>Test if there is currently a transaction in progress.</p>
|
819
|
-
</div></span>
|
820
|
-
|
821
|
-
</li>
|
822
|
-
|
823
|
-
|
824
|
-
<li class="public ">
|
825
|
-
<span class="summary_signature">
|
826
|
-
|
827
|
-
<a href="#update-instance_method" title="#update (instance method)">#<strong>update</strong>(hash) ⇒ Object </a>
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
</span>
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
<span class="summary_desc"><div class='inline'><p>Updates the database with multiple values from the specified object.</p>
|
842
|
-
</div></span>
|
843
|
-
|
844
|
-
</li>
|
845
|
-
|
846
|
-
|
847
|
-
<li class="public ">
|
848
|
-
<span class="summary_signature">
|
849
|
-
|
850
|
-
<a href="#values-instance_method" title="#values (instance method)">#<strong>values</strong> ⇒ Object </a>
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
</span>
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
<span class="summary_desc"><div class='inline'><p>Return an array of all values in the table.</p>
|
865
|
-
</div></span>
|
866
|
-
|
867
|
-
</li>
|
868
|
-
|
869
|
-
|
870
|
-
<li class="public ">
|
871
|
-
<span class="summary_signature">
|
872
|
-
|
873
|
-
<a href="#values_at-instance_method" title="#values_at (instance method)">#<strong>values_at</strong>(*keys) ⇒ Object </a>
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
</span>
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
<span class="summary_desc"><div class='inline'><p>Return a new <code>Array</code> containing the values corresponding to the given keys.</p>
|
888
|
-
</div></span>
|
889
|
-
|
890
|
-
</li>
|
891
|
-
|
892
|
-
|
893
|
-
</ul>
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
<div id="constructor_details" class="method_details_list">
|
898
|
-
<h2>Constructor Details</h2>
|
899
|
-
|
900
|
-
<div class="method_details first">
|
901
|
-
<h3 class="signature first" id="initialize-instance_method">
|
902
|
-
|
903
|
-
#<strong>initialize</strong>(filename, tablename, serializer = :yaml) ⇒ <tt><span class='object_link'><a href="" title="Lite3::DBM (class)">DBM</a></span></tt>
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
</h3><div class="docstring">
|
910
|
-
<div class="discussion">
|
911
|
-
<p>Create a new <code>Lite3::DBM</code> object that opens database file
|
912
|
-
<code>filename</code> and performs subsequent operations on <code>table</code>. Both
|
913
|
-
the database file and the table will be created if they do not
|
914
|
-
yet exist.</p>
|
915
|
-
|
916
|
-
<p>The optional third argument <code>serializer</code> is used to choose the
|
917
|
-
serialization method for converting Ruby values into storable
|
918
|
-
strings. There are three options:</p>
|
919
|
-
|
920
|
-
<ul>
|
921
|
-
<li><code>:yaml</code> uses the <code>Psych</code> module.</li>
|
922
|
-
<li><code>:marshal</code> uses the <code>Marshal</code> module.</li>
|
923
|
-
<li><code>:string</code> simply uses the default <code>to_s</code> method, just like the
|
924
|
-
stock <code>DBM</code>.</li>
|
925
|
-
</ul>
|
926
|
-
|
927
|
-
<p>Each of these will have their pros and cons. The default is
|
928
|
-
<code>:yaml</code> because that is the most portable. <code>:marshal</code> tends to
|
929
|
-
be faster but is incompatible across minor Ruby versions.</p>
|
930
|
-
|
931
|
-
<p>(Note that <code>DBM</code> does not check your Marshal version.)</p>
|
932
|
-
|
933
|
-
<p>Your serializer choice is registered in a metadata table when
|
934
|
-
<code>tablename</code> is created in the SQLite3 file. Afterward, it is an
|
935
|
-
error to attempt to open the table with a different serializer
|
936
|
-
and will result in a Lite3::Error exception.</p>
|
937
|
-
|
938
|
-
|
939
|
-
</div>
|
940
|
-
</div>
|
941
|
-
<div class="tags">
|
942
|
-
|
943
|
-
|
944
|
-
</div><table class="source_code">
|
945
|
-
<tr>
|
946
|
-
<td>
|
947
|
-
<pre class="lines">
|
948
|
-
|
949
|
-
|
950
|
-
416
|
951
|
-
417
|
952
|
-
418
|
953
|
-
419
|
954
|
-
420
|
955
|
-
421
|
956
|
-
422
|
957
|
-
423
|
958
|
-
424
|
959
|
-
425
|
960
|
-
426
|
961
|
-
427
|
962
|
-
428
|
963
|
-
429
|
964
|
-
430
|
965
|
-
431
|
966
|
-
432
|
967
|
-
433
|
968
|
-
434
|
969
|
-
435
|
970
|
-
436</pre>
|
971
|
-
</td>
|
972
|
-
<td>
|
973
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 416</span>
|
974
|
-
|
975
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_filename'>filename</span><span class='comma'>,</span> <span class='id identifier rubyid_tablename'>tablename</span><span class='comma'>,</span> <span class='id identifier rubyid_serializer'>serializer</span> <span class='op'>=</span> <span class='symbol'>:yaml</span><span class='rparen'>)</span>
|
976
|
-
<span class='ivar'>@filename</span> <span class='op'>=</span> <span class='id identifier rubyid_filename'>filename</span>
|
977
|
-
<span class='ivar'>@tablename</span> <span class='op'>=</span> <span class='id identifier rubyid_tablename'>tablename</span>
|
978
|
-
<span class='ivar'>@valenc</span><span class='comma'>,</span>
|
979
|
-
<span class='ivar'>@valdec</span> <span class='op'>=</span> <span class='id identifier rubyid_value_encoders'>value_encoders</span><span class='lparen'>(</span><span class='id identifier rubyid_serializer'>serializer</span><span class='rparen'>)</span>
|
980
|
-
<span class='ivar'>@handle</span> <span class='op'>=</span> <span class='const'>HandlePool</span><span class='period'>.</span><span class='id identifier rubyid_get'>get</span><span class='lparen'>(</span><span class='id identifier rubyid_filename'>filename</span><span class='rparen'>)</span>
|
981
|
-
|
982
|
-
<span class='ivar'>@handle</span><span class='period'>.</span><span class='id identifier rubyid_addref'>addref</span><span class='lparen'>(</span><span class='kw'>self</span><span class='rparen'>)</span>
|
983
|
-
|
984
|
-
<span class='id identifier rubyid_check'>check</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Malformed table name '</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_tablename'>tablename</span><span class='embexpr_end'>}</span><span class='tstring_content'>'; must be a valid identifer</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='lbrace'>{</span>
|
985
|
-
<span class='id identifier rubyid_tablename'>tablename</span> <span class='op'>=~</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>^[a-zA-Z_]\w*$</span><span class='regexp_end'>/</span></span>
|
986
|
-
<span class='rbrace'>}</span>
|
987
|
-
|
988
|
-
<span class='id identifier rubyid_transaction'>transaction</span> <span class='lbrace'>{</span>
|
989
|
-
<span class='id identifier rubyid_register_serialization_scheme'>register_serialization_scheme</span><span class='lparen'>(</span><span class='id identifier rubyid_serializer'>serializer</span><span class='rparen'>)</span>
|
990
|
-
<span class='id identifier rubyid_create_table_if_not_present'>create_table_if_not_present</span><span class='lparen'>(</span><span class='rparen'>)</span>
|
991
|
-
<span class='rbrace'>}</span>
|
992
|
-
<span class='kw'>rescue</span> <span class='const'><span class='object_link'><a href="Error.html" title="Lite3::Error (class)">Error</a></span></span> <span class='op'>=></span> <span class='id identifier rubyid_e'>e</span>
|
993
|
-
<span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_close'>close</span> <span class='kw'>if</span> <span class='ivar'>@handle</span>
|
994
|
-
<span class='id identifier rubyid_raise'>raise</span> <span class='id identifier rubyid_e'>e</span>
|
995
|
-
<span class='kw'>end</span></pre>
|
996
|
-
</td>
|
997
|
-
</tr>
|
998
|
-
</table>
|
999
|
-
</div>
|
1000
|
-
|
1001
|
-
</div>
|
1002
|
-
|
1003
|
-
|
1004
|
-
<div id="class_method_details" class="method_details_list">
|
1005
|
-
<h2>Class Method Details</h2>
|
1006
|
-
|
1007
|
-
|
1008
|
-
<div class="method_details first">
|
1009
|
-
<h3 class="signature first" id="open-class_method">
|
1010
|
-
|
1011
|
-
.<strong>open</strong>(filename, tablename, serializer = :yaml, &block) ⇒ <tt>Object</tt>
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
</h3><div class="docstring">
|
1018
|
-
<div class="discussion">
|
1019
|
-
<p>Identical to <code>initialize</code> except that if a block is provided, it
|
1020
|
-
is evaluated with a new Lite3::DBM which is then closed afterward.
|
1021
|
-
This is analagous to <code>File.open</code>.</p>
|
1022
|
-
|
1023
|
-
|
1024
|
-
</div>
|
1025
|
-
</div>
|
1026
|
-
<div class="tags">
|
1027
|
-
|
1028
|
-
|
1029
|
-
</div><table class="source_code">
|
1030
|
-
<tr>
|
1031
|
-
<td>
|
1032
|
-
<pre class="lines">
|
1033
|
-
|
1034
|
-
|
1035
|
-
442
|
1036
|
-
443
|
1037
|
-
444
|
1038
|
-
445
|
1039
|
-
446
|
1040
|
-
447
|
1041
|
-
448
|
1042
|
-
449
|
1043
|
-
450
|
1044
|
-
451</pre>
|
1045
|
-
</td>
|
1046
|
-
<td>
|
1047
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 442</span>
|
1048
|
-
|
1049
|
-
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_open'>open</span><span class='lparen'>(</span><span class='id identifier rubyid_filename'>filename</span><span class='comma'>,</span> <span class='id identifier rubyid_tablename'>tablename</span><span class='comma'>,</span> <span class='id identifier rubyid_serializer'>serializer</span> <span class='op'>=</span> <span class='symbol'>:yaml</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1050
|
-
<span class='id identifier rubyid_instance'>instance</span> <span class='op'>=</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_filename'>filename</span><span class='comma'>,</span> <span class='id identifier rubyid_tablename'>tablename</span><span class='comma'>,</span> <span class='id identifier rubyid_serializer'>serializer</span><span class='rparen'>)</span>
|
1051
|
-
<span class='kw'>return</span> <span class='id identifier rubyid_instance'>instance</span> <span class='kw'>unless</span> <span class='id identifier rubyid_block'>block</span>
|
1052
|
-
|
1053
|
-
<span class='kw'>begin</span>
|
1054
|
-
<span class='kw'>return</span> <span class='id identifier rubyid_block'>block</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span><span class='lparen'>(</span><span class='id identifier rubyid_instance'>instance</span><span class='rparen'>)</span>
|
1055
|
-
<span class='kw'>ensure</span>
|
1056
|
-
<span class='id identifier rubyid_instance'>instance</span><span class='period'>.</span><span class='id identifier rubyid_close'>close</span>
|
1057
|
-
<span class='kw'>end</span>
|
1058
|
-
<span class='kw'>end</span></pre>
|
1059
|
-
</td>
|
1060
|
-
</tr>
|
1061
|
-
</table>
|
1062
|
-
</div>
|
1063
|
-
|
1064
|
-
</div>
|
1065
|
-
|
1066
|
-
<div id="instance_method_details" class="method_details_list">
|
1067
|
-
<h2>Instance Method Details</h2>
|
1068
|
-
|
1069
|
-
|
1070
|
-
<div class="method_details first">
|
1071
|
-
<h3 class="signature first" id="[]-instance_method">
|
1072
|
-
|
1073
|
-
#<strong>[]</strong>(key) ⇒ <tt>Object</tt>
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
</h3><div class="docstring">
|
1080
|
-
<div class="discussion">
|
1081
|
-
<p>Retrieve the value associated with <code>key</code> from the database or
|
1082
|
-
nil if it is not present.</p>
|
1083
|
-
|
1084
|
-
|
1085
|
-
</div>
|
1086
|
-
</div>
|
1087
|
-
<div class="tags">
|
1088
|
-
|
1089
|
-
|
1090
|
-
</div><table class="source_code">
|
1091
|
-
<tr>
|
1092
|
-
<td>
|
1093
|
-
<pre class="lines">
|
1094
|
-
|
1095
|
-
|
1096
|
-
662
|
1097
|
-
663
|
1098
|
-
664</pre>
|
1099
|
-
</td>
|
1100
|
-
<td>
|
1101
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 662</span>
|
1102
|
-
|
1103
|
-
<span class='kw'>def</span> <span class='op'>[]</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span>
|
1104
|
-
<span class='kw'>return</span> <span class='id identifier rubyid_fetch'>fetch</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
1105
|
-
<span class='kw'>end</span></pre>
|
1106
|
-
</td>
|
1107
|
-
</tr>
|
1108
|
-
</table>
|
1109
|
-
</div>
|
1110
|
-
|
1111
|
-
<div class="method_details ">
|
1112
|
-
<h3 class="signature " id="[]=-instance_method">
|
1113
|
-
|
1114
|
-
#<strong>[]=</strong>(key, value) ⇒ <tt>Object</tt>
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1118
|
-
<span class="aliases">Also known as:
|
1119
|
-
<span class="names"><span id='store-instance_method'>store</span></span>
|
1120
|
-
</span>
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1124
|
-
</h3><div class="docstring">
|
1125
|
-
<div class="discussion">
|
1126
|
-
<p>Store <code>value</code> at <code>key</code> in the database.</p>
|
1127
|
-
|
1128
|
-
<p><code>key</code> <strong>must</strong> be a String or a Symbol.</p>
|
1129
|
-
|
1130
|
-
<p><code>value</code> <strong>must</strong> be convertable to string by whichever
|
1131
|
-
serialization method you have chosen.</p>
|
1132
|
-
|
1133
|
-
|
1134
|
-
</div>
|
1135
|
-
</div>
|
1136
|
-
<div class="tags">
|
1137
|
-
|
1138
|
-
|
1139
|
-
</div><table class="source_code">
|
1140
|
-
<tr>
|
1141
|
-
<td>
|
1142
|
-
<pre class="lines">
|
1143
|
-
|
1144
|
-
|
1145
|
-
615
|
1146
|
-
616
|
1147
|
-
617
|
1148
|
-
618
|
1149
|
-
619
|
1150
|
-
620
|
1151
|
-
621
|
1152
|
-
622
|
1153
|
-
623
|
1154
|
-
624
|
1155
|
-
625
|
1156
|
-
626
|
1157
|
-
627
|
1158
|
-
628
|
1159
|
-
629
|
1160
|
-
630
|
1161
|
-
631
|
1162
|
-
632
|
1163
|
-
633
|
1164
|
-
634
|
1165
|
-
635
|
1166
|
-
636
|
1167
|
-
637
|
1168
|
-
638
|
1169
|
-
639
|
1170
|
-
640
|
1171
|
-
641
|
1172
|
-
642
|
1173
|
-
643
|
1174
|
-
644
|
1175
|
-
645
|
1176
|
-
646
|
1177
|
-
647
|
1178
|
-
648
|
1179
|
-
649
|
1180
|
-
650
|
1181
|
-
651
|
1182
|
-
652
|
1183
|
-
653
|
1184
|
-
654
|
1185
|
-
655
|
1186
|
-
656
|
1187
|
-
657</pre>
|
1188
|
-
</td>
|
1189
|
-
<td>
|
1190
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 615</span>
|
1191
|
-
|
1192
|
-
<span class='kw'>def</span> <span class='op'>[]=</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
|
1193
|
-
<span class='id identifier rubyid_key'>key</span> <span class='op'>=</span> <span class='id identifier rubyid_check_key'>check_key</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span>
|
1194
|
-
<span class='id identifier rubyid_valstr'>valstr</span> <span class='op'>=</span> <span class='const'>SQLite3</span><span class='op'>::</span><span class='const'>Blob</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span> <span class='ivar'>@valenc</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span> <span class='rparen'>)</span>
|
1195
|
-
|
1196
|
-
<span class='comment'># At one point, this operation was done with SQLite3's UPSERT:
|
1197
|
-
</span> <span class='comment'>#
|
1198
|
-
</span> <span class='comment'># insert into #{actual_tbl} (key, value) values (?,?)
|
1199
|
-
</span> <span class='comment'># on conflict(key) do update set value = ?;
|
1200
|
-
</span> <span class='comment'>#
|
1201
|
-
</span> <span class='comment'># Unfortunately, this capability was only added to SQLite3 in
|
1202
|
-
</span> <span class='comment'># 2018, which means that at the time of this writing (2022)
|
1203
|
-
</span> <span class='comment'># there are still a lot of systems out there that have older
|
1204
|
-
</span> <span class='comment'># versions of SQLite3 and so can't do this.
|
1205
|
-
</span> <span class='comment'>#
|
1206
|
-
</span> <span class='comment'># The venerable `insert or replace` feature **almost** does what
|
1207
|
-
</span> <span class='comment'># I want:
|
1208
|
-
</span> <span class='comment'>#
|
1209
|
-
</span> <span class='comment'># insert or replace into #{actual_tbl} (key, value) values (?, ?);
|
1210
|
-
</span> <span class='comment'>#
|
1211
|
-
</span> <span class='comment'># The one problem is that it changes the order of the rows,
|
1212
|
-
</span> <span class='comment'># which we need to preserve in order to remain consistent with
|
1213
|
-
</span> <span class='comment'># `Hash` semantics (and because it's useful).
|
1214
|
-
</span> <span class='comment'>#
|
1215
|
-
</span> <span class='comment'># So we kick it old school and do a `select` followed by an
|
1216
|
-
</span> <span class='comment'># `insert` or `update` wrapped in a transaction.
|
1217
|
-
</span> <span class='id identifier rubyid_transaction'>transaction</span> <span class='lbrace'>{</span>
|
1218
|
-
<span class='id identifier rubyid_rowid'>rowid</span> <span class='op'>=</span> <span class='kw'>nil</span>
|
1219
|
-
<span class='id identifier rubyid_select'>select</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>select rowid, key, value from </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_actual_tbl'>actual_tbl</span><span class='embexpr_end'>}</span><span class='tstring_content'> where key = ?;</span><span class='tstring_end'>"</span></span>
|
1220
|
-
<span class='ivar'>@handle</span><span class='period'>.</span><span class='id identifier rubyid_sql'>sql</span><span class='lparen'>(</span><span class='id identifier rubyid_select'>select</span><span class='comma'>,</span> <span class='lbracket'>[</span><span class='id identifier rubyid_key'>key</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_row'>row</span><span class='op'>|</span>
|
1221
|
-
<span class='id identifier rubyid_rowid'>rowid</span> <span class='op'>=</span> <span class='id identifier rubyid_row'>row</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span>
|
1222
|
-
<span class='rbrace'>}</span>
|
1223
|
-
|
1224
|
-
<span class='kw'>if</span> <span class='id identifier rubyid_rowid'>rowid</span>
|
1225
|
-
<span class='id identifier rubyid_update'>update</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>update </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_actual_tbl'>actual_tbl</span><span class='embexpr_end'>}</span><span class='tstring_content'> set value = ? where rowid = ?;</span><span class='tstring_end'>"</span></span>
|
1226
|
-
<span class='ivar'>@handle</span><span class='period'>.</span><span class='id identifier rubyid_sql'>sql</span><span class='lparen'>(</span><span class='id identifier rubyid_update'>update</span><span class='comma'>,</span> <span class='lbracket'>[</span><span class='id identifier rubyid_valstr'>valstr</span><span class='comma'>,</span> <span class='id identifier rubyid_rowid'>rowid</span><span class='rbracket'>]</span><span class='rparen'>)</span>
|
1227
|
-
<span class='kw'>else</span>
|
1228
|
-
<span class='id identifier rubyid_insert'>insert</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>insert into </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_actual_tbl'>actual_tbl</span><span class='embexpr_end'>}</span><span class='tstring_content'> (key, value) values (?,?);</span><span class='tstring_end'>"</span></span>
|
1229
|
-
<span class='ivar'>@handle</span><span class='period'>.</span><span class='id identifier rubyid_sql'>sql</span><span class='lparen'>(</span><span class='id identifier rubyid_insert'>insert</span><span class='comma'>,</span> <span class='lbracket'>[</span><span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_valstr'>valstr</span><span class='rbracket'>]</span><span class='rparen'>)</span>
|
1230
|
-
<span class='kw'>end</span>
|
1231
|
-
<span class='rbrace'>}</span>
|
1232
|
-
|
1233
|
-
<span class='kw'>return</span> <span class='id identifier rubyid_value'>value</span>
|
1234
|
-
<span class='kw'>end</span></pre>
|
1235
|
-
</td>
|
1236
|
-
</tr>
|
1237
|
-
</table>
|
1238
|
-
</div>
|
1239
|
-
|
1240
|
-
<div class="method_details ">
|
1241
|
-
<h3 class="signature " id="clear-instance_method">
|
1242
|
-
|
1243
|
-
#<strong>clear</strong> ⇒ <tt>Object</tt>
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
|
1249
|
-
</h3><div class="docstring">
|
1250
|
-
<div class="discussion">
|
1251
|
-
<p>Delete all entries from the table.</p>
|
1252
|
-
|
1253
|
-
|
1254
|
-
</div>
|
1255
|
-
</div>
|
1256
|
-
<div class="tags">
|
1257
|
-
|
1258
|
-
|
1259
|
-
</div><table class="source_code">
|
1260
|
-
<tr>
|
1261
|
-
<td>
|
1262
|
-
<pre class="lines">
|
1263
|
-
|
1264
|
-
|
1265
|
-
746
|
1266
|
-
747
|
1267
|
-
748</pre>
|
1268
|
-
</td>
|
1269
|
-
<td>
|
1270
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 746</span>
|
1271
|
-
|
1272
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_clear'>clear</span>
|
1273
|
-
<span class='id identifier rubyid_transaction'>transaction</span> <span class='lbrace'>{</span> <span class='ivar'>@handle</span><span class='period'>.</span><span class='id identifier rubyid_sql'>sql</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>delete from </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_actual_tbl'>actual_tbl</span><span class='embexpr_end'>}</span><span class='tstring_content'>;</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='lbracket'>[</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
|
1274
|
-
<span class='kw'>end</span></pre>
|
1275
|
-
</td>
|
1276
|
-
</tr>
|
1277
|
-
</table>
|
1278
|
-
</div>
|
1279
|
-
|
1280
|
-
<div class="method_details ">
|
1281
|
-
<h3 class="signature " id="close-instance_method">
|
1282
|
-
|
1283
|
-
#<strong>close</strong> ⇒ <tt>Object</tt>
|
1284
|
-
|
1285
|
-
|
1286
|
-
|
1287
|
-
|
1288
|
-
|
1289
|
-
</h3><div class="docstring">
|
1290
|
-
<div class="discussion">
|
1291
|
-
<p>Close <code>self</code>. Subsequent attempts at database operations will
|
1292
|
-
fail with an exception but <code>closed?</code> will still work.</p>
|
1293
|
-
|
1294
|
-
<p>Note that the underlying file handle (via the
|
1295
|
-
<code>SQLite3::Database</code> object) will <strong>only</strong> be closed if there are
|
1296
|
-
no other <code>DBM</code> objects using that file.</p>
|
1297
|
-
|
1298
|
-
|
1299
|
-
</div>
|
1300
|
-
</div>
|
1301
|
-
<div class="tags">
|
1302
|
-
|
1303
|
-
|
1304
|
-
</div><table class="source_code">
|
1305
|
-
<tr>
|
1306
|
-
<td>
|
1307
|
-
<pre class="lines">
|
1308
|
-
|
1309
|
-
|
1310
|
-
550
|
1311
|
-
551
|
1312
|
-
552
|
1313
|
-
553</pre>
|
1314
|
-
</td>
|
1315
|
-
<td>
|
1316
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 550</span>
|
1317
|
-
|
1318
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_close'>close</span>
|
1319
|
-
<span class='ivar'>@handle</span><span class='period'>.</span><span class='id identifier rubyid_delref'>delref</span><span class='lparen'>(</span><span class='kw'>self</span><span class='rparen'>)</span>
|
1320
|
-
<span class='ivar'>@handle</span> <span class='op'>=</span> <span class='const'>ClosedHandle</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='ivar'>@filename</span><span class='comma'>,</span> <span class='ivar'>@tablename</span><span class='rparen'>)</span>
|
1321
|
-
<span class='kw'>end</span></pre>
|
1322
|
-
</td>
|
1323
|
-
</tr>
|
1324
|
-
</table>
|
1325
|
-
</div>
|
1326
|
-
|
1327
|
-
<div class="method_details ">
|
1328
|
-
<h3 class="signature " id="closed?-instance_method">
|
1329
|
-
|
1330
|
-
#<strong>closed?</strong> ⇒ <tt>Boolean</tt>
|
1331
|
-
|
1332
|
-
|
1333
|
-
|
1334
|
-
|
1335
|
-
|
1336
|
-
</h3><div class="docstring">
|
1337
|
-
<div class="discussion">
|
1338
|
-
<p>Test if this object has been closed. This is safe to call on a
|
1339
|
-
closed <code>DBM</code>.</p>
|
1340
|
-
|
1341
|
-
|
1342
|
-
</div>
|
1343
|
-
</div>
|
1344
|
-
<div class="tags">
|
1345
|
-
|
1346
|
-
<p class="tag_title">Returns:</p>
|
1347
|
-
<ul class="return">
|
1348
|
-
|
1349
|
-
<li>
|
1350
|
-
|
1351
|
-
|
1352
|
-
<span class='type'>(<tt>Boolean</tt>)</span>
|
1353
|
-
|
1354
|
-
|
1355
|
-
|
1356
|
-
</li>
|
1357
|
-
|
1358
|
-
</ul>
|
1359
|
-
|
1360
|
-
</div><table class="source_code">
|
1361
|
-
<tr>
|
1362
|
-
<td>
|
1363
|
-
<pre class="lines">
|
1364
|
-
|
1365
|
-
|
1366
|
-
557
|
1367
|
-
558
|
1368
|
-
559</pre>
|
1369
|
-
</td>
|
1370
|
-
<td>
|
1371
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 557</span>
|
1372
|
-
|
1373
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_closed?'>closed?</span><span class='lparen'>(</span><span class='rparen'>)</span>
|
1374
|
-
<span class='kw'>return</span> <span class='ivar'>@handle</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span> <span class='const'>ClosedHandle</span>
|
1375
|
-
<span class='kw'>end</span></pre>
|
1376
|
-
</td>
|
1377
|
-
</tr>
|
1378
|
-
</table>
|
1379
|
-
</div>
|
1380
|
-
|
1381
|
-
<div class="method_details ">
|
1382
|
-
<h3 class="signature " id="delete-instance_method">
|
1383
|
-
|
1384
|
-
#<strong>delete</strong>(key) ⇒ <tt>Object</tt>
|
1385
|
-
|
1386
|
-
|
1387
|
-
|
1388
|
-
|
1389
|
-
|
1390
|
-
</h3><div class="docstring">
|
1391
|
-
<div class="discussion">
|
1392
|
-
<p>Remove <code>key</code> and its associated value from <code>self</code>. If <code>key</code> is
|
1393
|
-
not present, does nothing.</p>
|
1394
|
-
|
1395
|
-
|
1396
|
-
</div>
|
1397
|
-
</div>
|
1398
|
-
<div class="tags">
|
1399
|
-
|
1400
|
-
|
1401
|
-
</div><table class="source_code">
|
1402
|
-
<tr>
|
1403
|
-
<td>
|
1404
|
-
<pre class="lines">
|
1405
|
-
|
1406
|
-
|
1407
|
-
835
|
1408
|
-
836
|
1409
|
-
837
|
1410
|
-
838
|
1411
|
-
839</pre>
|
1412
|
-
</td>
|
1413
|
-
<td>
|
1414
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 835</span>
|
1415
|
-
|
1416
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span>
|
1417
|
-
<span class='id identifier rubyid_transaction'>transaction</span> <span class='lbrace'>{</span>
|
1418
|
-
<span class='ivar'>@handle</span><span class='period'>.</span><span class='id identifier rubyid_sql'>sql</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>delete from </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_actual_tbl'>actual_tbl</span><span class='embexpr_end'>}</span><span class='tstring_content'> where key = ?</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='lbracket'>[</span><span class='id identifier rubyid_key'>key</span><span class='rbracket'>]</span><span class='rparen'>)</span>
|
1419
|
-
<span class='rbrace'>}</span>
|
1420
|
-
<span class='kw'>end</span></pre>
|
1421
|
-
</td>
|
1422
|
-
</tr>
|
1423
|
-
</table>
|
1424
|
-
</div>
|
1425
|
-
|
1426
|
-
<div class="method_details ">
|
1427
|
-
<h3 class="signature " id="delete_if-instance_method">
|
1428
|
-
|
1429
|
-
#<strong>delete_if</strong> {|value| ... } ⇒ <tt>Object</tt>
|
1430
|
-
|
1431
|
-
|
1432
|
-
|
1433
|
-
<span class="aliases">Also known as:
|
1434
|
-
<span class="names"><span id='reject!-instance_method'>reject!</span></span>
|
1435
|
-
</span>
|
1436
|
-
|
1437
|
-
|
1438
|
-
|
1439
|
-
</h3><div class="docstring">
|
1440
|
-
<div class="discussion">
|
1441
|
-
<p>Evaluate the block on each key-value pair in <code>self</code> end delete
|
1442
|
-
each entry for which the block returns true.</p>
|
1443
|
-
|
1444
|
-
|
1445
|
-
</div>
|
1446
|
-
</div>
|
1447
|
-
<div class="tags">
|
1448
|
-
|
1449
|
-
<p class="tag_title">Yields:</p>
|
1450
|
-
<ul class="yield">
|
1451
|
-
|
1452
|
-
<li>
|
1453
|
-
|
1454
|
-
|
1455
|
-
<span class='type'>(<tt>value</tt>)</span>
|
1456
|
-
|
1457
|
-
|
1458
|
-
|
1459
|
-
—
|
1460
|
-
<div class='inline'><p>The block to evaluate</p>
|
1461
|
-
</div>
|
1462
|
-
|
1463
|
-
</li>
|
1464
|
-
|
1465
|
-
</ul>
|
1466
|
-
|
1467
|
-
</div><table class="source_code">
|
1468
|
-
<tr>
|
1469
|
-
<td>
|
1470
|
-
<pre class="lines">
|
1471
|
-
|
1472
|
-
|
1473
|
-
845
|
1474
|
-
846
|
1475
|
-
847
|
1476
|
-
848
|
1477
|
-
849</pre>
|
1478
|
-
</td>
|
1479
|
-
<td>
|
1480
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 845</span>
|
1481
|
-
|
1482
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_delete_if'>delete_if</span><span class='lparen'>(</span><span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1483
|
-
<span class='id identifier rubyid_transaction'>transaction</span> <span class='lbrace'>{</span>
|
1484
|
-
<span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span><span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_k'>k</span><span class='comma'>,</span> <span class='id identifier rubyid_v'>v</span><span class='op'>|</span> <span class='id identifier rubyid_block'>block</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span><span class='lparen'>(</span><span class='id identifier rubyid_k'>k</span><span class='comma'>,</span><span class='id identifier rubyid_v'>v</span><span class='rparen'>)</span> <span class='kw'>and</span> <span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='id identifier rubyid_k'>k</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
|
1485
|
-
<span class='rbrace'>}</span>
|
1486
|
-
<span class='kw'>end</span></pre>
|
1487
|
-
</td>
|
1488
|
-
</tr>
|
1489
|
-
</table>
|
1490
|
-
</div>
|
1491
|
-
|
1492
|
-
<div class="method_details ">
|
1493
|
-
<h3 class="signature " id="each-instance_method">
|
1494
|
-
|
1495
|
-
#<strong>each</strong> {|key, value| ... } ⇒ <tt>Object</tt>
|
1496
|
-
|
1497
|
-
|
1498
|
-
|
1499
|
-
<span class="aliases">Also known as:
|
1500
|
-
<span class="names"><span id='each_pair-instance_method'>each_pair</span></span>
|
1501
|
-
</span>
|
1502
|
-
|
1503
|
-
|
1504
|
-
|
1505
|
-
</h3><div class="docstring">
|
1506
|
-
<div class="discussion">
|
1507
|
-
<p>Calls the given block with each key-value pair in the usual
|
1508
|
-
order, then return self. The entire call takes place in its own
|
1509
|
-
transaction.</p>
|
1510
|
-
|
1511
|
-
<p>If no block is given, returns an Enumerator instead. The
|
1512
|
-
Enumerator does <em>not</em> start a transaction but individual
|
1513
|
-
accesses of it (e.g. calling <code>next</code>) each take place in their
|
1514
|
-
own transaction.</p>
|
1515
|
-
|
1516
|
-
|
1517
|
-
</div>
|
1518
|
-
</div>
|
1519
|
-
<div class="tags">
|
1520
|
-
|
1521
|
-
<p class="tag_title">Yields:</p>
|
1522
|
-
<ul class="yield">
|
1523
|
-
|
1524
|
-
<li>
|
1525
|
-
|
1526
|
-
|
1527
|
-
<span class='type'>(<tt>key</tt>, <tt>value</tt>)</span>
|
1528
|
-
|
1529
|
-
|
1530
|
-
|
1531
|
-
—
|
1532
|
-
<div class='inline'><p>The block to evaluate</p>
|
1533
|
-
</div>
|
1534
|
-
|
1535
|
-
</li>
|
1536
|
-
|
1537
|
-
</ul>
|
1538
|
-
|
1539
|
-
</div><table class="source_code">
|
1540
|
-
<tr>
|
1541
|
-
<td>
|
1542
|
-
<pre class="lines">
|
1543
|
-
|
1544
|
-
|
1545
|
-
760
|
1546
|
-
761
|
1547
|
-
762
|
1548
|
-
763
|
1549
|
-
764</pre>
|
1550
|
-
</td>
|
1551
|
-
<td>
|
1552
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 760</span>
|
1553
|
-
|
1554
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_each'>each</span><span class='lparen'>(</span><span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1555
|
-
<span class='kw'>return</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_to_enum'>to_enum</span><span class='lparen'>(</span><span class='symbol'>:nt_each</span><span class='rparen'>)</span> <span class='kw'>unless</span> <span class='id identifier rubyid_block'>block</span>
|
1556
|
-
<span class='id identifier rubyid_transaction'>transaction</span> <span class='lbrace'>{</span> <span class='id identifier rubyid_nt_each'>nt_each</span><span class='lparen'>(</span><span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
|
1557
|
-
<span class='kw'>return</span> <span class='kw'>self</span>
|
1558
|
-
<span class='kw'>end</span></pre>
|
1559
|
-
</td>
|
1560
|
-
</tr>
|
1561
|
-
</table>
|
1562
|
-
</div>
|
1563
|
-
|
1564
|
-
<div class="method_details ">
|
1565
|
-
<h3 class="signature " id="each_key-instance_method">
|
1566
|
-
|
1567
|
-
#<strong>each_key</strong> {|key| ... } ⇒ <tt>Object</tt>
|
1568
|
-
|
1569
|
-
|
1570
|
-
|
1571
|
-
|
1572
|
-
|
1573
|
-
</h3><div class="docstring">
|
1574
|
-
<div class="discussion">
|
1575
|
-
<p>Calls the given block with each key; returns self. Exactly like
|
1576
|
-
<code>each</code> except for the block argument.</p>
|
1577
|
-
|
1578
|
-
|
1579
|
-
</div>
|
1580
|
-
</div>
|
1581
|
-
<div class="tags">
|
1582
|
-
|
1583
|
-
<p class="tag_title">Yields:</p>
|
1584
|
-
<ul class="yield">
|
1585
|
-
|
1586
|
-
<li>
|
1587
|
-
|
1588
|
-
|
1589
|
-
<span class='type'>(<tt>key</tt>)</span>
|
1590
|
-
|
1591
|
-
|
1592
|
-
|
1593
|
-
—
|
1594
|
-
<div class='inline'><p>The block to evaluate</p>
|
1595
|
-
</div>
|
1596
|
-
|
1597
|
-
</li>
|
1598
|
-
|
1599
|
-
</ul>
|
1600
|
-
|
1601
|
-
</div><table class="source_code">
|
1602
|
-
<tr>
|
1603
|
-
<td>
|
1604
|
-
<pre class="lines">
|
1605
|
-
|
1606
|
-
|
1607
|
-
810
|
1608
|
-
811
|
1609
|
-
812
|
1610
|
-
813</pre>
|
1611
|
-
</td>
|
1612
|
-
<td>
|
1613
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 810</span>
|
1614
|
-
|
1615
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_each_key'>each_key</span><span class='lparen'>(</span><span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1616
|
-
<span class='kw'>return</span> <span class='const'>Enumerator</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_y'>y</span><span class='op'>|</span> <span class='id identifier rubyid_nt_each'>nt_each</span><span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_k'>k</span><span class='comma'>,</span><span class='id identifier rubyid_v'>v</span><span class='op'>|</span> <span class='id identifier rubyid_y'>y</span> <span class='op'><<</span> <span class='id identifier rubyid_k'>k</span> <span class='rbrace'>}</span> <span class='rbrace'>}</span> <span class='kw'>unless</span> <span class='id identifier rubyid_block'>block</span>
|
1617
|
-
<span class='kw'>return</span> <span class='id identifier rubyid_each'>each</span><span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_k'>k</span><span class='comma'>,</span><span class='id identifier rubyid_v'>v</span><span class='op'>|</span> <span class='id identifier rubyid_block'>block</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span><span class='lparen'>(</span><span class='id identifier rubyid_k'>k</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
|
1618
|
-
<span class='kw'>end</span></pre>
|
1619
|
-
</td>
|
1620
|
-
</tr>
|
1621
|
-
</table>
|
1622
|
-
</div>
|
1623
|
-
|
1624
|
-
<div class="method_details ">
|
1625
|
-
<h3 class="signature " id="each_value-instance_method">
|
1626
|
-
|
1627
|
-
#<strong>each_value</strong> {|value| ... } ⇒ <tt>Object</tt>
|
1628
|
-
|
1629
|
-
|
1630
|
-
|
1631
|
-
|
1632
|
-
|
1633
|
-
</h3><div class="docstring">
|
1634
|
-
<div class="discussion">
|
1635
|
-
<p>Calls the given block with each value; returns self. Exactly like
|
1636
|
-
<code>each</code> except for the block argument.</p>
|
1637
|
-
|
1638
|
-
|
1639
|
-
</div>
|
1640
|
-
</div>
|
1641
|
-
<div class="tags">
|
1642
|
-
|
1643
|
-
<p class="tag_title">Yields:</p>
|
1644
|
-
<ul class="yield">
|
1645
|
-
|
1646
|
-
<li>
|
1647
|
-
|
1648
|
-
|
1649
|
-
<span class='type'>(<tt>value</tt>)</span>
|
1650
|
-
|
1651
|
-
|
1652
|
-
|
1653
|
-
—
|
1654
|
-
<div class='inline'><p>The block to evaluate</p>
|
1655
|
-
</div>
|
1656
|
-
|
1657
|
-
</li>
|
1658
|
-
|
1659
|
-
</ul>
|
1660
|
-
|
1661
|
-
</div><table class="source_code">
|
1662
|
-
<tr>
|
1663
|
-
<td>
|
1664
|
-
<pre class="lines">
|
1665
|
-
|
1666
|
-
|
1667
|
-
819
|
1668
|
-
820
|
1669
|
-
821
|
1670
|
-
822</pre>
|
1671
|
-
</td>
|
1672
|
-
<td>
|
1673
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 819</span>
|
1674
|
-
|
1675
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_each_value'>each_value</span><span class='lparen'>(</span><span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1676
|
-
<span class='kw'>return</span> <span class='const'>Enumerator</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_y'>y</span><span class='op'>|</span> <span class='id identifier rubyid_nt_each'>nt_each</span><span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_k'>k</span><span class='comma'>,</span><span class='id identifier rubyid_v'>v</span><span class='op'>|</span> <span class='id identifier rubyid_y'>y</span> <span class='op'><<</span> <span class='id identifier rubyid_v'>v</span> <span class='rbrace'>}</span> <span class='rbrace'>}</span> <span class='kw'>unless</span> <span class='id identifier rubyid_block'>block</span>
|
1677
|
-
<span class='kw'>return</span> <span class='id identifier rubyid_each'>each</span><span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_k'>k</span><span class='comma'>,</span><span class='id identifier rubyid_v'>v</span><span class='op'>|</span> <span class='id identifier rubyid_block'>block</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span><span class='lparen'>(</span><span class='id identifier rubyid_v'>v</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
|
1678
|
-
<span class='kw'>end</span></pre>
|
1679
|
-
</td>
|
1680
|
-
</tr>
|
1681
|
-
</table>
|
1682
|
-
</div>
|
1683
|
-
|
1684
|
-
<div class="method_details ">
|
1685
|
-
<h3 class="signature " id="empty?-instance_method">
|
1686
|
-
|
1687
|
-
#<strong>empty?</strong> ⇒ <tt>Boolean</tt>
|
1688
|
-
|
1689
|
-
|
1690
|
-
|
1691
|
-
|
1692
|
-
|
1693
|
-
</h3><div class="docstring">
|
1694
|
-
<div class="discussion">
|
1695
|
-
<p>Test if <code>self</code> is empty.</p>
|
1696
|
-
|
1697
|
-
|
1698
|
-
</div>
|
1699
|
-
</div>
|
1700
|
-
<div class="tags">
|
1701
|
-
|
1702
|
-
<p class="tag_title">Returns:</p>
|
1703
|
-
<ul class="return">
|
1704
|
-
|
1705
|
-
<li>
|
1706
|
-
|
1707
|
-
|
1708
|
-
<span class='type'>(<tt>Boolean</tt>)</span>
|
1709
|
-
|
1710
|
-
|
1711
|
-
|
1712
|
-
</li>
|
1713
|
-
|
1714
|
-
</ul>
|
1715
|
-
|
1716
|
-
</div><table class="source_code">
|
1717
|
-
<tr>
|
1718
|
-
<td>
|
1719
|
-
<pre class="lines">
|
1720
|
-
|
1721
|
-
|
1722
|
-
862
|
1723
|
-
863
|
1724
|
-
864</pre>
|
1725
|
-
</td>
|
1726
|
-
<td>
|
1727
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 862</span>
|
1728
|
-
|
1729
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_empty?'>empty?</span>
|
1730
|
-
<span class='kw'>return</span> <span class='id identifier rubyid_size'>size</span> <span class='op'>==</span> <span class='int'>0</span>
|
1731
|
-
<span class='kw'>end</span></pre>
|
1732
|
-
</td>
|
1733
|
-
</tr>
|
1734
|
-
</table>
|
1735
|
-
</div>
|
1736
|
-
|
1737
|
-
<div class="method_details ">
|
1738
|
-
<h3 class="signature " id="fetch-instance_method">
|
1739
|
-
|
1740
|
-
#<strong>fetch</strong>(key, *args) {|key| ... } ⇒ <tt>Object</tt>
|
1741
|
-
|
1742
|
-
|
1743
|
-
|
1744
|
-
|
1745
|
-
|
1746
|
-
</h3><div class="docstring">
|
1747
|
-
<div class="discussion">
|
1748
|
-
<p>Retrieve the value associated with <code>key</code>.</p>
|
1749
|
-
|
1750
|
-
<p>If it is not present and a block is given, evaluate the block
|
1751
|
-
with the key as its argument and return that.</p>
|
1752
|
-
|
1753
|
-
<p>If no block was given either but one extra parameter was given,
|
1754
|
-
that value is returned instead.</p>
|
1755
|
-
|
1756
|
-
<p>Finally, if none of these was given, it throws an <code>IndexError</code>
|
1757
|
-
exception.</p>
|
1758
|
-
|
1759
|
-
<p>It is an error if <code>fetch</code> is called with more than two arguments.</p>
|
1760
|
-
|
1761
|
-
|
1762
|
-
</div>
|
1763
|
-
</div>
|
1764
|
-
<div class="tags">
|
1765
|
-
|
1766
|
-
<p class="tag_title">Yields:</p>
|
1767
|
-
<ul class="yield">
|
1768
|
-
|
1769
|
-
<li>
|
1770
|
-
|
1771
|
-
|
1772
|
-
<span class='type'>(<tt>key</tt>)</span>
|
1773
|
-
|
1774
|
-
|
1775
|
-
|
1776
|
-
—
|
1777
|
-
<div class='inline'><p>The fallback block.</p>
|
1778
|
-
</div>
|
1779
|
-
|
1780
|
-
</li>
|
1781
|
-
|
1782
|
-
</ul>
|
1783
|
-
<p class="tag_title">Raises:</p>
|
1784
|
-
<ul class="raise">
|
1785
|
-
|
1786
|
-
<li>
|
1787
|
-
|
1788
|
-
|
1789
|
-
<span class='type'>(<tt>IndexError</tt>)</span>
|
1790
|
-
|
1791
|
-
|
1792
|
-
|
1793
|
-
</li>
|
1794
|
-
|
1795
|
-
</ul>
|
1796
|
-
|
1797
|
-
</div><table class="source_code">
|
1798
|
-
<tr>
|
1799
|
-
<td>
|
1800
|
-
<pre class="lines">
|
1801
|
-
|
1802
|
-
|
1803
|
-
680
|
1804
|
-
681
|
1805
|
-
682
|
1806
|
-
683
|
1807
|
-
684
|
1808
|
-
685
|
1809
|
-
686
|
1810
|
-
687
|
1811
|
-
688
|
1812
|
-
689
|
1813
|
-
690
|
1814
|
-
691
|
1815
|
-
692
|
1816
|
-
693
|
1817
|
-
694
|
1818
|
-
695
|
1819
|
-
696
|
1820
|
-
697
|
1821
|
-
698
|
1822
|
-
699
|
1823
|
-
700
|
1824
|
-
701
|
1825
|
-
702
|
1826
|
-
703
|
1827
|
-
704
|
1828
|
-
705
|
1829
|
-
706</pre>
|
1830
|
-
</td>
|
1831
|
-
<td>
|
1832
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 680</span>
|
1833
|
-
|
1834
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_fetch'>fetch</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_default_block'>default_block</span><span class='rparen'>)</span>
|
1835
|
-
|
1836
|
-
<span class='comment'># Ensure there are no extra arguments
|
1837
|
-
</span> <span class='id identifier rubyid_nargs'>nargs</span> <span class='op'>=</span> <span class='id identifier rubyid_args'>args</span><span class='period'>.</span><span class='id identifier rubyid_size'>size</span> <span class='op'>+</span> <span class='int'>1</span>
|
1838
|
-
<span class='id identifier rubyid_check'>check</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Too many arguments for 'fetch'; expected 1 or 2; got </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_nargs'>nargs</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='lbrace'>{</span>
|
1839
|
-
<span class='id identifier rubyid_nargs'>nargs</span> <span class='op'><=</span> <span class='int'>2</span>
|
1840
|
-
<span class='rbrace'>}</span>
|
1841
|
-
|
1842
|
-
<span class='comment'># Retrieve the value
|
1843
|
-
</span> <span class='id identifier rubyid_key'>key</span> <span class='op'>=</span> <span class='id identifier rubyid_check_key'>check_key</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span>
|
1844
|
-
<span class='id identifier rubyid_rows'>rows</span> <span class='op'>=</span> <span class='ivar'>@handle</span><span class='period'>.</span><span class='id identifier rubyid_sql'>sql</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>select * from </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_actual_tbl'>actual_tbl</span><span class='embexpr_end'>}</span><span class='tstring_content'> where key=?</span><span class='tstring_end'>"</span></span> <span class='op'>+</span>
|
1845
|
-
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'> order by rowid;</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='lbracket'>[</span><span class='id identifier rubyid_key'>key</span><span class='rbracket'>]</span><span class='rparen'>)</span>
|
1846
|
-
<span class='id identifier rubyid_check'>check</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Multiple matches for key '</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_key'>key</span><span class='embexpr_end'>}</span><span class='tstring_content'>'!</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='id identifier rubyid_rows'>rows</span><span class='period'>.</span><span class='id identifier rubyid_size'>size</span> <span class='op'><=</span> <span class='int'>1</span> <span class='rbrace'>}</span>
|
1847
|
-
|
1848
|
-
<span class='comment'># Return the value if found
|
1849
|
-
</span> <span class='kw'>return</span> <span class='ivar'>@valdec</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span><span class='lparen'>(</span><span class='id identifier rubyid_rows'>rows</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span><span class='lbracket'>[</span><span class='int'>1</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='kw'>unless</span> <span class='id identifier rubyid_rows'>rows</span><span class='period'>.</span><span class='id identifier rubyid_empty?'>empty?</span>
|
1850
|
-
|
1851
|
-
<span class='comment'># Otherwise, evaluate the block and use its result if a block was
|
1852
|
-
</span> <span class='comment'># given
|
1853
|
-
</span> <span class='kw'>return</span> <span class='id identifier rubyid_default_block'>default_block</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_default_block'>default_block</span>
|
1854
|
-
|
1855
|
-
<span class='comment'># Next, see if we have a default value we can return
|
1856
|
-
</span> <span class='kw'>return</span> <span class='id identifier rubyid_args'>args</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='id identifier rubyid_args'>args</span><span class='period'>.</span><span class='id identifier rubyid_size'>size</span> <span class='op'>></span> <span class='int'>0</span>
|
1857
|
-
|
1858
|
-
<span class='comment'># And if all else fails, raise an IndexError.
|
1859
|
-
</span> <span class='id identifier rubyid_raise'>raise</span> <span class='const'>IndexError</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>key '</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_key'>key</span><span class='embexpr_end'>}</span><span class='tstring_content'>' not found.</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
1860
|
-
<span class='kw'>end</span></pre>
|
1861
|
-
</td>
|
1862
|
-
</tr>
|
1863
|
-
</table>
|
1864
|
-
</div>
|
1865
|
-
|
1866
|
-
<div class="method_details ">
|
1867
|
-
<h3 class="signature " id="handle_closed?-instance_method">
|
1868
|
-
|
1869
|
-
#<strong>handle_closed?</strong> ⇒ <tt>Boolean</tt>
|
1870
|
-
|
1871
|
-
|
1872
|
-
|
1873
|
-
|
1874
|
-
|
1875
|
-
</h3><div class="docstring">
|
1876
|
-
<div class="discussion">
|
1877
|
-
<p>Test if the underlying <code>SQLite3::Database</code> is closed. You
|
1878
|
-
probably don't need to care about this method; it's mostly here
|
1879
|
-
to help with unit tests.</p>
|
1880
|
-
|
1881
|
-
<p>This will <strong>not</strong> work if <code>self</code> has been closed.</p>
|
1882
|
-
|
1883
|
-
|
1884
|
-
</div>
|
1885
|
-
</div>
|
1886
|
-
<div class="tags">
|
1887
|
-
|
1888
|
-
<p class="tag_title">Returns:</p>
|
1889
|
-
<ul class="return">
|
1890
|
-
|
1891
|
-
<li>
|
1892
|
-
|
1893
|
-
|
1894
|
-
<span class='type'>(<tt>Boolean</tt>)</span>
|
1895
|
-
|
1896
|
-
|
1897
|
-
|
1898
|
-
</li>
|
1899
|
-
|
1900
|
-
</ul>
|
1901
|
-
|
1902
|
-
</div><table class="source_code">
|
1903
|
-
<tr>
|
1904
|
-
<td>
|
1905
|
-
<pre class="lines">
|
1906
|
-
|
1907
|
-
|
1908
|
-
566
|
1909
|
-
567
|
1910
|
-
568</pre>
|
1911
|
-
</td>
|
1912
|
-
<td>
|
1913
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 566</span>
|
1914
|
-
|
1915
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_handle_closed?'>handle_closed?</span>
|
1916
|
-
<span class='kw'>return</span> <span class='ivar'>@handle</span><span class='period'>.</span><span class='id identifier rubyid_closed?'>closed?</span>
|
1917
|
-
<span class='kw'>end</span></pre>
|
1918
|
-
</td>
|
1919
|
-
</tr>
|
1920
|
-
</table>
|
1921
|
-
</div>
|
1922
|
-
|
1923
|
-
<div class="method_details ">
|
1924
|
-
<h3 class="signature " id="has_key?-instance_method">
|
1925
|
-
|
1926
|
-
#<strong>has_key?</strong>(key) ⇒ <tt>Boolean</tt>
|
1927
|
-
|
1928
|
-
|
1929
|
-
|
1930
|
-
<span class="aliases">Also known as:
|
1931
|
-
<span class="names"><span id='include?-instance_method'>include?</span>, <span id='member?-instance_method'>member?</span>, <span id='key?-instance_method'>key?</span></span>
|
1932
|
-
</span>
|
1933
|
-
|
1934
|
-
|
1935
|
-
|
1936
|
-
</h3><div class="docstring">
|
1937
|
-
<div class="discussion">
|
1938
|
-
<p>Return <code>true</code> if the table contains <code>key</code>; otherwise, return
|
1939
|
-
<code>false</code>.</p>
|
1940
|
-
|
1941
|
-
|
1942
|
-
</div>
|
1943
|
-
</div>
|
1944
|
-
<div class="tags">
|
1945
|
-
|
1946
|
-
<p class="tag_title">Returns:</p>
|
1947
|
-
<ul class="return">
|
1948
|
-
|
1949
|
-
<li>
|
1950
|
-
|
1951
|
-
|
1952
|
-
<span class='type'>(<tt>Boolean</tt>)</span>
|
1953
|
-
|
1954
|
-
|
1955
|
-
|
1956
|
-
</li>
|
1957
|
-
|
1958
|
-
</ul>
|
1959
|
-
|
1960
|
-
</div><table class="source_code">
|
1961
|
-
<tr>
|
1962
|
-
<td>
|
1963
|
-
<pre class="lines">
|
1964
|
-
|
1965
|
-
|
1966
|
-
736
|
1967
|
-
737
|
1968
|
-
738
|
1969
|
-
739
|
1970
|
-
740</pre>
|
1971
|
-
</td>
|
1972
|
-
<td>
|
1973
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 736</span>
|
1974
|
-
|
1975
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_has_key?'>has_key?</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span>
|
1976
|
-
<span class='kw'>return</span> <span class='kw'>false</span> <span class='kw'>unless</span> <span class='id identifier rubyid_key'>key</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span> <span class='op'>==</span> <span class='const'>String</span> <span class='op'>||</span> <span class='id identifier rubyid_key'>key</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span> <span class='op'>==</span> <span class='const'>Symbol</span>
|
1977
|
-
<span class='id identifier rubyid_fetch'>fetch</span><span class='lparen'>(</span> <span class='id identifier rubyid_key'>key</span> <span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='kw'>return</span> <span class='kw'>false</span> <span class='rbrace'>}</span>
|
1978
|
-
<span class='kw'>return</span> <span class='kw'>true</span>
|
1979
|
-
<span class='kw'>end</span></pre>
|
1980
|
-
</td>
|
1981
|
-
</tr>
|
1982
|
-
</table>
|
1983
|
-
</div>
|
1984
|
-
|
1985
|
-
<div class="method_details ">
|
1986
|
-
<h3 class="signature " id="has_value?-instance_method">
|
1987
|
-
|
1988
|
-
#<strong>has_value?</strong>(val) ⇒ <tt>Boolean</tt>
|
1989
|
-
|
1990
|
-
|
1991
|
-
|
1992
|
-
<span class="aliases">Also known as:
|
1993
|
-
<span class="names"><span id='value?-instance_method'>value?</span></span>
|
1994
|
-
</span>
|
1995
|
-
|
1996
|
-
|
1997
|
-
|
1998
|
-
</h3><div class="docstring">
|
1999
|
-
<div class="discussion">
|
2000
|
-
<p>Test if <code>val</code> is one of the values in this table.</p>
|
2001
|
-
|
2002
|
-
<p>Potentially very slow, especially on large tables.</p>
|
2003
|
-
|
2004
|
-
|
2005
|
-
</div>
|
2006
|
-
</div>
|
2007
|
-
<div class="tags">
|
2008
|
-
|
2009
|
-
<p class="tag_title">Returns:</p>
|
2010
|
-
<ul class="return">
|
2011
|
-
|
2012
|
-
<li>
|
2013
|
-
|
2014
|
-
|
2015
|
-
<span class='type'>(<tt>Boolean</tt>)</span>
|
2016
|
-
|
2017
|
-
|
2018
|
-
|
2019
|
-
</li>
|
2020
|
-
|
2021
|
-
</ul>
|
2022
|
-
|
2023
|
-
</div><table class="source_code">
|
2024
|
-
<tr>
|
2025
|
-
<td>
|
2026
|
-
<pre class="lines">
|
2027
|
-
|
2028
|
-
|
2029
|
-
905
|
2030
|
-
906
|
2031
|
-
907
|
2032
|
-
908</pre>
|
2033
|
-
</td>
|
2034
|
-
<td>
|
2035
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 905</span>
|
2036
|
-
|
2037
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_has_value?'>has_value?</span><span class='lparen'>(</span><span class='id identifier rubyid_val'>val</span><span class='rparen'>)</span>
|
2038
|
-
<span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span><span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_k'>k</span><span class='comma'>,</span><span class='id identifier rubyid_v'>v</span><span class='op'>|</span> <span class='kw'>return</span> <span class='kw'>true</span> <span class='kw'>if</span> <span class='id identifier rubyid_v'>v</span> <span class='op'>==</span> <span class='id identifier rubyid_val'>val</span><span class='rbrace'>}</span>
|
2039
|
-
<span class='kw'>return</span> <span class='kw'>false</span>
|
2040
|
-
<span class='kw'>end</span></pre>
|
2041
|
-
</td>
|
2042
|
-
</tr>
|
2043
|
-
</table>
|
2044
|
-
</div>
|
2045
|
-
|
2046
|
-
<div class="method_details ">
|
2047
|
-
<h3 class="signature " id="invert-instance_method">
|
2048
|
-
|
2049
|
-
#<strong>invert</strong> ⇒ <tt>Object</tt>
|
2050
|
-
|
2051
|
-
|
2052
|
-
|
2053
|
-
|
2054
|
-
|
2055
|
-
</h3><div class="docstring">
|
2056
|
-
<div class="discussion">
|
2057
|
-
<p>Return a <code>Hash</code> whose keys are the table's values and whose values
|
2058
|
-
are the table's keys.</p>
|
2059
|
-
|
2060
|
-
<p><strong>WARNING:</strong> it is possible for tables to be significantly larger
|
2061
|
-
than available RAM; in that case, this will likely crash your
|
2062
|
-
program.</p>
|
2063
|
-
|
2064
|
-
|
2065
|
-
</div>
|
2066
|
-
</div>
|
2067
|
-
<div class="tags">
|
2068
|
-
|
2069
|
-
|
2070
|
-
</div><table class="source_code">
|
2071
|
-
<tr>
|
2072
|
-
<td>
|
2073
|
-
<pre class="lines">
|
2074
|
-
|
2075
|
-
|
2076
|
-
917
|
2077
|
-
918
|
2078
|
-
919
|
2079
|
-
920
|
2080
|
-
921</pre>
|
2081
|
-
</td>
|
2082
|
-
<td>
|
2083
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 917</span>
|
2084
|
-
|
2085
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_invert'>invert</span>
|
2086
|
-
<span class='id identifier rubyid_result'>result</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
|
2087
|
-
<span class='id identifier rubyid_each'>each</span><span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_k'>k</span><span class='comma'>,</span><span class='id identifier rubyid_v'>v</span><span class='op'>|</span> <span class='id identifier rubyid_result'>result</span><span class='lbracket'>[</span><span class='id identifier rubyid_v'>v</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_k'>k</span><span class='rbrace'>}</span>
|
2088
|
-
<span class='kw'>return</span> <span class='id identifier rubyid_result'>result</span>
|
2089
|
-
<span class='kw'>end</span></pre>
|
2090
|
-
</td>
|
2091
|
-
</tr>
|
2092
|
-
</table>
|
2093
|
-
</div>
|
2094
|
-
|
2095
|
-
<div class="method_details ">
|
2096
|
-
<h3 class="signature " id="keys-instance_method">
|
2097
|
-
|
2098
|
-
#<strong>keys</strong> ⇒ <tt>Object</tt>
|
2099
|
-
|
2100
|
-
|
2101
|
-
|
2102
|
-
|
2103
|
-
|
2104
|
-
</h3><div class="docstring">
|
2105
|
-
<div class="discussion">
|
2106
|
-
<p>Return an <code>Array</code> of all of the keys in the table.</p>
|
2107
|
-
|
2108
|
-
<p><strong>WARNING:</strong> since this list is being read from disk, it is possible
|
2109
|
-
that the result could exceed available memory.</p>
|
2110
|
-
|
2111
|
-
|
2112
|
-
</div>
|
2113
|
-
</div>
|
2114
|
-
<div class="tags">
|
2115
|
-
|
2116
|
-
|
2117
|
-
</div><table class="source_code">
|
2118
|
-
<tr>
|
2119
|
-
<td>
|
2120
|
-
<pre class="lines">
|
2121
|
-
|
2122
|
-
|
2123
|
-
718
|
2124
|
-
719
|
2125
|
-
720
|
2126
|
-
721
|
2127
|
-
722</pre>
|
2128
|
-
</td>
|
2129
|
-
<td>
|
2130
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 718</span>
|
2131
|
-
|
2132
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_keys'>keys</span>
|
2133
|
-
<span class='id identifier rubyid_keys'>keys</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
|
2134
|
-
<span class='id identifier rubyid_each_key'>each_key</span><span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_k'>k</span><span class='op'>|</span> <span class='id identifier rubyid_keys'>keys</span><span class='period'>.</span><span class='id identifier rubyid_push'>push</span> <span class='id identifier rubyid_k'>k</span><span class='rbrace'>}</span>
|
2135
|
-
<span class='kw'>return</span> <span class='id identifier rubyid_keys'>keys</span>
|
2136
|
-
<span class='kw'>end</span></pre>
|
2137
|
-
</td>
|
2138
|
-
</tr>
|
2139
|
-
</table>
|
2140
|
-
</div>
|
2141
|
-
|
2142
|
-
<div class="method_details ">
|
2143
|
-
<h3 class="signature " id="shift-instance_method">
|
2144
|
-
|
2145
|
-
#<strong>shift</strong> ⇒ <tt>Object</tt>
|
2146
|
-
|
2147
|
-
|
2148
|
-
|
2149
|
-
|
2150
|
-
|
2151
|
-
</h3><div class="docstring">
|
2152
|
-
<div class="discussion">
|
2153
|
-
<p>Remove the first key/value pair from <code>self</code> and return it. "First"
|
2154
|
-
is defined by <code>self</code>'s row order, which is the order of insertion
|
2155
|
-
as determined by SQLite3.</p>
|
2156
|
-
|
2157
|
-
|
2158
|
-
</div>
|
2159
|
-
</div>
|
2160
|
-
<div class="tags">
|
2161
|
-
|
2162
|
-
|
2163
|
-
</div><table class="source_code">
|
2164
|
-
<tr>
|
2165
|
-
<td>
|
2166
|
-
<pre class="lines">
|
2167
|
-
|
2168
|
-
|
2169
|
-
926
|
2170
|
-
927
|
2171
|
-
928
|
2172
|
-
929
|
2173
|
-
930
|
2174
|
-
931
|
2175
|
-
932
|
2176
|
-
933
|
2177
|
-
934
|
2178
|
-
935</pre>
|
2179
|
-
</td>
|
2180
|
-
<td>
|
2181
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 926</span>
|
2182
|
-
|
2183
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_shift'>shift</span>
|
2184
|
-
<span class='id identifier rubyid_transaction'>transaction</span> <span class='lbrace'>{</span>
|
2185
|
-
<span class='kw'>return</span> <span class='kw'>nil</span> <span class='kw'>if</span> <span class='id identifier rubyid_empty?'>empty?</span>
|
2186
|
-
|
2187
|
-
<span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span> <span class='op'>=</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span>
|
2188
|
-
<span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span>
|
2189
|
-
|
2190
|
-
<span class='kw'>return</span> <span class='lbracket'>[</span><span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span><span class='rbracket'>]</span>
|
2191
|
-
<span class='rbrace'>}</span>
|
2192
|
-
<span class='kw'>end</span></pre>
|
2193
|
-
</td>
|
2194
|
-
</tr>
|
2195
|
-
</table>
|
2196
|
-
</div>
|
2197
|
-
|
2198
|
-
<div class="method_details ">
|
2199
|
-
<h3 class="signature " id="size-instance_method">
|
2200
|
-
|
2201
|
-
#<strong>size</strong> ⇒ <tt>Object</tt>
|
2202
|
-
|
2203
|
-
|
2204
|
-
|
2205
|
-
<span class="aliases">Also known as:
|
2206
|
-
<span class="names"><span id='length-instance_method'>length</span></span>
|
2207
|
-
</span>
|
2208
|
-
|
2209
|
-
|
2210
|
-
|
2211
|
-
</h3><div class="docstring">
|
2212
|
-
<div class="discussion">
|
2213
|
-
<p>Return the number of entries (key-value pairs) in <code>self</code>.</p>
|
2214
|
-
|
2215
|
-
|
2216
|
-
</div>
|
2217
|
-
</div>
|
2218
|
-
<div class="tags">
|
2219
|
-
|
2220
|
-
|
2221
|
-
</div><table class="source_code">
|
2222
|
-
<tr>
|
2223
|
-
<td>
|
2224
|
-
<pre class="lines">
|
2225
|
-
|
2226
|
-
|
2227
|
-
853
|
2228
|
-
854
|
2229
|
-
855
|
2230
|
-
856
|
2231
|
-
857
|
2232
|
-
858</pre>
|
2233
|
-
</td>
|
2234
|
-
<td>
|
2235
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 853</span>
|
2236
|
-
|
2237
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_size'>size</span>
|
2238
|
-
<span class='ivar'>@handle</span><span class='period'>.</span><span class='id identifier rubyid_sql'>sql</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>select count(*) from </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_actual_tbl'>actual_tbl</span><span class='embexpr_end'>}</span><span class='tstring_content'>;</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='lbracket'>[</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_row'>row</span><span class='op'>|</span>
|
2239
|
-
<span class='kw'>return</span> <span class='id identifier rubyid_row'>row</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span>
|
2240
|
-
<span class='rbrace'>}</span>
|
2241
|
-
<span class='id identifier rubyid_check'>check</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>count query failed!</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
2242
|
-
<span class='kw'>end</span></pre>
|
2243
|
-
</td>
|
2244
|
-
</tr>
|
2245
|
-
</table>
|
2246
|
-
</div>
|
2247
|
-
|
2248
|
-
<div class="method_details ">
|
2249
|
-
<h3 class="signature " id="to_a-instance_method">
|
2250
|
-
|
2251
|
-
#<strong>to_a</strong> ⇒ <tt>Object</tt>
|
2252
|
-
|
2253
|
-
|
2254
|
-
|
2255
|
-
|
2256
|
-
|
2257
|
-
</h3><div class="docstring">
|
2258
|
-
<div class="discussion">
|
2259
|
-
<p>Returns an <code>Array</code> of 2-element <code>Array</code> objects each containing a
|
2260
|
-
key-value pair from <code>self</code>.</p>
|
2261
|
-
|
2262
|
-
<p><strong>WARNING:</strong> it is possible for tables to be significantly larger
|
2263
|
-
than available RAM; in that case, this will likely crash your
|
2264
|
-
program.</p>
|
2265
|
-
|
2266
|
-
|
2267
|
-
</div>
|
2268
|
-
</div>
|
2269
|
-
<div class="tags">
|
2270
|
-
|
2271
|
-
|
2272
|
-
</div><table class="source_code">
|
2273
|
-
<tr>
|
2274
|
-
<td>
|
2275
|
-
<pre class="lines">
|
2276
|
-
|
2277
|
-
|
2278
|
-
890
|
2279
|
-
891
|
2280
|
-
892
|
2281
|
-
893
|
2282
|
-
894</pre>
|
2283
|
-
</td>
|
2284
|
-
<td>
|
2285
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 890</span>
|
2286
|
-
|
2287
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_to_a'>to_a</span>
|
2288
|
-
<span class='id identifier rubyid_result'>result</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
|
2289
|
-
<span class='id identifier rubyid_each'>each</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_k'>k</span><span class='comma'>,</span><span class='id identifier rubyid_v'>v</span><span class='op'>|</span> <span class='id identifier rubyid_result'>result</span><span class='period'>.</span><span class='id identifier rubyid_push'>push</span> <span class='lbracket'>[</span><span class='id identifier rubyid_k'>k</span><span class='comma'>,</span><span class='id identifier rubyid_v'>v</span><span class='rbracket'>]</span> <span class='rbrace'>}</span>
|
2290
|
-
<span class='kw'>return</span> <span class='id identifier rubyid_result'>result</span>
|
2291
|
-
<span class='kw'>end</span></pre>
|
2292
|
-
</td>
|
2293
|
-
</tr>
|
2294
|
-
</table>
|
2295
|
-
</div>
|
2296
|
-
|
2297
|
-
<div class="method_details ">
|
2298
|
-
<h3 class="signature " id="to_hash-instance_method">
|
2299
|
-
|
2300
|
-
#<strong>to_hash</strong> ⇒ <tt>Object</tt>
|
2301
|
-
|
2302
|
-
|
2303
|
-
|
2304
|
-
|
2305
|
-
|
2306
|
-
</h3><div class="docstring">
|
2307
|
-
<div class="discussion">
|
2308
|
-
<p>Copies the table into a <code>Hash</code> and returns it.</p>
|
2309
|
-
|
2310
|
-
<p><strong>WARNING:</strong> it is possible for tables to be significantly larger
|
2311
|
-
than available RAM; in that case, this will likely crash your
|
2312
|
-
program.</p>
|
2313
|
-
|
2314
|
-
|
2315
|
-
</div>
|
2316
|
-
</div>
|
2317
|
-
<div class="tags">
|
2318
|
-
|
2319
|
-
|
2320
|
-
</div><table class="source_code">
|
2321
|
-
<tr>
|
2322
|
-
<td>
|
2323
|
-
<pre class="lines">
|
2324
|
-
|
2325
|
-
|
2326
|
-
877
|
2327
|
-
878
|
2328
|
-
879
|
2329
|
-
880
|
2330
|
-
881</pre>
|
2331
|
-
</td>
|
2332
|
-
<td>
|
2333
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 877</span>
|
2334
|
-
|
2335
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_to_hash'>to_hash</span>
|
2336
|
-
<span class='id identifier rubyid_result'>result</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
|
2337
|
-
<span class='id identifier rubyid_each'>each</span><span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_k'>k</span><span class='comma'>,</span><span class='id identifier rubyid_v'>v</span><span class='op'>|</span> <span class='id identifier rubyid_result'>result</span><span class='lbracket'>[</span><span class='id identifier rubyid_k'>k</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_v'>v</span><span class='rbrace'>}</span>
|
2338
|
-
<span class='kw'>return</span> <span class='id identifier rubyid_result'>result</span>
|
2339
|
-
<span class='kw'>end</span></pre>
|
2340
|
-
</td>
|
2341
|
-
</tr>
|
2342
|
-
</table>
|
2343
|
-
</div>
|
2344
|
-
|
2345
|
-
<div class="method_details ">
|
2346
|
-
<h3 class="signature " id="to_s-instance_method">
|
2347
|
-
|
2348
|
-
#<strong>to_s</strong> ⇒ <tt>Object</tt>
|
2349
|
-
|
2350
|
-
|
2351
|
-
|
2352
|
-
<span class="aliases">Also known as:
|
2353
|
-
<span class="names"><span id='inspect-instance_method'>inspect</span></span>
|
2354
|
-
</span>
|
2355
|
-
|
2356
|
-
|
2357
|
-
|
2358
|
-
</h3><table class="source_code">
|
2359
|
-
<tr>
|
2360
|
-
<td>
|
2361
|
-
<pre class="lines">
|
2362
|
-
|
2363
|
-
|
2364
|
-
537
|
2365
|
-
538
|
2366
|
-
539
|
2367
|
-
540
|
2368
|
-
541</pre>
|
2369
|
-
</td>
|
2370
|
-
<td>
|
2371
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 537</span>
|
2372
|
-
|
2373
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_to_s'>to_s</span>
|
2374
|
-
<span class='id identifier rubyid_openstr'>openstr</span> <span class='op'>=</span> <span class='id identifier rubyid_closed?'>closed?</span> <span class='op'>?</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>CLOSED</span><span class='tstring_end'>'</span></span> <span class='op'>:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>OPEN</span><span class='tstring_end'>'</span></span>
|
2375
|
-
<span class='kw'>return</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'><</span><span class='embexpr_beg'>#{</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_content'>:0x</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_object_id'>object_id</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='lparen'>(</span><span class='int'>16</span><span class='rparen'>)</span><span class='embexpr_end'>}</span><span class='tstring_content'> file='</span><span class='embexpr_beg'>#{</span><span class='ivar'>@filename</span><span class='embexpr_end'>}</span><span class='tstring_content'>'</span><span class='tstring_end'>"</span></span> <span class='op'>+</span>
|
2376
|
-
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'> tablename='</span><span class='embexpr_beg'>#{</span><span class='ivar'>@tablename</span><span class='embexpr_end'>}</span><span class='tstring_content'>' </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_openstr'>openstr</span><span class='embexpr_end'>}</span><span class='tstring_content'>></span><span class='tstring_end'>"</span></span>
|
2377
|
-
<span class='kw'>end</span></pre>
|
2378
|
-
</td>
|
2379
|
-
</tr>
|
2380
|
-
</table>
|
2381
|
-
</div>
|
2382
|
-
|
2383
|
-
<div class="method_details ">
|
2384
|
-
<h3 class="signature " id="transaction-instance_method">
|
2385
|
-
|
2386
|
-
#<strong>transaction</strong> {|db| ... } ⇒ <tt>Object</tt>
|
2387
|
-
|
2388
|
-
|
2389
|
-
|
2390
|
-
|
2391
|
-
|
2392
|
-
</h3><div class="docstring">
|
2393
|
-
<div class="discussion">
|
2394
|
-
<p>Begins a transaction, evaluates the given block and then ends the
|
2395
|
-
transaction. If no error occurred, the transaction is committed;
|
2396
|
-
otherwise, it is rolled back.</p>
|
2397
|
-
|
2398
|
-
<p>It is safe to call <code>DBM.transaction</code> within another
|
2399
|
-
<code>DBM.transaction</code> block's call chain because <code>DBM</code> will not
|
2400
|
-
start a new transaction on a database handle that already has
|
2401
|
-
one in progress. (It may be possible to trick <code>DBM</code> into trying
|
2402
|
-
via fibers or other flow control trickery; don't do that.)</p>
|
2403
|
-
|
2404
|
-
<p>It is also not safe to mix <code>DBM</code> transactions and bare <code>SQLite3</code>
|
2405
|
-
transactions.</p>
|
2406
|
-
|
2407
|
-
<p>Transactions are always executed in <code>:deferred</code> mode.</p>
|
2408
|
-
|
2409
|
-
|
2410
|
-
</div>
|
2411
|
-
</div>
|
2412
|
-
<div class="tags">
|
2413
|
-
|
2414
|
-
<p class="tag_title">Yields:</p>
|
2415
|
-
<ul class="yield">
|
2416
|
-
|
2417
|
-
<li>
|
2418
|
-
|
2419
|
-
|
2420
|
-
<span class='type'>(<tt>db</tt>)</span>
|
2421
|
-
|
2422
|
-
|
2423
|
-
|
2424
|
-
—
|
2425
|
-
<div class='inline'><p>The block takes a reference to the receiver as an
|
2426
|
-
argument.</p>
|
2427
|
-
</div>
|
2428
|
-
|
2429
|
-
</li>
|
2430
|
-
|
2431
|
-
</ul>
|
2432
|
-
|
2433
|
-
</div><table class="source_code">
|
2434
|
-
<tr>
|
2435
|
-
<td>
|
2436
|
-
<pre class="lines">
|
2437
|
-
|
2438
|
-
|
2439
|
-
594
|
2440
|
-
595
|
2441
|
-
596</pre>
|
2442
|
-
</td>
|
2443
|
-
<td>
|
2444
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 594</span>
|
2445
|
-
|
2446
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_transaction'>transaction</span><span class='lparen'>(</span><span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
2447
|
-
<span class='kw'>return</span> <span class='ivar'>@handle</span><span class='period'>.</span><span class='id identifier rubyid_transaction'>transaction</span> <span class='lbrace'>{</span> <span class='id identifier rubyid_block'>block</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span><span class='lparen'>(</span><span class='kw'>self</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
|
2448
|
-
<span class='kw'>end</span></pre>
|
2449
|
-
</td>
|
2450
|
-
</tr>
|
2451
|
-
</table>
|
2452
|
-
</div>
|
2453
|
-
|
2454
|
-
<div class="method_details ">
|
2455
|
-
<h3 class="signature " id="transaction_active?-instance_method">
|
2456
|
-
|
2457
|
-
#<strong>transaction_active?</strong> ⇒ <tt>Boolean</tt>
|
2458
|
-
|
2459
|
-
|
2460
|
-
|
2461
|
-
|
2462
|
-
|
2463
|
-
</h3><div class="docstring">
|
2464
|
-
<div class="discussion">
|
2465
|
-
<p>Test if there is currently a transaction in progress</p>
|
2466
|
-
|
2467
|
-
|
2468
|
-
</div>
|
2469
|
-
</div>
|
2470
|
-
<div class="tags">
|
2471
|
-
|
2472
|
-
<p class="tag_title">Returns:</p>
|
2473
|
-
<ul class="return">
|
2474
|
-
|
2475
|
-
<li>
|
2476
|
-
|
2477
|
-
|
2478
|
-
<span class='type'>(<tt>Boolean</tt>)</span>
|
2479
|
-
|
2480
|
-
|
2481
|
-
|
2482
|
-
</li>
|
2483
|
-
|
2484
|
-
</ul>
|
2485
|
-
|
2486
|
-
</div><table class="source_code">
|
2487
|
-
<tr>
|
2488
|
-
<td>
|
2489
|
-
<pre class="lines">
|
2490
|
-
|
2491
|
-
|
2492
|
-
599
|
2493
|
-
600
|
2494
|
-
601</pre>
|
2495
|
-
</td>
|
2496
|
-
<td>
|
2497
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 599</span>
|
2498
|
-
|
2499
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_transaction_active?'>transaction_active?</span>
|
2500
|
-
<span class='kw'>return</span> <span class='ivar'>@handle</span><span class='period'>.</span><span class='id identifier rubyid_transaction_active?'>transaction_active?</span>
|
2501
|
-
<span class='kw'>end</span></pre>
|
2502
|
-
</td>
|
2503
|
-
</tr>
|
2504
|
-
</table>
|
2505
|
-
</div>
|
2506
|
-
|
2507
|
-
<div class="method_details ">
|
2508
|
-
<h3 class="signature " id="update-instance_method">
|
2509
|
-
|
2510
|
-
#<strong>update</strong>(hash) ⇒ <tt>Object</tt>
|
2511
|
-
|
2512
|
-
|
2513
|
-
|
2514
|
-
|
2515
|
-
|
2516
|
-
</h3><div class="docstring">
|
2517
|
-
<div class="discussion">
|
2518
|
-
<p>Updates the database with multiple values from the specified
|
2519
|
-
object. Takes any object which implements the each_pair method,
|
2520
|
-
including <code>Hash</code> and <code>DBM</code> objects.</p>
|
2521
|
-
|
2522
|
-
|
2523
|
-
</div>
|
2524
|
-
</div>
|
2525
|
-
<div class="tags">
|
2526
|
-
|
2527
|
-
|
2528
|
-
</div><table class="source_code">
|
2529
|
-
<tr>
|
2530
|
-
<td>
|
2531
|
-
<pre class="lines">
|
2532
|
-
|
2533
|
-
|
2534
|
-
827
|
2535
|
-
828
|
2536
|
-
829
|
2537
|
-
830
|
2538
|
-
831</pre>
|
2539
|
-
</td>
|
2540
|
-
<td>
|
2541
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 827</span>
|
2542
|
-
|
2543
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_update'>update</span><span class='lparen'>(</span><span class='id identifier rubyid_hash'>hash</span><span class='rparen'>)</span>
|
2544
|
-
<span class='id identifier rubyid_transaction'>transaction</span> <span class='lbrace'>{</span>
|
2545
|
-
<span class='id identifier rubyid_hash'>hash</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span><span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_k'>k</span><span class='comma'>,</span> <span class='id identifier rubyid_v'>v</span><span class='op'>|</span> <span class='kw'>self</span><span class='lbracket'>[</span><span class='id identifier rubyid_k'>k</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_v'>v</span> <span class='rbrace'>}</span>
|
2546
|
-
<span class='rbrace'>}</span>
|
2547
|
-
<span class='kw'>end</span></pre>
|
2548
|
-
</td>
|
2549
|
-
</tr>
|
2550
|
-
</table>
|
2551
|
-
</div>
|
2552
|
-
|
2553
|
-
<div class="method_details ">
|
2554
|
-
<h3 class="signature " id="values-instance_method">
|
2555
|
-
|
2556
|
-
#<strong>values</strong> ⇒ <tt>Object</tt>
|
2557
|
-
|
2558
|
-
|
2559
|
-
|
2560
|
-
|
2561
|
-
|
2562
|
-
</h3><div class="docstring">
|
2563
|
-
<div class="discussion">
|
2564
|
-
<p>Return an array of all values in the table.</p>
|
2565
|
-
|
2566
|
-
<p><strong>WARNING:</strong> since this list is being read from disk, it is possible
|
2567
|
-
that the result could exceed available memory.</p>
|
2568
|
-
|
2569
|
-
|
2570
|
-
</div>
|
2571
|
-
</div>
|
2572
|
-
<div class="tags">
|
2573
|
-
|
2574
|
-
|
2575
|
-
</div><table class="source_code">
|
2576
|
-
<tr>
|
2577
|
-
<td>
|
2578
|
-
<pre class="lines">
|
2579
|
-
|
2580
|
-
|
2581
|
-
728
|
2582
|
-
729
|
2583
|
-
730
|
2584
|
-
731
|
2585
|
-
732</pre>
|
2586
|
-
</td>
|
2587
|
-
<td>
|
2588
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 728</span>
|
2589
|
-
|
2590
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_values'>values</span>
|
2591
|
-
<span class='id identifier rubyid_values'>values</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
|
2592
|
-
<span class='id identifier rubyid_each_value'>each_value</span> <span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_val'>val</span><span class='op'>|</span> <span class='id identifier rubyid_values'>values</span><span class='period'>.</span><span class='id identifier rubyid_push'>push</span> <span class='id identifier rubyid_val'>val</span> <span class='rbrace'>}</span>
|
2593
|
-
<span class='kw'>return</span> <span class='id identifier rubyid_values'>values</span>
|
2594
|
-
<span class='kw'>end</span></pre>
|
2595
|
-
</td>
|
2596
|
-
</tr>
|
2597
|
-
</table>
|
2598
|
-
</div>
|
2599
|
-
|
2600
|
-
<div class="method_details ">
|
2601
|
-
<h3 class="signature " id="values_at-instance_method">
|
2602
|
-
|
2603
|
-
#<strong>values_at</strong>(*keys) ⇒ <tt>Object</tt>
|
2604
|
-
|
2605
|
-
|
2606
|
-
|
2607
|
-
|
2608
|
-
|
2609
|
-
</h3><div class="docstring">
|
2610
|
-
<div class="discussion">
|
2611
|
-
<p>Return a new <code>Array</code> containing the values corresponding to the
|
2612
|
-
given keys.</p>
|
2613
|
-
|
2614
|
-
|
2615
|
-
</div>
|
2616
|
-
</div>
|
2617
|
-
<div class="tags">
|
2618
|
-
|
2619
|
-
|
2620
|
-
</div><table class="source_code">
|
2621
|
-
<tr>
|
2622
|
-
<td>
|
2623
|
-
<pre class="lines">
|
2624
|
-
|
2625
|
-
|
2626
|
-
710
|
2627
|
-
711
|
2628
|
-
712</pre>
|
2629
|
-
</td>
|
2630
|
-
<td>
|
2631
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 710</span>
|
2632
|
-
|
2633
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_values_at'>values_at</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_keys'>keys</span><span class='rparen'>)</span>
|
2634
|
-
<span class='kw'>return</span> <span class='id identifier rubyid_keys'>keys</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span><span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_k'>k</span><span class='op'>|</span> <span class='kw'>self</span><span class='lbracket'>[</span><span class='id identifier rubyid_k'>k</span><span class='rbracket'>]</span><span class='rbrace'>}</span>
|
2635
|
-
<span class='kw'>end</span></pre>
|
2636
|
-
</td>
|
2637
|
-
</tr>
|
2638
|
-
</table>
|
2639
|
-
</div>
|
2640
|
-
|
2641
|
-
</div>
|
2642
|
-
|
2643
|
-
</div>
|
2644
|
-
|
2645
|
-
<div id="footer">
|
2646
|
-
Generated on Sun Feb 27 17:44:19 2022 by
|
2647
|
-
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
2648
|
-
0.9.25 (ruby-2.7.0).
|
2649
|
-
</div>
|
2650
|
-
|
2651
|
-
</div>
|
2652
|
-
</body>
|
2653
|
-
</html>
|