amalgalite 1.8.0-x64-mingw-ucrt

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +7 -0
  2. data/CONTRIBUTING.md +60 -0
  3. data/HISTORY.md +386 -0
  4. data/LICENSE +31 -0
  5. data/Manifest.txt +105 -0
  6. data/README.md +62 -0
  7. data/Rakefile +27 -0
  8. data/TODO.md +57 -0
  9. data/bin/amalgalite-pack +147 -0
  10. data/examples/a.rb +9 -0
  11. data/examples/blob.rb +88 -0
  12. data/examples/bootstrap.rb +36 -0
  13. data/examples/define_aggregate.rb +75 -0
  14. data/examples/define_function.rb +104 -0
  15. data/examples/fts5.rb +152 -0
  16. data/examples/gem-db.rb +94 -0
  17. data/examples/require_me.rb +11 -0
  18. data/examples/requires.rb +42 -0
  19. data/examples/schema-info.rb +34 -0
  20. data/ext/amalgalite/c/amalgalite.c +355 -0
  21. data/ext/amalgalite/c/amalgalite.h +151 -0
  22. data/ext/amalgalite/c/amalgalite_blob.c +240 -0
  23. data/ext/amalgalite/c/amalgalite_constants.c +1432 -0
  24. data/ext/amalgalite/c/amalgalite_database.c +1188 -0
  25. data/ext/amalgalite/c/amalgalite_requires_bootstrap.c +282 -0
  26. data/ext/amalgalite/c/amalgalite_statement.c +649 -0
  27. data/ext/amalgalite/c/extconf.rb +71 -0
  28. data/ext/amalgalite/c/gen_constants.rb +353 -0
  29. data/ext/amalgalite/c/notes.txt +134 -0
  30. data/ext/amalgalite/c/sqlite3.c +243616 -0
  31. data/ext/amalgalite/c/sqlite3.h +12894 -0
  32. data/ext/amalgalite/c/sqlite3_options.h +4 -0
  33. data/ext/amalgalite/c/sqlite3ext.h +705 -0
  34. data/lib/amalgalite/3.1/amalgalite.so +0 -0
  35. data/lib/amalgalite/aggregate.rb +73 -0
  36. data/lib/amalgalite/blob.rb +186 -0
  37. data/lib/amalgalite/boolean.rb +42 -0
  38. data/lib/amalgalite/busy_timeout.rb +47 -0
  39. data/lib/amalgalite/column.rb +99 -0
  40. data/lib/amalgalite/core_ext/kernel/require.rb +21 -0
  41. data/lib/amalgalite/csv_table_importer.rb +75 -0
  42. data/lib/amalgalite/database.rb +933 -0
  43. data/lib/amalgalite/function.rb +61 -0
  44. data/lib/amalgalite/index.rb +43 -0
  45. data/lib/amalgalite/memory_database.rb +15 -0
  46. data/lib/amalgalite/packer.rb +231 -0
  47. data/lib/amalgalite/paths.rb +80 -0
  48. data/lib/amalgalite/profile_tap.rb +131 -0
  49. data/lib/amalgalite/progress_handler.rb +21 -0
  50. data/lib/amalgalite/requires.rb +151 -0
  51. data/lib/amalgalite/schema.rb +225 -0
  52. data/lib/amalgalite/sqlite3/constants.rb +95 -0
  53. data/lib/amalgalite/sqlite3/database/function.rb +48 -0
  54. data/lib/amalgalite/sqlite3/database/status.rb +68 -0
  55. data/lib/amalgalite/sqlite3/status.rb +60 -0
  56. data/lib/amalgalite/sqlite3/version.rb +55 -0
  57. data/lib/amalgalite/sqlite3.rb +6 -0
  58. data/lib/amalgalite/statement.rb +421 -0
  59. data/lib/amalgalite/table.rb +91 -0
  60. data/lib/amalgalite/taps/console.rb +27 -0
  61. data/lib/amalgalite/taps/io.rb +74 -0
  62. data/lib/amalgalite/taps.rb +2 -0
  63. data/lib/amalgalite/trace_tap.rb +35 -0
  64. data/lib/amalgalite/type_map.rb +63 -0
  65. data/lib/amalgalite/type_maps/default_map.rb +166 -0
  66. data/lib/amalgalite/type_maps/storage_map.rb +38 -0
  67. data/lib/amalgalite/type_maps/text_map.rb +21 -0
  68. data/lib/amalgalite/version.rb +8 -0
  69. data/lib/amalgalite/view.rb +26 -0
  70. data/lib/amalgalite.rb +51 -0
  71. data/spec/aggregate_spec.rb +158 -0
  72. data/spec/amalgalite_spec.rb +4 -0
  73. data/spec/blob_spec.rb +78 -0
  74. data/spec/boolean_spec.rb +24 -0
  75. data/spec/busy_handler.rb +157 -0
  76. data/spec/data/iso-3166-country.txt +242 -0
  77. data/spec/data/iso-3166-schema.sql +22 -0
  78. data/spec/data/iso-3166-subcountry.txt +3995 -0
  79. data/spec/data/make-iso-db.sh +12 -0
  80. data/spec/database_spec.rb +505 -0
  81. data/spec/default_map_spec.rb +92 -0
  82. data/spec/function_spec.rb +78 -0
  83. data/spec/integeration_spec.rb +97 -0
  84. data/spec/iso_3166_database.rb +58 -0
  85. data/spec/json_spec.rb +24 -0
  86. data/spec/packer_spec.rb +60 -0
  87. data/spec/paths_spec.rb +28 -0
  88. data/spec/progress_handler_spec.rb +91 -0
  89. data/spec/requires_spec.rb +54 -0
  90. data/spec/rtree_spec.rb +66 -0
  91. data/spec/schema_spec.rb +131 -0
  92. data/spec/spec_helper.rb +48 -0
  93. data/spec/sqlite3/constants_spec.rb +108 -0
  94. data/spec/sqlite3/database_status_spec.rb +36 -0
  95. data/spec/sqlite3/status_spec.rb +22 -0
  96. data/spec/sqlite3/version_spec.rb +28 -0
  97. data/spec/sqlite3_spec.rb +53 -0
  98. data/spec/statement_spec.rb +168 -0
  99. data/spec/storage_map_spec.rb +38 -0
  100. data/spec/tap_spec.rb +57 -0
  101. data/spec/text_map_spec.rb +20 -0
  102. data/spec/type_map_spec.rb +14 -0
  103. data/spec/version_spec.rb +8 -0
  104. data/tasks/custom.rake +101 -0
  105. data/tasks/default.rake +244 -0
  106. data/tasks/extension.rake +28 -0
  107. data/tasks/this.rb +208 -0
  108. metadata +325 -0
@@ -0,0 +1,157 @@
1
+ require 'spec_helper'
2
+
3
+ class BusyHandlerTest < Amalgalite::BusyHandler
4
+ attr_accessor :call_count
5
+ def initialize( max = 5 )
6
+ @max = max
7
+ @call_count = 0
8
+ end
9
+
10
+ def call( c )
11
+ @call_count += 1
12
+ if call_count >= @max then
13
+ return false
14
+ end
15
+ return true
16
+ end
17
+ end
18
+
19
+ describe "Busy Handlers" do
20
+ before(:each) do
21
+ @read_db = Amalgalite::Database.new( @iso_db_path )
22
+ @write_db = Amalgalite::Database.new( @iso_db_path )
23
+ end
24
+
25
+ after(:each) do
26
+ @write_db.close
27
+ @read_db.close
28
+ end
29
+
30
+ it "raises NotImplemented if #call is not overwritten" do
31
+ bh = ::Amalgalite::BusyHandler.new
32
+ lambda { bh.call( 42 ) }.should raise_error( ::NotImplementedError, /The busy handler call\(N\) method must be implemented/ )
33
+ end
34
+
35
+ it "can be registered as block" do
36
+ call_count = 0
37
+ @write_db.busy_handler do |x|
38
+ call_count = x
39
+ if call_count >= 20 then
40
+ false
41
+ else
42
+ true
43
+ end
44
+ end
45
+
46
+ # put a read lock on the database
47
+ @read_db.transaction( "DEFERRED" )
48
+
49
+ # put a read lock on the database, but want to go to an exclusive
50
+ @write_db.transaction( "IMMEDIATE" )
51
+
52
+ # do a read operation
53
+ @read_db.execute("SELECT count(*) FROM subcountry")
54
+
55
+ # attempt to do a write operation and commit it
56
+ @write_db.execute("DELETE FROM subcountry")
57
+ lambda { @write_db.execute("COMMIT"); }.should raise_error( ::Amalgalite::SQLite3::Error, /database is locked/ )
58
+ call_count.should == 20
59
+ end
60
+
61
+ it "can be registered as lambda" do
62
+ call_count = 0
63
+ callable = lambda do |x|
64
+ call_count = x
65
+ if call_count >= 40 then
66
+ false
67
+ else
68
+ true
69
+ end
70
+ end
71
+
72
+ @write_db.busy_handler( callable )
73
+
74
+ # put a read lock on the database
75
+ @read_db.transaction( "DEFERRED" )
76
+
77
+ # put a read lock on the database, but want to go to an exclusive
78
+ @write_db.transaction( "IMMEDIATE" )
79
+
80
+ # do a read operation
81
+ @read_db.execute("SELECT count(*) FROM subcountry")
82
+
83
+ # attempt to do a write operation and commit it
84
+ @write_db.execute("DELETE FROM subcountry")
85
+ lambda { @write_db.execute("COMMIT"); }.should raise_error( ::Amalgalite::SQLite3::Error, /database is locked/ )
86
+ call_count.should == 40
87
+ end
88
+
89
+ it "can be registered as a class" do
90
+ h = BusyHandlerTest.new( 10 )
91
+ @write_db.busy_handler( h )
92
+
93
+ # put a read lock on the database
94
+ @read_db.transaction( "DEFERRED" )
95
+
96
+ # put a read lock on the database, but want to go to an exclusive
97
+ @write_db.transaction( "IMMEDIATE" )
98
+
99
+ # do a read operation
100
+ @read_db.execute("SELECT count(*) FROM subcountry")
101
+
102
+ # attempt to do a write operation and commit it
103
+ @write_db.execute("DELETE FROM subcountry")
104
+ lambda { @write_db.execute("COMMIT"); }.should raise_error( ::Amalgalite::SQLite3::Error, /database is locked/ )
105
+ h.call_count.should == 10
106
+ end
107
+
108
+ it "has a default timeout class available " do
109
+ to = ::Amalgalite::BusyTimeout.new( 5, 10 )
110
+ @write_db.busy_handler( to )
111
+
112
+ # put a read lock on the database
113
+ @read_db.transaction( "DEFERRED" )
114
+
115
+ # put a read lock on the database, but want to go to an exclusive
116
+ @write_db.transaction( "IMMEDIATE" )
117
+
118
+ # do a read operation
119
+ @read_db.execute("SELECT count(*) FROM subcountry")
120
+
121
+ # attempt to do a write operation and commit it
122
+ @write_db.execute("DELETE FROM subcountry")
123
+ before = Time.now
124
+ lambda { @write_db.execute("COMMIT"); }.should raise_error( ::Amalgalite::SQLite3::Error, /database is locked/ )
125
+ after = Time.now
126
+ to.call_count.should > 5
127
+ (after - before).should > 0.05
128
+ end
129
+
130
+ it "cannot register a block with the wrong arity" do
131
+ lambda do
132
+ @write_db.define_busy_handler { |x,y| puts "What!" }
133
+ end.should raise_error( ::Amalgalite::Database::BusyHandlerError, /A busy handler expects 1 and only 1 argument/ )
134
+ end
135
+
136
+ it "can remove a busy handler" do
137
+ bht = BusyHandlerTest.new
138
+
139
+ @write_db.busy_handler( bht )
140
+
141
+ # put a read lock on the database
142
+ @read_db.transaction( "DEFERRED" )
143
+
144
+ # put a read lock on the database, but want to go to an exclusive
145
+ @write_db.transaction( "IMMEDIATE" )
146
+
147
+ # do a read operation
148
+ @read_db.execute("SELECT count(*) FROM subcountry")
149
+
150
+ # attempt to do a write operation and commit it
151
+ @write_db.execute("DELETE FROM subcountry")
152
+ @write_db.remove_busy_handler
153
+ lambda { @write_db.execute("COMMIT"); }.should raise_error( ::Amalgalite::SQLite3::Error, /database is locked/ )
154
+ bht.call_count.should == 0
155
+ end
156
+
157
+ end
@@ -0,0 +1,242 @@
1
+ Afghanistan|AF|4
2
+ Albania|AL|8
3
+ Algeria|DZ|12
4
+ American Samoa|AS|16
5
+ Andorra|AD|20
6
+ Angola|AO|24
7
+ Anguilla|AI|660
8
+ Antarctica|AQ|10
9
+ Antigua and Barbuda|AG|28
10
+ Argentina|AR|32
11
+ Armenia|AM|51
12
+ Aruba|AW|533
13
+ Australia|AU|36
14
+ Austria|AT|40
15
+ Azerbaijan|AZ|31
16
+ Bahamas|BS|44
17
+ Bahrain|BH|48
18
+ Bangladesh|BD|50
19
+ Barbados|BB|52
20
+ Belarus|BY|112
21
+ Belgium|BE|56
22
+ Belize|BZ|84
23
+ Benin|BJ|204
24
+ Bermuda|BM|60
25
+ Bhutan|BT|64
26
+ Bolivia|BO|68
27
+ Bosnia and Herzegowina|BA|70
28
+ Botswana|BW|72
29
+ Bouvet Island|BV|74
30
+ Brazil|BR|76
31
+ British Indian Ocean Territory|IO|86
32
+ Brunei Darussalam|BN|96
33
+ Bulgaria|BG|100
34
+ Burkina Faso|BF|854
35
+ Burundi|BI|108
36
+ Cambodia|KH|116
37
+ Cameroon|CM|120
38
+ Cape Verde|CV|132
39
+ Cayman Islands|KY|136
40
+ Central African Republic|CF|140
41
+ Chad|TD|148
42
+ Chile|CL|152
43
+ China|CN|156
44
+ Christmas Island|CX|162
45
+ Cocos (Keeling) Islands|CC|166
46
+ Colombia|CO|170
47
+ Comoros|KM|174
48
+ Congo|CG|178
49
+ Congo, The Democratic Republic of the|CD|180
50
+ Cook Islands|CK|184
51
+ Costa Rica|CR|188
52
+ Cote D'Ivoire|CI|384
53
+ Croatia (local name: Hrvatska)|HR|191
54
+ Cuba|CU|192
55
+ Cyprus|CY|196
56
+ Czech Republic|CZ|203
57
+ Denmark|DK|208
58
+ Djibouti|DJ|262
59
+ Dominica|DM|212
60
+ Dominican Republic|DO|214
61
+ East Timor|TP|626
62
+ Ecuador|EC|218
63
+ Egypt|EG|818
64
+ El Salvador|SV|222
65
+ Equatorial Guinea|GQ|226
66
+ Eritrea|ER|232
67
+ Estonia|EE|233
68
+ Ethiopia|ET|231
69
+ Falkland Islands (Malvinas)|FK|238
70
+ Faroe Islands|FO|234
71
+ Fiji|FJ|242
72
+ Finland|FI|246
73
+ France|FR|250
74
+ France, Metropolitan|FX|249
75
+ French Guiana|GF|254
76
+ French Polynesia|PF|258
77
+ French Southern Territories|TF|260
78
+ Gabon|GA|266
79
+ Gambia|GM|270
80
+ Georgia|GE|268
81
+ Germany|DE|276
82
+ Ghana|GH|288
83
+ Gibraltar|GI|292
84
+ Greece|GR|300
85
+ Greenland|GL|304
86
+ Grenada|GD|308
87
+ Guadeloupe|GP|312
88
+ Guam|GU|316
89
+ Guatemala|GT|320
90
+ Guinea|GN|324
91
+ Guinea-Bissau|GW|624
92
+ Guyana|GY|328
93
+ Haiti|HT|332
94
+ Heard and McDonald Islands|HM|334
95
+ Holy See (Vatican City State)|VA|336
96
+ Honduras|HN|340
97
+ Hong Kong|HK|344
98
+ Hungary|HU|348
99
+ Iceland|IS|352
100
+ India|IN|356
101
+ Indonesia|ID|360
102
+ Iran (Islamic Republic of)|IR|364
103
+ Iraq|IQ|368
104
+ Ireland|IE|372
105
+ Israel|IL|376
106
+ Italy|IT|380
107
+ Jamaica|JM|388
108
+ Japan|JP|392
109
+ Jordan|JO|400
110
+ Kazakhstan|KZ|398
111
+ Kenya|KE|404
112
+ Kiribati|KI|296
113
+ Korea, Democratic People's Republic of|KP|408
114
+ Korea, Republic of|KR|410
115
+ Kuwait|KW|414
116
+ Kyrgyzstan|KG|417
117
+ Lao People's Democratic Republic|LA|418
118
+ Latvia|LV|428
119
+ Lebanon|LB|422
120
+ Lesotho|LS|426
121
+ Liberia|LR|430
122
+ Libyan Arab Jamahiriya|LY|434
123
+ Liechtenstein|LI|438
124
+ Lithuania|LT|440
125
+ Luxembourg|LU|442
126
+ Macau|MO|446
127
+ Macedonia, the Former Yugoslav Republic of|MK|807
128
+ Madagascar|MG|450
129
+ Malawi|MW|454
130
+ Malaysia|MY|458
131
+ Maldives|MV|462
132
+ Mali|ML|466
133
+ Malta|MT|470
134
+ Marshall Islands|MH|584
135
+ Martinique|MQ|474
136
+ Mauritania|MR|478
137
+ Mauritius|MU|480
138
+ Mayotte|YT|175
139
+ Micronesia, Federated States of|FM|583
140
+ Moldova, Republic of|MD|498
141
+ Monaco|MC|492
142
+ Mongolia|MN|496
143
+ Montserrat|MS|500
144
+ Morocco|MA|504
145
+ Mozambique|MZ|508
146
+ Myanmar|MM|104
147
+ Namibia|NA|516
148
+ Nauru|NR|520
149
+ Nepal|NP|524
150
+ Netherlands|NL|528
151
+ Netherlands Antilles|AN|530
152
+ New Caledonia|NC|540
153
+ New Zealand|NZ|554
154
+ Nicaragua|NI|558
155
+ Niger|NE|562
156
+ Nigeria|NG|566
157
+ Niue|NU|570
158
+ Norfolk Island|NF|574
159
+ Northern Mariana Islands|MP|580
160
+ Norway|NO|578
161
+ Oman|OM|512
162
+ Pakistan|PK|586
163
+ Palau|PW|585
164
+ Palestinian Territory, Occupied|PS|275
165
+ Panama|PA|591
166
+ Papua New Guinea|PG|598
167
+ Paraguay|PY|600
168
+ Peru|PE|604
169
+ Philippines|PH|608
170
+ Pitcairn|PN|612
171
+ Poland|PL|616
172
+ Portugal|PT|620
173
+ Puerto Rico|PR|630
174
+ Qatar|QA|634
175
+ Reunion|RE|638
176
+ Romania|RO|642
177
+ Russian Federation|RU|643
178
+ Rwanda|RW|646
179
+ Saint Kitts and Nevis|KN|659
180
+ Saint Lucia|LC|662
181
+ Saint Vincent and the Grenadines|VC|670
182
+ Samoa|WS|882
183
+ San Marino|SM|674
184
+ Sao Tome and Principe|ST|678
185
+ Saudi Arabia|SA|682
186
+ Senegal|SN|686
187
+ Serbia and Montenegro|CS|891
188
+ Seychelles|SC|690
189
+ Sierra Leone|SL|694
190
+ Singapore|SG|702
191
+ Slovakia (Slovak Republic)|SK|703
192
+ Slovenia|SI|705
193
+ Solomon Islands|SB|90
194
+ Somalia|SO|706
195
+ South Africa|ZA|710
196
+ South Georgia and the South Sandwich Islands|GS|239
197
+ Spain|ES|724
198
+ Sri Lanka|LK|144
199
+ St. Helena|SH|654
200
+ St. Pierre and Miquelon|PM|666
201
+ Sudan|SD|736
202
+ Suriname|SR|740
203
+ Svalbard and Jan Mayen Islands|SJ|744
204
+ Swaziland|SZ|748
205
+ Sweden|SE|752
206
+ Switzerland|CH|756
207
+ Syrian Arab Republic|SY|760
208
+ Taiwan, Province of China|TW|158
209
+ Tajikistan|TJ|762
210
+ Tanzania, United Republic of|TZ|834
211
+ Thailand|TH|764
212
+ Timor-Leste|TL|626
213
+ Togo|TG|768
214
+ Tokelau|TK|772
215
+ Tonga|TO|776
216
+ Trinidad and Tobago|TT|780
217
+ Tunisia|TN|788
218
+ Turkey|TR|792
219
+ Turkmenistan|TM|795
220
+ Turks and Caicos Islands|TC|796
221
+ Tuvalu|TV|798
222
+ Uganda|UG|800
223
+ Ukraine|UA|804
224
+ United Arab Emirates|AE|784
225
+ United States Minor Outlying Islands|UM|581
226
+ Uruguay|UY|858
227
+ Uzbekistan|UZ|860
228
+ Vanuatu|VU|548
229
+ Venezuela|VE|862
230
+ Viet Nam|VN|704
231
+ Virgin Islands (British)|VG|92
232
+ Virgin Islands (U.S.)|VI|850
233
+ Wallis and Futuna Islands|WF|876
234
+ Western Sahara|EH|732
235
+ Yemen|YE|887
236
+ Yugoslavia|YU|891
237
+ Zambia|ZM|894
238
+ Zimbabwe|ZW|716
239
+ Canada|CA|124
240
+ Mexico|MX|484
241
+ United Kingdom|GB|826
242
+ United States|US|840
@@ -0,0 +1,22 @@
1
+
2
+ -- SET client_encoding TO 'UNICODE';
3
+
4
+ CREATE TABLE country (
5
+ name TEXT NOT NULL,
6
+ two_letter TEXT PRIMARY KEY,
7
+ id integer NOT NULL
8
+ );
9
+ CREATE INDEX country_name ON country(name);
10
+
11
+
12
+ CREATE TABLE subcountry (
13
+ country TEXT NOT NULL REFERENCES country(two_letter),
14
+ name TEXT,
15
+ subdivision TEXT,
16
+ level TEXT,
17
+ UNIQUE(country, name)
18
+ );
19
+
20
+ CREATE INDEX subcountry_country ON subcountry(country);
21
+ CREATE INDEX subcountry_name ON subcountry(name);
22
+