sqlite3 1.4.2 → 1.5.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,235 @@
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.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)
111
+ - version 2.1 or later, then you'll need to run `bundle config set force_ruby_platform true`
112
+ - version 2.0 or earlier, then you'll need to run `bundle config force_ruby_platform true`
113
+
114
+
115
+ ### Compiling the source gem
116
+
117
+ 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.
118
+
119
+
120
+ #### Packaged libsqlite3
121
+
122
+ 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.
123
+
124
+ For example, on a linux system running Ruby 2.5:
125
+
126
+ ``` text
127
+ $ ruby -v
128
+ ruby 2.5.9p229 (2021-04-05 revision 67939) [x86_64-linux]
129
+
130
+ $ time gem install sqlite3
131
+ Building native extensions. This could take a while...
132
+ Successfully installed sqlite3-1.5.0
133
+ 1 gem installed
134
+
135
+ real 0m20.620s
136
+ user 0m23.361s
137
+ sys 0m5.839s
138
+ ```
139
+
140
+
141
+ #### System libsqlite3
142
+
143
+ 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.
144
+
145
+ PLEASE NOTE:
146
+
147
+ - you must avoid installing a precompiled native gem (see [previous section](#avoiding-the-precompiled-native-gem))
148
+ - only versions of libsqlite3 `>= 3.5.0` are supported,
149
+ - and some library features may depend on how your libsqlite3 was compiled.
150
+
151
+ For example, on a linux system running Ruby 2.5:
152
+
153
+ ``` text
154
+ $ time gem install sqlite3 -- --enable-system-libraries
155
+ Building native extensions with: '--enable-system-libraries'
156
+ This could take a while...
157
+ Successfully installed sqlite3-1.5.0
158
+ 1 gem installed
159
+
160
+ real 0m4.234s
161
+ user 0m3.809s
162
+ sys 0m0.912s
163
+ ```
164
+
165
+ If you're using bundler, you can opt into system libraries like this:
166
+
167
+ ``` sh
168
+ bundle config build.sqlite3 --enable-system-libraries
169
+ ```
170
+
171
+ 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.
172
+
173
+ ``` sh
174
+ gem install sqlite3 -- \
175
+ --enable-system-libraries \
176
+ --with-sqlite3-include=/opt/local/include \
177
+ --with-sqlite3-lib=/opt/local/lib
178
+ ```
179
+
180
+
181
+ #### System libsqlcipher
182
+
183
+ If you'd like to link against a system-installed libsqlcipher, you may do so by using the `--with-sqlcipher` flag:
184
+
185
+ ``` text
186
+ $ time gem install sqlite3 -- --with-sqlcipher
187
+ Building native extensions with: '--with-sqlcipher'
188
+ This could take a while...
189
+ Successfully installed sqlite3-1.5.0
190
+ 1 gem installed
191
+
192
+ real 0m4.772s
193
+ user 0m3.906s
194
+ sys 0m0.896s
195
+ ```
196
+
197
+ 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.
198
+
199
+
200
+ ## Support
201
+
202
+ ### Something has gone wrong! Where do I get help?
203
+
204
+ You can ask for help or support from the
205
+ [sqlite3-ruby mailing list](http://groups.google.com/group/sqlite3-ruby) which
206
+ can be found here:
207
+
208
+ > http://groups.google.com/group/sqlite3-ruby
209
+
210
+
211
+ ### I've found a bug! How do I report it?
212
+
213
+ 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:
214
+
215
+ > https://github.com/sparklemotion/sqlite3-ruby/issues
216
+
217
+
218
+ ## Usage
219
+
220
+ 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).
221
+
222
+
223
+ ## Contributing
224
+
225
+ See [`CONTRIBUTING.md`](./CONTRIBUTING.md).
226
+
227
+
228
+ ## License
229
+
230
+ This library is licensed under `BSD-3-Clause`, see [`LICENSE`](./LICENSE).
231
+
232
+
233
+ ### Dependencies
234
+
235
+ 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/dependencies.yml ADDED
@@ -0,0 +1,14 @@
1
+ # TODO: stop using symbols here once we no longer support Ruby 2.7 and can rely on symbolize_names
2
+ :sqlite3:
3
+ # checksum verified by first checking the published sha3(256) checksum against https://sqlite.org/download.html:
4
+ #
5
+ # $ sha3sum -a 256 ports/archives/sqlite-autoconf-3400000.tar.gz
6
+ # 7ee8f02b21edb4489df5082b5cf5b7ef47bcebcdb0e209bf14240db69633c878 ports/archives/sqlite-autoconf-3400000.tar.gz
7
+ #
8
+ # $ sha256sum ports/archives/sqlite-autoconf-3400000.tar.gz
9
+ # 0333552076d2700c75352256e91c78bf5cd62491589ba0c69aed0a81868980e7 ports/archives/sqlite-autoconf-3400000.tar.gz
10
+ #
11
+ :version: "3.40.0"
12
+ :files:
13
+ - :url: "https://sqlite.org/2022/sqlite-autoconf-3400000.tar.gz"
14
+ :sha256: "0333552076d2700c75352256e91c78bf5cd62491589ba0c69aed0a81868980e7"
@@ -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);
@@ -265,9 +265,10 @@ rb_sqlite3_define_aggregator2(VALUE self, VALUE aggregator, VALUE ruby_name)
265
265
  void
266
266
  rb_sqlite3_aggregator_init(void)
267
267
  {
268
- rb_gc_register_address(&cAggregatorWrapper);
269
- rb_gc_register_address(&cAggregatorInstance);
270
268
  /* rb_class_new generatos class with undefined allocator in ruby 1.9 */
271
269
  cAggregatorWrapper = rb_funcall(rb_cClass, rb_intern("new"), 0);
270
+ rb_gc_register_mark_object(cAggregatorWrapper);
271
+
272
272
  cAggregatorInstance = rb_funcall(rb_cClass, rb_intern("new"), 0);
273
+ rb_gc_register_mark_object(cAggregatorInstance);
273
274
  }
@@ -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");
@@ -26,7 +31,7 @@ static char *
26
31
  utf16_string_value_ptr(VALUE str)
27
32
  {
28
33
  StringValue(str);
29
- rb_str_buf_cat(str, "\x00", 1L);
34
+ rb_str_buf_cat(str, "\x00\x00", 2L);
30
35
  return RSTRING_PTR(str);
31
36
  }
32
37
 
@@ -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.
@@ -582,7 +603,7 @@ static VALUE load_extension(VALUE self, VALUE file)
582
603
  Data_Get_Struct(self, sqlite3Ruby, ctx);
583
604
  REQUIRE_OPEN_DB(ctx);
584
605
 
585
- status = sqlite3_load_extension(ctx->db, RSTRING_PTR(file), 0, &errMsg);
606
+ status = sqlite3_load_extension(ctx->db, StringValuePtr(file), 0, &errMsg);
586
607
  if (status != SQLITE_OK)
587
608
  {
588
609
  errexp = rb_exc_new2(rb_eRuntimeError, errMsg);
@@ -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