sqlite3-ffi 0.1.6 → 0.1.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4a7ab9e95562191fa0a9dbc1e41206379def028455f2bf5d76332829034bd2ef
4
- data.tar.gz: 7866ba35fb73f902f8c1511046ebbbbe684a537358dd0a8513a0ef5facbbcbb6
3
+ metadata.gz: 6a81fec0d3b0e0c8f1ff287c1e14d8bbeef181b2d03d5708a344324d722c8960
4
+ data.tar.gz: 4340fbba91c04afb1ab0da5528d2f7277f695fe354c06e0ca61b1fd1ab94b863
5
5
  SHA512:
6
- metadata.gz: 9954f178afb06b6d43dc1e3cda5241d3a4c8d7ad57bf43efede58aba563abcfcbc4a56bdc2941b9ac1c9983bb15274de0bfd16fc35fb1b8b4be118f3e4c090c4
7
- data.tar.gz: f7e0486214763d90a26ab03df63be2a45495bb5569b60143b6728da9ce6f81d71a4ac68eb551f2ab32519a29a5c8c0623e227a58ade6b9928db0e7bdf412eaf9
6
+ metadata.gz: 67a1ee9b4b3c84022f681fbc8180c620fd42e27b34078621261c44e229a954b4c9c97907df0a61d50593b8e62238f30c8589aefc4e4a674e8c8c5e2a7b87f197
7
+ data.tar.gz: 7fa688353cf24e25a164a721b5c2edcf573960fed63bae701aa039d68aebbe9555aaf41e984ce7e9329ce06dabb0a9472c4f39fc42d0914ba407feba23664205
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 0.1.8 (2026-08-11)
2
+
3
+ - Synced with sqlite3-ruby 2.9.6
4
+
5
+ ## 0.1.7 (2026-06-07)
6
+
7
+ - Synced with sqlite3-ruby 2.9.5
8
+ - Fixed [GHSA-28hh-pr2h-2w89](https://github.com/sparklemotion/sqlite3-ruby/security/advisories/GHSA-28hh-pr2h-2w89) and [GHSA-j7fr-3v8c-3qc3](https://github.com/sparklemotion/sqlite3-ruby/security/advisories/GHSA-j7fr-3v8c-3qc3)
9
+
1
10
  ## 0.1.6 (2026-02-19)
2
11
 
3
12
  - Fixed memory leaks
data/LICENSE.txt CHANGED
@@ -1,5 +1,5 @@
1
1
  Copyright (c) 2004-2024, Jamis Buck, Luis Lavena, Aaron Patterson, Mike Dalessio, et al.
2
- Copyright (c) 2025, Andrew Kane.
2
+ Copyright (c) 2025-2026, Andrew Kane.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without modification, are permitted
5
5
  provided that the following conditions are met:
@@ -171,11 +171,9 @@ module SQLite3
171
171
  end
172
172
  end
173
173
 
174
- @tracefunc = nil
175
- @authorizer = nil
176
174
  @progress_handler = nil
177
175
  @collations = {}
178
- @functions = {}
176
+ @functions = []
179
177
  @results_as_hash = options[:results_as_hash]
180
178
  @readonly = mode & Constants::Open::READONLY != 0
181
179
  @default_transaction_mode = options[:default_transaction_mode] || :deferred
@@ -398,6 +396,8 @@ module SQLite3
398
396
  # the FunctionProxy#result= method on the +func+ parameter and
399
397
  # indicate the return value that way.
400
398
  #
399
+ # A reference to the block will be kept for the lifetime of the database object.
400
+ #
401
401
  # Example:
402
402
  #
403
403
  # db.create_function( "maim", 1 ) do |func, value|
@@ -437,6 +437,8 @@ module SQLite3
437
437
  # function invocation. It should invoke FunctionProxy#result= to
438
438
  # store the result of the function.
439
439
  #
440
+ # A reference to the block will be kept for the lifetime of the database object.
441
+ #
440
442
  # Example:
441
443
  #
442
444
  # db.create_aggregate( "lengths", 1 ) do
@@ -454,9 +456,7 @@ module SQLite3
454
456
  #
455
457
  # See also #create_aggregate_handler for a more object-oriented approach to
456
458
  # aggregate functions.
457
- def create_aggregate(name, arity, step = nil, finalize = nil,
458
- text_rep = Constants::TextRep::ANY, &block)
459
-
459
+ def create_aggregate(name, arity, step = nil, finalize = nil, text_rep = Constants::TextRep::ANY, &block)
460
460
  proxy = Class.new do
461
461
  def self.step(&block)
462
462
  define_method(:step_with_ctx, &block)
@@ -145,7 +145,7 @@ module SQLite3
145
145
  attach_function :sqlite3_bind_parameter_count, [:pointer], :int
146
146
  attach_function :sqlite3_bind_parameter_index, [:pointer, :string], :int
147
147
  attach_function :sqlite3_bind_parameter_name, [:pointer, :int], :string
148
- attach_function :sqlite3_bind_text, [:pointer, :int, :string, :int, :pointer], :int
148
+ attach_function :sqlite3_bind_text, [:pointer, :int, :pointer, :int, :pointer], :int
149
149
  attach_function :sqlite3_bind_text16, [:pointer, :int, :pointer, :int, :pointer], :int
150
150
  attach_function :sqlite3_busy_handler, [:pointer, :pointer, :pointer], :int
151
151
  attach_function :sqlite3_busy_timeout, [:pointer, :int], :int
@@ -182,8 +182,9 @@ module SQLite3
182
182
  attach_function :sqlite3_last_insert_rowid, [:pointer], :int64
183
183
  attach_function :sqlite3_libversion, [], :string
184
184
  attach_function :sqlite3_libversion_number, [], :int
185
+ attach_function :sqlite3_mprintf, [:string, :varargs], :pointer
185
186
  attach_function :sqlite3_open16, [:pointer, :pointer], :int
186
- attach_function :sqlite3_open_v2, [:string, :pointer, :int, :pointer], :int
187
+ attach_function :sqlite3_open_v2, [:string, :pointer, :int, :string], :int
187
188
  attach_function :sqlite3_prepare_v2, [:pointer, :string, :int, :pointer, :pointer], :int
188
189
  attach_function :sqlite3_progress_handler, [:pointer, :int, :pointer, :pointer], :void
189
190
  attach_function :sqlite3_reset, [:pointer], :int
@@ -2,7 +2,6 @@ module SQLite3
2
2
  class Database
3
3
  def close
4
4
  close_or_discard_db
5
- @aggregators = nil
6
5
  self
7
6
  end
8
7
 
@@ -53,7 +52,7 @@ module SQLite3
53
52
 
54
53
  status = FFI::CApi.sqlite3_create_function(@db, FFI.string_value(name), block.arity, flags, FFI.wrap(block), FFI::FUNC, nil, nil)
55
54
  FFI.check(@db, status)
56
- @functions[name] = block
55
+ @functions << block
57
56
  self
58
57
  end
59
58
 
@@ -168,6 +167,12 @@ module SQLite3
168
167
  end
169
168
  end
170
169
 
170
+ def require_closed_db
171
+ if !@db.nil?
172
+ raise SQLite3::Exception, "cannot open a database that is already open"
173
+ end
174
+ end
175
+
171
176
  def discard_db
172
177
  sfile = ::FFI::MemoryPointer.new(:pointer)
173
178
 
@@ -210,13 +215,28 @@ module SQLite3
210
215
  end
211
216
 
212
217
  def utf16_string_value_ptr(str)
213
- str + "\x00\x00".encode(Encoding::UTF_16LE)
218
+ str = FFI.string_value(str)
219
+
220
+ utf16str = str.dup
221
+ if utf16str.encoding != Encoding::UTF_16LE && utf16str.encoding != Encoding::UTF_16BE
222
+ utf16str.force_encoding(Encoding::UTF_16LE)
223
+ end
224
+ codepoints = utf16str.codepoints
225
+ if codepoints.include?(0)
226
+ raise ArgumentError, "string contains null char"
227
+ end
228
+
229
+ str = str.dup
230
+ str << 0
231
+ str << 0
232
+ str
214
233
  end
215
234
 
216
235
  def open_v2(file, flags, zvfs)
236
+ require_closed_db
217
237
  @owner = Process.pid
218
238
  db = ::FFI::MemoryPointer.new(:pointer)
219
- status = FFI::CApi.sqlite3_open_v2(FFI.string_value(file), db, flags, zvfs)
239
+ status = FFI::CApi.sqlite3_open_v2(FFI.string_value_cstr(file), db, flags, zvfs.nil? ? nil : FFI.string_value_cstr(zvfs))
220
240
  @db = db.read_pointer
221
241
  @db = ::FFI::AutoPointer.new(db.read_pointer, FFI::CApi.method(:sqlite3_close_v2))
222
242
  FFI.check(@db, status)
@@ -236,7 +256,6 @@ module SQLite3
236
256
 
237
257
  def discard
238
258
  discard_db
239
- @aggregators = nil
240
259
  self
241
260
  end
242
261
 
@@ -252,11 +271,20 @@ module SQLite3
252
271
  end
253
272
 
254
273
  def open16(file)
274
+ require_closed_db
255
275
  @owner = Process.pid
256
276
  db = ::FFI::MemoryPointer.new(:pointer)
257
277
  status = FFI::CApi.sqlite3_open16(utf16_string_value_ptr(file), db)
258
278
  @db = ::FFI::AutoPointer.new(db.read_pointer, FFI::CApi.method(:sqlite3_close_v2))
259
- FFI.check(@db, status)
279
+ if status != FFI::CApi::SQLITE_OK
280
+ # https://github.com/ffi/ffi/issues/1121
281
+ # msg = FFI::CApi.sqlite3_mprintf("%s", :string, FFI::CApi.sqlite3_errmsg(@db))
282
+ # msg = ::FFI::MemoryPointer.new(:pointer).write_pointer(msg)
283
+ msg = FFI::CApi.sqlite3_errmsg(@db)
284
+ @db.free
285
+ @db = nil
286
+ FFI.check_msg(@db, status, msg)
287
+ end
260
288
  status
261
289
  end
262
290
 
@@ -87,9 +87,9 @@ module SQLite3
87
87
  klass = status2klass(status)
88
88
  return if klass.nil?
89
89
 
90
- exception = klass.new(msg.read_pointer.read_string)
90
+ exception = klass.new(msg.is_a?(String) ? msg : msg.read_pointer.read_string)
91
91
  exception.instance_variable_set(:@code, status)
92
- CApi.sqlite3_free(msg.read_pointer)
92
+ CApi.sqlite3_free(msg.read_pointer) unless msg.is_a?(String)
93
93
 
94
94
  raise exception
95
95
  end
@@ -111,7 +111,7 @@ module SQLite3
111
111
  if value.encoding != Encoding::UTF_8 && value.encoding != Encoding::US_ASCII
112
112
  value = value.encode(Encoding::UTF_8)
113
113
  end
114
- status = FFI::CApi.sqlite3_bind_text(@stmt, index, value, value.bytesize, FFI::CApi::SQLITE_TRANSIENT)
114
+ status = FFI::CApi.sqlite3_bind_text(@stmt, index, +value, value.bytesize, FFI::CApi::SQLITE_TRANSIENT)
115
115
  end
116
116
  when Float
117
117
  status = FFI::CApi.sqlite3_bind_double(@stmt, index, value)
@@ -58,6 +58,14 @@ module SQLite3
58
58
  obj.to_str
59
59
  end
60
60
 
61
+ def self.string_value_cstr(obj)
62
+ obj = string_value(obj)
63
+ if obj.include?("\x00")
64
+ raise ArgumentError, "string contains null byte"
65
+ end
66
+ obj
67
+ end
68
+
61
69
  RB_ERRINFO = :sqlite3_ffi_rb_errinfo
62
70
 
63
71
  def self.rb_errinfo
@@ -1,5 +1,5 @@
1
1
  module SQLite3
2
2
  module FFI
3
- VERSION = "0.1.6"
3
+ VERSION = "0.1.8"
4
4
  end
5
5
  end
@@ -1,4 +1,4 @@
1
1
  module SQLite3
2
2
  # (String) the version of the sqlite3 gem, e.g. "2.1.1"
3
- VERSION = "2.9.0"
3
+ VERSION = "2.9.6"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sqlite3-ffi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamis Buck
@@ -77,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
77
  - !ruby/object:Gem::Version
78
78
  version: '0'
79
79
  requirements: []
80
- rubygems_version: 4.0.3
80
+ rubygems_version: 4.0.16
81
81
  specification_version: 4
82
82
  summary: A drop-in replacement for the sqlite3 gem for JRuby
83
83
  test_files: []