aim-sqlite3 2.9.6.1.rc1-arm64-darwin
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.
- checksums.yaml +7 -0
- data/.gemtest +0 -0
- data/CHANGELOG.md +1062 -0
- data/CONTRIBUTING.md +130 -0
- data/FAQ.md +399 -0
- data/INSTALLATION.md +267 -0
- data/LICENSE +23 -0
- data/README.md +218 -0
- data/dependencies.yml +13 -0
- data/ext/sqlite3/aggregator.c +314 -0
- data/ext/sqlite3/aggregator.h +14 -0
- data/ext/sqlite3/backup.c +190 -0
- data/ext/sqlite3/backup.h +15 -0
- data/ext/sqlite3/database.c +1263 -0
- data/ext/sqlite3/database.h +36 -0
- data/ext/sqlite3/exception.c +122 -0
- data/ext/sqlite3/exception.h +12 -0
- data/ext/sqlite3/extconf.rb +299 -0
- data/ext/sqlite3/gvl.c +88 -0
- data/ext/sqlite3/gvl.h +15 -0
- data/ext/sqlite3/sqlite3.c +225 -0
- data/ext/sqlite3/sqlite3_ruby.h +49 -0
- data/ext/sqlite3/statement.c +755 -0
- data/ext/sqlite3/statement.h +17 -0
- data/ext/sqlite3/timespec.h +20 -0
- data/lib/sqlite3/3.2/sqlite3_native.bundle +0 -0
- data/lib/sqlite3/3.3/sqlite3_native.bundle +0 -0
- data/lib/sqlite3/3.4/sqlite3_native.bundle +0 -0
- data/lib/sqlite3/4.0/sqlite3_native.bundle +0 -0
- data/lib/sqlite3/cli.rb +8 -0
- data/lib/sqlite3/constants.rb +198 -0
- data/lib/sqlite3/database.rb +798 -0
- data/lib/sqlite3/errors.rb +88 -0
- data/lib/sqlite3/fork_safety.rb +66 -0
- data/lib/sqlite3/pragmas.rb +648 -0
- data/lib/sqlite3/resultset.rb +96 -0
- data/lib/sqlite3/statement.rb +208 -0
- data/lib/sqlite3/value.rb +54 -0
- data/lib/sqlite3/version.rb +4 -0
- data/lib/sqlite3/version_info.rb +17 -0
- data/lib/sqlite3.rb +20 -0
- data/ports/aarch64-apple-darwin20.2/sqlite3/3.53.2/bin/sqlite3 +0 -0
- metadata +105 -0
data/INSTALLATION.md
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
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.5.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-mingw-ucrt`
|
|
18
|
+
- `x86-linux-gnu` (requires: glibc >= 2.29)
|
|
19
|
+
- `x86-linux-musl`
|
|
20
|
+
- `x86_64-darwin`
|
|
21
|
+
- `x86_64-linux-gnu` (requires: glibc >= 2.29)
|
|
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
|
|
25
|
+
|
|
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.
|
|
27
|
+
|
|
28
|
+
For example, on a linux system running Ruby 3.4:
|
|
29
|
+
|
|
30
|
+
``` text
|
|
31
|
+
$ ruby -v
|
|
32
|
+
ruby 3.4.7 (2025-10-08 revision 7a5688e2a2) +PRISM [x86_64-linux]
|
|
33
|
+
|
|
34
|
+
$ time gem install sqlite3
|
|
35
|
+
Fetching sqlite3-2.8.1-x86_64-linux-gnu.gem
|
|
36
|
+
Successfully installed sqlite3-2.8.1-x86_64-linux-gnu
|
|
37
|
+
1 gem installed
|
|
38
|
+
|
|
39
|
+
real 0m1.273s
|
|
40
|
+
user 0m0.496s
|
|
41
|
+
sys 0m0.078s
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
#### Avoiding the precompiled native gem
|
|
45
|
+
|
|
46
|
+
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.
|
|
47
|
+
|
|
48
|
+
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:
|
|
49
|
+
|
|
50
|
+
- If you're not using Bundler, then run `gem install sqlite3 --platform=ruby`
|
|
51
|
+
- If you are using Bundler
|
|
52
|
+
- 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)
|
|
53
|
+
- version 2.1 or later, then you'll need to run `bundle config set force_ruby_platform true`
|
|
54
|
+
- version 2.0 or earlier, then you'll need to run `bundle config force_ruby_platform true`
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
### Compiling the source gem
|
|
58
|
+
|
|
59
|
+
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.
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
#### Packaged libsqlite3
|
|
63
|
+
|
|
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.
|
|
65
|
+
|
|
66
|
+
⚠ A prerequisite to build the gem with the packaged sqlite3 is that you must have `pkgconf` installed.
|
|
67
|
+
|
|
68
|
+
For example, on a linux system running Ruby 2.5:
|
|
69
|
+
|
|
70
|
+
``` text
|
|
71
|
+
$ ruby -v
|
|
72
|
+
ruby 2.5.9p229 (2021-04-05 revision 67939) [x86_64-linux]
|
|
73
|
+
|
|
74
|
+
$ time gem install sqlite3
|
|
75
|
+
Building native extensions. This could take a while...
|
|
76
|
+
Successfully installed sqlite3-1.5.0
|
|
77
|
+
1 gem installed
|
|
78
|
+
|
|
79
|
+
real 0m20.620s
|
|
80
|
+
user 0m23.361s
|
|
81
|
+
sys 0m5.839s
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
##### Controlling compilation flags for sqlite
|
|
85
|
+
|
|
86
|
+
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 ...
|
|
87
|
+
|
|
88
|
+
**If you're installing the gem using `gem install`** then you can pass in these compile-time flags like this:
|
|
89
|
+
|
|
90
|
+
``` sh
|
|
91
|
+
gem install sqlite3 --platform=ruby -- \
|
|
92
|
+
--with-sqlite-cflags="-DSQLITE_DEFAULT_CACHE_SIZE=9999 -DSQLITE_DEFAULT_PAGE_SIZE=4444"
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
or the equivalent:
|
|
96
|
+
|
|
97
|
+
``` sh
|
|
98
|
+
CFLAGS="-DSQLITE_DEFAULT_CACHE_SIZE=9999 -DSQLITE_DEFAULT_PAGE_SIZE=4444" \
|
|
99
|
+
gem install sqlite3 --platform=ruby
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
**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:
|
|
103
|
+
|
|
104
|
+
``` ruby
|
|
105
|
+
# Gemfile
|
|
106
|
+
gem "sqlite3", force_ruby_platform: true # requires bundler >= 2.3.18
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
and then set up a bundler config parameter for `build.sqlite3`:
|
|
110
|
+
|
|
111
|
+
``` sh
|
|
112
|
+
bundle config set build.sqlite3 \
|
|
113
|
+
"--with-sqlite-cflags='-DSQLITE_DEFAULT_CACHE_SIZE=9999 -DSQLITE_DEFAULT_PAGE_SIZE=4444'"
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
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:
|
|
117
|
+
|
|
118
|
+
``` yaml
|
|
119
|
+
---
|
|
120
|
+
BUNDLE_BUILD__SQLITE3: "--with-sqlite-cflags='-DSQLITE_DEFAULT_CACHE_SIZE=9999 -DSQLITE_DEFAULT_PAGE_SIZE=4444'"
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
#### System libsqlite3
|
|
125
|
+
|
|
126
|
+
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.
|
|
127
|
+
|
|
128
|
+
PLEASE NOTE:
|
|
129
|
+
|
|
130
|
+
- you must avoid installing a precompiled native gem (see [previous section](#avoiding-the-precompiled-native-gem))
|
|
131
|
+
- only versions of libsqlite3 `>= 3.5.0` are supported,
|
|
132
|
+
- and some library features may depend on how your libsqlite3 was compiled.
|
|
133
|
+
|
|
134
|
+
For example, on a linux system running Ruby 2.5:
|
|
135
|
+
|
|
136
|
+
``` text
|
|
137
|
+
$ time gem install sqlite3 -- --enable-system-libraries
|
|
138
|
+
Building native extensions with: '--enable-system-libraries'
|
|
139
|
+
This could take a while...
|
|
140
|
+
Successfully installed sqlite3-1.5.0
|
|
141
|
+
1 gem installed
|
|
142
|
+
|
|
143
|
+
real 0m4.234s
|
|
144
|
+
user 0m3.809s
|
|
145
|
+
sys 0m0.912s
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
If you're using bundler, you can opt into system libraries like this:
|
|
149
|
+
|
|
150
|
+
``` sh
|
|
151
|
+
bundle config build.sqlite3 --enable-system-libraries
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
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.
|
|
155
|
+
|
|
156
|
+
``` sh
|
|
157
|
+
gem install sqlite3 -- \
|
|
158
|
+
--enable-system-libraries \
|
|
159
|
+
--with-sqlite3-include=/opt/local/include \
|
|
160
|
+
--with-sqlite3-lib=/opt/local/lib
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
#### System libsqlcipher
|
|
165
|
+
|
|
166
|
+
If you'd like to link against a system-installed libsqlcipher, you may do so by using the `--with-sqlcipher` flag:
|
|
167
|
+
|
|
168
|
+
``` text
|
|
169
|
+
$ time gem install sqlite3 -- --with-sqlcipher
|
|
170
|
+
Building native extensions with: '--with-sqlcipher'
|
|
171
|
+
This could take a while...
|
|
172
|
+
Successfully installed sqlite3-1.5.0
|
|
173
|
+
1 gem installed
|
|
174
|
+
|
|
175
|
+
real 0m4.772s
|
|
176
|
+
user 0m3.906s
|
|
177
|
+
sys 0m0.896s
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
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.
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
## Using SQLite3 extensions
|
|
184
|
+
|
|
185
|
+
### How do I load a sqlite extension?
|
|
186
|
+
|
|
187
|
+
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.
|
|
188
|
+
|
|
189
|
+
In this example, I'll be loading the ["spellfix" extension](https://www.sqlite.org/spellfix1.html):
|
|
190
|
+
|
|
191
|
+
``` text
|
|
192
|
+
# download spellfix.c from somewherehttp://www.sqlite.org/src/finfo?name=ext/misc/spellfix.c
|
|
193
|
+
$ wget https://raw.githubusercontent.com/sqlite/sqlite/master/ext/misc/spellfix.c
|
|
194
|
+
spellfix.c 100%[=================================================>] 100.89K --.-KB/s in 0.09s
|
|
195
|
+
|
|
196
|
+
# follow instructions at https://www.sqlite.org/loadext.html
|
|
197
|
+
# (you will need sqlite3 development packages for this)
|
|
198
|
+
$ gcc -g -fPIC -shared spellfix.c -o spellfix.o
|
|
199
|
+
|
|
200
|
+
$ ls -lt
|
|
201
|
+
total 192
|
|
202
|
+
-rwxrwxr-x 1 flavorjones flavorjones 87984 2023-05-24 10:44 spellfix.o
|
|
203
|
+
-rw-rw-r-- 1 flavorjones flavorjones 103310 2023-05-24 10:43 spellfix.c
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Then, in your application, use that `spellfix.o` file like this:
|
|
207
|
+
|
|
208
|
+
``` ruby
|
|
209
|
+
require "sqlite3"
|
|
210
|
+
|
|
211
|
+
db = SQLite3::Database.new(':memory:')
|
|
212
|
+
db.enable_load_extension(true)
|
|
213
|
+
db.load_extension("/path/to/sqlite/spellfix.o")
|
|
214
|
+
db.execute("CREATE VIRTUAL TABLE demo USING spellfix1;")
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### How do I use my own sqlite3 shared library?
|
|
218
|
+
|
|
219
|
+
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.
|
|
220
|
+
|
|
221
|
+
If you've installed your alternative as an autotools-style installation, the directory structure will look like this:
|
|
222
|
+
|
|
223
|
+
```
|
|
224
|
+
/opt/sqlite3
|
|
225
|
+
├── bin
|
|
226
|
+
│ └── sqlite3
|
|
227
|
+
├── include
|
|
228
|
+
│ ├── sqlite3.h
|
|
229
|
+
│ └── sqlite3ext.h
|
|
230
|
+
├── lib
|
|
231
|
+
│ ├── libsqlite3.a
|
|
232
|
+
│ ├── libsqlite3.la
|
|
233
|
+
│ ├── libsqlite3.so -> libsqlite3.so.0.8.6
|
|
234
|
+
│ ├── libsqlite3.so.0 -> libsqlite3.so.0.8.6
|
|
235
|
+
│ ├── libsqlite3.so.0.8.6
|
|
236
|
+
│ └── pkgconfig
|
|
237
|
+
│ └── sqlite3.pc
|
|
238
|
+
└── share
|
|
239
|
+
└── man
|
|
240
|
+
└── man1
|
|
241
|
+
└── sqlite3.1
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
You can build this gem against that library like this:
|
|
245
|
+
|
|
246
|
+
```
|
|
247
|
+
gem install sqlite3 --platform=ruby -- \
|
|
248
|
+
--enable-system-libraries \
|
|
249
|
+
--with-opt-dir=/opt/sqlite
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
Explanation:
|
|
253
|
+
|
|
254
|
+
- use `--platform=ruby` to avoid the precompiled native gems (see the README)
|
|
255
|
+
- the `--` separates arguments passed to "gem install" from arguments passed to the C extension builder
|
|
256
|
+
- use `--enable-system-libraries` to avoid the vendored sqlite3 source
|
|
257
|
+
- use `--with-opt-dir=/path/to/installation` to point the build process at the desired header files and shared object files
|
|
258
|
+
|
|
259
|
+
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:
|
|
260
|
+
|
|
261
|
+
```
|
|
262
|
+
gem install sqlite3 --platform=ruby -- \
|
|
263
|
+
--enable-system-libraries \
|
|
264
|
+
--with-opt-include=/path/to/include \
|
|
265
|
+
--with-opt-lib=/path/to/lib
|
|
266
|
+
```
|
|
267
|
+
|
data/LICENSE
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Copyright (c) 2004-2024, Jamis Buck, Luis Lavena, Aaron Patterson, Mike Dalessio, et al.
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted
|
|
4
|
+
provided that the following conditions are met:
|
|
5
|
+
|
|
6
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions
|
|
7
|
+
and the following disclaimer.
|
|
8
|
+
|
|
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.
|
|
12
|
+
|
|
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.
|
|
15
|
+
|
|
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
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
> [!NOTE]
|
|
2
|
+
> **AccountAim fork** of [sparklemotion/sqlite3-ruby](https://github.com/sparklemotion/sqlite3-ruby).
|
|
3
|
+
> Our changes sit as a few commits on top of upstream `main` (`git log upstream/main..`):
|
|
4
|
+
>
|
|
5
|
+
> - **`statement_timeout` honors its duration.** Upstream sets the deadline to "now", so long
|
|
6
|
+
> queries are interrupted almost at once; the deadline is also cleared on `Statement#reset!`.
|
|
7
|
+
> - **Queries run without the GVL.** `Statement#step` and `execute_batch2` release the GVL, so
|
|
8
|
+
> other threads keep running during long queries, and `Thread#kill` / `Thread#raise` cancel a
|
|
9
|
+
> running query through `sqlite3_interrupt`. Ruby callbacks (UDFs, aggregates, busy handler,
|
|
10
|
+
> authorizer, collations, trace) take the GVL back first. See `ext/sqlite3/gvl.c`.
|
|
11
|
+
> - **Published as `aim-sqlite3`**, versioned `<upstream>.<n>` (e.g. `2.9.6.1`) and released by
|
|
12
|
+
> pushing tag `v2.9.6.1` on `main`. PR branches publish release candidates (`v2.9.6.1.rc1`,
|
|
13
|
+
> `rc2`, …) to validate in apps before merging. Precompiled for x86_64/aarch64 Linux and x86_64/arm64 macOS, with a
|
|
14
|
+
> source gem for anything else. The packaged sqlite is built with `SQLITE_MAX_ATTACHED=50`,
|
|
15
|
+
> and every gem carries the `sqlite3` program from the same build at `SQLite3.cli_path`.
|
|
16
|
+
> CI and releases use `aim-ci.yml` / `aim-release.yml`; upstream workflows are disabled in the
|
|
17
|
+
> repository settings.
|
|
18
|
+
>
|
|
19
|
+
> To pull in upstream: `git fetch upstream && git rebase upstream/main`.
|
|
20
|
+
|
|
21
|
+
# Ruby Interface for SQLite3
|
|
22
|
+
|
|
23
|
+
## Overview
|
|
24
|
+
|
|
25
|
+
This library allows Ruby programs to use the SQLite3 database engine (http://www.sqlite.org).
|
|
26
|
+
|
|
27
|
+
Note that this module is only compatible with SQLite 3.6.16 or newer.
|
|
28
|
+
|
|
29
|
+
* Source code: https://github.com/sparklemotion/sqlite3-ruby
|
|
30
|
+
* Mailing list: http://groups.google.com/group/sqlite3-ruby
|
|
31
|
+
* Download: http://rubygems.org/gems/sqlite3
|
|
32
|
+
* Documentation: https://sparklemotion.github.io/sqlite3-ruby/
|
|
33
|
+
|
|
34
|
+
[](https://github.com/sparklemotion/sqlite3-ruby/actions/workflows/ci.yml)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
## Quick start
|
|
38
|
+
|
|
39
|
+
For help understanding the SQLite3 Ruby API, please read the [FAQ](./FAQ.md) and the [full API documentation](https://sparklemotion.github.io/sqlite3-ruby/).
|
|
40
|
+
|
|
41
|
+
A few key classes whose APIs are often-used are:
|
|
42
|
+
|
|
43
|
+
- SQLite3::Database ([rdoc](https://sparklemotion.github.io/sqlite3-ruby/SQLite3/Database.html))
|
|
44
|
+
- SQLite3::Statement ([rdoc](https://sparklemotion.github.io/sqlite3-ruby/SQLite3/Statement.html))
|
|
45
|
+
- SQLite3::ResultSet ([rdoc](https://sparklemotion.github.io/sqlite3-ruby/SQLite3/ResultSet.html))
|
|
46
|
+
|
|
47
|
+
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).
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
``` ruby
|
|
51
|
+
require "sqlite3"
|
|
52
|
+
|
|
53
|
+
# Open a database
|
|
54
|
+
db = SQLite3::Database.new "test.db"
|
|
55
|
+
|
|
56
|
+
# Create a table
|
|
57
|
+
rows = db.execute <<-SQL
|
|
58
|
+
create table numbers (
|
|
59
|
+
name varchar(30),
|
|
60
|
+
val int
|
|
61
|
+
);
|
|
62
|
+
SQL
|
|
63
|
+
|
|
64
|
+
# Execute a few inserts
|
|
65
|
+
{
|
|
66
|
+
"one" => 1,
|
|
67
|
+
"two" => 2,
|
|
68
|
+
}.each do |pair|
|
|
69
|
+
db.execute "insert into numbers values ( ?, ? )", pair
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Find a few rows
|
|
73
|
+
db.execute( "select * from numbers" ) do |row|
|
|
74
|
+
p row
|
|
75
|
+
end
|
|
76
|
+
# => ["one", 1]
|
|
77
|
+
# ["two", 2]
|
|
78
|
+
|
|
79
|
+
# Create another table with multiple columns
|
|
80
|
+
db.execute <<-SQL
|
|
81
|
+
create table students (
|
|
82
|
+
name varchar(50),
|
|
83
|
+
email varchar(50),
|
|
84
|
+
grade varchar(5),
|
|
85
|
+
blog varchar(50)
|
|
86
|
+
);
|
|
87
|
+
SQL
|
|
88
|
+
|
|
89
|
+
# Execute inserts with parameter markers
|
|
90
|
+
db.execute("INSERT INTO students (name, email, grade, blog)
|
|
91
|
+
VALUES (?, ?, ?, ?)", ["Jane", "me@janedoe.com", "A", "http://blog.janedoe.com"])
|
|
92
|
+
|
|
93
|
+
db.execute( "select * from students" ) do |row|
|
|
94
|
+
p row
|
|
95
|
+
end
|
|
96
|
+
# => ["Jane", "me@janedoe.com", "A", "http://blog.janedoe.com"]
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Thread Safety
|
|
100
|
+
|
|
101
|
+
When `SQLite3.threadsafe?` returns `true`, then SQLite3 has been compiled to
|
|
102
|
+
support running in a multithreaded environment. However, this doesn't mean
|
|
103
|
+
that all classes in the SQLite3 gem can be considered "thread safe".
|
|
104
|
+
|
|
105
|
+
When `SQLite3.threadsafe?` returns `true`, it is safe to share only
|
|
106
|
+
`SQLite3::Database` instances among threads without providing your own locking
|
|
107
|
+
mechanism. For example, the following code is fine because only the database
|
|
108
|
+
instance is shared among threads:
|
|
109
|
+
|
|
110
|
+
```ruby
|
|
111
|
+
require 'sqlite3'
|
|
112
|
+
|
|
113
|
+
db = SQLite3::Database.new ":memory:"
|
|
114
|
+
|
|
115
|
+
latch = Queue.new
|
|
116
|
+
|
|
117
|
+
ts = 10.times.map {
|
|
118
|
+
Thread.new {
|
|
119
|
+
latch.pop
|
|
120
|
+
db.execute "SELECT '#{Thread.current.inspect}'"
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
10.times { latch << nil }
|
|
124
|
+
|
|
125
|
+
p ts.map(&:value)
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Other instances can be shared among threads, but they require that you provide
|
|
129
|
+
your own locking for thread safety. For example, `SQLite3::Statement` objects
|
|
130
|
+
(prepared statements) are mutable, so applications must take care to add
|
|
131
|
+
appropriate locks to avoid data race conditions when sharing these objects
|
|
132
|
+
among threads.
|
|
133
|
+
|
|
134
|
+
Lets rewrite the above example but use a prepared statement and safely share
|
|
135
|
+
the prepared statement among threads:
|
|
136
|
+
|
|
137
|
+
```ruby
|
|
138
|
+
db = SQLite3::Database.new ":memory:"
|
|
139
|
+
|
|
140
|
+
# Prepare a statement
|
|
141
|
+
stmt = db.prepare "SELECT :inspect"
|
|
142
|
+
stmt_lock = Mutex.new
|
|
143
|
+
|
|
144
|
+
latch = Queue.new
|
|
145
|
+
|
|
146
|
+
ts = 10.times.map {
|
|
147
|
+
Thread.new {
|
|
148
|
+
latch.pop
|
|
149
|
+
|
|
150
|
+
# Add a lock when using the prepared statement.
|
|
151
|
+
# Binding values, and walking over results will mutate the statement, so
|
|
152
|
+
# in order to prevent other threads from "seeing" this thread's data, we
|
|
153
|
+
# must lock when using the statement object
|
|
154
|
+
stmt_lock.synchronize do
|
|
155
|
+
stmt.execute(Thread.current.inspect).to_a
|
|
156
|
+
end
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
10.times { latch << nil }
|
|
161
|
+
|
|
162
|
+
p ts.map(&:value)
|
|
163
|
+
|
|
164
|
+
stmt.close
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
It is generally recommended that if applications want to share a database among
|
|
168
|
+
threads, they _only_ share the database instance object. Other objects are
|
|
169
|
+
fine to share, but may require manual locking for thread safety.
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
## Fork Safety
|
|
173
|
+
|
|
174
|
+
[Sqlite is not fork
|
|
175
|
+
safe](https://www.sqlite.org/howtocorrupt.html#_carrying_an_open_database_connection_across_a_fork_)
|
|
176
|
+
and instructs users to not carry an open writable database connection across a `fork()`. Using an inherited
|
|
177
|
+
connection in the child may corrupt your database, leak memory, or cause other undefined behavior.
|
|
178
|
+
|
|
179
|
+
To help protect users of this gem from accidental corruption due to this lack of fork safety, the gem will immediately close any open writable databases in the child after a fork. Discarding writable
|
|
180
|
+
connections in the child will incur a small one-time memory leak per connection, but that's
|
|
181
|
+
preferable to potentially corrupting your database.
|
|
182
|
+
|
|
183
|
+
Whenever possible, close writable 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!`.
|
|
184
|
+
|
|
185
|
+
See [./adr/2024-09-fork-safety.md](./adr/2024-09-fork-safety.md) for more information and context.
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
## Support
|
|
189
|
+
|
|
190
|
+
### Installation or database extensions
|
|
191
|
+
|
|
192
|
+
If you're having trouble with installation, please first read [`INSTALLATION.md`](./INSTALLATION.md).
|
|
193
|
+
|
|
194
|
+
### General help requests
|
|
195
|
+
|
|
196
|
+
You can ask for help or support:
|
|
197
|
+
|
|
198
|
+
* by emailing the [sqlite3-ruby mailing list](http://groups.google.com/group/sqlite3-ruby)
|
|
199
|
+
* by opening a [discussion thread](https://github.com/sparklemotion/sqlite3-ruby/discussions/categories/q-a) on Github
|
|
200
|
+
|
|
201
|
+
### Bug reports
|
|
202
|
+
|
|
203
|
+
You can file the bug at the [github issues page](https://github.com/sparklemotion/sqlite3-ruby/issues).
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
## Contributing
|
|
207
|
+
|
|
208
|
+
See [`CONTRIBUTING.md`](./CONTRIBUTING.md).
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
## License
|
|
212
|
+
|
|
213
|
+
This library is licensed under `BSD-3-Clause`, see [`LICENSE`](./LICENSE).
|
|
214
|
+
|
|
215
|
+
### Dependencies
|
|
216
|
+
|
|
217
|
+
The source code of `sqlite` is distributed in the "ruby platform" gem. This code is public domain,
|
|
218
|
+
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
|
+
# 025328da165109f48abccc6e7478508060804412bed2bd81d47e98ba1b72983b
|
|
4
|
+
#
|
|
5
|
+
# $ sha3sum -a 256 ports/archives/sqlite-autoconf-3530200.tar.gz
|
|
6
|
+
# 025328da165109f48abccc6e7478508060804412bed2bd81d47e98ba1b72983b ports/archives/sqlite-autoconf-3530200.tar.gz
|
|
7
|
+
#
|
|
8
|
+
# $ sha256sum ports/archives/sqlite-autoconf-3530200.tar.gz
|
|
9
|
+
# 588ad51949419a56ebe81fe56193d510c559eb94c9a57748387860b5d3069316 ports/archives/sqlite-autoconf-3530200.tar.gz
|
|
10
|
+
version: "3.53.2"
|
|
11
|
+
files:
|
|
12
|
+
- url: "https://sqlite.org/2026/sqlite-autoconf-3530200.tar.gz"
|
|
13
|
+
sha256: "588ad51949419a56ebe81fe56193d510c559eb94c9a57748387860b5d3069316"
|