sqlite3 1.7.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +182 -1
  3. data/CONTRIBUTING.md +23 -1
  4. data/FAQ.md +0 -43
  5. data/INSTALLATION.md +15 -5
  6. data/LICENSE +18 -22
  7. data/README.md +75 -4
  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 +535 -482
  14. data/ext/sqlite3/database.h +7 -4
  15. data/ext/sqlite3/exception.c +111 -92
  16. data/ext/sqlite3/exception.h +3 -1
  17. data/ext/sqlite3/extconf.rb +21 -22
  18. data/ext/sqlite3/sqlite3.c +159 -115
  19. data/ext/sqlite3/sqlite3_ruby.h +2 -2
  20. data/ext/sqlite3/statement.c +516 -300
  21. data/ext/sqlite3/statement.h +3 -3
  22. data/ext/sqlite3/timespec.h +20 -0
  23. data/lib/sqlite3/constants.rb +171 -47
  24. data/lib/sqlite3/database.rb +106 -166
  25. data/lib/sqlite3/errors.rb +26 -1
  26. data/lib/sqlite3/pragmas.rb +126 -136
  27. data/lib/sqlite3/resultset.rb +14 -97
  28. data/lib/sqlite3/statement.rb +58 -13
  29. data/lib/sqlite3/value.rb +17 -20
  30. data/lib/sqlite3/version.rb +1 -21
  31. data/lib/sqlite3.rb +6 -4
  32. data/ports/archives/sqlite-autoconf-3460000.tar.gz +0 -0
  33. metadata +10 -35
  34. data/API_CHANGES.md +0 -49
  35. data/ChangeLog.cvs +0 -88
  36. data/Gemfile +0 -10
  37. data/LICENSE-DEPENDENCIES +0 -20
  38. data/lib/sqlite3/translator.rb +0 -117
  39. data/ports/archives/sqlite-autoconf-3450000.tar.gz +0 -0
  40. data/test/helper.rb +0 -27
  41. data/test/test_backup.rb +0 -33
  42. data/test/test_collation.rb +0 -82
  43. data/test/test_database.rb +0 -668
  44. data/test/test_database_flags.rb +0 -95
  45. data/test/test_database_readonly.rb +0 -36
  46. data/test/test_database_readwrite.rb +0 -41
  47. data/test/test_deprecated.rb +0 -49
  48. data/test/test_encoding.rb +0 -165
  49. data/test/test_integration.rb +0 -507
  50. data/test/test_integration_aggregate.rb +0 -336
  51. data/test/test_integration_open_close.rb +0 -30
  52. data/test/test_integration_pending.rb +0 -115
  53. data/test/test_integration_resultset.rb +0 -142
  54. data/test/test_integration_statement.rb +0 -194
  55. data/test/test_pragmas.rb +0 -22
  56. data/test/test_result_set.rb +0 -47
  57. data/test/test_sqlite3.rb +0 -30
  58. data/test/test_statement.rb +0 -290
  59. data/test/test_statement_execute.rb +0 -39
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 29f918d3ca102b856248a3c33ffa077b46f394aa548a26f69c7dd7ac5bc63d1c
4
- data.tar.gz: 676cc3802634e743b601717c6fbcf6c89bd269d58edfd45a65590f1667193c93
3
+ metadata.gz: f55003062c0de8516574697a3a8aa323c0ec16265c6fea50ab51012447ea3751
4
+ data.tar.gz: 4c176a14ff9f12850b9f2cb5ebc1b7141127076a25d7ce75fd36aa14514a5b98
5
5
  SHA512:
6
- metadata.gz: 5b764f248fe028c26968325e744b8d638b7491e1e960ec4791bc010c2a1b1d2a90874b3bc73b43fb593d4ef3236508cb90665d232226191e9002cd3e784d04a8
7
- data.tar.gz: '069640c56388fa759a879d79c3c4ac91c194ec8e312b89aad2659f74255d69ea0b870e17c5b4d164a76ef5df5af07a0e29e9243758ad68333dbddb1d33cd5cf8'
6
+ metadata.gz: a7f2b0891c6480a9cf2731ac8712cedcf15ffab08f2d2a68967cb9e1afc2a33e7d7501050d2056de74a069f65ae113e2e8bf195edb7f28dc010f8b6e70c2d795
7
+ data.tar.gz: aad1f26e943b7dd01543f86682b36a0f319fab42446501f747f2add4825d767eacf4efcb4f32d652e306d4ecd41ab2d4556501b7b3072361d9276fa99023a6d8
data/CHANGELOG.md CHANGED
@@ -1,10 +1,191 @@
1
1
  # sqlite3-ruby Changelog
2
2
 
3
+ ## 2.0.2 / 2024-05-23
4
+
5
+ ### Dependencies
6
+
7
+ - Vendored sqlite is updated to [v3.46.0](https://sqlite.org/releaselog/3_46_0.html) @flavorjones
8
+
9
+
10
+ ## 2.0.1 / 2024-04-20
11
+
12
+ ### Fixed
13
+
14
+ - 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
15
+ - 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
16
+
17
+
18
+ ## 2.0.0 / 2024-04-17
19
+
20
+ This is a major release which contains some breaking changes, primarily the removal of
21
+ long-deprecated functionality. Before upgrading, please make sure to address deprecation warnings
22
+ emitted from your application using sqlite3-ruby v1.7.x.
23
+
24
+
25
+ ### Ruby
26
+
27
+ - This release drops support for Ruby 2.7. [#453] @flavorjones
28
+
29
+
30
+ ### Packaging
31
+
32
+ Native (precompiled) gems are now available for Linux Musl. [#442] @flavorjones
33
+
34
+ Here are the platforms for which native gems are shipped:
35
+
36
+ - `aarch64-linux-gnu` (requires: glibc >= 2.29)
37
+ - `aarch64-linux-musl`
38
+ - `arm-linux-gnu` (requires: glibc >= 2.29)
39
+ - `arm-linux-musl`
40
+ - `arm64-darwin`
41
+ - `x64-mingw32` / `x64-mingw-ucrt`
42
+ - `x86-linux-gnu` (requires: glibc >= 2.17)
43
+ - `x86-linux-musl`
44
+ - `x86_64-darwin`
45
+ - `x86_64-linux-gnu` (requires: glibc >= 2.17)
46
+ - `x86_64-linux-musl`
47
+
48
+ ⚠ Ruby 3.0 linux users must use Rubygems >= 3.3.22 in order to use these gems.
49
+
50
+ ⚠ Musl linux users should update to Bundler >= 2.5.6 to avoid https://github.com/rubygems/rubygems/issues/7432
51
+
52
+ See [the INSTALLATION doc](https://github.com/sparklemotion/sqlite3-ruby/blob/main/INSTALLATION.md) for more information.
53
+
54
+
55
+ ### Dependencies
56
+
57
+ - Vendored sqlite is updated to [v3.45.3](https://sqlite.org/releaselog/3_45_3.html). @flavorjones
58
+
59
+
60
+ ### Added
61
+
62
+ - `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
63
+ - Support the `SUPER_JOURNAL` flag which is an alias for `MASTER_JOURNAL` as of sqlite 3.33.0. [#467] @flavorjones
64
+ - `Statement#stat` and `Statement#memused` introduced to report statistics. [#461] @fractaledmind
65
+ - `Statement#sql` and `Statement#expanded_sql` introduced to retrieve the SQL statement associated with the `Statement` object. [#293, #498] @tenderlove
66
+ - `SQLite3.status` introduced to return run-time status and reset high-water marks. See `SQLite3::Constants::Status` for details. [#520] @wjlroe
67
+
68
+
69
+ ### Improved
70
+
71
+ - Avoid leaking memory for statements that are not closed properly. [#392] @haileys
72
+ - Moved some C code into Ruby. [#451, #455] @tenderlove
73
+ - Improve performance of `ResultSet` hashes. [#154, #484, #468] @tenderlove
74
+ - Fix a GC compaction issue with `busy_handler`. [#466] @byroot
75
+ - Remove unused `ResultSet` instance variable. [#469] @tenderlove
76
+ - Fix encoding for values passed to custom functions. [#218, #488] @tenderlove
77
+
78
+
79
+ ### Changed
80
+
81
+ - 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
82
+ - `Database#columns` returns a list of internal frozen strings. [#155, #474, #486] @tenderlove
83
+ - Freeze results that come from the database. [#480] @tenderlove
84
+ - The encoding of a Database is no longer cached. [#485] @tenderlove
85
+ - `Database#transaction` returns the result of the block when used with a block. [#508] @alexcwatt
86
+ - `Database#execute_batch` returns the result of the last statement executed. [#512] @alexcwatt
87
+
88
+
89
+ ### Removed
90
+
91
+ - Removed class `SQLite3::Translator` and all related type translation methods which have been deprecated since v1.3.2. [#470] @tenderlove
92
+
93
+ If you need to do type translation on values returned from the statement object, please wrap it
94
+ with a delegate object. Here is an example of using a delegate class to implement type
95
+ translation:
96
+
97
+ ```ruby
98
+ require "sqlite3"
99
+ require "delegate"
100
+
101
+ db = SQLite3::Database.new(":memory:")
102
+
103
+ return_value = db.execute_batch2 <<-EOSQL
104
+ CREATE TABLE items (id integer PRIMARY KEY AUTOINCREMENT, name string);
105
+ INSERT INTO items (name) VALUES ("foo");
106
+ INSERT INTO items (name) VALUES ("bar");
107
+ EOSQL
108
+
109
+ class MyTranslator < DelegateClass(SQLite3::Statement)
110
+ def step
111
+ row = super
112
+ return if done?
113
+
114
+ row.map.with_index do |item, i|
115
+ case types[i]
116
+ when "integer" # turn all integers to floats
117
+ item.to_f
118
+ when "string" # add "hello" to all strings
119
+ item + "hello"
120
+ end
121
+ end
122
+ end
123
+ end
124
+
125
+ db.prepare("SELECT * FROM items") do |stmt|
126
+ stmt = MyTranslator.new(stmt)
127
+ while row = stmt.step
128
+ p row
129
+ end
130
+ end
131
+ ```
132
+
133
+ - Removed `types` and `fields` readers on row objects, which have been deprecated since
134
+ v1.3.6. [#471] @tenderlove
135
+
136
+ Deprecated code looks like this:
137
+
138
+ ```ruby
139
+ row = @db.execute("select * from foo")
140
+ assert_equal ["blob"], row.first.types
141
+ ```
142
+
143
+ If you would like to access the "types" associated with a returned query,
144
+ use a prepared statement like this:
145
+
146
+ ```ruby
147
+ @db.prepare("select * from foo") do |v|
148
+ assert_equal ["blob"], v.types
149
+ end
150
+ ```
151
+
152
+ - 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
153
+
154
+ Deprecated code looks like this:
155
+
156
+ ``` ruby
157
+ @db.query("select * from foo where a = ? and b = ? and c = ?", 1, 2, 3)
158
+ ```
159
+
160
+ For these cases, pass the bind parameters as an array:
161
+
162
+ ``` ruby
163
+ @db.query("select * from foo where a = ? and b = ? and c = ?", [1, 2, 3])
164
+ ```
165
+
166
+ - Removed class `SQLite3::VersionProxy` which has been deprecated since v1.3.2. [#453] @flavorjones
167
+ - Removed methods `SQLite3::Database::FunctionProxy#count` and `#set_error` which have been broken since at least v1.3.13. [#164, #509, #510] @alexcwatt @flavorjones
168
+
169
+
170
+ ## 1.7.3 / 2024-03-15
171
+
172
+ ### Dependencies
173
+
174
+ - Vendored sqlite is updated to [v3.45.2](https://www.sqlite.org/releaselog/3_45_2.html). @flavorjones
175
+
176
+
177
+ ## 1.7.2 / 2024-01-30
178
+
179
+ ### Dependencies
180
+
181
+ - Vendored sqlite is updated to [v3.45.1](https://www.sqlite.org/releaselog/3_45_1.html). @flavorjones
182
+
183
+
3
184
  ## 1.7.1 / 2024-01-24
4
185
 
5
186
  ### Dependencies
6
187
 
7
- - Vendored sqlite is update to [v3.45.0](https://www.sqlite.org/releaselog/3_45_0.html). @flavorjones
188
+ - Vendored sqlite is updated to [v3.45.0](https://www.sqlite.org/releaselog/3_45_0.html). @flavorjones
8
189
 
9
190
 
10
191
  ## 1.7.0 / 2023-12-27
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
+ ### Garbage collection
11
+
12
+ All statements keep pointers back to their respective database connections.
13
+ The `@connection` instance variable on the `Statement` handle keeps the database
14
+ connection alive. Memory allocated for a statement handler will be freed in
15
+ two cases:
16
+
17
+ 1. `#close` is called on the statement
18
+ 2. The `SQLite3::Database` object gets garbage collected
19
+
20
+ We can't free the memory for the statement in the garbage collection function
21
+ for the statement handler. The reason is because there exists a race
22
+ condition. We cannot guarantee the order in which objects will be garbage
23
+ collected. So, it is possible that a connection and a statement are up for
24
+ garbage collection. If the database connection were to be free'd before the
25
+ statement, then boom. Instead we'll be conservative and free unclosed
26
+ statements when the connection is terminated.
27
+
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.
@@ -26,7 +48,7 @@ Update `/dependencies.yml` to reflect:
26
48
  A quick checklist:
27
49
 
28
50
  - [ ] make sure CI is green!
29
- - [ ] update `CHANGELOG.md` and `lib/sqlite3/version.rb` including `VersionProxy::{MINOR,TINY}`
51
+ - [ ] update `CHANGELOG.md` and `lib/sqlite3/version.rb`
30
52
  - [ ] run `bin/build-gems` and make sure it completes and all the tests pass
31
53
  - [ ] create a git tag using a format that matches the pattern `v\d+\.\d+\.\d+`, e.g. `v1.3.13`
32
54
  - [ ] `git push && git push --tags`
data/FAQ.md CHANGED
@@ -289,49 +289,6 @@ by column name, even though they are still arrays!
289
289
  end
290
290
  ```
291
291
 
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
292
  ## How do I insert binary data into the database?
336
293
 
337
294
  Use blobs. Blobs are new features of SQLite3. You have to use bind
data/INSTALLATION.md CHANGED
@@ -7,15 +7,23 @@ 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
17
  - `x64-mingw32` / `x64-mingw-ucrt`
16
- - `x86-linux` (requires: glibc >= 2.17)
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
+ ⚠ Ruby 3.0 linux users must use Rubygems >= 3.3.22 in order to use these gems.
25
+
26
+ ⚠ Musl linux users should update to Bundler >= 2.5.6 to avoid https://github.com/rubygems/rubygems/issues/7432
19
27
 
20
28
  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
29
 
@@ -57,6 +65,8 @@ If you are on a platform or version of Ruby that is not covered by the Native Ge
57
65
 
58
66
  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
67
 
68
+ ⚠ A prerequisite to build the gem with the packaged sqlite3 is that you must have `pkgconf` installed.
69
+
60
70
  For example, on a linux system running Ruby 2.5:
61
71
 
62
72
  ``` 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.
data/README.md CHANGED
@@ -11,8 +11,7 @@ Note that this module is only compatible with SQLite 3.6.16 or newer.
11
11
  * Download: http://rubygems.org/gems/sqlite3
12
12
  * Documentation: http://www.rubydoc.info/gems/sqlite3
13
13
 
14
- [![Unit tests](https://github.com/sparklemotion/sqlite3-ruby/actions/workflows/sqlite3-ruby.yml/badge.svg)](https://github.com/sparklemotion/sqlite3-ruby/actions/workflows/sqlite3-ruby.yml)
15
- [![Native packages](https://github.com/sparklemotion/sqlite3-ruby/actions/workflows/gem-install.yml/badge.svg)](https://github.com/sparklemotion/sqlite3-ruby/actions/workflows/gem-install.yml)
14
+ [![Test suite](https://github.com/sparklemotion/sqlite3-ruby/actions/workflows/ci.yml/badge.svg)](https://github.com/sparklemotion/sqlite3-ruby/actions/workflows/ci.yml)
16
15
 
17
16
 
18
17
  ## Quick start
@@ -77,6 +76,78 @@ end
77
76
  # => ["Jane", "me@janedoe.com", "A", "http://blog.janedoe.com"]
78
77
  ```
79
78
 
79
+ ## Thread Safety
80
+
81
+ When `SQLite3.threadsafe?` returns `true`, then SQLite3 has been compiled to
82
+ support running in a multithreaded environment. However, this doesn't mean
83
+ that all classes in the SQLite3 gem can be considered "thread safe".
84
+
85
+ When `SQLite3.threadsafe?` returns `true`, it is safe to share only
86
+ `SQLite3::Database` instances among threads without providing your own locking
87
+ mechanism. For example, the following code is fine because only the database
88
+ instance is shared among threads:
89
+
90
+ ```ruby
91
+ require 'sqlite3'
92
+
93
+ db = SQLite3::Database.new ":memory:"
94
+
95
+ latch = Queue.new
96
+
97
+ ts = 10.times.map {
98
+ Thread.new {
99
+ latch.pop
100
+ db.execute "SELECT '#{Thread.current.inspect}'"
101
+ }
102
+ }
103
+ 10.times { latch << nil }
104
+
105
+ p ts.map(&:value)
106
+ ```
107
+
108
+ Other instances can be shared among threads, but they require that you provide
109
+ your own locking for thread safety. For example, `SQLite3::Statement` objects
110
+ (prepared statements) are mutable, so applications must take care to add
111
+ appropriate locks to avoid data race conditions when sharing these objects
112
+ among threads.
113
+
114
+ Lets rewrite the above example but use a prepared statement and safely share
115
+ the prepared statement among threads:
116
+
117
+ ```ruby
118
+ db = SQLite3::Database.new ":memory:"
119
+
120
+ # Prepare a statement
121
+ stmt = db.prepare "SELECT :inspect"
122
+ stmt_lock = Mutex.new
123
+
124
+ latch = Queue.new
125
+
126
+ ts = 10.times.map {
127
+ Thread.new {
128
+ latch.pop
129
+
130
+ # Add a lock when using the prepared statement.
131
+ # Binding values, and walking over results will mutate the statement, so
132
+ # in order to prevent other threads from "seeing" this thread's data, we
133
+ # must lock when using the statement object
134
+ stmt_lock.synchronize do
135
+ stmt.execute(Thread.current.inspect).to_a
136
+ end
137
+ }
138
+ }
139
+
140
+ 10.times { latch << nil }
141
+
142
+ p ts.map(&:value)
143
+
144
+ stmt.close
145
+ ```
146
+
147
+ It is generally recommended that if applications want to share a database among
148
+ threads, they _only_ share the database instance object. Other objects are
149
+ fine to share, but may require manual locking for thread safety.
150
+
80
151
  ## Support
81
152
 
82
153
  ### Installation or database extensions
@@ -104,7 +175,7 @@ See [`CONTRIBUTING.md`](./CONTRIBUTING.md).
104
175
 
105
176
  This library is licensed under `BSD-3-Clause`, see [`LICENSE`](./LICENSE).
106
177
 
107
-
108
178
  ### Dependencies
109
179
 
110
- The source code of `sqlite` is distributed in the "ruby platform" gem. This code is public domain, see [`LICENSE-DEPENDENCIES`](./LICENSE-DEPENDENCIES) for details.
180
+ The source code of `sqlite` is distributed in the "ruby platform" gem. This code is public domain,
181
+ see https://www.sqlite.org/copyright.html for details.
data/dependencies.yml CHANGED
@@ -1,14 +1,13 @@
1
- # TODO: stop using symbols here once we no longer support Ruby 2.7 and can rely on symbolize_names
2
- :sqlite3:
1
+ sqlite3:
3
2
  # checksum verified by first checking the published sha3(256) checksum against https://sqlite.org/download.html:
4
- # 9fc2a78088875ae7c112957d58ccc52b1a0a4afa34ac669290be42f352b1aa76
3
+ # 83d2acf79453deb7d6520338b1f4585f12e39b27cd370fb08593afa198f471fc
5
4
  #
6
- # $ sha3sum -a 256 ports/archives/sqlite-autoconf-3450000.tar.gz
7
- # 9fc2a78088875ae7c112957d58ccc52b1a0a4afa34ac669290be42f352b1aa76 ports/archives/sqlite-autoconf-3450000.tar.gz
5
+ # $ sha3sum -a 256 ports/archives/sqlite-autoconf-3460000.tar.gz
6
+ # 83d2acf79453deb7d6520338b1f4585f12e39b27cd370fb08593afa198f471fc ports/archives/sqlite-autoconf-3460000.tar.gz
8
7
  #
9
- # $ sha256sum ports/archives/sqlite-autoconf-3450000.tar.gz
10
- # 72887d57a1d8f89f52be38ef84a6353ce8c3ed55ada7864eb944abd9a495e436 ports/archives/sqlite-autoconf-3450000.tar.gz
11
- :version: "3.45.0"
12
- :files:
13
- - :url: "https://sqlite.org/2024/sqlite-autoconf-3450000.tar.gz"
14
- :sha256: "72887d57a1d8f89f52be38ef84a6353ce8c3ed55ada7864eb944abd9a495e436"
8
+ # $ sha256sum ports/archives/sqlite-autoconf-3460000.tar.gz
9
+ # 6f8e6a7b335273748816f9b3b62bbdc372a889de8782d7f048c653a447417a7d ports/archives/sqlite-autoconf-3460000.tar.gz
10
+ version: "3.46.0"
11
+ files:
12
+ - url: "https://sqlite.org/2024/sqlite-autoconf-3460000.tar.gz"
13
+ sha256: "6f8e6a7b335273748816f9b3b62bbdc372a889de8782d7f048c653a447417a7d"