sqlite3 1.5.0 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +390 -0
- data/CONTRIBUTING.md +34 -2
- data/{faq/faq.md → FAQ.md} +0 -43
- data/INSTALLATION.md +269 -0
- data/LICENSE +18 -22
- data/README.md +76 -128
- data/dependencies.yml +13 -0
- data/ext/sqlite3/aggregator.c +142 -146
- data/ext/sqlite3/aggregator.h +2 -4
- data/ext/sqlite3/backup.c +86 -64
- data/ext/sqlite3/backup.h +2 -2
- data/ext/sqlite3/database.c +543 -465
- data/ext/sqlite3/database.h +9 -4
- data/ext/sqlite3/exception.c +111 -92
- data/ext/sqlite3/exception.h +3 -1
- data/ext/sqlite3/extconf.rb +83 -51
- data/ext/sqlite3/sqlite3.c +160 -115
- data/ext/sqlite3/sqlite3_ruby.h +2 -2
- data/ext/sqlite3/statement.c +518 -293
- data/ext/sqlite3/statement.h +3 -3
- data/ext/sqlite3/timespec.h +20 -0
- data/lib/sqlite3/constants.rb +171 -47
- data/lib/sqlite3/database.rb +141 -181
- data/lib/sqlite3/errors.rb +26 -1
- data/lib/sqlite3/pragmas.rb +128 -138
- data/lib/sqlite3/resultset.rb +14 -105
- 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
- data/ports/archives/sqlite-autoconf-3460000.tar.gz +0 -0
- metadata +19 -107
- data/API_CHANGES.md +0 -49
- data/ChangeLog.cvs +0 -88
- data/Gemfile +0 -3
- data/LICENSE-DEPENDENCIES +0 -20
- data/faq/faq.rb +0 -145
- data/faq/faq.yml +0 -426
- data/lib/sqlite3/translator.rb +0 -118
- data/ports/archives/sqlite-autoconf-3380500.tar.gz +0 -0
- 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 -545
- 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 -44
- data/test/test_encoding.rb +0 -155
- 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_result_set.rb +0 -37
- data/test/test_sqlite3.rb +0 -30
- data/test/test_statement.rb +0 -263
- data/test/test_statement_execute.rb +0 -35
data/INSTALLATION.md
ADDED
@@ -0,0 +1,269 @@
|
|
1
|
+
|
2
|
+
# Installation and Using SQLite3 extensions
|
3
|
+
|
4
|
+
This document will help you install the `sqlite3` ruby gem. It also contains instructions on loading database extensions and building against drop-in replacements for sqlite3.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
### Native Gems (recommended)
|
9
|
+
|
10
|
+
In v2.0.0 and later, native (precompiled) gems are available for recent Ruby versions on these platforms:
|
11
|
+
|
12
|
+
- `aarch64-linux-gnu` (requires: glibc >= 2.29)
|
13
|
+
- `aarch64-linux-musl`
|
14
|
+
- `arm-linux-gnu` (requires: glibc >= 2.29)
|
15
|
+
- `arm-linux-musl`
|
16
|
+
- `arm64-darwin`
|
17
|
+
- `x64-mingw32` / `x64-mingw-ucrt`
|
18
|
+
- `x86-linux-gnu` (requires: glibc >= 2.17)
|
19
|
+
- `x86-linux-musl`
|
20
|
+
- `x86_64-darwin`
|
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
|
27
|
+
|
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.
|
29
|
+
|
30
|
+
For example, on a linux system running Ruby 3.1:
|
31
|
+
|
32
|
+
``` text
|
33
|
+
$ ruby -v
|
34
|
+
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux]
|
35
|
+
|
36
|
+
$ time gem install sqlite3
|
37
|
+
Fetching sqlite3-1.5.0-x86_64-linux.gem
|
38
|
+
Successfully installed sqlite3-1.5.0-x86_64-linux
|
39
|
+
1 gem installed
|
40
|
+
|
41
|
+
real 0m4.274s
|
42
|
+
user 0m0.734s
|
43
|
+
sys 0m0.165s
|
44
|
+
```
|
45
|
+
|
46
|
+
#### Avoiding the precompiled native gem
|
47
|
+
|
48
|
+
The maintainers strongly urge you to use a native gem if at all possible. It will be a better experience for you and allow us to focus our efforts on improving functionality rather than diagnosing installation issues.
|
49
|
+
|
50
|
+
If you're on a platform that supports a native gem but you want to avoid using it in your project, do one of the following:
|
51
|
+
|
52
|
+
- If you're not using Bundler, then run `gem install sqlite3 --platform=ruby`
|
53
|
+
- If you are using Bundler
|
54
|
+
- version 2.3.18 or later, you can specify [`gem "sqlite3", force_ruby_platform: true`](https://bundler.io/v2.3/man/gemfile.5.html#FORCE_RUBY_PLATFORM)
|
55
|
+
- version 2.1 or later, then you'll need to run `bundle config set force_ruby_platform true`
|
56
|
+
- version 2.0 or earlier, then you'll need to run `bundle config force_ruby_platform true`
|
57
|
+
|
58
|
+
|
59
|
+
### Compiling the source gem
|
60
|
+
|
61
|
+
If you are on a platform or version of Ruby that is not covered by the Native Gems, then the vanilla "ruby platform" (non-native) gem will be installed by the `gem install` or `bundle` commands.
|
62
|
+
|
63
|
+
|
64
|
+
#### Packaged libsqlite3
|
65
|
+
|
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.
|
67
|
+
|
68
|
+
⚠ A prerequisite to build the gem with the packaged sqlite3 is that you must have `pkgconf` installed.
|
69
|
+
|
70
|
+
For example, on a linux system running Ruby 2.5:
|
71
|
+
|
72
|
+
``` text
|
73
|
+
$ ruby -v
|
74
|
+
ruby 2.5.9p229 (2021-04-05 revision 67939) [x86_64-linux]
|
75
|
+
|
76
|
+
$ time gem install sqlite3
|
77
|
+
Building native extensions. This could take a while...
|
78
|
+
Successfully installed sqlite3-1.5.0
|
79
|
+
1 gem installed
|
80
|
+
|
81
|
+
real 0m20.620s
|
82
|
+
user 0m23.361s
|
83
|
+
sys 0m5.839s
|
84
|
+
```
|
85
|
+
|
86
|
+
##### Controlling compilation flags for sqlite
|
87
|
+
|
88
|
+
Upstream sqlite allows for the setting of some parameters at compile time. If you're an expert and would like to set these, you may do so at gem install time in two different ways ...
|
89
|
+
|
90
|
+
**If you're installing the gem using `gem install`** then you can pass in these compile-time flags like this:
|
91
|
+
|
92
|
+
``` sh
|
93
|
+
gem install sqlite3 --platform=ruby -- \
|
94
|
+
--with-sqlite-cflags="-DSQLITE_DEFAULT_CACHE_SIZE=9999 -DSQLITE_DEFAULT_PAGE_SIZE=4444"
|
95
|
+
```
|
96
|
+
|
97
|
+
or the equivalent:
|
98
|
+
|
99
|
+
``` sh
|
100
|
+
CFLAGS="-DSQLITE_DEFAULT_CACHE_SIZE=9999 -DSQLITE_DEFAULT_PAGE_SIZE=4444" \
|
101
|
+
gem install sqlite3 --platform=ruby
|
102
|
+
```
|
103
|
+
|
104
|
+
**If you're installing the gem using `bundler`** then you should first pin the gem to the "ruby" platform gem, so that you are compiling from source:
|
105
|
+
|
106
|
+
``` ruby
|
107
|
+
# Gemfile
|
108
|
+
gem "sqlite3", force_ruby_platform: true # requires bundler >= 2.3.18
|
109
|
+
```
|
110
|
+
|
111
|
+
and then set up a bundler config parameter for `build.sqlite3`:
|
112
|
+
|
113
|
+
``` sh
|
114
|
+
bundle config set build.sqlite3 \
|
115
|
+
"--with-sqlite-cflags='-DSQLITE_DEFAULT_CACHE_SIZE=9999 -DSQLITE_DEFAULT_PAGE_SIZE=4444'"
|
116
|
+
```
|
117
|
+
|
118
|
+
NOTE the use of single quotes within the double-quoted string to ensure the space between compiler flags is interpreted correctly. The contents of your `.bundle/config` file should look like:
|
119
|
+
|
120
|
+
``` yaml
|
121
|
+
---
|
122
|
+
BUNDLE_BUILD__SQLITE3: "--with-sqlite-cflags='-DSQLITE_DEFAULT_CACHE_SIZE=9999 -DSQLITE_DEFAULT_PAGE_SIZE=4444'"
|
123
|
+
```
|
124
|
+
|
125
|
+
|
126
|
+
#### System libsqlite3
|
127
|
+
|
128
|
+
If you would prefer to build the sqlite3-ruby gem against your system libsqlite3, which requires that you install libsqlite3 and its development files yourself, you may do so by using the `--enable-system-libraries` flag at gem install time.
|
129
|
+
|
130
|
+
PLEASE NOTE:
|
131
|
+
|
132
|
+
- you must avoid installing a precompiled native gem (see [previous section](#avoiding-the-precompiled-native-gem))
|
133
|
+
- only versions of libsqlite3 `>= 3.5.0` are supported,
|
134
|
+
- and some library features may depend on how your libsqlite3 was compiled.
|
135
|
+
|
136
|
+
For example, on a linux system running Ruby 2.5:
|
137
|
+
|
138
|
+
``` text
|
139
|
+
$ time gem install sqlite3 -- --enable-system-libraries
|
140
|
+
Building native extensions with: '--enable-system-libraries'
|
141
|
+
This could take a while...
|
142
|
+
Successfully installed sqlite3-1.5.0
|
143
|
+
1 gem installed
|
144
|
+
|
145
|
+
real 0m4.234s
|
146
|
+
user 0m3.809s
|
147
|
+
sys 0m0.912s
|
148
|
+
```
|
149
|
+
|
150
|
+
If you're using bundler, you can opt into system libraries like this:
|
151
|
+
|
152
|
+
``` sh
|
153
|
+
bundle config build.sqlite3 --enable-system-libraries
|
154
|
+
```
|
155
|
+
|
156
|
+
If you have sqlite3 installed in a non-standard location, you may need to specify the location of the include and lib files by using `--with-sqlite-include` and `--with-sqlite-lib` options (or a `--with-sqlite-dir` option, see [MakeMakefile#dir_config](https://ruby-doc.org/stdlib-3.1.1/libdoc/mkmf/rdoc/MakeMakefile.html#method-i-dir_config)). If you have pkg-config installed and configured properly, this may not be necessary.
|
157
|
+
|
158
|
+
``` sh
|
159
|
+
gem install sqlite3 -- \
|
160
|
+
--enable-system-libraries \
|
161
|
+
--with-sqlite3-include=/opt/local/include \
|
162
|
+
--with-sqlite3-lib=/opt/local/lib
|
163
|
+
```
|
164
|
+
|
165
|
+
|
166
|
+
#### System libsqlcipher
|
167
|
+
|
168
|
+
If you'd like to link against a system-installed libsqlcipher, you may do so by using the `--with-sqlcipher` flag:
|
169
|
+
|
170
|
+
``` text
|
171
|
+
$ time gem install sqlite3 -- --with-sqlcipher
|
172
|
+
Building native extensions with: '--with-sqlcipher'
|
173
|
+
This could take a while...
|
174
|
+
Successfully installed sqlite3-1.5.0
|
175
|
+
1 gem installed
|
176
|
+
|
177
|
+
real 0m4.772s
|
178
|
+
user 0m3.906s
|
179
|
+
sys 0m0.896s
|
180
|
+
```
|
181
|
+
|
182
|
+
If you have sqlcipher installed in a non-standard location, you may need to specify the location of the include and lib files by using `--with-sqlite-include` and `--with-sqlite-lib` options (or a `--with-sqlite-dir` option, see [MakeMakefile#dir_config](https://ruby-doc.org/stdlib-3.1.1/libdoc/mkmf/rdoc/MakeMakefile.html#method-i-dir_config)). If you have pkg-config installed and configured properly, this may not be necessary.
|
183
|
+
|
184
|
+
|
185
|
+
## Using SQLite3 extensions
|
186
|
+
|
187
|
+
### How do I load a sqlite extension?
|
188
|
+
|
189
|
+
Some add-ons are available to sqlite as "extensions". The instructions that upstream sqlite provides at https://www.sqlite.org/loadext.html are the canonical source of advice, but here's a brief example showing how you can do this with the `sqlite3` ruby gem.
|
190
|
+
|
191
|
+
In this example, I'll be loading the ["spellfix" extension](https://www.sqlite.org/spellfix1.html):
|
192
|
+
|
193
|
+
``` text
|
194
|
+
# download spellfix.c from somewherehttp://www.sqlite.org/src/finfo?name=ext/misc/spellfix.c
|
195
|
+
$ wget https://raw.githubusercontent.com/sqlite/sqlite/master/ext/misc/spellfix.c
|
196
|
+
spellfix.c 100%[=================================================>] 100.89K --.-KB/s in 0.09s
|
197
|
+
|
198
|
+
# follow instructions at https://www.sqlite.org/loadext.html
|
199
|
+
# (you will need sqlite3 development packages for this)
|
200
|
+
$ gcc -g -fPIC -shared spellfix.c -o spellfix.o
|
201
|
+
|
202
|
+
$ ls -lt
|
203
|
+
total 192
|
204
|
+
-rwxrwxr-x 1 flavorjones flavorjones 87984 2023-05-24 10:44 spellfix.o
|
205
|
+
-rw-rw-r-- 1 flavorjones flavorjones 103310 2023-05-24 10:43 spellfix.c
|
206
|
+
```
|
207
|
+
|
208
|
+
Then, in your application, use that `spellfix.o` file like this:
|
209
|
+
|
210
|
+
``` ruby
|
211
|
+
require "sqlite3"
|
212
|
+
|
213
|
+
db = SQLite3::Database.new(':memory:')
|
214
|
+
db.enable_load_extension(true)
|
215
|
+
db.load_extension("/path/to/sqlite/spellfix.o")
|
216
|
+
db.execute("CREATE VIRTUAL TABLE demo USING spellfix1;")
|
217
|
+
```
|
218
|
+
|
219
|
+
### How do I use my own sqlite3 shared library?
|
220
|
+
|
221
|
+
Some folks have strong opinions about what features they want compiled into sqlite3; or may be using a package like SQLite Encryption Extension ("SEE"). This section will explain how to get your Ruby application to load that specific shared library.
|
222
|
+
|
223
|
+
If you've installed your alternative as an autotools-style installation, the directory structure will look like this:
|
224
|
+
|
225
|
+
```
|
226
|
+
/opt/sqlite3
|
227
|
+
├── bin
|
228
|
+
│ └── sqlite3
|
229
|
+
├── include
|
230
|
+
│ ├── sqlite3.h
|
231
|
+
│ └── sqlite3ext.h
|
232
|
+
├── lib
|
233
|
+
│ ├── libsqlite3.a
|
234
|
+
│ ├── libsqlite3.la
|
235
|
+
│ ├── libsqlite3.so -> libsqlite3.so.0.8.6
|
236
|
+
│ ├── libsqlite3.so.0 -> libsqlite3.so.0.8.6
|
237
|
+
│ ├── libsqlite3.so.0.8.6
|
238
|
+
│ └── pkgconfig
|
239
|
+
│ └── sqlite3.pc
|
240
|
+
└── share
|
241
|
+
└── man
|
242
|
+
└── man1
|
243
|
+
└── sqlite3.1
|
244
|
+
```
|
245
|
+
|
246
|
+
You can build this gem against that library like this:
|
247
|
+
|
248
|
+
```
|
249
|
+
gem install sqlite3 --platform=ruby -- \
|
250
|
+
--enable-system-libraries \
|
251
|
+
--with-opt-dir=/opt/sqlite
|
252
|
+
```
|
253
|
+
|
254
|
+
Explanation:
|
255
|
+
|
256
|
+
- use `--platform=ruby` to avoid the precompiled native gems (see the README)
|
257
|
+
- the `--` separates arguments passed to "gem install" from arguments passed to the C extension builder
|
258
|
+
- use `--enable-system-libraries` to avoid the vendored sqlite3 source
|
259
|
+
- use `--with-opt-dir=/path/to/installation` to point the build process at the desired header files and shared object files
|
260
|
+
|
261
|
+
Alternatively, if you've simply downloaded an "amalgamation" and so your compiled library and header files are in arbitrary locations, try this more detailed command:
|
262
|
+
|
263
|
+
```
|
264
|
+
gem install sqlite3 --platform=ruby -- \
|
265
|
+
--enable-system-libraries \
|
266
|
+
--with-opt-include=/path/to/include \
|
267
|
+
--with-opt-lib=/path/to/lib
|
268
|
+
```
|
269
|
+
|
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
@@ -1,22 +1,31 @@
|
|
1
1
|
# Ruby Interface for SQLite3
|
2
2
|
|
3
|
+
## Overview
|
4
|
+
|
5
|
+
This library allows Ruby programs to use the SQLite3 database engine (http://www.sqlite.org).
|
6
|
+
|
7
|
+
Note that this module is only compatible with SQLite 3.6.16 or newer.
|
8
|
+
|
3
9
|
* Source code: https://github.com/sparklemotion/sqlite3-ruby
|
4
10
|
* Mailing list: http://groups.google.com/group/sqlite3-ruby
|
5
11
|
* Download: http://rubygems.org/gems/sqlite3
|
6
12
|
* Documentation: http://www.rubydoc.info/gems/sqlite3
|
7
13
|
|
8
|
-
[![
|
9
|
-
[![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)
|
10
15
|
|
11
16
|
|
12
|
-
##
|
17
|
+
## Quick start
|
13
18
|
|
14
|
-
|
19
|
+
For help understanding the SQLite3 Ruby API, please read the [FAQ](./FAQ.md) and the [full API documentation](https://rubydoc.info/gems/sqlite3).
|
15
20
|
|
16
|
-
|
21
|
+
A few key classes whose APIs are often-used are:
|
22
|
+
|
23
|
+
- SQLite3::Database ([rdoc](https://rubydoc.info/gems/sqlite3/SQLite3/Database))
|
24
|
+
- SQLite3::Statement ([rdoc](https://rubydoc.info/gems/sqlite3/SQLite3/Statement))
|
25
|
+
- SQLite3::ResultSet ([rdoc](https://rubydoc.info/gems/sqlite3/SQLite3/ResultSet))
|
17
26
|
|
27
|
+
If you have any questions that you feel should be addressed in the FAQ, please send them to [the mailing list](http://groups.google.com/group/sqlite3-ruby) or open a [discussion thread](https://github.com/sparklemotion/sqlite3-ruby/discussions/categories/q-a).
|
18
28
|
|
19
|
-
## Synopsis
|
20
29
|
|
21
30
|
``` ruby
|
22
31
|
require "sqlite3"
|
@@ -67,155 +76,94 @@ end
|
|
67
76
|
# => ["Jane", "me@janedoe.com", "A", "http://blog.janedoe.com"]
|
68
77
|
```
|
69
78
|
|
70
|
-
##
|
79
|
+
## Thread Safety
|
71
80
|
|
72
|
-
|
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".
|
73
84
|
|
74
|
-
|
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:
|
75
89
|
|
76
|
-
|
77
|
-
|
78
|
-
- `arm64-darwin`
|
79
|
-
- `x64-mingw32` / `x64-mingw-ucrt`
|
80
|
-
- `x86-linux`
|
81
|
-
- `x86_64-darwin`
|
82
|
-
- `x86_64-linux`
|
90
|
+
```ruby
|
91
|
+
require 'sqlite3'
|
83
92
|
|
84
|
-
|
93
|
+
db = SQLite3::Database.new ":memory:"
|
85
94
|
|
86
|
-
|
95
|
+
latch = Queue.new
|
87
96
|
|
88
|
-
|
89
|
-
|
90
|
-
|
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 }
|
91
104
|
|
92
|
-
|
93
|
-
Fetching sqlite3-1.5.0-x86_64-linux.gem
|
94
|
-
Successfully installed sqlite3-1.5.0-x86_64-linux
|
95
|
-
1 gem installed
|
96
|
-
|
97
|
-
real 0m4.274s
|
98
|
-
user 0m0.734s
|
99
|
-
sys 0m0.165s
|
105
|
+
p ts.map(&:value)
|
100
106
|
```
|
101
107
|
|
102
|
-
|
103
|
-
|
104
|
-
|
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.
|
105
113
|
|
106
|
-
|
114
|
+
Lets rewrite the above example but use a prepared statement and safely share
|
115
|
+
the prepared statement among threads:
|
107
116
|
|
108
|
-
|
109
|
-
|
110
|
-
- version 2.1 or later, then you'll need to run `bundle config set force_ruby_platform true`,
|
111
|
-
- version 2.0 or earlier, then you'll need to run `bundle config force_ruby_platform true`
|
117
|
+
```ruby
|
118
|
+
db = SQLite3::Database.new ":memory:"
|
112
119
|
|
120
|
+
# Prepare a statement
|
121
|
+
stmt = db.prepare "SELECT :inspect"
|
122
|
+
stmt_lock = Mutex.new
|
113
123
|
|
114
|
-
|
124
|
+
latch = Queue.new
|
115
125
|
|
116
|
-
|
126
|
+
ts = 10.times.map {
|
127
|
+
Thread.new {
|
128
|
+
latch.pop
|
117
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
|
+
}
|
118
139
|
|
119
|
-
|
140
|
+
10.times { latch << nil }
|
120
141
|
|
121
|
-
|
142
|
+
p ts.map(&:value)
|
122
143
|
|
123
|
-
|
124
|
-
|
125
|
-
``` text
|
126
|
-
$ ruby -v
|
127
|
-
ruby 2.5.9p229 (2021-04-05 revision 67939) [x86_64-linux]
|
128
|
-
|
129
|
-
$ time gem install sqlite3
|
130
|
-
Building native extensions. This could take a while...
|
131
|
-
Successfully installed sqlite3-1.5.0
|
132
|
-
1 gem installed
|
133
|
-
|
134
|
-
real 0m20.620s
|
135
|
-
user 0m23.361s
|
136
|
-
sys 0m5.839s
|
144
|
+
stmt.close
|
137
145
|
```
|
138
146
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
If you would prefer to build the sqlite3-ruby gem against your system libsqlite3, which requires that you install libsqlite3 and its development files yourself, you may do so by using the `--enable-system-libraries` flag at gem install time.
|
143
|
-
|
144
|
-
PLEASE NOTE:
|
145
|
-
|
146
|
-
- only versions of libsqlite3 `>= 3.5.0` are supported,
|
147
|
-
- and some library features may depend on how your libsqlite3 was compiled.
|
148
|
-
|
149
|
-
For example, on a linux system running Ruby 2.5:
|
150
|
-
|
151
|
-
``` text
|
152
|
-
$ time gem install sqlite3 -- --enable-system-libraries
|
153
|
-
Building native extensions with: '--enable-system-libraries'
|
154
|
-
This could take a while...
|
155
|
-
Successfully installed sqlite3-1.5.0
|
156
|
-
1 gem installed
|
157
|
-
|
158
|
-
real 0m4.234s
|
159
|
-
user 0m3.809s
|
160
|
-
sys 0m0.912s
|
161
|
-
```
|
162
|
-
|
163
|
-
If you're using bundler, you can opt into system libraries like this:
|
164
|
-
|
165
|
-
``` sh
|
166
|
-
bundle config build.sqlite3 --enable-system-libraries
|
167
|
-
```
|
168
|
-
|
169
|
-
If you have sqlite3 installed in a non-standard location, you may need to specify the location of the include and lib files by using `--with-sqlite-include` and `--with-sqlite-lib` options (or a `--with-sqlite-dir` option, see [MakeMakefile#dir_config](https://ruby-doc.org/stdlib-3.1.1/libdoc/mkmf/rdoc/MakeMakefile.html#method-i-dir_config)). If you have pkg-config installed and configured properly, this may not be necessary.
|
170
|
-
|
171
|
-
``` sh
|
172
|
-
gem install sqlite3 -- \
|
173
|
-
--enable-system-libraries \
|
174
|
-
--with-sqlite3-include=/opt/local/include \
|
175
|
-
--with-sqlite3-lib=/opt/local/lib
|
176
|
-
```
|
177
|
-
|
178
|
-
|
179
|
-
#### System libsqlcipher
|
180
|
-
|
181
|
-
If you'd like to link against a system-installed libsqlcipher, you may do so by using the `--with-sqlcipher` flag:
|
182
|
-
|
183
|
-
``` text
|
184
|
-
$ time gem install sqlite3 -- --with-sqlcipher
|
185
|
-
Building native extensions with: '--with-sqlcipher'
|
186
|
-
This could take a while...
|
187
|
-
Successfully installed sqlite3-1.5.0
|
188
|
-
1 gem installed
|
189
|
-
|
190
|
-
real 0m4.772s
|
191
|
-
user 0m3.906s
|
192
|
-
sys 0m0.896s
|
193
|
-
```
|
194
|
-
|
195
|
-
If you have sqlcipher installed in a non-standard location, you may need to specify the location of the include and lib files by using `--with-sqlite-include` and `--with-sqlite-lib` options (or a `--with-sqlite-dir` option, see [MakeMakefile#dir_config](https://ruby-doc.org/stdlib-3.1.1/libdoc/mkmf/rdoc/MakeMakefile.html#method-i-dir_config)). If you have pkg-config installed and configured properly, this may not be necessary.
|
196
|
-
|
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.
|
197
150
|
|
198
151
|
## Support
|
199
152
|
|
200
|
-
###
|
153
|
+
### Installation or database extensions
|
201
154
|
|
202
|
-
|
203
|
-
[sqlite3-ruby mailing list](http://groups.google.com/group/sqlite3-ruby) which
|
204
|
-
can be found here:
|
155
|
+
If you're having trouble with installation, please first read [`INSTALLATION.md`](./INSTALLATION.md).
|
205
156
|
|
206
|
-
|
157
|
+
### General help requests
|
207
158
|
|
159
|
+
You can ask for help or support:
|
208
160
|
|
209
|
-
|
161
|
+
* by emailing the [sqlite3-ruby mailing list](http://groups.google.com/group/sqlite3-ruby)
|
162
|
+
* by opening a [discussion thread](https://github.com/sparklemotion/sqlite3-ruby/discussions/categories/q-a) on Github
|
210
163
|
|
211
|
-
|
164
|
+
### Bug reports
|
212
165
|
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
## Usage
|
217
|
-
|
218
|
-
For help figuring out the SQLite3/Ruby interface, check out the SYNOPSIS as well as the RDoc. It includes examples of usage. If you have any questions that you feel should be addressed in the FAQ, please send them to [the mailing list](http://groups.google.com/group/sqlite3-ruby).
|
166
|
+
You can file the bug at the [github issues page](https://github.com/sparklemotion/sqlite3-ruby/issues).
|
219
167
|
|
220
168
|
|
221
169
|
## Contributing
|
@@ -227,7 +175,7 @@ See [`CONTRIBUTING.md`](./CONTRIBUTING.md).
|
|
227
175
|
|
228
176
|
This library is licensed under `BSD-3-Clause`, see [`LICENSE`](./LICENSE).
|
229
177
|
|
230
|
-
|
231
178
|
### Dependencies
|
232
179
|
|
233
|
-
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
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
sqlite3:
|
2
|
+
# checksum verified by first checking the published sha3(256) checksum against https://sqlite.org/download.html:
|
3
|
+
# 83d2acf79453deb7d6520338b1f4585f12e39b27cd370fb08593afa198f471fc
|
4
|
+
#
|
5
|
+
# $ sha3sum -a 256 ports/archives/sqlite-autoconf-3460000.tar.gz
|
6
|
+
# 83d2acf79453deb7d6520338b1f4585f12e39b27cd370fb08593afa198f471fc ports/archives/sqlite-autoconf-3460000.tar.gz
|
7
|
+
#
|
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"
|