sqlite3-ffi 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +3 -0
- data/LICENSE.txt +24 -0
- data/README.md +55 -0
- data/lib/sqlite3/constants.rb +198 -0
- data/lib/sqlite3/database.rb +797 -0
- data/lib/sqlite3/errors.rb +88 -0
- data/lib/sqlite3/ffi/aggregator.rb +89 -0
- data/lib/sqlite3/ffi/backup.rb +59 -0
- data/lib/sqlite3/ffi/c_api.rb +214 -0
- data/lib/sqlite3/ffi/core_ext.rb +14 -0
- data/lib/sqlite3/ffi/database.rb +261 -0
- data/lib/sqlite3/ffi/exception.rb +111 -0
- data/lib/sqlite3/ffi/functions.rb +79 -0
- data/lib/sqlite3/ffi/sqlite3.rb +62 -0
- data/lib/sqlite3/ffi/statement.rb +242 -0
- data/lib/sqlite3/ffi/utils.rb +83 -0
- data/lib/sqlite3/ffi/version.rb +5 -0
- data/lib/sqlite3/ffi.rb +1 -0
- data/lib/sqlite3/fork_safety.rb +66 -0
- data/lib/sqlite3/pragmas.rb +599 -0
- data/lib/sqlite3/resultset.rb +96 -0
- data/lib/sqlite3/sqlite3_native.rb +14 -0
- data/lib/sqlite3/statement.rb +190 -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 +19 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f6057cc11c164cee5826611c884086b9b2c1e624b168bb0f141a8f0527cea6c6
|
4
|
+
data.tar.gz: cb0fc326b3b60ddccf66d76487397bedf3dc7af6246e97eb29812c685a089ace
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e5741192faba70b8e6c18535642a14f652e9dabdb55d9279a8f4706397bf19a1f53a64dc33acd524852015d317e69c548886691b20715c07bdad91377e594dcd
|
7
|
+
data.tar.gz: a3a9ec82f458c9aff089fd3e555a86f6691db6e3992917eab43c2734a8b6f9dae1022c9dba4141b4111e6a1fbbc2fe23188af0b865e599988b6484c8901000aa
|
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Copyright (c) 2004-2024, Jamis Buck, Luis Lavena, Aaron Patterson, Mike Dalessio, et al.
|
2
|
+
Copyright (c) 2025, Andrew Kane.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted
|
5
|
+
provided that the following conditions are met:
|
6
|
+
|
7
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions
|
8
|
+
and the following disclaimer.
|
9
|
+
|
10
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of
|
11
|
+
conditions and the following disclaimer in the documentation and/or other materials provided with
|
12
|
+
the distribution.
|
13
|
+
|
14
|
+
3. Neither the name of the copyright holder nor the names of its contributors may be used to
|
15
|
+
endorse or promote products derived from this software without specific prior written permission.
|
16
|
+
|
17
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
|
18
|
+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
20
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
21
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
22
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
23
|
+
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
24
|
+
THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# sqlite3-ffi
|
2
|
+
|
3
|
+
:tada: A drop-in replacement for [sqlite3](https://github.com/sparklemotion/sqlite3-ruby) for JRuby
|
4
|
+
|
5
|
+
- Passes 99% of the sqlite3 test suite
|
6
|
+
- Works with Active Record without a custom adapter
|
7
|
+
|
8
|
+
[](https://github.com/ankane/sqlite3-ffi/actions)
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem "sqlite3-ffi"
|
16
|
+
```
|
17
|
+
|
18
|
+
And use it the exact same way as the sqlite3 gem.
|
19
|
+
|
20
|
+
## Why FFI for JRuby?
|
21
|
+
|
22
|
+
I tried [JDBC](https://github.com/xerial/sqlite-jdbc), [JNI](https://sqlite.org/src/dir/ext/jni), and FFI. Since SQLite is written in C, all three approaches eventually call C, but FFI provides the most compatibility.
|
23
|
+
|
24
|
+
## Credits
|
25
|
+
|
26
|
+
This library uses code from the [sqlite3](https://github.com/sparklemotion/sqlite3-ruby) gem and is available under the same license.
|
27
|
+
|
28
|
+
The code in `lib` and `test` is an exact copy, plus some additional files:
|
29
|
+
|
30
|
+
- `lib/sqlite3/ffi/*` (port of `ext`)
|
31
|
+
- `lib/sqlite3/ffi.rb`
|
32
|
+
- `lib/sqlite3/sqlite3_native.rb`
|
33
|
+
- `test/ffi_helper.rb`
|
34
|
+
|
35
|
+
## History
|
36
|
+
|
37
|
+
View the [changelog](https://github.com/ankane/sqlite3-ffi/blob/master/CHANGELOG.md)
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
Everyone is encouraged to help improve this project. Here are a few ways you can help:
|
42
|
+
|
43
|
+
- [Report bugs](https://github.com/ankane/sqlite3-ffi/issues)
|
44
|
+
- Fix bugs and [submit pull requests](https://github.com/ankane/sqlite3-ffi/pulls)
|
45
|
+
- Write, clarify, or fix documentation
|
46
|
+
- Suggest or add new features
|
47
|
+
|
48
|
+
To get started with development:
|
49
|
+
|
50
|
+
```sh
|
51
|
+
git clone https://github.com/ankane/sqlite3-ffi.git
|
52
|
+
cd sqlite3-ffi
|
53
|
+
bundle install
|
54
|
+
bundle exec rake test
|
55
|
+
```
|
@@ -0,0 +1,198 @@
|
|
1
|
+
module SQLite3
|
2
|
+
module Constants
|
3
|
+
#
|
4
|
+
# CAPI3REF: Text Encodings
|
5
|
+
#
|
6
|
+
# These constant define integer codes that represent the various
|
7
|
+
# text encodings supported by SQLite.
|
8
|
+
#
|
9
|
+
module TextRep
|
10
|
+
# IMP: R-37514-35566
|
11
|
+
UTF8 = 1
|
12
|
+
# IMP: R-03371-37637
|
13
|
+
UTF16LE = 2
|
14
|
+
# IMP: R-51971-34154
|
15
|
+
UTF16BE = 3
|
16
|
+
# Use native byte order
|
17
|
+
UTF16 = 4
|
18
|
+
# Deprecated
|
19
|
+
ANY = 5
|
20
|
+
# sqlite3_create_collation only
|
21
|
+
DETERMINISTIC = 0x800
|
22
|
+
end
|
23
|
+
|
24
|
+
#
|
25
|
+
# CAPI3REF: Fundamental Datatypes
|
26
|
+
#
|
27
|
+
# ^(Every value in SQLite has one of five fundamental datatypes:
|
28
|
+
#
|
29
|
+
# <ul>
|
30
|
+
# <li> 64-bit signed integer
|
31
|
+
# <li> 64-bit IEEE floating point number
|
32
|
+
# <li> string
|
33
|
+
# <li> BLOB
|
34
|
+
# <li> NULL
|
35
|
+
# </ul>)^
|
36
|
+
#
|
37
|
+
# These constants are codes for each of those types.
|
38
|
+
#
|
39
|
+
module ColumnType
|
40
|
+
INTEGER = 1
|
41
|
+
FLOAT = 2
|
42
|
+
TEXT = 3
|
43
|
+
BLOB = 4
|
44
|
+
NULL = 5
|
45
|
+
end
|
46
|
+
|
47
|
+
#
|
48
|
+
# CAPI3REF: Result Codes
|
49
|
+
#
|
50
|
+
# Many SQLite functions return an integer result code from the set shown
|
51
|
+
# here in order to indicate success or failure.
|
52
|
+
#
|
53
|
+
# New error codes may be added in future versions of SQLite.
|
54
|
+
#
|
55
|
+
module ErrorCode
|
56
|
+
# Successful result
|
57
|
+
OK = 0
|
58
|
+
# SQL error or missing database
|
59
|
+
ERROR = 1
|
60
|
+
# An internal logic error in SQLite
|
61
|
+
INTERNAL = 2
|
62
|
+
# Access permission denied
|
63
|
+
PERM = 3
|
64
|
+
# Callback routine requested an abort
|
65
|
+
ABORT = 4
|
66
|
+
# The database file is locked
|
67
|
+
BUSY = 5
|
68
|
+
# A table in the database is locked
|
69
|
+
LOCKED = 6
|
70
|
+
# A malloc() failed
|
71
|
+
NOMEM = 7
|
72
|
+
# Attempt to write a readonly database
|
73
|
+
READONLY = 8
|
74
|
+
# Operation terminated by sqlite_interrupt()
|
75
|
+
INTERRUPT = 9
|
76
|
+
# Some kind of disk I/O error occurred
|
77
|
+
IOERR = 10
|
78
|
+
# The database disk image is malformed
|
79
|
+
CORRUPT = 11
|
80
|
+
# (Internal Only) Table or record not found
|
81
|
+
NOTFOUND = 12
|
82
|
+
# Insertion failed because database is full
|
83
|
+
FULL = 13
|
84
|
+
# Unable to open the database file
|
85
|
+
CANTOPEN = 14
|
86
|
+
# Database lock protocol error
|
87
|
+
PROTOCOL = 15
|
88
|
+
# (Internal Only) Database table is empty
|
89
|
+
EMPTY = 16
|
90
|
+
# The database schema changed
|
91
|
+
SCHEMA = 17
|
92
|
+
# Too much data for one row of a table
|
93
|
+
TOOBIG = 18
|
94
|
+
# Abort due to constraint violation
|
95
|
+
CONSTRAINT = 19
|
96
|
+
# Data type mismatch
|
97
|
+
MISMATCH = 20
|
98
|
+
# Library used incorrectly
|
99
|
+
MISUSE = 21
|
100
|
+
# Uses OS features not supported on host
|
101
|
+
NOLFS = 22
|
102
|
+
# Authorization denied
|
103
|
+
AUTH = 23
|
104
|
+
# Not used
|
105
|
+
FORMAT = 24
|
106
|
+
# 2nd parameter to sqlite3_bind out of range
|
107
|
+
RANGE = 25
|
108
|
+
# File opened that is not a database file
|
109
|
+
NOTADB = 26
|
110
|
+
# Notifications from sqlite3_log()
|
111
|
+
NOTICE = 27
|
112
|
+
# Warnings from sqlite3_log()
|
113
|
+
WARNING = 28
|
114
|
+
# sqlite_step() has another row ready
|
115
|
+
ROW = 100
|
116
|
+
# sqlite_step() has finished executing
|
117
|
+
DONE = 101
|
118
|
+
end
|
119
|
+
|
120
|
+
#
|
121
|
+
# CAPI3REF: Status Parameters
|
122
|
+
#
|
123
|
+
# These integer constants designate various run-time status parameters
|
124
|
+
# that can be returned by SQLite3.status
|
125
|
+
#
|
126
|
+
module Status
|
127
|
+
# This parameter is the current amount of memory checked out using sqlite3_malloc(), either
|
128
|
+
# directly or indirectly. The figure includes calls made to sqlite3_malloc() by the
|
129
|
+
# application and internal memory usage by the SQLite library. Auxiliary page-cache memory
|
130
|
+
# controlled by SQLITE_CONFIG_PAGECACHE is not included in this parameter. The amount returned
|
131
|
+
# is the sum of the allocation sizes as reported by the xSize method in sqlite3_mem_methods.
|
132
|
+
MEMORY_USED = 0
|
133
|
+
|
134
|
+
# This parameter returns the number of pages used out of the pagecache memory allocator that
|
135
|
+
# was configured using SQLITE_CONFIG_PAGECACHE. The value returned is in pages, not in bytes.
|
136
|
+
PAGECACHE_USED = 1
|
137
|
+
|
138
|
+
# This parameter returns the number of bytes of page cache allocation which could not be
|
139
|
+
# satisfied by the SQLITE_CONFIG_PAGECACHE buffer and where forced to overflow to
|
140
|
+
# sqlite3_malloc(). The returned value includes allocations that overflowed because they where
|
141
|
+
# too large (they were larger than the "sz" parameter to SQLITE_CONFIG_PAGECACHE) and
|
142
|
+
# allocations that overflowed because no space was left in the page cache.
|
143
|
+
PAGECACHE_OVERFLOW = 2
|
144
|
+
|
145
|
+
# NOT USED
|
146
|
+
SCRATCH_USED = 3
|
147
|
+
|
148
|
+
# NOT USED
|
149
|
+
SCRATCH_OVERFLOW = 4
|
150
|
+
|
151
|
+
# This parameter records the largest memory allocation request handed to sqlite3_malloc() or
|
152
|
+
# sqlite3_realloc() (or their internal equivalents). Only the value returned in the
|
153
|
+
# *pHighwater parameter to sqlite3_status() is of interest. The value written into the
|
154
|
+
# *pCurrent parameter is undefined.
|
155
|
+
MALLOC_SIZE = 5
|
156
|
+
|
157
|
+
# The *pHighwater parameter records the deepest parser stack. The *pCurrent value is
|
158
|
+
# undefined. The *pHighwater value is only meaningful if SQLite is compiled with
|
159
|
+
# YYTRACKMAXSTACKDEPTH.
|
160
|
+
PARSER_STACK = 6
|
161
|
+
|
162
|
+
# This parameter records the largest memory allocation request handed to the pagecache memory
|
163
|
+
# allocator. Only the value returned in the *pHighwater parameter to sqlite3_status() is of
|
164
|
+
# interest. The value written into the *pCurrent parameter is undefined.
|
165
|
+
PAGECACHE_SIZE = 7
|
166
|
+
|
167
|
+
# NOT USED
|
168
|
+
SCRATCH_SIZE = 8
|
169
|
+
|
170
|
+
# This parameter records the number of separate memory allocations currently checked out.
|
171
|
+
MALLOC_COUNT = 9
|
172
|
+
end
|
173
|
+
|
174
|
+
module Optimize
|
175
|
+
# Debugging mode. Do not actually perform any optimizations but instead return one line of
|
176
|
+
# text for each optimization that would have been done. Off by default.
|
177
|
+
DEBUG = 0x00001
|
178
|
+
|
179
|
+
# Run ANALYZE on tables that might benefit. On by default.
|
180
|
+
ANALYZE_TABLES = 0x00002
|
181
|
+
|
182
|
+
# When running ANALYZE, set a temporary PRAGMA analysis_limit to prevent excess run-time. On
|
183
|
+
# by default.
|
184
|
+
LIMIT_ANALYZE = 0x00010
|
185
|
+
|
186
|
+
# Check the size of all tables, not just tables that have not been recently used, to see if
|
187
|
+
# any have grown and shrunk significantly and hence might benefit from being re-analyzed. Off
|
188
|
+
# by default.
|
189
|
+
CHECK_ALL_TABLES = 0x10000
|
190
|
+
|
191
|
+
# Useful for adding a bit to the default behavior, for example
|
192
|
+
#
|
193
|
+
# db.optimize(Optimize::DEFAULT | Optimize::CHECK_ALL_TABLES)
|
194
|
+
#
|
195
|
+
DEFAULT = ANALYZE_TABLES | LIMIT_ANALYZE
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|