sqlite3 1.4.3 → 1.5.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{API_CHANGES.rdoc → API_CHANGES.md} +3 -4
- data/CHANGELOG.md +425 -0
- data/CONTRIBUTING.md +24 -0
- data/Gemfile +2 -19
- data/LICENSE-DEPENDENCIES +20 -0
- data/README.md +233 -0
- data/ext/sqlite3/database.c +10 -11
- data/ext/sqlite3/extconf.rb +236 -84
- data/ext/sqlite3/sqlite3.c +2 -0
- data/ext/sqlite3/sqlite3_ruby.h +5 -2
- data/faq/faq.md +431 -0
- data/lib/sqlite3/version.rb +4 -4
- data/ports/archives/sqlite-autoconf-3380500.tar.gz +0 -0
- data/test/helper.rb +5 -3
- data/test/test_database.rb +24 -6
- data/test/test_sqlite3.rb +9 -0
- metadata +40 -84
- data/CHANGELOG.rdoc +0 -327
- data/Manifest.txt +0 -59
- data/README.rdoc +0 -118
- data/Rakefile +0 -8
- data/appveyor.yml +0 -36
- data/rakelib/faq.rake +0 -9
- data/rakelib/gem.rake +0 -40
- data/rakelib/native.rake +0 -59
- data/rakelib/vendor_sqlite3.rake +0 -108
- data/setup.rb +0 -1333
data/README.md
ADDED
@@ -0,0 +1,233 @@
|
|
1
|
+
# Ruby Interface for SQLite3
|
2
|
+
|
3
|
+
* Source code: https://github.com/sparklemotion/sqlite3-ruby
|
4
|
+
* Mailing list: http://groups.google.com/group/sqlite3-ruby
|
5
|
+
* Download: http://rubygems.org/gems/sqlite3
|
6
|
+
* Documentation: http://www.rubydoc.info/gems/sqlite3
|
7
|
+
|
8
|
+
[![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)
|
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)
|
10
|
+
|
11
|
+
|
12
|
+
## Description
|
13
|
+
|
14
|
+
This library allows Ruby programs to use the SQLite3 database engine (http://www.sqlite.org).
|
15
|
+
|
16
|
+
Note that this module is only compatible with SQLite 3.6.16 or newer.
|
17
|
+
|
18
|
+
|
19
|
+
## Synopsis
|
20
|
+
|
21
|
+
``` ruby
|
22
|
+
require "sqlite3"
|
23
|
+
|
24
|
+
# Open a database
|
25
|
+
db = SQLite3::Database.new "test.db"
|
26
|
+
|
27
|
+
# Create a table
|
28
|
+
rows = db.execute <<-SQL
|
29
|
+
create table numbers (
|
30
|
+
name varchar(30),
|
31
|
+
val int
|
32
|
+
);
|
33
|
+
SQL
|
34
|
+
|
35
|
+
# Execute a few inserts
|
36
|
+
{
|
37
|
+
"one" => 1,
|
38
|
+
"two" => 2,
|
39
|
+
}.each do |pair|
|
40
|
+
db.execute "insert into numbers values ( ?, ? )", pair
|
41
|
+
end
|
42
|
+
|
43
|
+
# Find a few rows
|
44
|
+
db.execute( "select * from numbers" ) do |row|
|
45
|
+
p row
|
46
|
+
end
|
47
|
+
# => ["one", 1]
|
48
|
+
# ["two", 2]
|
49
|
+
|
50
|
+
# Create another table with multiple columns
|
51
|
+
db.execute <<-SQL
|
52
|
+
create table students (
|
53
|
+
name varchar(50),
|
54
|
+
email varchar(50),
|
55
|
+
grade varchar(5),
|
56
|
+
blog varchar(50)
|
57
|
+
);
|
58
|
+
SQL
|
59
|
+
|
60
|
+
# Execute inserts with parameter markers
|
61
|
+
db.execute("INSERT INTO students (name, email, grade, blog)
|
62
|
+
VALUES (?, ?, ?, ?)", ["Jane", "me@janedoe.com", "A", "http://blog.janedoe.com"])
|
63
|
+
|
64
|
+
db.execute( "select * from students" ) do |row|
|
65
|
+
p row
|
66
|
+
end
|
67
|
+
# => ["Jane", "me@janedoe.com", "A", "http://blog.janedoe.com"]
|
68
|
+
```
|
69
|
+
|
70
|
+
## Installation
|
71
|
+
|
72
|
+
### Native Gems (recommended)
|
73
|
+
|
74
|
+
As of v1.5.0 of this library, native (precompiled) gems are available for Ruby 2.6, 2.7, 3.0, and 3.1 on all these platforms:
|
75
|
+
|
76
|
+
- `aarch64-linux`
|
77
|
+
- `arm-linux`
|
78
|
+
- `arm64-darwin`
|
79
|
+
- `x64-mingw32` / `x64-mingw-ucrt`
|
80
|
+
- `x86-linux`
|
81
|
+
- `x86_64-darwin`
|
82
|
+
- `x86_64-linux`
|
83
|
+
|
84
|
+
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.
|
85
|
+
|
86
|
+
For example, on a linux system running Ruby 3.1:
|
87
|
+
|
88
|
+
``` text
|
89
|
+
$ ruby -v
|
90
|
+
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux]
|
91
|
+
|
92
|
+
$ time gem install sqlite3
|
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
|
100
|
+
```
|
101
|
+
|
102
|
+
#### Avoiding the precompiled native gem
|
103
|
+
|
104
|
+
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.
|
105
|
+
|
106
|
+
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:
|
107
|
+
|
108
|
+
- If you're not using Bundler, then run `gem install sqlite3 --platform=ruby`
|
109
|
+
- If you are using Bundler
|
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`
|
112
|
+
|
113
|
+
|
114
|
+
### Compiling the source gem
|
115
|
+
|
116
|
+
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.
|
117
|
+
|
118
|
+
|
119
|
+
#### Packaged libsqlite3
|
120
|
+
|
121
|
+
By default, as of v1.5.0 of this library, libsqlite3 v3.38.5 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.
|
122
|
+
|
123
|
+
For example, on a linux system running Ruby 2.5:
|
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
|
137
|
+
```
|
138
|
+
|
139
|
+
|
140
|
+
#### System libsqlite3
|
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
|
+
|
197
|
+
|
198
|
+
## Support
|
199
|
+
|
200
|
+
### Something has gone wrong! Where do I get help?
|
201
|
+
|
202
|
+
You can ask for help or support from the
|
203
|
+
[sqlite3-ruby mailing list](http://groups.google.com/group/sqlite3-ruby) which
|
204
|
+
can be found here:
|
205
|
+
|
206
|
+
> http://groups.google.com/group/sqlite3-ruby
|
207
|
+
|
208
|
+
|
209
|
+
### I've found a bug! How do I report it?
|
210
|
+
|
211
|
+
After contacting the mailing list, you've found that you've uncovered a bug. You can file the bug at the [github issues page](https://github.com/sparklemotion/sqlite3-ruby/issues) which can be found here:
|
212
|
+
|
213
|
+
> https://github.com/sparklemotion/sqlite3-ruby/issues
|
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).
|
219
|
+
|
220
|
+
|
221
|
+
## Contributing
|
222
|
+
|
223
|
+
See [`CONTRIBUTING.md`](./CONTRIBUTING.md).
|
224
|
+
|
225
|
+
|
226
|
+
## License
|
227
|
+
|
228
|
+
This library is licensed under `BSD-3-Clause`, see [`LICENSE`](./LICENSE).
|
229
|
+
|
230
|
+
|
231
|
+
### Dependencies
|
232
|
+
|
233
|
+
The source code of `sqlite` is distributed in the "ruby platform" gem. This code is public domain, see [`LICENSE-DEPENDENCIES`](./LICENSE-DEPENDENCIES) for details.
|
data/ext/sqlite3/database.c
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#include <sqlite3_ruby.h>
|
2
2
|
#include <aggregator.h>
|
3
3
|
|
4
|
-
#
|
4
|
+
#ifdef _MSC_VER
|
5
5
|
#pragma warning( push )
|
6
6
|
#pragma warning( disable : 4028 )
|
7
7
|
#endif
|
@@ -31,7 +31,7 @@ static char *
|
|
31
31
|
utf16_string_value_ptr(VALUE str)
|
32
32
|
{
|
33
33
|
StringValue(str);
|
34
|
-
rb_str_buf_cat(str, "\x00",
|
34
|
+
rb_str_buf_cat(str, "\x00\x00", 2L);
|
35
35
|
return RSTRING_PTR(str);
|
36
36
|
}
|
37
37
|
|
@@ -40,18 +40,17 @@ static VALUE sqlite3_rb_close(VALUE self);
|
|
40
40
|
static VALUE rb_sqlite3_open_v2(VALUE self, VALUE file, VALUE mode, VALUE zvfs)
|
41
41
|
{
|
42
42
|
sqlite3RubyPtr ctx;
|
43
|
-
VALUE flags;
|
44
43
|
int status;
|
45
44
|
|
46
45
|
Data_Get_Struct(self, sqlite3Ruby, ctx);
|
47
46
|
|
48
47
|
#if defined TAINTING_SUPPORT
|
49
|
-
#if defined StringValueCStr
|
48
|
+
# if defined StringValueCStr
|
50
49
|
StringValuePtr(file);
|
51
50
|
rb_check_safe_obj(file);
|
52
|
-
#else
|
51
|
+
# else
|
53
52
|
Check_SafeStr(file);
|
54
|
-
#endif
|
53
|
+
# endif
|
55
54
|
#endif
|
56
55
|
|
57
56
|
status = sqlite3_open_v2(
|
@@ -79,7 +78,7 @@ static VALUE rb_sqlite3_disable_quirk_mode(VALUE self)
|
|
79
78
|
|
80
79
|
return Qtrue;
|
81
80
|
#else
|
82
|
-
return Qfalse
|
81
|
+
return Qfalse;
|
83
82
|
#endif
|
84
83
|
}
|
85
84
|
|
@@ -604,7 +603,7 @@ static VALUE load_extension(VALUE self, VALUE file)
|
|
604
603
|
Data_Get_Struct(self, sqlite3Ruby, ctx);
|
605
604
|
REQUIRE_OPEN_DB(ctx);
|
606
605
|
|
607
|
-
status = sqlite3_load_extension(ctx->db,
|
606
|
+
status = sqlite3_load_extension(ctx->db, StringValuePtr(file), 0, &errMsg);
|
608
607
|
if (status != SQLITE_OK)
|
609
608
|
{
|
610
609
|
errexp = rb_exc_new2(rb_eRuntimeError, errMsg);
|
@@ -745,9 +744,9 @@ static VALUE exec_batch(VALUE self, VALUE sql, VALUE results_as_hash)
|
|
745
744
|
REQUIRE_OPEN_DB(ctx);
|
746
745
|
|
747
746
|
if(results_as_hash == Qtrue) {
|
748
|
-
status = sqlite3_exec(ctx->db, StringValuePtr(sql), hash_callback_function, callback_ary, &errMsg);
|
747
|
+
status = sqlite3_exec(ctx->db, StringValuePtr(sql), (sqlite3_callback)hash_callback_function, (void*)callback_ary, &errMsg);
|
749
748
|
} else {
|
750
|
-
status = sqlite3_exec(ctx->db, StringValuePtr(sql), regular_callback_function, callback_ary, &errMsg);
|
749
|
+
status = sqlite3_exec(ctx->db, StringValuePtr(sql), (sqlite3_callback)regular_callback_function, (void*)callback_ary, &errMsg);
|
751
750
|
}
|
752
751
|
|
753
752
|
if (status != SQLITE_OK)
|
@@ -849,6 +848,6 @@ void init_sqlite3_database()
|
|
849
848
|
rb_sqlite3_aggregator_init();
|
850
849
|
}
|
851
850
|
|
852
|
-
#
|
851
|
+
#ifdef _MSC_VER
|
853
852
|
#pragma warning( pop )
|
854
853
|
#endif
|
data/ext/sqlite3/extconf.rb
CHANGED
@@ -1,100 +1,252 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
1
|
+
require "mkmf"
|
2
|
+
require "mini_portile2"
|
3
|
+
|
4
|
+
module Sqlite3
|
5
|
+
module ExtConf
|
6
|
+
ENV_ALLOWLIST = ["CC", "CFLAGS", "LDFLAGS", "LIBS", "CPPFLAGS", "LT_SYS_LIBRARY_PATH", "CPP"]
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def configure
|
10
|
+
configure_cross_compiler
|
11
|
+
|
12
|
+
if system_libraries?
|
13
|
+
message "Building sqlite3-ruby using system #{libname}.\n"
|
14
|
+
configure_system_libraries
|
15
|
+
else
|
16
|
+
message "Building sqlite3-ruby using packaged sqlite3.\n"
|
17
|
+
configure_packaged_libraries
|
18
|
+
end
|
19
|
+
|
20
|
+
configure_extension
|
21
|
+
|
22
|
+
create_makefile('sqlite3/sqlite3_native')
|
23
|
+
end
|
24
|
+
|
25
|
+
def configure_cross_compiler
|
26
|
+
RbConfig::CONFIG["CC"] = RbConfig::MAKEFILE_CONFIG["CC"] = ENV["CC"] if ENV["CC"]
|
27
|
+
ENV["CC"] = RbConfig::CONFIG["CC"]
|
28
|
+
end
|
29
|
+
|
30
|
+
def system_libraries?
|
31
|
+
sqlcipher? || enable_config("system-libraries")
|
32
|
+
end
|
33
|
+
|
34
|
+
def libname
|
35
|
+
sqlcipher? ? "sqlcipher" : "sqlite3"
|
36
|
+
end
|
37
|
+
|
38
|
+
def sqlcipher?
|
39
|
+
with_config("sqlcipher") ||
|
40
|
+
with_config("sqlcipher-dir") ||
|
41
|
+
with_config("sqlcipher-include") ||
|
42
|
+
with_config("sqlcipher-lib")
|
43
|
+
end
|
44
|
+
|
45
|
+
def configure_system_libraries
|
46
|
+
pkg_config(libname)
|
47
|
+
append_cppflags("-DUSING_SQLCIPHER") if sqlcipher?
|
48
|
+
end
|
49
|
+
|
50
|
+
def configure_packaged_libraries
|
51
|
+
minimal_recipe.tap do |recipe|
|
52
|
+
recipe.configure_options += ["--enable-shared=no", "--enable-static=yes"]
|
53
|
+
ENV.to_h.tap do |env|
|
54
|
+
additional_cflags = [
|
55
|
+
"-fPIC", # needed for linking the static library into a shared library
|
56
|
+
"-O2", # see https://github.com/sparklemotion/sqlite3-ruby/issues/335 for some benchmarks
|
57
|
+
]
|
58
|
+
env["CFLAGS"] = [env["CFLAGS"], additional_cflags].flatten.join(" ")
|
59
|
+
recipe.configure_options += env.select { |k,v| ENV_ALLOWLIST.include?(k) }
|
60
|
+
.map { |key, value| "#{key}=#{value.strip}" }
|
61
|
+
end
|
62
|
+
|
63
|
+
unless File.exist?(File.join(recipe.target, recipe.host, recipe.name, recipe.version))
|
64
|
+
recipe.cook
|
65
|
+
end
|
66
|
+
recipe.activate
|
67
|
+
|
68
|
+
ENV["PKG_CONFIG_ALLOW_SYSTEM_CFLAGS"] = "t" # on macos, pkg-config will not return --cflags without this
|
69
|
+
pcfile = File.join(recipe.path, "lib", "pkgconfig", "sqlite3.pc")
|
70
|
+
if pkg_config(pcfile)
|
71
|
+
# see https://bugs.ruby-lang.org/issues/18490
|
72
|
+
libs = xpopen(["pkg-config", "--libs", "--static", pcfile], err: [:child, :out], &:read)
|
73
|
+
libs.split.each { |lib| append_ldflags(lib) } if $?.success?
|
74
|
+
else
|
75
|
+
abort("\nCould not configure the build properly. Please install either the `pkg-config` utility or the `pkg-config` rubygem.\n\n")
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def configure_extension
|
81
|
+
if Gem::Requirement.new("< 2.7").satisfied_by?(Gem::Version.new(RUBY_VERSION))
|
82
|
+
append_cppflags("-DTAINTING_SUPPORT")
|
83
|
+
end
|
84
|
+
|
85
|
+
if find_header("sqlite3.h")
|
86
|
+
# noop
|
87
|
+
elsif sqlcipher? && find_header("sqlcipher/sqlite3.h")
|
88
|
+
append_cppflags("-DUSING_SQLCIPHER_INC_SUBDIR")
|
89
|
+
else
|
90
|
+
abort_could_not_find("sqlite3.h")
|
91
|
+
end
|
92
|
+
|
93
|
+
abort_could_not_find(libname) unless find_library(libname, "sqlite3_libversion_number", "sqlite3.h")
|
94
|
+
|
95
|
+
# Functions defined in 1.9 but not 1.8
|
96
|
+
have_func('rb_proc_arity')
|
97
|
+
|
98
|
+
# Functions defined in 2.1 but not 2.0
|
99
|
+
have_func('rb_integer_pack')
|
100
|
+
|
101
|
+
# These functions may not be defined
|
102
|
+
have_func('sqlite3_initialize')
|
103
|
+
have_func('sqlite3_backup_init')
|
104
|
+
have_func('sqlite3_column_database_name')
|
105
|
+
have_func('sqlite3_enable_load_extension')
|
106
|
+
have_func('sqlite3_load_extension')
|
107
|
+
|
108
|
+
unless have_func('sqlite3_open_v2') # https://www.sqlite.org/releaselog/3_5_0.html
|
109
|
+
abort("\nPlease use a version of SQLite3 >= 3.5.0\n\n")
|
110
|
+
end
|
111
|
+
|
112
|
+
have_func('sqlite3_prepare_v2')
|
113
|
+
have_type('sqlite3_int64', 'sqlite3.h')
|
114
|
+
have_type('sqlite3_uint64', 'sqlite3.h')
|
115
|
+
end
|
116
|
+
|
117
|
+
def minimal_recipe
|
118
|
+
MiniPortile.new(libname, sqlite3_config[:version]).tap do |recipe|
|
119
|
+
recipe.files = sqlite3_config[:files]
|
120
|
+
recipe.target = File.join(package_root_dir, "ports")
|
121
|
+
recipe.patch_files = Dir[File.join(package_root_dir, "patches", "*.patch")].sort
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def package_root_dir
|
126
|
+
File.expand_path(File.join(File.dirname(__FILE__), "..", ".."))
|
127
|
+
end
|
128
|
+
|
129
|
+
def sqlite3_config
|
130
|
+
mini_portile_config[:sqlite3]
|
131
|
+
end
|
132
|
+
|
133
|
+
def mini_portile_config
|
134
|
+
{
|
135
|
+
sqlite3: {
|
136
|
+
# checksum verified by first checking the published sha3(256) checksum:
|
137
|
+
#
|
138
|
+
# $ sha3sum -a 256 ports/archives/sqlite-autoconf-3390200.tar.gz
|
139
|
+
# b195891eb32305481e61c6718b8cc3b090685b613c4824a076c63166a46c5bee ports/archives/sqlite-autoconf-3390200.tar.gz
|
140
|
+
#
|
141
|
+
# $ sha256sum ports/archives/sqlite-autoconf-3390200.tar.gz
|
142
|
+
# 852be8a6183a17ba47cee0bbff7400b7aa5affd283bf3beefc34fcd088a239de ports/archives/sqlite-autoconf-3390200.tar.gz
|
143
|
+
#
|
144
|
+
version: "3.39.2",
|
145
|
+
files: [{
|
146
|
+
url: "https://www.sqlite.org/2022/sqlite-autoconf-3390200.tar.gz",
|
147
|
+
sha256: "852be8a6183a17ba47cee0bbff7400b7aa5affd283bf3beefc34fcd088a239de",
|
148
|
+
}],
|
149
|
+
}
|
150
|
+
}
|
151
|
+
end
|
152
|
+
|
153
|
+
def abort_could_not_find(missing)
|
154
|
+
abort("\nCould not find #{missing}.\nPlease visit https://github.com/sparklemotion/sqlite3-ruby for installation instructions.\n\n")
|
155
|
+
end
|
156
|
+
|
157
|
+
def cross_build?
|
158
|
+
enable_config("cross-build")
|
159
|
+
end
|
160
|
+
|
161
|
+
def download
|
162
|
+
minimal_recipe.download
|
163
|
+
end
|
164
|
+
|
165
|
+
def print_help
|
166
|
+
print(<<~TEXT)
|
167
|
+
USAGE: ruby #{$PROGRAM_NAME} [options]
|
168
|
+
|
169
|
+
Flags that are always valid:
|
170
|
+
|
171
|
+
--disable-system-libraries
|
172
|
+
Use the packaged libraries, and ignore the system libraries.
|
173
|
+
(This is the default behavior.)
|
23
174
|
|
24
|
-
|
25
|
-
|
26
|
-
# in case the user doesn't have pkg-config installed
|
27
|
-
ENV['PKG_CONFIG_PATH'] ||= pkg_conf
|
28
|
-
rescue
|
29
|
-
end
|
30
|
-
end
|
175
|
+
--enable-system-libraries
|
176
|
+
Use system libraries instead of building and using the packaged libraries.
|
31
177
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
pkg_config("sqlite3")
|
36
|
-
end
|
178
|
+
--with-sqlcipher
|
179
|
+
Use libsqlcipher instead of libsqlite3.
|
180
|
+
(Implies `--enable-system-libraries`.)
|
37
181
|
|
38
|
-
|
39
|
-
|
40
|
-
$CFLAGS << ' -DUSING_SQLCIPHER'
|
41
|
-
dir_config("sqlcipher", cppflags, ldflags)
|
42
|
-
else
|
43
|
-
dir_config("sqlite3", cppflags, ldflags)
|
44
|
-
end
|
182
|
+
--help
|
183
|
+
Display this message.
|
45
184
|
|
46
|
-
if RbConfig::CONFIG["host_os"] =~ /mswin/
|
47
|
-
$CFLAGS << ' -W3'
|
48
|
-
end
|
49
185
|
|
50
|
-
|
51
|
-
$CFLAGS << ' -DTAINTING_SUPPORT'
|
52
|
-
end
|
186
|
+
Flags only used when using system libraries:
|
53
187
|
|
54
|
-
|
55
|
-
if RUBY_PLATFORM =~ /mingw|mswin/
|
56
|
-
abort "#{missing} is missing. Install SQLite3 from " +
|
57
|
-
"http://www.sqlite.org/ first."
|
58
|
-
else
|
59
|
-
abort <<-error
|
60
|
-
#{missing} is missing. Try 'brew install sqlite3',
|
61
|
-
'yum install sqlite-devel' or 'apt-get install libsqlite3-dev'
|
62
|
-
and check your shared library search path (the
|
63
|
-
location where your sqlite3 shared library is located).
|
64
|
-
error
|
65
|
-
end
|
66
|
-
end
|
188
|
+
General (applying to all system libraries):
|
67
189
|
|
68
|
-
|
69
|
-
|
190
|
+
--with-opt-dir=DIRECTORY
|
191
|
+
Look for headers and libraries in DIRECTORY.
|
70
192
|
|
71
|
-
|
193
|
+
--with-opt-lib=DIRECTORY
|
194
|
+
Look for libraries in DIRECTORY.
|
72
195
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
196
|
+
--with-opt-include=DIRECTORY
|
197
|
+
Look for headers in DIRECTORY.
|
198
|
+
|
199
|
+
Related to sqlcipher:
|
200
|
+
|
201
|
+
--with-sqlcipher-dir=DIRECTORY
|
202
|
+
Look for sqlcipher headers and library in DIRECTORY.
|
203
|
+
(Implies `--with-sqlcipher` and `--enable-system-libraries`.)
|
204
|
+
|
205
|
+
--with-sqlcipher-lib=DIRECTORY
|
206
|
+
Look for sqlcipher library in DIRECTORY.
|
207
|
+
(Implies `--with-sqlcipher` and `--enable-system-libraries`.)
|
78
208
|
|
79
|
-
|
80
|
-
|
209
|
+
--with-sqlcipher-include=DIRECTORY
|
210
|
+
Look for sqlcipher headers in DIRECTORY.
|
211
|
+
(Implies `--with-sqlcipher` and `--enable-system-libraries`.)
|
81
212
|
|
82
|
-
# Functions defined in 2.1 but not 2.0
|
83
|
-
have_func('rb_integer_pack')
|
84
213
|
|
85
|
-
|
86
|
-
have_func('sqlite3_initialize')
|
87
|
-
have_func('sqlite3_backup_init')
|
88
|
-
have_func('sqlite3_column_database_name')
|
89
|
-
have_func('sqlite3_enable_load_extension')
|
90
|
-
have_func('sqlite3_load_extension')
|
214
|
+
Flags only used when building and using the packaged libraries:
|
91
215
|
|
92
|
-
|
93
|
-
|
216
|
+
--enable-cross-build
|
217
|
+
Enable cross-build mode. (You probably do not want to set this manually.)
|
218
|
+
|
219
|
+
|
220
|
+
Environment variables used for compiling the C extension:
|
221
|
+
|
222
|
+
CC
|
223
|
+
Use this path to invoke the compiler instead of `RbConfig::CONFIG['CC']`
|
224
|
+
|
225
|
+
|
226
|
+
Environment variables passed through to the compilation of packaged libraries:
|
227
|
+
|
228
|
+
CC
|
229
|
+
CPPFLAGS
|
230
|
+
CFLAGS
|
231
|
+
LDFLAGS
|
232
|
+
LIBS
|
233
|
+
LT_SYS_LIBRARY_PATH
|
234
|
+
CPP
|
235
|
+
|
236
|
+
TEXT
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
94
240
|
end
|
95
241
|
|
96
|
-
|
97
|
-
|
98
|
-
|
242
|
+
if arg_config("--help")
|
243
|
+
Sqlite3::ExtConf.print_help
|
244
|
+
exit!(0)
|
245
|
+
end
|
246
|
+
|
247
|
+
if arg_config("--download-dependencies")
|
248
|
+
Sqlite3::ExtConf.download
|
249
|
+
exit!(0)
|
250
|
+
end
|
99
251
|
|
100
|
-
|
252
|
+
Sqlite3::ExtConf.configure
|
data/ext/sqlite3/sqlite3.c
CHANGED
@@ -158,4 +158,6 @@ void Init_sqlite3_native()
|
|
158
158
|
rb_define_singleton_method(mSqlite3, "threadsafe", threadsafe_p, 0);
|
159
159
|
rb_define_const(mSqlite3, "SQLITE_VERSION", rb_str_new2(SQLITE_VERSION));
|
160
160
|
rb_define_const(mSqlite3, "SQLITE_VERSION_NUMBER", INT2FIX(SQLITE_VERSION_NUMBER));
|
161
|
+
rb_define_const(mSqlite3, "SQLITE_LOADED_VERSION", rb_str_new2(sqlite3_libversion()));
|
162
|
+
|
161
163
|
}
|
data/ext/sqlite3/sqlite3_ruby.h
CHANGED
@@ -21,8 +21,11 @@
|
|
21
21
|
#define SQLITE3_UTF8_STR_NEW2(_obj) \
|
22
22
|
(rb_enc_associate_index(rb_str_new2(_obj), rb_utf8_encindex()))
|
23
23
|
|
24
|
-
|
25
|
-
#include <sqlite3.h>
|
24
|
+
#ifdef USING_SQLCIPHER_INC_SUBDIR
|
25
|
+
# include <sqlcipher/sqlite3.h>
|
26
|
+
#else
|
27
|
+
# include <sqlite3.h>
|
28
|
+
#endif
|
26
29
|
|
27
30
|
#ifndef HAVE_TYPE_SQLITE3_INT64
|
28
31
|
typedef sqlite_int64 sqlite3_int64;
|