sqlite3 1.4.2 → 1.5.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
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.
@@ -10,13 +10,13 @@
10
10
  * in-flight for this aggregator. */
11
11
  static VALUE cAggregatorWrapper;
12
12
 
13
- /* wraps a intance of the "handler" class. Loses its reference at the end of
13
+ /* wraps a instance of the "handler" class. Loses its reference at the end of
14
14
  * the xFinal callback.
15
15
  *
16
- * An AggregatorInstance holds the following instnace variables:
16
+ * An AggregatorInstance holds the following instance variables:
17
17
  * -handler_instance: the instance to call `step` and `finalize` on.
18
18
  * -exc_status: status returned by rb_protect.
19
- * != 0 if an exception occurred. If an exception occured
19
+ * != 0 if an exception occurred. If an exception occurred
20
20
  * `step` and `finalize` won't be called any more. */
21
21
  static VALUE cAggregatorInstance;
22
22
 
@@ -48,7 +48,7 @@ rb_sqlite3_protected_funcall(VALUE self, ID method, int argc, VALUE *params,
48
48
  }
49
49
 
50
50
  /* called in rb_sqlite3_aggregator_step and rb_sqlite3_aggregator_final. It
51
- * checks if the exection context already has an associated instance. If it
51
+ * checks if the execution context already has an associated instance. If it
52
52
  * has one, it returns it. If there is no instance yet, it creates one and
53
53
  * associates it with the context. */
54
54
  static VALUE
@@ -165,8 +165,8 @@ rb_sqlite3_aggregator_final(sqlite3_context * ctx)
165
165
  if (exc_status) {
166
166
  /* the user should never see this, as Statement.step() will pick up the
167
167
  * outstanding exception and raise it instead of generating a new one
168
- * for SQLITE_ERROR with message "Ruby Exception occured" */
169
- sqlite3_result_error(ctx, "Ruby Exception occured", -1);
168
+ * for SQLITE_ERROR with message "Ruby Exception occurred" */
169
+ sqlite3_result_error(ctx, "Ruby Exception occurred", -1);
170
170
  }
171
171
 
172
172
  rb_sqlite3_aggregate_instance_destroy(ctx);
@@ -1,6 +1,11 @@
1
1
  #include <sqlite3_ruby.h>
2
2
  #include <aggregator.h>
3
3
 
4
+ #ifdef _MSC_VER
5
+ #pragma warning( push )
6
+ #pragma warning( disable : 4028 )
7
+ #endif
8
+
4
9
  #define REQUIRE_OPEN_DB(_ctxt) \
5
10
  if(!_ctxt->db) \
6
11
  rb_raise(rb_path2class("SQLite3::Exception"), "cannot use a closed database");
@@ -35,18 +40,17 @@ static VALUE sqlite3_rb_close(VALUE self);
35
40
  static VALUE rb_sqlite3_open_v2(VALUE self, VALUE file, VALUE mode, VALUE zvfs)
36
41
  {
37
42
  sqlite3RubyPtr ctx;
38
- VALUE flags;
39
43
  int status;
40
44
 
41
45
  Data_Get_Struct(self, sqlite3Ruby, ctx);
42
46
 
43
47
  #if defined TAINTING_SUPPORT
44
- #if defined StringValueCStr
48
+ # if defined StringValueCStr
45
49
  StringValuePtr(file);
46
50
  rb_check_safe_obj(file);
47
- #else
51
+ # else
48
52
  Check_SafeStr(file);
49
- #endif
53
+ # endif
50
54
  #endif
51
55
 
52
56
  status = sqlite3_open_v2(
@@ -61,6 +65,23 @@ static VALUE rb_sqlite3_open_v2(VALUE self, VALUE file, VALUE mode, VALUE zvfs)
61
65
  return self;
62
66
  }
63
67
 
68
+ static VALUE rb_sqlite3_disable_quirk_mode(VALUE self)
69
+ {
70
+ #if defined SQLITE_DBCONFIG_DQS_DDL
71
+ sqlite3RubyPtr ctx;
72
+ Data_Get_Struct(self, sqlite3Ruby, ctx);
73
+
74
+ if(!ctx->db) return Qfalse;
75
+
76
+ sqlite3_db_config(ctx->db, SQLITE_DBCONFIG_DQS_DDL, 0, (void*)0);
77
+ sqlite3_db_config(ctx->db, SQLITE_DBCONFIG_DQS_DML, 0, (void*)0);
78
+
79
+ return Qtrue;
80
+ #else
81
+ return Qfalse;
82
+ #endif
83
+ }
84
+
64
85
  /* call-seq: db.close
65
86
  *
66
87
  * Closes this database.
@@ -705,7 +726,7 @@ static int regular_callback_function(VALUE callback_ary, int count, char **data,
705
726
 
706
727
  /* Is invoked by calling db.execute_batch2(sql, &block)
707
728
  *
708
- * Executes all statments in a given string separated by semicolons.
729
+ * Executes all statements in a given string separated by semicolons.
709
730
  * If a query is made, all values returned are strings
710
731
  * (except for 'NULL' values which return nil),
711
732
  * so the user may parse values with a block.
@@ -723,9 +744,9 @@ static VALUE exec_batch(VALUE self, VALUE sql, VALUE results_as_hash)
723
744
  REQUIRE_OPEN_DB(ctx);
724
745
 
725
746
  if(results_as_hash == Qtrue) {
726
- 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);
727
748
  } else {
728
- 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);
729
750
  }
730
751
 
731
752
  if (status != SQLITE_OK)
@@ -800,6 +821,7 @@ void init_sqlite3_database()
800
821
  /* public "define_aggregator" is now a shim around define_aggregator2
801
822
  * implemented in Ruby */
802
823
  rb_define_private_method(cSqlite3Database, "define_aggregator2", rb_sqlite3_define_aggregator2, 2);
824
+ rb_define_private_method(cSqlite3Database, "disable_quirk_mode", rb_sqlite3_disable_quirk_mode, 0);
803
825
  rb_define_method(cSqlite3Database, "interrupt", interrupt, 0);
804
826
  rb_define_method(cSqlite3Database, "errmsg", errmsg, 0);
805
827
  rb_define_method(cSqlite3Database, "errcode", errcode_, 0);
@@ -825,3 +847,7 @@ void init_sqlite3_database()
825
847
 
826
848
  rb_sqlite3_aggregator_init();
827
849
  }
850
+
851
+ #ifdef _MSC_VER
852
+ #pragma warning( pop )
853
+ #endif
@@ -1,100 +1,159 @@
1
- ENV['RC_ARCHS'] = '' if RUBY_PLATFORM =~ /darwin/
2
-
3
- require 'mkmf'
4
-
5
- # :stopdoc:
6
-
7
- RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
8
-
9
- ldflags = cppflags = nil
10
- if RbConfig::CONFIG["host_os"] =~ /darwin/
11
- begin
12
- if with_config('sqlcipher')
13
- brew_prefix = `brew --prefix sqlcipher`.chomp
14
- ldflags = "#{brew_prefix}/lib"
15
- cppflags = "#{brew_prefix}/include/sqlcipher"
16
- pkg_conf = "#{brew_prefix}/lib/pkgconfig"
17
- else
18
- brew_prefix = `brew --prefix sqlite3`.chomp
19
- ldflags = "#{brew_prefix}/lib"
20
- cppflags = "#{brew_prefix}/include"
21
- pkg_conf = "#{brew_prefix}/lib/pkgconfig"
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
+ end
41
+
42
+ def configure_system_libraries
43
+ pkg_config(libname)
44
+ append_cflags("-DUSING_SQLCIPHER") if sqlcipher?
45
+ end
46
+
47
+ def configure_packaged_libraries
48
+ minimal_recipe.tap do |recipe|
49
+ recipe.configure_options += ["--enable-shared=no", "--enable-static=yes"]
50
+ ENV.to_h.tap do |env|
51
+ env["CFLAGS"] = [env["CFLAGS"], "-fPIC"].join(" ") # needed for linking the static library into a shared library
52
+ recipe.configure_options += env.select { |k,v| ENV_ALLOWLIST.include?(k) }
53
+ .map { |key, value| "#{key}=#{value.strip}" }
54
+ end
55
+
56
+ unless File.exist?(File.join(recipe.target, recipe.host, recipe.name, recipe.version))
57
+ recipe.cook
58
+ end
59
+ recipe.activate
60
+
61
+ ENV["PKG_CONFIG_ALLOW_SYSTEM_CFLAGS"] = "t" # on macos, pkg-config will not return --cflags without this
62
+ pcfile = File.join(recipe.path, "lib", "pkgconfig", "sqlite3.pc")
63
+ if pkg_config(pcfile)
64
+ # see https://bugs.ruby-lang.org/issues/18490
65
+ libs = xpopen(["pkg-config", "--libs", "--static", pcfile], err: [:child, :out], &:read)
66
+ libs.split.each { |lib| append_ldflags(lib) } if $?.success?
67
+ else
68
+ abort("\nCould not configure the build properly. Please install either the `pkg-config` utility or the `pkg-config` rubygem.\n\n")
69
+ end
70
+ end
71
+ end
72
+
73
+ def configure_extension
74
+ if Gem::Requirement.new("< 2.7").satisfied_by?(Gem::Version.new(RUBY_VERSION))
75
+ append_cflags("-DTAINTING_SUPPORT")
76
+ end
77
+
78
+ abort_could_not_find("sqlite3.h") unless find_header("sqlite3.h")
79
+ abort_could_not_find(libname) unless find_library(libname, "sqlite3_libversion_number", "sqlite3.h")
80
+
81
+ # Functions defined in 1.9 but not 1.8
82
+ have_func('rb_proc_arity')
83
+
84
+ # Functions defined in 2.1 but not 2.0
85
+ have_func('rb_integer_pack')
86
+
87
+ # These functions may not be defined
88
+ have_func('sqlite3_initialize')
89
+ have_func('sqlite3_backup_init')
90
+ have_func('sqlite3_column_database_name')
91
+ have_func('sqlite3_enable_load_extension')
92
+ have_func('sqlite3_load_extension')
93
+
94
+ unless have_func('sqlite3_open_v2') # https://www.sqlite.org/releaselog/3_5_0.html
95
+ abort("\nPlease use a version of SQLite3 >= 3.5.0\n\n")
96
+ end
97
+
98
+ have_func('sqlite3_prepare_v2')
99
+ have_type('sqlite3_int64', 'sqlite3.h')
100
+ have_type('sqlite3_uint64', 'sqlite3.h')
101
+ end
102
+
103
+ def minimal_recipe
104
+ MiniPortile.new(libname, sqlite3_config[:version]).tap do |recipe|
105
+ recipe.files = sqlite3_config[:files]
106
+ recipe.target = File.join(package_root_dir, "ports")
107
+ recipe.patch_files = Dir[File.join(package_root_dir, "patches", "*.patch")].sort
108
+ end
109
+ end
110
+
111
+ def package_root_dir
112
+ File.expand_path(File.join(File.dirname(__FILE__), "..", ".."))
113
+ end
114
+
115
+ def sqlite3_config
116
+ mini_portile_config[:sqlite3]
117
+ end
118
+
119
+ def mini_portile_config
120
+ {
121
+ sqlite3: {
122
+ # checksum verified by first checking the published sha3(256) checksum:
123
+ #
124
+ # $ sha3sum -a 256 sqlite-autoconf-3390000.tar.gz
125
+ # b8e5b3265992350d40c4ad31efc2e6dec6256813f1d5acc8f0ea805e9f33ca2a sqlite-autoconf-3390000.tar.gz
126
+ #
127
+ # $ sha256sum sqlite-autoconf-3390000.tar.gz
128
+ # e90bcaef6dd5813fcdee4e867f6b65f3c9bfd0aec0f1017f9f3bbce1e4ed09e2 sqlite-autoconf-3390000.tar.gz
129
+ #
130
+ version: "3.39.0",
131
+ files: [{
132
+ url: "https://www.sqlite.org/2022/sqlite-autoconf-3390000.tar.gz",
133
+ sha256: "e90bcaef6dd5813fcdee4e867f6b65f3c9bfd0aec0f1017f9f3bbce1e4ed09e2",
134
+ }],
135
+ }
136
+ }
137
+ end
138
+
139
+ def abort_could_not_find(missing)
140
+ abort("\nCould not find #{missing}.\nPlease visit https://github.com/sparklemotion/sqlite3-ruby for installation instructions.\n\n")
141
+ end
142
+
143
+ def cross_build?
144
+ enable_config("cross-build")
145
+ end
146
+
147
+ def download
148
+ minimal_recipe.download
149
+ end
22
150
  end
23
-
24
- # pkg_config should be less error prone than parsing compiler
25
- # commandline options, but we need to set default ldflags and cpp flags
26
- # in case the user doesn't have pkg-config installed
27
- ENV['PKG_CONFIG_PATH'] ||= pkg_conf
28
- rescue
29
- end
30
- end
31
-
32
- if with_config('sqlcipher')
33
- pkg_config("sqlcipher")
34
- else
35
- pkg_config("sqlite3")
36
- end
37
-
38
- # --with-sqlite3-{dir,include,lib}
39
- if with_config('sqlcipher')
40
- $CFLAGS << ' -DUSING_SQLCIPHER'
41
- dir_config("sqlcipher", cppflags, ldflags)
42
- else
43
- dir_config("sqlite3", cppflags, ldflags)
44
- end
45
-
46
- if RbConfig::CONFIG["host_os"] =~ /mswin/
47
- $CFLAGS << ' -W3'
48
- end
49
-
50
- if RUBY_VERSION < '2.7'
51
- $CFLAGS << ' -DTAINTING_SUPPORT'
52
- end
53
-
54
- def asplode missing
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
151
  end
66
152
  end
67
153
 
68
- asplode('sqlite3.h') unless find_header 'sqlite3.h'
69
- find_library 'pthread', 'pthread_create' # 1.8 support. *shrug*
70
-
71
- have_library 'dl' # for static builds
72
-
73
- if with_config('sqlcipher')
74
- asplode('sqlcipher') unless find_library 'sqlcipher', 'sqlite3_libversion_number'
75
- else
76
- asplode('sqlite3') unless find_library 'sqlite3', 'sqlite3_libversion_number'
77
- end
78
-
79
- # Functions defined in 1.9 but not 1.8
80
- have_func('rb_proc_arity')
81
-
82
- # Functions defined in 2.1 but not 2.0
83
- have_func('rb_integer_pack')
84
-
85
- # These functions may not be defined
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')
91
-
92
- unless have_func('sqlite3_open_v2')
93
- abort "Please use a newer version of SQLite3"
154
+ if arg_config("--download-dependencies")
155
+ Sqlite3::ExtConf.download
156
+ exit!(0)
94
157
  end
95
158
 
96
- have_func('sqlite3_prepare_v2')
97
- have_type('sqlite3_int64', 'sqlite3.h')
98
- have_type('sqlite3_uint64', 'sqlite3.h')
99
-
100
- create_makefile('sqlite3/sqlite3_native')
159
+ Sqlite3::ExtConf.configure
@@ -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
  }
@@ -290,7 +290,7 @@ static VALUE bind_param(VALUE self, VALUE key, VALUE value)
290
290
  /* call-seq: stmt.reset!
291
291
  *
292
292
  * Resets the statement. This is typically done internally, though it might
293
- * occassionally be necessary to manually reset the statement.
293
+ * occasionally be necessary to manually reset the statement.
294
294
  */
295
295
  static VALUE reset_bang(VALUE self)
296
296
  {
@@ -309,7 +309,7 @@ static VALUE reset_bang(VALUE self)
309
309
  /* call-seq: stmt.clear_bindings!
310
310
  *
311
311
  * Resets the statement. This is typically done internally, though it might
312
- * occassionally be necessary to manually reset the statement.
312
+ * occasionally be necessary to manually reset the statement.
313
313
  */
314
314
  static VALUE clear_bindings_bang(VALUE self)
315
315
  {