sqlite3 1.7.3 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +292 -0
  3. data/CONTRIBUTING.md +33 -7
  4. data/FAQ.md +43 -77
  5. data/INSTALLATION.md +14 -6
  6. data/LICENSE +18 -22
  7. data/README.md +97 -9
  8. data/dependencies.yml +10 -11
  9. data/ext/sqlite3/aggregator.c +142 -145
  10. data/ext/sqlite3/aggregator.h +2 -4
  11. data/ext/sqlite3/backup.c +74 -65
  12. data/ext/sqlite3/backup.h +2 -2
  13. data/ext/sqlite3/database.c +621 -493
  14. data/ext/sqlite3/database.h +13 -4
  15. data/ext/sqlite3/exception.c +116 -92
  16. data/ext/sqlite3/exception.h +5 -1
  17. data/ext/sqlite3/extconf.rb +33 -24
  18. data/ext/sqlite3/sqlite3.c +176 -115
  19. data/ext/sqlite3/sqlite3_ruby.h +2 -2
  20. data/ext/sqlite3/statement.c +553 -300
  21. data/ext/sqlite3/statement.h +4 -3
  22. data/ext/sqlite3/timespec.h +20 -0
  23. data/lib/sqlite3/constants.rb +195 -47
  24. data/lib/sqlite3/database.rb +223 -187
  25. data/lib/sqlite3/errors.rb +54 -1
  26. data/lib/sqlite3/fork_safety.rb +66 -0
  27. data/lib/sqlite3/pragmas.rb +140 -136
  28. data/lib/sqlite3/resultset.rb +14 -97
  29. data/lib/sqlite3/statement.rb +58 -13
  30. data/lib/sqlite3/value.rb +17 -20
  31. data/lib/sqlite3/version.rb +2 -21
  32. data/lib/sqlite3/version_info.rb +17 -0
  33. data/lib/sqlite3.rb +8 -4
  34. data/ports/archives/sqlite-autoconf-3470200.tar.gz +0 -0
  35. metadata +9 -37
  36. data/API_CHANGES.md +0 -49
  37. data/ChangeLog.cvs +0 -88
  38. data/Gemfile +0 -10
  39. data/LICENSE-DEPENDENCIES +0 -20
  40. data/lib/sqlite3/translator.rb +0 -117
  41. data/ports/archives/sqlite-autoconf-3450200.tar.gz +0 -0
  42. data/test/helper.rb +0 -27
  43. data/test/test_backup.rb +0 -33
  44. data/test/test_collation.rb +0 -82
  45. data/test/test_database.rb +0 -668
  46. data/test/test_database_flags.rb +0 -95
  47. data/test/test_database_readonly.rb +0 -36
  48. data/test/test_database_readwrite.rb +0 -41
  49. data/test/test_deprecated.rb +0 -49
  50. data/test/test_encoding.rb +0 -165
  51. data/test/test_integration.rb +0 -507
  52. data/test/test_integration_aggregate.rb +0 -336
  53. data/test/test_integration_open_close.rb +0 -30
  54. data/test/test_integration_pending.rb +0 -115
  55. data/test/test_integration_resultset.rb +0 -142
  56. data/test/test_integration_statement.rb +0 -194
  57. data/test/test_pragmas.rb +0 -22
  58. data/test/test_result_set.rb +0 -47
  59. data/test/test_sqlite3.rb +0 -30
  60. data/test/test_statement.rb +0 -290
  61. data/test/test_statement_execute.rb +0 -39
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa192827777bfe9eff54316d0310216ac32f709a52a8dab174d31ffd1e262796
4
- data.tar.gz: bdd121ee85b74600e61778868665e17ef4e8b314fcdd94760d2ab408f2bbf17f
3
+ metadata.gz: 6c77087bc2b7d9598f011a86607768b9500f9734ee3e37ef46590deb46e0396a
4
+ data.tar.gz: 46532d41a1cff9d677195260dfc2475be49398ebbe989910e2534187d301a223
5
5
  SHA512:
6
- metadata.gz: eed82c398ae8eaf6d773998c8bd4162550263869aae17513d4e3274671c365dd4eb234f3a227c75dfd1a4b488c874697e1d208aee7a81ee593b8685e6ffb354b
7
- data.tar.gz: 6cc96542b17c78472d648730506cb7b0ea77dc9ffb14f3b5c8fec966598b9dbb3441ba58765065e0bb8536059f50ecfed63f2f41badc2b84da3ee07a30d41418
6
+ metadata.gz: d20f408cbbda35ae2e8c37365b71f0ce1836eaab6ebcf8d9f7ed6470b0530a487a571fdc3438b17300656c9a264e3aa11e90ef9b1a02db15f2bf7de1c3ca1943
7
+ data.tar.gz: 47051aa730bd1cdfc3c41e9933d993edb4f66928365a811c717b14a0fd40773558ee3a5b491b7ae1f492a27db5cc6f009ec088da75e6b73da6d47de47a83a280
data/CHANGELOG.md CHANGED
@@ -1,5 +1,297 @@
1
1
  # sqlite3-ruby Changelog
2
2
 
3
+ ## 2.5.0 / 2024-12-25
4
+
5
+ ### Ruby
6
+
7
+ This release introduces native gem packages that include Ruby 3.4.
8
+
9
+
10
+ ## 2.4.1 / 2024-12-08
11
+
12
+ ### Dependencies
13
+
14
+ - Vendored sqlite is updated to [v3.47.2](https://sqlite.org/releaselog/3_47.2.html) #593 @flavorjones
15
+
16
+ The description from the upstream maintainers is:
17
+
18
+ > SQLite version 3.47.2, now available, fixes an important bug that first appeared in the 3.47.0
19
+ > release. In SQLite versions 3.47.0 and 3.47.1, if you try to convert a string into a
20
+ > floating-point value and the first 16 significant digits of the value are exactly
21
+ > "1844674407370955", then the floating-point number generated might be incorrect. The problem
22
+ > only affects x64 and i386 CPUs, so it does not affect you if you are running on ARM. And it only
23
+ > affects releases 3.47.0 and 3.47.1. **If you are running SQLite versions 3.47.0 or 3.47.1, then
24
+ > upgrading is recommended.**
25
+
26
+ Saving you a click, you should upgrade if you're running sqlite3-ruby v2.1.1 or later.
27
+
28
+
29
+ ### Fixed
30
+
31
+ - Prevent unnecessary "Invalid Reference" warnings from the `ForkSafety` module when GC runs during the "after fork" hook. #592 @flavorjones
32
+
33
+
34
+ ## 2.4.0 / 2024-12-03
35
+
36
+ ### Added
37
+
38
+ - `Database#load_extension` now accepts any object that responds to `#to_path`, in addition to String filesystem paths. [#586] @flavorjones
39
+ - `Database.new` now accepts an `extensions:` parameter, which is an array of SQLite extensions that will be loaded during initialization. The array may contain String filesystem paths and objects that respond to `#to_path`. [#586] @flavorjones
40
+
41
+
42
+ ## 2.3.1 / 2024-11-25
43
+
44
+ ### Dependencies
45
+
46
+ - Vendored sqlite is updated to [v3.47.1](https://sqlite.org/releaselog/3_47_1.html) [#589] @flavorjones
47
+
48
+
49
+ ## 2.3.0 / 2024-11-20
50
+
51
+ ### Added
52
+
53
+ - The SQLITE_DBPAGE extension is now enabled by default, which implements an eponymous-only virtual table that provides direct access to the underlying database file by interacting with the pager. See https://www.sqlite.org/dbpage.html for more information. [#578] @flavorjones
54
+ - The DBSTAT extension is now enabled by default, which implements a read-only eponymous virtual table that returns information about the amount of disk space used to store the content of an SQLite database. See https://sqlite.org/dbstat.html for more information. [#580] @pawurb @flavorjones
55
+ - `Database#optimize` which wraps the `pragma optimize;` statement. Also added `Constants::Optimize` to allow advanced users to pass a bitmask of options. See https://www.sqlite.org/pragma.html#pragma_optimize. [#572] @alexcwatt @flavorjones
56
+ - `SQLite3::VERSION_INFO` is contains a bag of metadata about the gem and the sqlite library used. `SQLite3::SQLITE_PACKAGED_LIBRARIES` and `SQLite3::SQLITE_PRECOMPILED_LIBRARIES` are indicate how the gem was built. [#581] @flavorjones
57
+
58
+
59
+ ### Fixed
60
+
61
+ - `Database#encoding=` support for switching the database encoding to `UTF-16BE`, which has been broken since `Database#encoding=` was introduced in v1.3.12 in 2016. [#575] @miyucy
62
+ - Omit mention of the `pkg-config` gem when failing to build from source, since it is not used. [#358] @flavorjones
63
+
64
+
65
+ ## 2.2.0 / 2024-10-30
66
+
67
+ ### Added
68
+
69
+ - URI filenames are now allowed. This allows the injection of some behavior via recognized query parameters. See https://www.sqlite.org/uri.html for more information. [#571] @flavorjones
70
+
71
+
72
+ ### Improved
73
+
74
+ - SQL Syntax errors during `Database#prepare` will raise a verbose exception with a multiline message indicating with a "^" exactly where in the statement the error occurred. [#554] @fractaledmind @flavorjones
75
+
76
+
77
+ ## 2.1.1 / 2024-10-22
78
+
79
+ ### Dependencies
80
+
81
+ - Vendored sqlite is updated to [v3.47.0](https://sqlite.org/releaselog/3_47_0.html) [#570] @flavorjones
82
+
83
+
84
+ ## 2.1.0 / 2024-09-24
85
+
86
+ ### Ruby
87
+
88
+ - This release drops support for Ruby 3.0. [#563] @flavorjones
89
+
90
+
91
+ ### Fork safety improvements
92
+
93
+ Sqlite itself is [not fork-safe](https://www.sqlite.org/howtocorrupt.html#_carrying_an_open_database_connection_across_a_fork_). Specifically, writing in a child process to a database connection that was created in the parent process may corrupt the database file. To mitigate this risk, sqlite3-ruby has implemented the following changes:
94
+
95
+ - All open writable database connections carried across a `fork()` will immediately be closed in the child process to mitigate the risk of corrupting the database file.
96
+ - These connections will be incompletely closed ("discarded") which will result in a one-time memory leak in the child process.
97
+
98
+ If it's at all possible, we strongly recommend that you close writable database connections in the parent before forking. If absolutely necessary (and you know what you're doing), you may suppress the fork safety warnings by calling `SQLite3::ForkSafety.suppress_warnings!`.
99
+
100
+ See the README's "Fork Safety" section and `adr/2024-09-fork-safety.md` for more information. [#558, #565, #566] @flavorjones
101
+
102
+
103
+ ### Improved
104
+
105
+ - Use `sqlite3_close_v2` to close databases in a deferred manner if there are unclosed prepared statements. Previously closing a database while statements were open resulted in a `BusyException`. See https://www.sqlite.org/c3ref/close.html for more context. [#557] @flavorjones
106
+ - When setting a Database `busy_handler`, fire the write barrier to prevent potential crashes during the GC mark phase. [#556] @jhawthorn
107
+
108
+
109
+ ### Documentation
110
+
111
+ - The `FAQ.md` has been updated to fix some inaccuracies. [#562] @rickhull
112
+
113
+
114
+ ## 2.0.4 / 2024-08-13
115
+
116
+ ### Dependencies
117
+
118
+ - Vendored sqlite is updated to [v3.46.1](https://sqlite.org/releaselog/3_46_1.html) @flavorjones
119
+
120
+
121
+ ## 2.0.3 / 2024-07-29
122
+
123
+ ### Improved
124
+
125
+ - `Database#quote` avoids allocating strings where reusing frozen strings is preferable. #548 @casperisfine
126
+
127
+
128
+ ## 2.0.2 / 2024-05-23
129
+
130
+ ### Dependencies
131
+
132
+ - Vendored sqlite is updated to [v3.46.0](https://sqlite.org/releaselog/3_46_0.html) @flavorjones
133
+
134
+
135
+ ## 2.0.1 / 2024-04-20
136
+
137
+ ### Fixed
138
+
139
+ - Raise `ArgumentError` if `Database#execute`, `#execute_batch`, or `#query` are passed multiple bind parameters that are not in an Array. In v2.0.0 these methods would silently swallow additional arguments, and this change makes the failure explicit. See the CHANGELOG notes for v2.0.0 for examples on how to update your code. [#527] @flavorjones
140
+ - Fixed a regression in v2.0.0 that caused `Database#execute_batch` to raise an encoding exception when passed some non-ascii strings. As a result of this fix, `Database#prepare` now ensures the "remainder" string will always be encoded as UTF-8. [#524] @flavorjones
141
+
142
+
143
+ ## 2.0.0 / 2024-04-17
144
+
145
+ This is a major release which contains some breaking changes, primarily the removal of
146
+ long-deprecated functionality. Before upgrading, please make sure to address deprecation warnings
147
+ emitted from your application using sqlite3-ruby v1.7.x.
148
+
149
+
150
+ ### Ruby
151
+
152
+ - This release drops support for Ruby 2.7. [#453] @flavorjones
153
+
154
+
155
+ ### Packaging
156
+
157
+ Native (precompiled) gems are now available for Linux Musl. [#442] @flavorjones
158
+
159
+ Here are the platforms for which native gems are shipped:
160
+
161
+ - `aarch64-linux-gnu` (requires: glibc >= 2.29)
162
+ - `aarch64-linux-musl`
163
+ - `arm-linux-gnu` (requires: glibc >= 2.29)
164
+ - `arm-linux-musl`
165
+ - `arm64-darwin`
166
+ - `x64-mingw32` / `x64-mingw-ucrt`
167
+ - `x86-linux-gnu` (requires: glibc >= 2.17)
168
+ - `x86-linux-musl`
169
+ - `x86_64-darwin`
170
+ - `x86_64-linux-gnu` (requires: glibc >= 2.17)
171
+ - `x86_64-linux-musl`
172
+
173
+ ⚠ Ruby 3.0 linux users must use Rubygems >= 3.3.22 in order to use these gems.
174
+
175
+ ⚠ Musl linux users should update to Bundler >= 2.5.6 to avoid https://github.com/rubygems/rubygems/issues/7432
176
+
177
+ See [the INSTALLATION doc](https://github.com/sparklemotion/sqlite3-ruby/blob/main/INSTALLATION.md) for more information.
178
+
179
+
180
+ ### Dependencies
181
+
182
+ - Vendored sqlite is updated to [v3.45.3](https://sqlite.org/releaselog/3_45_3.html). @flavorjones
183
+
184
+
185
+ ### Added
186
+
187
+ - `Database#busy_handler_timeout=` introduced as an alternative to `#busy_timeout=` that can be used when it's desired to release the GVL between retries. [#443, #456] @fractaledmind
188
+ - Support the `SUPER_JOURNAL` flag which is an alias for `MASTER_JOURNAL` as of sqlite 3.33.0. [#467] @flavorjones
189
+ - `Statement#stat` and `Statement#memused` introduced to report statistics. [#461] @fractaledmind
190
+ - `Statement#sql` and `Statement#expanded_sql` introduced to retrieve the SQL statement associated with the `Statement` object. [#293, #498] @tenderlove
191
+ - `SQLite3.status` introduced to return run-time status and reset high-water marks. See `SQLite3::Constants::Status` for details. [#520] @wjlroe
192
+
193
+
194
+ ### Improved
195
+
196
+ - Avoid leaking memory for statements that are not closed properly. [#392] @haileys
197
+ - Moved some C code into Ruby. [#451, #455] @tenderlove
198
+ - Improve performance of `ResultSet` hashes. [#154, #484, #468] @tenderlove
199
+ - Fix a GC compaction issue with `busy_handler`. [#466] @byroot
200
+ - Remove unused `ResultSet` instance variable. [#469] @tenderlove
201
+ - Fix encoding for values passed to custom functions. [#218, #488] @tenderlove
202
+
203
+
204
+ ### Changed
205
+
206
+ - Consistently use `SQLite3::Exception` or subclasses. Previously some `Pragmas` methods raised `Exception`, and `Database#execute_batch2` and `Database#load_extension` raised `RuntimeError`. [#467, #490] @flavorjones
207
+ - `Database#columns` returns a list of internal frozen strings. [#155, #474, #486] @tenderlove
208
+ - Freeze results that come from the database. [#480] @tenderlove
209
+ - The encoding of a Database is no longer cached. [#485] @tenderlove
210
+ - `Database#transaction` returns the result of the block when used with a block. [#508] @alexcwatt
211
+ - `Database#execute_batch` returns the result of the last statement executed. [#512] @alexcwatt
212
+
213
+
214
+ ### Removed
215
+
216
+ - Removed class `SQLite3::Translator` and all related type translation methods which have been deprecated since v1.3.2. [#470] @tenderlove
217
+
218
+ If you need to do type translation on values returned from the statement object, please wrap it
219
+ with a delegate object. Here is an example of using a delegate class to implement type
220
+ translation:
221
+
222
+ ```ruby
223
+ require "sqlite3"
224
+ require "delegate"
225
+
226
+ db = SQLite3::Database.new(":memory:")
227
+
228
+ return_value = db.execute_batch2 <<-EOSQL
229
+ CREATE TABLE items (id integer PRIMARY KEY AUTOINCREMENT, name string);
230
+ INSERT INTO items (name) VALUES ("foo");
231
+ INSERT INTO items (name) VALUES ("bar");
232
+ EOSQL
233
+
234
+ class MyTranslator < DelegateClass(SQLite3::Statement)
235
+ def step
236
+ row = super
237
+ return if done?
238
+
239
+ row.map.with_index do |item, i|
240
+ case types[i]
241
+ when "integer" # turn all integers to floats
242
+ item.to_f
243
+ when "string" # add "hello" to all strings
244
+ item + "hello"
245
+ end
246
+ end
247
+ end
248
+ end
249
+
250
+ db.prepare("SELECT * FROM items") do |stmt|
251
+ stmt = MyTranslator.new(stmt)
252
+ while row = stmt.step
253
+ p row
254
+ end
255
+ end
256
+ ```
257
+
258
+ - Removed `types` and `fields` readers on row objects, which have been deprecated since
259
+ v1.3.6. [#471] @tenderlove
260
+
261
+ Deprecated code looks like this:
262
+
263
+ ```ruby
264
+ row = @db.execute("select * from foo")
265
+ assert_equal ["blob"], row.first.types
266
+ ```
267
+
268
+ If you would like to access the "types" associated with a returned query,
269
+ use a prepared statement like this:
270
+
271
+ ```ruby
272
+ @db.prepare("select * from foo") do |v|
273
+ assert_equal ["blob"], v.types
274
+ end
275
+ ```
276
+
277
+ - Removed support for non-Array bind parameters to methods `Database#execute`, `#execute_batch`, and `#query`, which has been deprecated since v1.3.0. [#511] @flavorjones
278
+
279
+ Deprecated code looks like this:
280
+
281
+ ``` ruby
282
+ @db.query("select * from foo where a = ? and b = ? and c = ?", 1, 2, 3)
283
+ ```
284
+
285
+ For these cases, pass the bind parameters as an array:
286
+
287
+ ``` ruby
288
+ @db.query("select * from foo where a = ? and b = ? and c = ?", [1, 2, 3])
289
+ ```
290
+
291
+ - Removed class `SQLite3::VersionProxy` which has been deprecated since v1.3.2. [#453] @flavorjones
292
+ - Removed methods `SQLite3::Database::FunctionProxy#count` and `#set_error` which have been broken since at least v1.3.13. [#164, #509, #510] @alexcwatt @flavorjones
293
+
294
+
3
295
  ## 1.7.3 / 2024-03-15
4
296
 
5
297
  ### Dependencies
data/CONTRIBUTING.md CHANGED
@@ -5,6 +5,28 @@
5
5
  This doc is a short introduction on how to modify and maintain the sqlite3-ruby gem.
6
6
 
7
7
 
8
+ ## Architecture notes
9
+
10
+ ### Decision record
11
+
12
+ As of 2024-09, we're starting to keep some architecture decisions in the subdirectory `/adr`, so
13
+ please look there for additional information.
14
+
15
+ ### Garbage collection
16
+
17
+ All statements keep pointers back to their respective database connections.
18
+ The `@connection` instance variable on the `Statement` handle keeps the database
19
+ connection alive.
20
+
21
+ We use `sqlite3_close_v2` in `Database#close` since v2.1.0 which defers _actually_ closing the
22
+ connection and freeing the underlying memory until all open statments are closed; though the
23
+ `Database` object will immediately behave as though it's been fully closed. If a Database is not
24
+ explicitly closed, it will be closed when it is GCed.
25
+
26
+ `Statement#close` finalizes the underlying statement. If a Statement is not explicitly closed, it
27
+ will be closed/finalized when it is GCed.
28
+
29
+
8
30
  ## Building gems
9
31
 
10
32
  As a prerequisite please make sure you have `docker` correctly installed, so that you're able to cross-compile the native gems.
@@ -23,12 +45,16 @@ Update `/dependencies.yml` to reflect:
23
45
 
24
46
  ## Making a release
25
47
 
26
- A quick checklist:
48
+ A quick checklist to cutting a release of the sqlite3 gem:
27
49
 
28
50
  - [ ] make sure CI is green!
29
- - [ ] update `CHANGELOG.md` and `lib/sqlite3/version.rb` including `VersionProxy::{MINOR,TINY}`
30
- - [ ] run `bin/build-gems` and make sure it completes and all the tests pass
31
- - [ ] create a git tag using a format that matches the pattern `v\d+\.\d+\.\d+`, e.g. `v1.3.13`
32
- - [ ] `git push && git push --tags`
33
- - [ ] `for g in gems/*.gem ; do gem push $g ; done`
34
- - [ ] create a release at https://github.com/sparklemotion/sqlite3-ruby/releases and include sha2 checksums
51
+ - bump the version
52
+ - [ ] update `CHANGELOG.md` and `lib/sqlite3/version.rb`
53
+ - [ ] create a git tag using a format that matches the pattern `v\d+\.\d+\.\d+`, e.g. `v1.3.13`
54
+ - build the native gems
55
+ - [ ] run `bin/build-gems` and make sure it completes and all the tests pass
56
+ - push
57
+ - [ ] `git push && git push --tags`
58
+ - [ ] `for g in gems/*.gem ; do gem push $g ; done`
59
+ - announce
60
+ - [ ] create a release at https://github.com/sparklemotion/sqlite3-ruby/releases and include sha2 checksums
data/FAQ.md CHANGED
@@ -207,48 +207,46 @@ Or do a `Database#prepare` to get the `Statement`, and then use either
207
207
  stmt.bind_params( "value", "name" => "bob" )
208
208
  ```
209
209
 
210
- ## How do I discover metadata about a query?
210
+ ## How do I discover metadata about a query result?
211
211
 
212
- If you ever want to know the names or types of the columns in a result
213
- set, you can do it in several ways.
212
+ IMPORTANT: `Database#execute` returns an Array of Array of Strings
213
+ which will have no metadata about the query or the result, such
214
+ as column names.
214
215
 
215
216
 
216
- The first way is to ask the row object itself. Each row will have a
217
- property "fields" that returns an array of the column names. The row
218
- will also have a property "types" that returns an array of the column
219
- types:
217
+ There are 2 main sources of query metadata:
220
218
 
221
-
222
- ```ruby
223
- rows = db.execute( "select * from table" )
224
- p rows[0].fields
225
- p rows[0].types
226
- ```
219
+ * `Statement`
220
+ * `ResultSet`
227
221
 
228
222
 
229
- Obviously, this approach requires you to execute a statement that actually
230
- returns data. If you don't know if the statement will return any rows, but
231
- you still need the metadata, you can use `Database#query` and ask the
232
- `ResultSet` object itself:
223
+ You can get a `Statement` via `Database#prepare`, and you can get
224
+ a `ResultSet` via `Statement#execute` or `Database#query`.
233
225
 
234
226
 
235
227
  ```ruby
236
- db.query( "select * from table" ) do |result|
237
- p result.columns
238
- p result.types
239
- ...
240
- end
241
- ```
242
-
243
-
244
- Lastly, you can use `Database#prepare` and ask the `Statement` object what
245
- the metadata are:
246
-
247
-
248
- ```ruby
249
- stmt = db.prepare( "select * from table" )
250
- p stmt.columns
251
- p stmt.types
228
+ sql = 'select * from table'
229
+
230
+ # No metadata
231
+ rows = db.execute(sql)
232
+ rows.class # => Array, no metadata
233
+ rows.first.class # => Array, no metadata
234
+ rows.first.first.class #=> String, no metadata
235
+
236
+ # Statement has metadata
237
+ stmt = db.prepare(sql)
238
+ stmt.columns # => [ ... ]
239
+ stmt.types # => [ ... ]
240
+
241
+ # ResultSet has metadata
242
+ results = stmt.execute
243
+ results.columns # => [ ... ]
244
+ results.types # => [ ... ]
245
+
246
+ # ResultSet has metadata
247
+ results = db.query(sql)
248
+ results.columns # => [ ... ]
249
+ results.types # => [ ... ]
252
250
  ```
253
251
 
254
252
  ## I'd like the rows to be indexible by column name.
@@ -273,7 +271,18 @@ is unavailable on the row, although the "types" property remains.)
273
271
  ```
274
272
 
275
273
 
276
- The other way is to use Ara Howard's
274
+ A more granular way to do this is via `ResultSet#next_hash` or
275
+ `ResultSet#each_hash`.
276
+
277
+
278
+ ```ruby
279
+ results = db.query( "select * from table" )
280
+ row = results.next_hash
281
+ p row['column1']
282
+ ```
283
+
284
+
285
+ Another way is to use Ara Howard's
277
286
  [`ArrayFields`](http://rubyforge.org/projects/arrayfields)
278
287
  module. Just `require "arrayfields"`, and all of your rows will be indexable
279
288
  by column name, even though they are still arrays!
@@ -289,49 +298,6 @@ by column name, even though they are still arrays!
289
298
  end
290
299
  ```
291
300
 
292
- ## I'd like the values from a query to be the correct types, instead of String.
293
-
294
- You can turn on "type translation" by setting `Database#type_translation` to
295
- true:
296
-
297
-
298
- ```ruby
299
- db.type_translation = true
300
- db.execute( "select * from table" ) do |row|
301
- p row
302
- end
303
- ```
304
-
305
-
306
- By doing this, each return value for each row will be translated to its
307
- correct type, based on its declared column type.
308
-
309
-
310
- You can even declare your own translation routines, if (for example) you are
311
- using an SQL type that is not handled by default:
312
-
313
-
314
- ```ruby
315
- # assume "objects" table has the following schema:
316
- # create table objects (
317
- # name varchar2(20),
318
- # thing object
319
- # )
320
-
321
- db.type_translation = true
322
- db.translator.add_translator( "object" ) do |type, value|
323
- db.decode( value )
324
- end
325
-
326
- h = { :one=>:two, "three"=>"four", 5=>6 }
327
- dump = db.encode( h )
328
-
329
- db.execute( "insert into objects values ( ?, ? )", "bob", dump )
330
-
331
- obj = db.get_first_value( "select thing from objects where name='bob'" )
332
- p obj == h
333
- ```
334
-
335
301
  ## How do I insert binary data into the database?
336
302
 
337
303
  Use blobs. Blobs are new features of SQLite3. You have to use bind
data/INSTALLATION.md CHANGED
@@ -7,15 +7,21 @@ This document will help you install the `sqlite3` ruby gem. It also contains ins
7
7
 
8
8
  ### Native Gems (recommended)
9
9
 
10
- In v1.5.0 and later, native (precompiled) gems are available for recent Ruby versions on these platforms:
10
+ In v2.0.0 and later, native (precompiled) gems are available for recent Ruby versions on these platforms:
11
11
 
12
- - `aarch64-linux` (requires: glibc >= 2.29)
13
- - `arm-linux` (requires: glibc >= 2.29)
12
+ - `aarch64-linux-gnu` (requires: glibc >= 2.29)
13
+ - `aarch64-linux-musl`
14
+ - `arm-linux-gnu` (requires: glibc >= 2.29)
15
+ - `arm-linux-musl`
14
16
  - `arm64-darwin`
15
- - `x64-mingw32` / `x64-mingw-ucrt`
16
- - `x86-linux` (requires: glibc >= 2.17)
17
+ - `x64-mingw-ucrt`
18
+ - `x86-linux-gnu` (requires: glibc >= 2.17)
19
+ - `x86-linux-musl`
17
20
  - `x86_64-darwin`
18
- - `x86_64-linux` (requires: glibc >= 2.17)
21
+ - `x86_64-linux-gnu` (requires: glibc >= 2.17)
22
+ - `x86_64-linux-musl`
23
+
24
+ ⚠ Musl linux users should update to Bundler >= 2.5.6 to avoid https://github.com/rubygems/rubygems/issues/7432
19
25
 
20
26
  If you are using one of these Ruby versions on one of these platforms, the native gem is the recommended way to install sqlite3-ruby.
21
27
 
@@ -57,6 +63,8 @@ If you are on a platform or version of Ruby that is not covered by the Native Ge
57
63
 
58
64
  By default, as of v1.5.0 of this library, the latest available version of libsqlite3 is packaged with the gem and will be compiled and used automatically. This takes a bit longer than the native gem, but will provide a modern, well-supported version of libsqlite3.
59
65
 
66
+ ⚠ A prerequisite to build the gem with the packaged sqlite3 is that you must have `pkgconf` installed.
67
+
60
68
  For example, on a linux system running Ruby 2.5:
61
69
 
62
70
  ``` text
data/LICENSE CHANGED
@@ -1,27 +1,23 @@
1
- Copyright (c) 2004, Jamis Buck (jamis@jamisbuck.org)
2
- All rights reserved.
1
+ Copyright (c) 2004-2024, Jamis Buck, Luis Lavena, Aaron Patterson, Mike Dalessio, et al.
3
2
 
4
- Redistribution and use in source and binary forms, with or without
5
- modification, are permitted provided that the following conditions are met:
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted
4
+ provided that the following conditions are met:
6
5
 
7
- * Redistributions of source code must retain the above copyright notice,
8
- this list of conditions and the following disclaimer.
6
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions
7
+ and the following disclaimer.
9
8
 
10
- * Redistributions in binary form must reproduce the above copyright
11
- notice, this list of conditions and the following disclaimer in the
12
- documentation and/or other materials provided with the distribution.
9
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of
10
+ conditions and the following disclaimer in the documentation and/or other materials provided with
11
+ the distribution.
13
12
 
14
- * The names of its contributors may not be used to endorse or promote
15
- products derived from this software without specific prior written
16
- permission.
13
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to
14
+ endorse or promote products derived from this software without specific prior written permission.
17
15
 
18
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
22
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
- SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25
- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
17
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
18
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
19
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22
+ IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
23
+ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.