sqlite3-ffi 0.1.7 → 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: '0099c7235d3e7b13c26861041a474d279952101488139c9b11c40053658bb095'
4
- data.tar.gz: e809f4772c73162b7417c79ae56674606c689e2a1fddb3181ac637d958066f04
3
+ metadata.gz: 6a81fec0d3b0e0c8f1ff287c1e14d8bbeef181b2d03d5708a344324d722c8960
4
+ data.tar.gz: 4340fbba91c04afb1ab0da5528d2f7277f695fe354c06e0ca61b1fd1ab94b863
5
5
  SHA512:
6
- metadata.gz: 916507cb952494f227d6182cf92d9e910cf3534f01995706efff64523eb86750fe7601238b9e4d6c32813cff3a097a073b541bad0632dc74f87e2b35e589ccca
7
- data.tar.gz: 78586b3eb030fdcb58e4afbcace803efcf78c3e02d3939d73524186148f55cc6b7699c5f15b42df774f6007681ac22bbf82a434887874b1092b3a72ec66efadf
6
+ metadata.gz: 67a1ee9b4b3c84022f681fbc8180c620fd42e27b34078621261c44e229a954b4c9c97907df0a61d50593b8e62238f30c8589aefc4e4a674e8c8c5e2a7b87f197
7
+ data.tar.gz: 7fa688353cf24e25a164a721b5c2edcf573960fed63bae701aa039d68aebbe9555aaf41e984ce7e9329ce06dabb0a9472c4f39fc42d0914ba407feba23664205
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.1.8 (2026-08-11)
2
+
3
+ - Synced with sqlite3-ruby 2.9.6
4
+
1
5
  ## 0.1.7 (2026-06-07)
2
6
 
3
7
  - Synced with sqlite3-ruby 2.9.5
@@ -171,8 +171,6 @@ 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
176
  @functions = []
@@ -458,9 +456,7 @@ module SQLite3
458
456
  #
459
457
  # See also #create_aggregate_handler for a more object-oriented approach to
460
458
  # aggregate functions.
461
- def create_aggregate(name, arity, step = nil, finalize = nil,
462
- text_rep = Constants::TextRep::ANY, &block)
463
-
459
+ def create_aggregate(name, arity, step = nil, finalize = nil, text_rep = Constants::TextRep::ANY, &block)
464
460
  proxy = Class.new do
465
461
  def self.step(&block)
466
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
@@ -167,6 +167,12 @@ module SQLite3
167
167
  end
168
168
  end
169
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
+
170
176
  def discard_db
171
177
  sfile = ::FFI::MemoryPointer.new(:pointer)
172
178
 
@@ -209,13 +215,28 @@ module SQLite3
209
215
  end
210
216
 
211
217
  def utf16_string_value_ptr(str)
212
- 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
213
233
  end
214
234
 
215
235
  def open_v2(file, flags, zvfs)
236
+ require_closed_db
216
237
  @owner = Process.pid
217
238
  db = ::FFI::MemoryPointer.new(:pointer)
218
- 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))
219
240
  @db = db.read_pointer
220
241
  @db = ::FFI::AutoPointer.new(db.read_pointer, FFI::CApi.method(:sqlite3_close_v2))
221
242
  FFI.check(@db, status)
@@ -250,11 +271,20 @@ module SQLite3
250
271
  end
251
272
 
252
273
  def open16(file)
274
+ require_closed_db
253
275
  @owner = Process.pid
254
276
  db = ::FFI::MemoryPointer.new(:pointer)
255
277
  status = FFI::CApi.sqlite3_open16(utf16_string_value_ptr(file), db)
256
278
  @db = ::FFI::AutoPointer.new(db.read_pointer, FFI::CApi.method(:sqlite3_close_v2))
257
- 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
258
288
  status
259
289
  end
260
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.7"
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.5"
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.7
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.13
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: []