sqlite3 1.4.2 → 1.7.2

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.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/{API_CHANGES.rdoc → API_CHANGES.md} +3 -4
  3. data/CHANGELOG.md +641 -0
  4. data/CONTRIBUTING.md +34 -0
  5. data/FAQ.md +431 -0
  6. data/Gemfile +7 -14
  7. data/INSTALLATION.md +259 -0
  8. data/LICENSE-DEPENDENCIES +20 -0
  9. data/README.md +110 -0
  10. data/dependencies.yml +14 -0
  11. data/ext/sqlite3/aggregator.c +10 -10
  12. data/ext/sqlite3/backup.c +26 -13
  13. data/ext/sqlite3/database.c +89 -38
  14. data/ext/sqlite3/database.h +2 -0
  15. data/ext/sqlite3/extconf.rb +269 -84
  16. data/ext/sqlite3/sqlite3.c +5 -2
  17. data/ext/sqlite3/sqlite3_ruby.h +5 -2
  18. data/ext/sqlite3/statement.c +37 -28
  19. data/lib/sqlite3/constants.rb +1 -1
  20. data/lib/sqlite3/database.rb +55 -30
  21. data/lib/sqlite3/pragmas.rb +13 -6
  22. data/lib/sqlite3/resultset.rb +4 -12
  23. data/lib/sqlite3/statement.rb +2 -1
  24. data/lib/sqlite3/translator.rb +2 -3
  25. data/lib/sqlite3/version.rb +3 -5
  26. data/ports/archives/sqlite-autoconf-3450100.tar.gz +0 -0
  27. data/test/helper.rb +9 -0
  28. data/test/test_database.rb +182 -17
  29. data/test/test_deprecated.rb +10 -5
  30. data/test/test_encoding.rb +10 -0
  31. data/test/test_integration_resultset.rb +2 -2
  32. data/test/test_integration_statement.rb +2 -2
  33. data/test/test_pragmas.rb +22 -0
  34. data/test/test_result_set.rb +18 -8
  35. data/test/test_sqlite3.rb +9 -0
  36. data/test/test_statement.rb +28 -1
  37. data/test/test_statement_execute.rb +4 -0
  38. metadata +36 -144
  39. data/.travis.yml +0 -33
  40. data/CHANGELOG.rdoc +0 -318
  41. data/Manifest.txt +0 -60
  42. data/README.rdoc +0 -118
  43. data/Rakefile +0 -8
  44. data/appveyor.yml +0 -36
  45. data/faq/faq.rb +0 -145
  46. data/faq/faq.yml +0 -426
  47. data/rakelib/faq.rake +0 -9
  48. data/rakelib/gem.rake +0 -40
  49. data/rakelib/native.rake +0 -56
  50. data/rakelib/vendor_sqlite3.rake +0 -97
  51. data/setup.rb +0 -1333
data/INSTALLATION.md ADDED
@@ -0,0 +1,259 @@
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 v1.5.0 and later, native (precompiled) gems are available for recent Ruby versions on these platforms:
11
+
12
+ - `aarch64-linux` (requires: glibc >= 2.29)
13
+ - `arm-linux` (requires: glibc >= 2.29)
14
+ - `arm64-darwin`
15
+ - `x64-mingw32` / `x64-mingw-ucrt`
16
+ - `x86-linux` (requires: glibc >= 2.17)
17
+ - `x86_64-darwin`
18
+ - `x86_64-linux` (requires: glibc >= 2.17)
19
+
20
+ 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.
21
+
22
+ For example, on a linux system running Ruby 3.1:
23
+
24
+ ``` text
25
+ $ ruby -v
26
+ ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux]
27
+
28
+ $ time gem install sqlite3
29
+ Fetching sqlite3-1.5.0-x86_64-linux.gem
30
+ Successfully installed sqlite3-1.5.0-x86_64-linux
31
+ 1 gem installed
32
+
33
+ real 0m4.274s
34
+ user 0m0.734s
35
+ sys 0m0.165s
36
+ ```
37
+
38
+ #### Avoiding the precompiled native gem
39
+
40
+ 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.
41
+
42
+ 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:
43
+
44
+ - If you're not using Bundler, then run `gem install sqlite3 --platform=ruby`
45
+ - If you are using Bundler
46
+ - 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)
47
+ - version 2.1 or later, then you'll need to run `bundle config set force_ruby_platform true`
48
+ - version 2.0 or earlier, then you'll need to run `bundle config force_ruby_platform true`
49
+
50
+
51
+ ### Compiling the source gem
52
+
53
+ 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.
54
+
55
+
56
+ #### Packaged libsqlite3
57
+
58
+ 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.
59
+
60
+ For example, on a linux system running Ruby 2.5:
61
+
62
+ ``` text
63
+ $ ruby -v
64
+ ruby 2.5.9p229 (2021-04-05 revision 67939) [x86_64-linux]
65
+
66
+ $ time gem install sqlite3
67
+ Building native extensions. This could take a while...
68
+ Successfully installed sqlite3-1.5.0
69
+ 1 gem installed
70
+
71
+ real 0m20.620s
72
+ user 0m23.361s
73
+ sys 0m5.839s
74
+ ```
75
+
76
+ ##### Controlling compilation flags for sqlite
77
+
78
+ 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 ...
79
+
80
+ **If you're installing the gem using `gem install`** then you can pass in these compile-time flags like this:
81
+
82
+ ``` sh
83
+ gem install sqlite3 --platform=ruby -- \
84
+ --with-sqlite-cflags="-DSQLITE_DEFAULT_CACHE_SIZE=9999 -DSQLITE_DEFAULT_PAGE_SIZE=4444"
85
+ ```
86
+
87
+ or the equivalent:
88
+
89
+ ``` sh
90
+ CFLAGS="-DSQLITE_DEFAULT_CACHE_SIZE=9999 -DSQLITE_DEFAULT_PAGE_SIZE=4444" \
91
+ gem install sqlite3 --platform=ruby
92
+ ```
93
+
94
+ **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:
95
+
96
+ ``` ruby
97
+ # Gemfile
98
+ gem "sqlite3", force_ruby_platform: true # requires bundler >= 2.3.18
99
+ ```
100
+
101
+ and then set up a bundler config parameter for `build.sqlite3`:
102
+
103
+ ``` sh
104
+ bundle config set build.sqlite3 \
105
+ "--with-sqlite-cflags='-DSQLITE_DEFAULT_CACHE_SIZE=9999 -DSQLITE_DEFAULT_PAGE_SIZE=4444'"
106
+ ```
107
+
108
+ 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:
109
+
110
+ ``` yaml
111
+ ---
112
+ BUNDLE_BUILD__SQLITE3: "--with-sqlite-cflags='-DSQLITE_DEFAULT_CACHE_SIZE=9999 -DSQLITE_DEFAULT_PAGE_SIZE=4444'"
113
+ ```
114
+
115
+
116
+ #### System libsqlite3
117
+
118
+ 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.
119
+
120
+ PLEASE NOTE:
121
+
122
+ - you must avoid installing a precompiled native gem (see [previous section](#avoiding-the-precompiled-native-gem))
123
+ - only versions of libsqlite3 `>= 3.5.0` are supported,
124
+ - and some library features may depend on how your libsqlite3 was compiled.
125
+
126
+ For example, on a linux system running Ruby 2.5:
127
+
128
+ ``` text
129
+ $ time gem install sqlite3 -- --enable-system-libraries
130
+ Building native extensions with: '--enable-system-libraries'
131
+ This could take a while...
132
+ Successfully installed sqlite3-1.5.0
133
+ 1 gem installed
134
+
135
+ real 0m4.234s
136
+ user 0m3.809s
137
+ sys 0m0.912s
138
+ ```
139
+
140
+ If you're using bundler, you can opt into system libraries like this:
141
+
142
+ ``` sh
143
+ bundle config build.sqlite3 --enable-system-libraries
144
+ ```
145
+
146
+ 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.
147
+
148
+ ``` sh
149
+ gem install sqlite3 -- \
150
+ --enable-system-libraries \
151
+ --with-sqlite3-include=/opt/local/include \
152
+ --with-sqlite3-lib=/opt/local/lib
153
+ ```
154
+
155
+
156
+ #### System libsqlcipher
157
+
158
+ If you'd like to link against a system-installed libsqlcipher, you may do so by using the `--with-sqlcipher` flag:
159
+
160
+ ``` text
161
+ $ time gem install sqlite3 -- --with-sqlcipher
162
+ Building native extensions with: '--with-sqlcipher'
163
+ This could take a while...
164
+ Successfully installed sqlite3-1.5.0
165
+ 1 gem installed
166
+
167
+ real 0m4.772s
168
+ user 0m3.906s
169
+ sys 0m0.896s
170
+ ```
171
+
172
+ 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.
173
+
174
+
175
+ ## Using SQLite3 extensions
176
+
177
+ ### How do I load a sqlite extension?
178
+
179
+ 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.
180
+
181
+ In this example, I'll be loading the ["spellfix" extension](https://www.sqlite.org/spellfix1.html):
182
+
183
+ ``` text
184
+ # download spellfix.c from somewherehttp://www.sqlite.org/src/finfo?name=ext/misc/spellfix.c
185
+ $ wget https://raw.githubusercontent.com/sqlite/sqlite/master/ext/misc/spellfix.c
186
+ spellfix.c 100%[=================================================>] 100.89K --.-KB/s in 0.09s
187
+
188
+ # follow instructions at https://www.sqlite.org/loadext.html
189
+ # (you will need sqlite3 development packages for this)
190
+ $ gcc -g -fPIC -shared spellfix.c -o spellfix.o
191
+
192
+ $ ls -lt
193
+ total 192
194
+ -rwxrwxr-x 1 flavorjones flavorjones 87984 2023-05-24 10:44 spellfix.o
195
+ -rw-rw-r-- 1 flavorjones flavorjones 103310 2023-05-24 10:43 spellfix.c
196
+ ```
197
+
198
+ Then, in your application, use that `spellfix.o` file like this:
199
+
200
+ ``` ruby
201
+ require "sqlite3"
202
+
203
+ db = SQLite3::Database.new(':memory:')
204
+ db.enable_load_extension(true)
205
+ db.load_extension("/path/to/sqlite/spellfix.o")
206
+ db.execute("CREATE VIRTUAL TABLE demo USING spellfix1;")
207
+ ```
208
+
209
+ ### How do I use my own sqlite3 shared library?
210
+
211
+ 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.
212
+
213
+ If you've installed your alternative as an autotools-style installation, the directory structure will look like this:
214
+
215
+ ```
216
+ /opt/sqlite3
217
+ ├── bin
218
+ │   └── sqlite3
219
+ ├── include
220
+ │   ├── sqlite3.h
221
+ │   └── sqlite3ext.h
222
+ ├── lib
223
+ │   ├── libsqlite3.a
224
+ │   ├── libsqlite3.la
225
+ │   ├── libsqlite3.so -> libsqlite3.so.0.8.6
226
+ │   ├── libsqlite3.so.0 -> libsqlite3.so.0.8.6
227
+ │   ├── libsqlite3.so.0.8.6
228
+ │   └── pkgconfig
229
+ │   └── sqlite3.pc
230
+ └── share
231
+ └── man
232
+ └── man1
233
+ └── sqlite3.1
234
+ ```
235
+
236
+ You can build this gem against that library like this:
237
+
238
+ ```
239
+ gem install sqlite3 --platform=ruby -- \
240
+ --enable-system-libraries \
241
+ --with-opt-dir=/opt/sqlite
242
+ ```
243
+
244
+ Explanation:
245
+
246
+ - use `--platform=ruby` to avoid the precompiled native gems (see the README)
247
+ - the `--` separates arguments passed to "gem install" from arguments passed to the C extension builder
248
+ - use `--enable-system-libraries` to avoid the vendored sqlite3 source
249
+ - use `--with-opt-dir=/path/to/installation` to point the build process at the desired header files and shared object files
250
+
251
+ 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:
252
+
253
+ ```
254
+ gem install sqlite3 --platform=ruby -- \
255
+ --enable-system-libraries \
256
+ --with-opt-include=/path/to/include \
257
+ --with-opt-lib=/path/to/lib
258
+ ```
259
+
@@ -0,0 +1,20 @@
1
+ # Vendored Dependency Licenses
2
+
3
+ The library `sqlite3-ruby` (which lives at https://github.com/sparklemotion/sqlite3-ruby) may include the source code for `sqlite` (which lives at https://www.sqlite.org/)
4
+
5
+ `sqlite` source code is licensed under the public domain:
6
+
7
+ > https://www.sqlite.org/copyright.html
8
+
9
+ The license terms shipped with `sqlite` are included here for your convenience:
10
+
11
+ ```
12
+ The author disclaims copyright to this source code. In place of
13
+ a legal notice, here is a blessing:
14
+
15
+ May you do good and not evil.
16
+ May you find forgiveness for yourself and forgive others.
17
+ May you share freely, never taking more than you give.
18
+ ```
19
+
20
+ Note that these license terms do not apply to the `sqlite3-ruby` library itself.
data/README.md ADDED
@@ -0,0 +1,110 @@
1
+ # Ruby Interface for SQLite3
2
+
3
+ ## Overview
4
+
5
+ This library allows Ruby programs to use the SQLite3 database engine (http://www.sqlite.org).
6
+
7
+ Note that this module is only compatible with SQLite 3.6.16 or newer.
8
+
9
+ * Source code: https://github.com/sparklemotion/sqlite3-ruby
10
+ * Mailing list: http://groups.google.com/group/sqlite3-ruby
11
+ * Download: http://rubygems.org/gems/sqlite3
12
+ * Documentation: http://www.rubydoc.info/gems/sqlite3
13
+
14
+ [![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)
15
+ [![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)
16
+
17
+
18
+ ## Quick start
19
+
20
+ For help understanding the SQLite3 Ruby API, please read the [FAQ](./FAQ.md) and the [full API documentation](https://rubydoc.info/gems/sqlite3).
21
+
22
+ A few key classes whose APIs are often-used are:
23
+
24
+ - SQLite3::Database ([rdoc](https://rubydoc.info/gems/sqlite3/SQLite3/Database))
25
+ - SQLite3::Statement ([rdoc](https://rubydoc.info/gems/sqlite3/SQLite3/Statement))
26
+ - SQLite3::ResultSet ([rdoc](https://rubydoc.info/gems/sqlite3/SQLite3/ResultSet))
27
+
28
+ 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).
29
+
30
+
31
+ ``` ruby
32
+ require "sqlite3"
33
+
34
+ # Open a database
35
+ db = SQLite3::Database.new "test.db"
36
+
37
+ # Create a table
38
+ rows = db.execute <<-SQL
39
+ create table numbers (
40
+ name varchar(30),
41
+ val int
42
+ );
43
+ SQL
44
+
45
+ # Execute a few inserts
46
+ {
47
+ "one" => 1,
48
+ "two" => 2,
49
+ }.each do |pair|
50
+ db.execute "insert into numbers values ( ?, ? )", pair
51
+ end
52
+
53
+ # Find a few rows
54
+ db.execute( "select * from numbers" ) do |row|
55
+ p row
56
+ end
57
+ # => ["one", 1]
58
+ # ["two", 2]
59
+
60
+ # Create another table with multiple columns
61
+ db.execute <<-SQL
62
+ create table students (
63
+ name varchar(50),
64
+ email varchar(50),
65
+ grade varchar(5),
66
+ blog varchar(50)
67
+ );
68
+ SQL
69
+
70
+ # Execute inserts with parameter markers
71
+ db.execute("INSERT INTO students (name, email, grade, blog)
72
+ VALUES (?, ?, ?, ?)", ["Jane", "me@janedoe.com", "A", "http://blog.janedoe.com"])
73
+
74
+ db.execute( "select * from students" ) do |row|
75
+ p row
76
+ end
77
+ # => ["Jane", "me@janedoe.com", "A", "http://blog.janedoe.com"]
78
+ ```
79
+
80
+ ## Support
81
+
82
+ ### Installation or database extensions
83
+
84
+ If you're having trouble with installation, please first read [`INSTALLATION.md`](./INSTALLATION.md).
85
+
86
+ ### General help requests
87
+
88
+ You can ask for help or support:
89
+
90
+ * by emailing the [sqlite3-ruby mailing list](http://groups.google.com/group/sqlite3-ruby)
91
+ * by opening a [discussion thread](https://github.com/sparklemotion/sqlite3-ruby/discussions/categories/q-a) on Github
92
+
93
+ ### Bug reports
94
+
95
+ You can file the bug at the [github issues page](https://github.com/sparklemotion/sqlite3-ruby/issues).
96
+
97
+
98
+ ## Contributing
99
+
100
+ See [`CONTRIBUTING.md`](./CONTRIBUTING.md).
101
+
102
+
103
+ ## License
104
+
105
+ This library is licensed under `BSD-3-Clause`, see [`LICENSE`](./LICENSE).
106
+
107
+
108
+ ### Dependencies
109
+
110
+ 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
+ # a54395aa2cf76b5b973fa420715b6108afedc4d8c0209c763fd2c1b517f8ad9f
5
+ #
6
+ # $ sha3sum -a 256 ports/archives/sqlite-autoconf-3450100.tar.gz
7
+ # a54395aa2cf76b5b973fa420715b6108afedc4d8c0209c763fd2c1b517f8ad9f ports/archives/sqlite-autoconf-3450100.tar.gz
8
+ #
9
+ # $ sha256sum ports/archives/sqlite-autoconf-3450100.tar.gz
10
+ # cd9c27841b7a5932c9897651e20b86c701dd740556989b01ca596fcfa3d49a0a ports/archives/sqlite-autoconf-3450100.tar.gz
11
+ :version: "3.45.1"
12
+ :files:
13
+ - :url: "https://sqlite.org/2024/sqlite-autoconf-3450100.tar.gz"
14
+ :sha256: "cd9c27841b7a5932c9897651e20b86c701dd740556989b01ca596fcfa3d49a0a"
@@ -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);
@@ -206,12 +206,11 @@ VALUE
206
206
  rb_sqlite3_define_aggregator2(VALUE self, VALUE aggregator, VALUE ruby_name)
207
207
  {
208
208
  /* define_aggregator is added as a method to SQLite3::Database in database.c */
209
- sqlite3RubyPtr ctx;
209
+ sqlite3RubyPtr ctx = sqlite3_database_unwrap(self);
210
210
  int arity, status;
211
211
  VALUE aw;
212
212
  VALUE aggregators;
213
213
 
214
- Data_Get_Struct(self, sqlite3Ruby, ctx);
215
214
  if (!ctx->db) {
216
215
  rb_raise(rb_path2class("SQLite3::Exception"), "cannot use a closed database");
217
216
  }
@@ -265,9 +264,10 @@ rb_sqlite3_define_aggregator2(VALUE self, VALUE aggregator, VALUE ruby_name)
265
264
  void
266
265
  rb_sqlite3_aggregator_init(void)
267
266
  {
268
- rb_gc_register_address(&cAggregatorWrapper);
269
- rb_gc_register_address(&cAggregatorInstance);
270
267
  /* rb_class_new generatos class with undefined allocator in ruby 1.9 */
271
268
  cAggregatorWrapper = rb_funcall(rb_cClass, rb_intern("new"), 0);
269
+ rb_gc_register_mark_object(cAggregatorWrapper);
270
+
272
271
  cAggregatorInstance = rb_funcall(rb_cClass, rb_intern("new"), 0);
272
+ rb_gc_register_mark_object(cAggregatorInstance);
273
273
  }
data/ext/sqlite3/backup.c CHANGED
@@ -8,16 +8,29 @@
8
8
 
9
9
  VALUE cSqlite3Backup;
10
10
 
11
- static void deallocate(void * ctx)
11
+ static size_t backup_memsize(const void *data)
12
12
  {
13
- sqlite3BackupRubyPtr c = (sqlite3BackupRubyPtr)ctx;
14
- xfree(c);
13
+ sqlite3BackupRubyPtr ctx = (sqlite3BackupRubyPtr)data;
14
+ // NB: can't account for ctx->p because the type is incomplete.
15
+ return sizeof(*ctx);
15
16
  }
16
17
 
18
+ static const rb_data_type_t backup_type = {
19
+ "SQLite3::Backup",
20
+ {
21
+ NULL,
22
+ RUBY_TYPED_DEFAULT_FREE,
23
+ backup_memsize,
24
+ },
25
+ 0,
26
+ 0,
27
+ RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
28
+ };
29
+
17
30
  static VALUE allocate(VALUE klass)
18
31
  {
19
- sqlite3BackupRubyPtr ctx = xcalloc((size_t)1, sizeof(sqlite3BackupRuby));
20
- return Data_Wrap_Struct(klass, NULL, deallocate, ctx);
32
+ sqlite3BackupRubyPtr ctx;
33
+ return TypedData_Make_Struct(klass, sqlite3BackupRuby, &backup_type, ctx);
21
34
  }
22
35
 
23
36
  /* call-seq: SQLite3::Backup.new(dstdb, dstname, srcdb, srcname)
@@ -62,9 +75,9 @@ static VALUE initialize(VALUE self, VALUE dstdb, VALUE dstname, VALUE srcdb, VAL
62
75
  sqlite3RubyPtr ddb_ctx, sdb_ctx;
63
76
  sqlite3_backup *pBackup;
64
77
 
65
- Data_Get_Struct(self, sqlite3BackupRuby, ctx);
66
- Data_Get_Struct(dstdb, sqlite3Ruby, ddb_ctx);
67
- Data_Get_Struct(srcdb, sqlite3Ruby, sdb_ctx);
78
+ TypedData_Get_Struct(self, sqlite3BackupRuby, &backup_type, ctx);
79
+ ddb_ctx = sqlite3_database_unwrap(dstdb);
80
+ sdb_ctx = sqlite3_database_unwrap(srcdb);
68
81
 
69
82
  if(!sdb_ctx->db)
70
83
  rb_raise(rb_eArgError, "cannot backup from a closed database");
@@ -97,7 +110,7 @@ static VALUE step(VALUE self, VALUE nPage)
97
110
  sqlite3BackupRubyPtr ctx;
98
111
  int status;
99
112
 
100
- Data_Get_Struct(self, sqlite3BackupRuby, ctx);
113
+ TypedData_Get_Struct(self, sqlite3BackupRuby, &backup_type, ctx);
101
114
  REQUIRE_OPEN_BACKUP(ctx);
102
115
  status = sqlite3_backup_step(ctx->p, NUM2INT(nPage));
103
116
  return INT2NUM(status);
@@ -111,7 +124,7 @@ static VALUE finish(VALUE self)
111
124
  {
112
125
  sqlite3BackupRubyPtr ctx;
113
126
 
114
- Data_Get_Struct(self, sqlite3BackupRuby, ctx);
127
+ TypedData_Get_Struct(self, sqlite3BackupRuby, &backup_type, ctx);
115
128
  REQUIRE_OPEN_BACKUP(ctx);
116
129
  (void)sqlite3_backup_finish(ctx->p);
117
130
  ctx->p = NULL;
@@ -129,7 +142,7 @@ static VALUE remaining(VALUE self)
129
142
  {
130
143
  sqlite3BackupRubyPtr ctx;
131
144
 
132
- Data_Get_Struct(self, sqlite3BackupRuby, ctx);
145
+ TypedData_Get_Struct(self, sqlite3BackupRuby, &backup_type, ctx);
133
146
  REQUIRE_OPEN_BACKUP(ctx);
134
147
  return INT2NUM(sqlite3_backup_remaining(ctx->p));
135
148
  }
@@ -145,12 +158,12 @@ static VALUE pagecount(VALUE self)
145
158
  {
146
159
  sqlite3BackupRubyPtr ctx;
147
160
 
148
- Data_Get_Struct(self, sqlite3BackupRuby, ctx);
161
+ TypedData_Get_Struct(self, sqlite3BackupRuby, &backup_type, ctx);
149
162
  REQUIRE_OPEN_BACKUP(ctx);
150
163
  return INT2NUM(sqlite3_backup_pagecount(ctx->p));
151
164
  }
152
165
 
153
- void init_sqlite3_backup()
166
+ void init_sqlite3_backup(void)
154
167
  {
155
168
  #if 0
156
169
  VALUE mSqlite3 = rb_define_module("SQLite3");