dbmlite3 1.0.a3 → 1.0.a4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/DBMLite3.gemspec +1 -1
- data/doc/Lite3/DBM.html +202 -144
- data/doc/Lite3/Error.html +1 -1
- data/doc/Lite3/SQL.html +1 -1
- data/doc/Lite3.html +1 -1
- data/doc/_index.html +1 -1
- data/doc/file.README.html +1 -1
- data/doc/index.html +1 -1
- data/doc/top-level-namespace.html +1 -1
- data/lib/dbmlite3.rb +35 -6
- data/spec/dbmlite3_spec.rb +19 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fac72547c8bd87ca5fcc089e5570ee80b4a7beeb539e76df1888c8b1b97b163b
|
4
|
+
data.tar.gz: d689bf111e159c2c46568f921c945fdbdbed53f57e7a6fd68f24bc52baa5cf34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8706449a100a494853f57f5ee5f7d2c79a67794d835efb3ab5453a56898909129811b4acf72a9770ed61a55b4919105adedc1cdbf005b87475801c7effcb84a
|
7
|
+
data.tar.gz: ef3fc4ad6f06c4b270584cc86d60a0b9526f9e51f1456077edd8076d676bdf1b69f124fe45fca50eabfa88067214c669f7563bd1a29ac23921630614c82b7b35
|
data/DBMLite3.gemspec
CHANGED
data/doc/Lite3/DBM.html
CHANGED
@@ -1086,12 +1086,12 @@ nil if it is not present.</p>
|
|
1086
1086
|
<pre class="lines">
|
1087
1087
|
|
1088
1088
|
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1089
|
+
644
|
1090
|
+
645
|
1091
|
+
646</pre>
|
1092
1092
|
</td>
|
1093
1093
|
<td>
|
1094
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line
|
1094
|
+
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 644</span>
|
1095
1095
|
|
1096
1096
|
<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>
|
1097
1097
|
<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>
|
@@ -1148,7 +1148,36 @@ serialization method you have chosen.</p>
|
|
1148
1148
|
607
|
1149
1149
|
608
|
1150
1150
|
609
|
1151
|
-
610
|
1151
|
+
610
|
1152
|
+
611
|
1153
|
+
612
|
1154
|
+
613
|
1155
|
+
614
|
1156
|
+
615
|
1157
|
+
616
|
1158
|
+
617
|
1159
|
+
618
|
1160
|
+
619
|
1161
|
+
620
|
1162
|
+
621
|
1163
|
+
622
|
1164
|
+
623
|
1165
|
+
624
|
1166
|
+
625
|
1167
|
+
626
|
1168
|
+
627
|
1169
|
+
628
|
1170
|
+
629
|
1171
|
+
630
|
1172
|
+
631
|
1173
|
+
632
|
1174
|
+
633
|
1175
|
+
634
|
1176
|
+
635
|
1177
|
+
636
|
1178
|
+
637
|
1179
|
+
638
|
1180
|
+
639</pre>
|
1152
1181
|
</td>
|
1153
1182
|
<td>
|
1154
1183
|
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 597</span>
|
@@ -1157,12 +1186,41 @@ serialization method you have chosen.</p>
|
|
1157
1186
|
<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>
|
1158
1187
|
<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>
|
1159
1188
|
|
1160
|
-
<span class='
|
1161
|
-
|
1162
|
-
</span
|
1163
|
-
</span
|
1189
|
+
<span class='comment'># At one point, this operation was done with SQLite3's UPSERT:
|
1190
|
+
</span> <span class='comment'>#
|
1191
|
+
</span> <span class='comment'># insert into #{actual_tbl} (key, value) values (?,?)
|
1192
|
+
</span> <span class='comment'># on conflict(key) do update set value = ?;
|
1193
|
+
</span> <span class='comment'>#
|
1194
|
+
</span> <span class='comment'># Unfortunately, this capability was only added to SQLite3 in
|
1195
|
+
</span> <span class='comment'># 2018, which means that at the time of this writing (2022)
|
1196
|
+
</span> <span class='comment'># there are still a lot of systems out there that have older
|
1197
|
+
</span> <span class='comment'># versions of SQLite3 and so can't do this.
|
1198
|
+
</span> <span class='comment'>#
|
1199
|
+
</span> <span class='comment'># The venerable `insert or replace` feature **almost** does what
|
1200
|
+
</span> <span class='comment'># I want:
|
1201
|
+
</span> <span class='comment'>#
|
1202
|
+
</span> <span class='comment'># insert or replace into #{actual_tbl} (key, value) values (?, ?);
|
1203
|
+
</span> <span class='comment'>#
|
1204
|
+
</span> <span class='comment'># The one problem is that it changes the order of the rows,
|
1205
|
+
</span> <span class='comment'># which we need to preserve in order to remain consistent with
|
1206
|
+
</span> <span class='comment'># `Hash` semantics (and because it's useful).
|
1207
|
+
</span> <span class='comment'>#
|
1208
|
+
</span> <span class='comment'># So we kick it old school and do a `select` followed by an
|
1209
|
+
</span> <span class='comment'># `insert` or `update` wrapped in a transaction.
|
1164
1210
|
</span> <span class='id identifier rubyid_transaction'>transaction</span> <span class='lbrace'>{</span>
|
1165
|
-
<span class='
|
1211
|
+
<span class='id identifier rubyid_rowid'>rowid</span> <span class='op'>=</span> <span class='kw'>nil</span>
|
1212
|
+
<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>
|
1213
|
+
<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>
|
1214
|
+
<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>
|
1215
|
+
<span class='rbrace'>}</span>
|
1216
|
+
|
1217
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_rowid'>rowid</span>
|
1218
|
+
<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>
|
1219
|
+
<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>
|
1220
|
+
<span class='kw'>else</span>
|
1221
|
+
<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>
|
1222
|
+
<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>
|
1223
|
+
<span class='kw'>end</span>
|
1166
1224
|
<span class='rbrace'>}</span>
|
1167
1225
|
|
1168
1226
|
<span class='kw'>return</span> <span class='id identifier rubyid_value'>value</span>
|
@@ -1197,12 +1255,12 @@ serialization method you have chosen.</p>
|
|
1197
1255
|
<pre class="lines">
|
1198
1256
|
|
1199
1257
|
|
1200
|
-
|
1201
|
-
|
1202
|
-
|
1258
|
+
728
|
1259
|
+
729
|
1260
|
+
730</pre>
|
1203
1261
|
</td>
|
1204
1262
|
<td>
|
1205
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line
|
1263
|
+
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 728</span>
|
1206
1264
|
|
1207
1265
|
<span class='kw'>def</span> <span class='id identifier rubyid_clear'>clear</span>
|
1208
1266
|
<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>
|
@@ -1339,14 +1397,14 @@ not present, does nothing.</p>
|
|
1339
1397
|
<pre class="lines">
|
1340
1398
|
|
1341
1399
|
|
1342
|
-
|
1343
|
-
|
1344
|
-
|
1345
|
-
|
1346
|
-
|
1400
|
+
817
|
1401
|
+
818
|
1402
|
+
819
|
1403
|
+
820
|
1404
|
+
821</pre>
|
1347
1405
|
</td>
|
1348
1406
|
<td>
|
1349
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line
|
1407
|
+
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 817</span>
|
1350
1408
|
|
1351
1409
|
<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>
|
1352
1410
|
<span class='id identifier rubyid_transaction'>transaction</span> <span class='lbrace'>{</span>
|
@@ -1405,14 +1463,14 @@ each entry for which the block returns true.</p>
|
|
1405
1463
|
<pre class="lines">
|
1406
1464
|
|
1407
1465
|
|
1408
|
-
|
1409
|
-
|
1410
|
-
|
1411
|
-
|
1412
|
-
|
1466
|
+
827
|
1467
|
+
828
|
1468
|
+
829
|
1469
|
+
830
|
1470
|
+
831</pre>
|
1413
1471
|
</td>
|
1414
1472
|
<td>
|
1415
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line
|
1473
|
+
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 827</span>
|
1416
1474
|
|
1417
1475
|
<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>
|
1418
1476
|
<span class='id identifier rubyid_transaction'>transaction</span> <span class='lbrace'>{</span>
|
@@ -1477,14 +1535,14 @@ own transaction.</p>
|
|
1477
1535
|
<pre class="lines">
|
1478
1536
|
|
1479
1537
|
|
1480
|
-
|
1481
|
-
|
1482
|
-
|
1483
|
-
|
1484
|
-
|
1538
|
+
742
|
1539
|
+
743
|
1540
|
+
744
|
1541
|
+
745
|
1542
|
+
746</pre>
|
1485
1543
|
</td>
|
1486
1544
|
<td>
|
1487
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line
|
1545
|
+
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 742</span>
|
1488
1546
|
|
1489
1547
|
<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>
|
1490
1548
|
<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>
|
@@ -1539,13 +1597,13 @@ own transaction.</p>
|
|
1539
1597
|
<pre class="lines">
|
1540
1598
|
|
1541
1599
|
|
1542
|
-
|
1543
|
-
|
1544
|
-
|
1545
|
-
|
1600
|
+
792
|
1601
|
+
793
|
1602
|
+
794
|
1603
|
+
795</pre>
|
1546
1604
|
</td>
|
1547
1605
|
<td>
|
1548
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line
|
1606
|
+
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 792</span>
|
1549
1607
|
|
1550
1608
|
<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>
|
1551
1609
|
<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>
|
@@ -1599,13 +1657,13 @@ own transaction.</p>
|
|
1599
1657
|
<pre class="lines">
|
1600
1658
|
|
1601
1659
|
|
1602
|
-
|
1603
|
-
|
1604
|
-
|
1605
|
-
|
1660
|
+
801
|
1661
|
+
802
|
1662
|
+
803
|
1663
|
+
804</pre>
|
1606
1664
|
</td>
|
1607
1665
|
<td>
|
1608
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line
|
1666
|
+
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 801</span>
|
1609
1667
|
|
1610
1668
|
<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>
|
1611
1669
|
<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>
|
@@ -1654,12 +1712,12 @@ own transaction.</p>
|
|
1654
1712
|
<pre class="lines">
|
1655
1713
|
|
1656
1714
|
|
1657
|
-
|
1658
|
-
|
1659
|
-
|
1715
|
+
844
|
1716
|
+
845
|
1717
|
+
846</pre>
|
1660
1718
|
</td>
|
1661
1719
|
<td>
|
1662
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line
|
1720
|
+
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 844</span>
|
1663
1721
|
|
1664
1722
|
<span class='kw'>def</span> <span class='id identifier rubyid_empty?'>empty?</span>
|
1665
1723
|
<span class='kw'>return</span> <span class='id identifier rubyid_size'>size</span> <span class='op'>==</span> <span class='int'>0</span>
|
@@ -1735,36 +1793,36 @@ exception.</p>
|
|
1735
1793
|
<pre class="lines">
|
1736
1794
|
|
1737
1795
|
|
1738
|
-
|
1739
|
-
|
1740
|
-
|
1741
|
-
|
1742
|
-
|
1743
|
-
|
1744
|
-
|
1745
|
-
|
1746
|
-
|
1747
|
-
|
1748
|
-
|
1749
|
-
|
1750
|
-
|
1751
|
-
|
1752
|
-
|
1753
|
-
|
1754
|
-
|
1755
|
-
|
1756
|
-
|
1757
|
-
|
1758
|
-
|
1759
|
-
|
1760
|
-
|
1761
|
-
|
1762
|
-
|
1763
|
-
|
1764
|
-
|
1796
|
+
662
|
1797
|
+
663
|
1798
|
+
664
|
1799
|
+
665
|
1800
|
+
666
|
1801
|
+
667
|
1802
|
+
668
|
1803
|
+
669
|
1804
|
+
670
|
1805
|
+
671
|
1806
|
+
672
|
1807
|
+
673
|
1808
|
+
674
|
1809
|
+
675
|
1810
|
+
676
|
1811
|
+
677
|
1812
|
+
678
|
1813
|
+
679
|
1814
|
+
680
|
1815
|
+
681
|
1816
|
+
682
|
1817
|
+
683
|
1818
|
+
684
|
1819
|
+
685
|
1820
|
+
686
|
1821
|
+
687
|
1822
|
+
688</pre>
|
1765
1823
|
</td>
|
1766
1824
|
<td>
|
1767
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line
|
1825
|
+
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 662</span>
|
1768
1826
|
|
1769
1827
|
<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>
|
1770
1828
|
|
@@ -1898,14 +1956,14 @@ to help with unit tests.</p>
|
|
1898
1956
|
<pre class="lines">
|
1899
1957
|
|
1900
1958
|
|
1901
|
-
|
1902
|
-
|
1903
|
-
|
1904
|
-
|
1905
|
-
|
1959
|
+
718
|
1960
|
+
719
|
1961
|
+
720
|
1962
|
+
721
|
1963
|
+
722</pre>
|
1906
1964
|
</td>
|
1907
1965
|
<td>
|
1908
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line
|
1966
|
+
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 718</span>
|
1909
1967
|
|
1910
1968
|
<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>
|
1911
1969
|
<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>
|
@@ -1961,13 +2019,13 @@ to help with unit tests.</p>
|
|
1961
2019
|
<pre class="lines">
|
1962
2020
|
|
1963
2021
|
|
1964
|
-
|
1965
|
-
|
1966
|
-
|
1967
|
-
|
2022
|
+
887
|
2023
|
+
888
|
2024
|
+
889
|
2025
|
+
890</pre>
|
1968
2026
|
</td>
|
1969
2027
|
<td>
|
1970
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line
|
2028
|
+
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 887</span>
|
1971
2029
|
|
1972
2030
|
<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>
|
1973
2031
|
<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>
|
@@ -2008,14 +2066,14 @@ program.</p>
|
|
2008
2066
|
<pre class="lines">
|
2009
2067
|
|
2010
2068
|
|
2011
|
-
|
2012
|
-
|
2013
|
-
|
2014
|
-
|
2015
|
-
|
2069
|
+
899
|
2070
|
+
900
|
2071
|
+
901
|
2072
|
+
902
|
2073
|
+
903</pre>
|
2016
2074
|
</td>
|
2017
2075
|
<td>
|
2018
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line
|
2076
|
+
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 899</span>
|
2019
2077
|
|
2020
2078
|
<span class='kw'>def</span> <span class='id identifier rubyid_invert'>invert</span>
|
2021
2079
|
<span class='id identifier rubyid_result'>result</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
|
@@ -2055,14 +2113,14 @@ that the result could exceed available memory.</p>
|
|
2055
2113
|
<pre class="lines">
|
2056
2114
|
|
2057
2115
|
|
2058
|
-
|
2059
|
-
|
2060
|
-
|
2061
|
-
|
2062
|
-
|
2116
|
+
700
|
2117
|
+
701
|
2118
|
+
702
|
2119
|
+
703
|
2120
|
+
704</pre>
|
2063
2121
|
</td>
|
2064
2122
|
<td>
|
2065
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line
|
2123
|
+
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 700</span>
|
2066
2124
|
|
2067
2125
|
<span class='kw'>def</span> <span class='id identifier rubyid_keys'>keys</span>
|
2068
2126
|
<span class='id identifier rubyid_keys'>keys</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
|
@@ -2101,19 +2159,19 @@ as determined by SQLite3.</p>
|
|
2101
2159
|
<pre class="lines">
|
2102
2160
|
|
2103
2161
|
|
2104
|
-
|
2105
|
-
|
2106
|
-
|
2107
|
-
|
2108
|
-
|
2109
|
-
|
2110
|
-
|
2111
|
-
|
2112
|
-
|
2113
|
-
|
2162
|
+
908
|
2163
|
+
909
|
2164
|
+
910
|
2165
|
+
911
|
2166
|
+
912
|
2167
|
+
913
|
2168
|
+
914
|
2169
|
+
915
|
2170
|
+
916
|
2171
|
+
917</pre>
|
2114
2172
|
</td>
|
2115
2173
|
<td>
|
2116
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line
|
2174
|
+
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 908</span>
|
2117
2175
|
|
2118
2176
|
<span class='kw'>def</span> <span class='id identifier rubyid_shift'>shift</span>
|
2119
2177
|
<span class='id identifier rubyid_transaction'>transaction</span> <span class='lbrace'>{</span>
|
@@ -2159,15 +2217,15 @@ as determined by SQLite3.</p>
|
|
2159
2217
|
<pre class="lines">
|
2160
2218
|
|
2161
2219
|
|
2162
|
-
|
2163
|
-
|
2164
|
-
|
2165
|
-
|
2166
|
-
|
2167
|
-
|
2220
|
+
835
|
2221
|
+
836
|
2222
|
+
837
|
2223
|
+
838
|
2224
|
+
839
|
2225
|
+
840</pre>
|
2168
2226
|
</td>
|
2169
2227
|
<td>
|
2170
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line
|
2228
|
+
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 835</span>
|
2171
2229
|
|
2172
2230
|
<span class='kw'>def</span> <span class='id identifier rubyid_size'>size</span>
|
2173
2231
|
<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>
|
@@ -2210,14 +2268,14 @@ program.</p>
|
|
2210
2268
|
<pre class="lines">
|
2211
2269
|
|
2212
2270
|
|
2213
|
-
|
2214
|
-
|
2215
|
-
|
2216
|
-
|
2217
|
-
|
2271
|
+
872
|
2272
|
+
873
|
2273
|
+
874
|
2274
|
+
875
|
2275
|
+
876</pre>
|
2218
2276
|
</td>
|
2219
2277
|
<td>
|
2220
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line
|
2278
|
+
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 872</span>
|
2221
2279
|
|
2222
2280
|
<span class='kw'>def</span> <span class='id identifier rubyid_to_a'>to_a</span>
|
2223
2281
|
<span class='id identifier rubyid_result'>result</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
|
@@ -2258,14 +2316,14 @@ program.</p>
|
|
2258
2316
|
<pre class="lines">
|
2259
2317
|
|
2260
2318
|
|
2261
|
-
|
2262
|
-
|
2263
|
-
|
2264
|
-
|
2265
|
-
|
2319
|
+
859
|
2320
|
+
860
|
2321
|
+
861
|
2322
|
+
862
|
2323
|
+
863</pre>
|
2266
2324
|
</td>
|
2267
2325
|
<td>
|
2268
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line
|
2326
|
+
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 859</span>
|
2269
2327
|
|
2270
2328
|
<span class='kw'>def</span> <span class='id identifier rubyid_to_hash'>to_hash</span>
|
2271
2329
|
<span class='id identifier rubyid_result'>result</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
|
@@ -2466,14 +2524,14 @@ including <code>Hash</code> and <code>DBM</code> objects.</p>
|
|
2466
2524
|
<pre class="lines">
|
2467
2525
|
|
2468
2526
|
|
2469
|
-
|
2470
|
-
|
2471
|
-
|
2472
|
-
|
2473
|
-
|
2527
|
+
809
|
2528
|
+
810
|
2529
|
+
811
|
2530
|
+
812
|
2531
|
+
813</pre>
|
2474
2532
|
</td>
|
2475
2533
|
<td>
|
2476
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line
|
2534
|
+
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 809</span>
|
2477
2535
|
|
2478
2536
|
<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>
|
2479
2537
|
<span class='id identifier rubyid_transaction'>transaction</span> <span class='lbrace'>{</span>
|
@@ -2513,14 +2571,14 @@ that the result could exceed available memory.</p>
|
|
2513
2571
|
<pre class="lines">
|
2514
2572
|
|
2515
2573
|
|
2516
|
-
|
2517
|
-
|
2518
|
-
|
2519
|
-
|
2520
|
-
|
2574
|
+
710
|
2575
|
+
711
|
2576
|
+
712
|
2577
|
+
713
|
2578
|
+
714</pre>
|
2521
2579
|
</td>
|
2522
2580
|
<td>
|
2523
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line
|
2581
|
+
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 710</span>
|
2524
2582
|
|
2525
2583
|
<span class='kw'>def</span> <span class='id identifier rubyid_values'>values</span>
|
2526
2584
|
<span class='id identifier rubyid_values'>values</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
|
@@ -2558,12 +2616,12 @@ given keys.</p>
|
|
2558
2616
|
<pre class="lines">
|
2559
2617
|
|
2560
2618
|
|
2561
|
-
|
2562
|
-
|
2563
|
-
|
2619
|
+
692
|
2620
|
+
693
|
2621
|
+
694</pre>
|
2564
2622
|
</td>
|
2565
2623
|
<td>
|
2566
|
-
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line
|
2624
|
+
<pre class="code"><span class="info file"># File 'lib/dbmlite3.rb', line 692</span>
|
2567
2625
|
|
2568
2626
|
<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>
|
2569
2627
|
<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>
|
@@ -2578,7 +2636,7 @@ given keys.</p>
|
|
2578
2636
|
</div>
|
2579
2637
|
|
2580
2638
|
<div id="footer">
|
2581
|
-
Generated on
|
2639
|
+
Generated on Sat Feb 26 11:46:07 2022 by
|
2582
2640
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
2583
2641
|
0.9.25 (ruby-2.7.0).
|
2584
2642
|
</div>
|
data/doc/Lite3/Error.html
CHANGED
@@ -125,7 +125,7 @@
|
|
125
125
|
</div>
|
126
126
|
|
127
127
|
<div id="footer">
|
128
|
-
Generated on
|
128
|
+
Generated on Sat Feb 26 11:46:07 2022 by
|
129
129
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
130
130
|
0.9.25 (ruby-2.7.0).
|
131
131
|
</div>
|
data/doc/Lite3/SQL.html
CHANGED
@@ -380,7 +380,7 @@ thread safe. Just a wrapper around <code>SQLite3.threadsafe?</code></p>
|
|
380
380
|
</div>
|
381
381
|
|
382
382
|
<div id="footer">
|
383
|
-
Generated on
|
383
|
+
Generated on Sat Feb 26 11:46:07 2022 by
|
384
384
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
385
385
|
0.9.25 (ruby-2.7.0).
|
386
386
|
</div>
|
data/doc/Lite3.html
CHANGED
@@ -107,7 +107,7 @@
|
|
107
107
|
</div>
|
108
108
|
|
109
109
|
<div id="footer">
|
110
|
-
Generated on
|
110
|
+
Generated on Sat Feb 26 11:46:07 2022 by
|
111
111
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
112
112
|
0.9.25 (ruby-2.7.0).
|
113
113
|
</div>
|
data/doc/_index.html
CHANGED
@@ -142,7 +142,7 @@
|
|
142
142
|
</div>
|
143
143
|
|
144
144
|
<div id="footer">
|
145
|
-
Generated on
|
145
|
+
Generated on Sat Feb 26 11:46:07 2022 by
|
146
146
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
147
147
|
0.9.25 (ruby-2.7.0).
|
148
148
|
</div>
|
data/doc/file.README.html
CHANGED
@@ -193,7 +193,7 @@ make sense of them.</p>
|
|
193
193
|
</div></div>
|
194
194
|
|
195
195
|
<div id="footer">
|
196
|
-
Generated on
|
196
|
+
Generated on Sat Feb 26 11:46:07 2022 by
|
197
197
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
198
198
|
0.9.25 (ruby-2.7.0).
|
199
199
|
</div>
|
data/doc/index.html
CHANGED
@@ -193,7 +193,7 @@ make sense of them.</p>
|
|
193
193
|
</div></div>
|
194
194
|
|
195
195
|
<div id="footer">
|
196
|
-
Generated on
|
196
|
+
Generated on Sat Feb 26 11:46:07 2022 by
|
197
197
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
198
198
|
0.9.25 (ruby-2.7.0).
|
199
199
|
</div>
|
@@ -100,7 +100,7 @@
|
|
100
100
|
</div>
|
101
101
|
|
102
102
|
<div id="footer">
|
103
|
-
Generated on
|
103
|
+
Generated on Sat Feb 26 11:46:07 2022 by
|
104
104
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
105
105
|
0.9.25 (ruby-2.7.0).
|
106
106
|
</div>
|
data/lib/dbmlite3.rb
CHANGED
@@ -340,7 +340,7 @@ module Lite3
|
|
340
340
|
# string. you will need to do this instead:
|
341
341
|
#
|
342
342
|
# db.keys.include?('foo') or raise AbjectFailure.new
|
343
|
-
#
|
343
|
+
#
|
344
344
|
# Unlike DBM, values may (optionally) be any serializable Ruby type.
|
345
345
|
#
|
346
346
|
# You can select the serialization method with an optional third
|
@@ -598,12 +598,41 @@ SQL
|
|
598
598
|
key = check_key(key)
|
599
599
|
valstr = SQLite3::Blob.new( @valenc.call(value) )
|
600
600
|
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
601
|
+
# At one point, this operation was done with SQLite3's UPSERT:
|
602
|
+
#
|
603
|
+
# insert into #{actual_tbl} (key, value) values (?,?)
|
604
|
+
# on conflict(key) do update set value = ?;
|
605
|
+
#
|
606
|
+
# Unfortunately, this capability was only added to SQLite3 in
|
607
|
+
# 2018, which means that at the time of this writing (2022)
|
608
|
+
# there are still a lot of systems out there that have older
|
609
|
+
# versions of SQLite3 and so can't do this.
|
610
|
+
#
|
611
|
+
# The venerable `insert or replace` feature **almost** does what
|
612
|
+
# I want:
|
613
|
+
#
|
614
|
+
# insert or replace into #{actual_tbl} (key, value) values (?, ?);
|
615
|
+
#
|
616
|
+
# The one problem is that it changes the order of the rows,
|
617
|
+
# which we need to preserve in order to remain consistent with
|
618
|
+
# `Hash` semantics (and because it's useful).
|
619
|
+
#
|
620
|
+
# So we kick it old school and do a `select` followed by an
|
621
|
+
# `insert` or `update` wrapped in a transaction.
|
605
622
|
transaction {
|
606
|
-
|
623
|
+
rowid = nil
|
624
|
+
select = "select rowid, key, value from #{actual_tbl} where key = ?;"
|
625
|
+
@handle.sql(select, [key]) { |row|
|
626
|
+
rowid = row[0]
|
627
|
+
}
|
628
|
+
|
629
|
+
if rowid
|
630
|
+
update = "update #{actual_tbl} set value = ? where rowid = ?;"
|
631
|
+
@handle.sql(update, [valstr, rowid])
|
632
|
+
else
|
633
|
+
insert = "insert into #{actual_tbl} (key, value) values (?,?);"
|
634
|
+
@handle.sql(insert, [key, valstr])
|
635
|
+
end
|
607
636
|
}
|
608
637
|
|
609
638
|
return value
|
data/spec/dbmlite3_spec.rb
CHANGED
@@ -120,6 +120,25 @@ Serializations = Set.new
|
|
120
120
|
db.close
|
121
121
|
end
|
122
122
|
|
123
|
+
it "preserves order after modification" do
|
124
|
+
path = Tmp.file
|
125
|
+
db = newdb.call(path, "floop")
|
126
|
+
|
127
|
+
expect( db.keys ) .to eq []
|
128
|
+
expect( db.values ) .to eq []
|
129
|
+
|
130
|
+
db["foo"] = 42
|
131
|
+
db["bar"] = 99
|
132
|
+
db["quux"] = 123
|
133
|
+
|
134
|
+
db["foo"] = 88
|
135
|
+
|
136
|
+
expect( db.keys ) .to eq %w{foo bar quux}
|
137
|
+
expect( db.values ) .to eq [88, 99, 123]
|
138
|
+
|
139
|
+
db.close
|
140
|
+
end
|
141
|
+
|
123
142
|
it "implements has_key?" do
|
124
143
|
path = Tmp.file
|
125
144
|
db = newdb.call(path, "floop")
|