sqlite3 1.7.3-x64-mingw32 → 2.0.0-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +152 -0
- data/CONTRIBUTING.md +23 -1
- data/FAQ.md +0 -43
- data/INSTALLATION.md +13 -5
- data/LICENSE +18 -22
- data/README.md +75 -4
- data/dependencies.yml +10 -11
- data/ext/sqlite3/aggregator.c +142 -145
- data/ext/sqlite3/aggregator.h +2 -4
- data/ext/sqlite3/backup.c +74 -65
- data/ext/sqlite3/backup.h +2 -2
- data/ext/sqlite3/database.c +535 -482
- data/ext/sqlite3/database.h +7 -4
- data/ext/sqlite3/exception.c +111 -92
- data/ext/sqlite3/exception.h +3 -1
- data/ext/sqlite3/extconf.rb +21 -22
- data/ext/sqlite3/sqlite3.c +159 -115
- data/ext/sqlite3/sqlite3_ruby.h +2 -2
- data/ext/sqlite3/statement.c +516 -300
- data/ext/sqlite3/statement.h +3 -3
- data/ext/sqlite3/timespec.h +20 -0
- data/lib/sqlite3/3.0/sqlite3_native.so +0 -0
- data/lib/sqlite3/constants.rb +171 -47
- data/lib/sqlite3/database.rb +105 -165
- data/lib/sqlite3/errors.rb +26 -1
- data/lib/sqlite3/pragmas.rb +126 -136
- data/lib/sqlite3/resultset.rb +14 -97
- data/lib/sqlite3/statement.rb +58 -13
- data/lib/sqlite3/value.rb +17 -20
- data/lib/sqlite3/version.rb +1 -21
- data/lib/sqlite3.rb +6 -4
- metadata +3 -28
- data/API_CHANGES.md +0 -49
- data/ChangeLog.cvs +0 -88
- data/Gemfile +0 -10
- data/LICENSE-DEPENDENCIES +0 -20
- data/lib/sqlite3/translator.rb +0 -117
- data/test/helper.rb +0 -27
- data/test/test_backup.rb +0 -33
- data/test/test_collation.rb +0 -82
- data/test/test_database.rb +0 -668
- data/test/test_database_flags.rb +0 -95
- data/test/test_database_readonly.rb +0 -36
- data/test/test_database_readwrite.rb +0 -41
- data/test/test_deprecated.rb +0 -49
- data/test/test_encoding.rb +0 -165
- data/test/test_integration.rb +0 -507
- data/test/test_integration_aggregate.rb +0 -336
- data/test/test_integration_open_close.rb +0 -30
- data/test/test_integration_pending.rb +0 -115
- data/test/test_integration_resultset.rb +0 -142
- data/test/test_integration_statement.rb +0 -194
- data/test/test_pragmas.rb +0 -22
- data/test/test_result_set.rb +0 -47
- data/test/test_sqlite3.rb +0 -30
- data/test/test_statement.rb +0 -290
- data/test/test_statement_execute.rb +0 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9dad5eecb43e93776faafdfd313df1c56c08a87292595606036a9f1f94bf5cd2
|
4
|
+
data.tar.gz: 789ad885536608c9f0c58a85ff8310a8fb63224856aefe0487244f6ddbf4cd1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b945b7f84838567cc387c34cb588ae09e0413dc5db831cdace01a8e436a20cb0a25e4734e90371373590be564fb08a034fa4f7320b4fb8b81b0e3a9889c6f94
|
7
|
+
data.tar.gz: 0a72ca5ee06487ef46e8e802a5d43db665913d2d3b4a019a4d136d4b8061c0bf34e7b40d603ed8c91af6cdf31f71bf8a1670fd552dc0d14a22938f0b21166f28
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,157 @@
|
|
1
1
|
# sqlite3-ruby Changelog
|
2
2
|
|
3
|
+
## 2.0.0 / 2024-04-17
|
4
|
+
|
5
|
+
This is a major release which contains some breaking changes, primarily the removal of
|
6
|
+
long-deprecated functionality. Before upgrading, please make sure to address deprecation warnings
|
7
|
+
emitted from your application using sqlite3-ruby v1.7.x.
|
8
|
+
|
9
|
+
|
10
|
+
### Ruby
|
11
|
+
|
12
|
+
- This release drops support for Ruby 2.7. [#453] @flavorjones
|
13
|
+
|
14
|
+
|
15
|
+
### Packaging
|
16
|
+
|
17
|
+
Native (precompiled) gems are now available for Linux Musl. [#442] @flavorjones
|
18
|
+
|
19
|
+
Here are the platforms for which native gems are shipped:
|
20
|
+
|
21
|
+
- `aarch64-linux-gnu` (requires: glibc >= 2.29)
|
22
|
+
- `aarch64-linux-musl`
|
23
|
+
- `arm-linux-gnu` (requires: glibc >= 2.29)
|
24
|
+
- `arm-linux-musl`
|
25
|
+
- `arm64-darwin`
|
26
|
+
- `x64-mingw32` / `x64-mingw-ucrt`
|
27
|
+
- `x86-linux-gnu` (requires: glibc >= 2.17)
|
28
|
+
- `x86-linux-musl`
|
29
|
+
- `x86_64-darwin`
|
30
|
+
- `x86_64-linux-gnu` (requires: glibc >= 2.17)
|
31
|
+
- `x86_64-linux-musl`
|
32
|
+
|
33
|
+
⚠ Ruby 3.0 linux users must use Rubygems >= 3.3.22 in order to use these gems.
|
34
|
+
|
35
|
+
⚠ Musl linux users should update to Bundler >= 2.5.6 to avoid https://github.com/rubygems/rubygems/issues/7432
|
36
|
+
|
37
|
+
See [the INSTALLATION doc](https://github.com/sparklemotion/sqlite3-ruby/blob/main/INSTALLATION.md) for more information.
|
38
|
+
|
39
|
+
|
40
|
+
### Dependencies
|
41
|
+
|
42
|
+
- Vendored sqlite is updated to [v3.45.3](https://sqlite.org/releaselog/3_45_3.html). @flavorjones
|
43
|
+
|
44
|
+
|
45
|
+
### Added
|
46
|
+
|
47
|
+
- `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
|
48
|
+
- Support the `SUPER_JOURNAL` flag which is an alias for `MASTER_JOURNAL` as of sqlite 3.33.0. [#467] @flavorjones
|
49
|
+
- `Statement#stat` and `Statement#memused` introduced to report statistics. [#461] @fractaledmind
|
50
|
+
- `Statement#sql` and `Statement#expanded_sql` introduced to retrieve the SQL statement associated with the `Statement` object. [#293, #498] @tenderlove
|
51
|
+
- `SQLite3.status` introduced to return run-time status and reset high-water marks. See `SQLite3::Constants::Status` for details. [#520] @wjlroe
|
52
|
+
|
53
|
+
|
54
|
+
### Improved
|
55
|
+
|
56
|
+
- Avoid leaking memory for statements that are not closed properly. [#392] @haileys
|
57
|
+
- Moved some C code into Ruby. [#451, #455] @tenderlove
|
58
|
+
- Improve performance of `ResultSet` hashes. [#154, #484, #468] @tenderlove
|
59
|
+
- Fix a GC compaction issue with `busy_handler`. [#466] @byroot
|
60
|
+
- Remove unused `ResultSet` instance variable. [#469] @tenderlove
|
61
|
+
- Fix encoding for values passed to custom functions. [#218, #488] @tenderlove
|
62
|
+
|
63
|
+
|
64
|
+
### Changed
|
65
|
+
|
66
|
+
- 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
|
67
|
+
- `Database#columns` returns a list of internal frozen strings. [#155, #474, #486] @tenderlove
|
68
|
+
- Freeze results that come from the database. [#480] @tenderlove
|
69
|
+
- The encoding of a Database is no longer cached. [#485] @tenderlove
|
70
|
+
- `Database#transaction` returns the result of the block when used with a block. [#508] @alexcwatt
|
71
|
+
- `Database#execute_batch` returns the result of the last statement executed. [#512] @alexcwatt
|
72
|
+
|
73
|
+
|
74
|
+
### Removed
|
75
|
+
|
76
|
+
- Removed class `SQLite3::Translator` and all related type translation methods which have been deprecated since v1.3.2. [#470] @tenderlove
|
77
|
+
|
78
|
+
If you need to do type translation on values returned from the statement object, please wrap it
|
79
|
+
with a delegate object. Here is an example of using a delegate class to implement type
|
80
|
+
translation:
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
require "sqlite3"
|
84
|
+
require "delegate"
|
85
|
+
|
86
|
+
db = SQLite3::Database.new(":memory:")
|
87
|
+
|
88
|
+
return_value = db.execute_batch2 <<-EOSQL
|
89
|
+
CREATE TABLE items (id integer PRIMARY KEY AUTOINCREMENT, name string);
|
90
|
+
INSERT INTO items (name) VALUES ("foo");
|
91
|
+
INSERT INTO items (name) VALUES ("bar");
|
92
|
+
EOSQL
|
93
|
+
|
94
|
+
class MyTranslator < DelegateClass(SQLite3::Statement)
|
95
|
+
def step
|
96
|
+
row = super
|
97
|
+
return if done?
|
98
|
+
|
99
|
+
row.map.with_index do |item, i|
|
100
|
+
case types[i]
|
101
|
+
when "integer" # turn all integers to floats
|
102
|
+
item.to_f
|
103
|
+
when "string" # add "hello" to all strings
|
104
|
+
item + "hello"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
db.prepare("SELECT * FROM items") do |stmt|
|
111
|
+
stmt = MyTranslator.new(stmt)
|
112
|
+
while row = stmt.step
|
113
|
+
p row
|
114
|
+
end
|
115
|
+
end
|
116
|
+
```
|
117
|
+
|
118
|
+
- Removed `types` and `fields` readers on row objects, which have been deprecated since
|
119
|
+
v1.3.6. [#471] @tenderlove
|
120
|
+
|
121
|
+
Deprecated code looks like this:
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
row = @db.execute("select * from foo")
|
125
|
+
assert_equal ["blob"], row.first.types
|
126
|
+
```
|
127
|
+
|
128
|
+
If you would like to access the "types" associated with a returned query,
|
129
|
+
use a prepared statement like this:
|
130
|
+
|
131
|
+
```ruby
|
132
|
+
@db.prepare("select * from foo") do |v|
|
133
|
+
assert_equal ["blob"], v.types
|
134
|
+
end
|
135
|
+
```
|
136
|
+
|
137
|
+
- 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
|
138
|
+
|
139
|
+
Deprecated code looks like this:
|
140
|
+
|
141
|
+
``` ruby
|
142
|
+
@db.query("select * from foo where a = ? and b = ? and c = ?", 1, 2, 3)
|
143
|
+
```
|
144
|
+
|
145
|
+
For these cases, pass the bind parameters as an array:
|
146
|
+
|
147
|
+
``` ruby
|
148
|
+
@db.query("select * from foo where a = ? and b = ? and c = ?", [1, 2, 3])
|
149
|
+
```
|
150
|
+
|
151
|
+
- Removed class `SQLite3::VersionProxy` which has been deprecated since v1.3.2. [#453] @flavorjones
|
152
|
+
- Removed methods `SQLite3::Database::FunctionProxy#count` and `#set_error` which have been broken since at least v1.3.13. [#164, #509, #510] @alexcwatt @flavorjones
|
153
|
+
|
154
|
+
|
3
155
|
## 1.7.3 / 2024-03-15
|
4
156
|
|
5
157
|
### 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
|
+
### 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`
|
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
|
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
|
-
- `
|
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
|
|
data/LICENSE
CHANGED
@@ -1,27 +1,23 @@
|
|
1
|
-
Copyright (c) 2004, Jamis Buck
|
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
|
-
|
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
|
-
|
8
|
-
|
6
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions
|
7
|
+
and the following disclaimer.
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
15
|
-
|
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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
-
[![
|
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,
|
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
|
-
|
2
|
-
:sqlite3:
|
1
|
+
sqlite3:
|
3
2
|
# checksum verified by first checking the published sha3(256) checksum against https://sqlite.org/download.html:
|
4
|
-
#
|
3
|
+
# cc1050780e0266de4d91b31c8deaf4638336908c12c21898e9f1fcae1e2ac303
|
5
4
|
#
|
6
|
-
# $ sha3sum -a 256 ports/archives/sqlite-autoconf-
|
7
|
-
#
|
5
|
+
# $ sha3sum -a 256 ports/archives/sqlite-autoconf-3450300.tar.gz
|
6
|
+
# cc1050780e0266de4d91b31c8deaf4638336908c12c21898e9f1fcae1e2ac303 ports/archives/sqlite-autoconf-3450300.tar.gz
|
8
7
|
#
|
9
|
-
# $ sha256sum ports/archives/sqlite-autoconf-
|
10
|
-
#
|
11
|
-
|
12
|
-
|
13
|
-
-
|
14
|
-
|
8
|
+
# $ sha256sum ports/archives/sqlite-autoconf-3450300.tar.gz
|
9
|
+
# b2809ca53124c19c60f42bf627736eae011afdcc205bb48270a5ee9a38191531 ports/archives/sqlite-autoconf-3450300.tar.gz
|
10
|
+
version: "3.45.3"
|
11
|
+
files:
|
12
|
+
- url: "https://sqlite.org/2024/sqlite-autoconf-3450300.tar.gz"
|
13
|
+
sha256: "b2809ca53124c19c60f42bf627736eae011afdcc205bb48270a5ee9a38191531"
|