sqlite3-ffi 0.1.4 → 0.1.6

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: dbbaa5e5e143c05707d0a5862d7a18b795bbd862d0e1a2fd952ac116b1abc614
4
- data.tar.gz: 1b0a5244008fb363938d6db3367085b9df6024400f0bf99d94dc70f42be446e1
3
+ metadata.gz: 4a7ab9e95562191fa0a9dbc1e41206379def028455f2bf5d76332829034bd2ef
4
+ data.tar.gz: 7866ba35fb73f902f8c1511046ebbbbe684a537358dd0a8513a0ef5facbbcbb6
5
5
  SHA512:
6
- metadata.gz: 15ea673d89d9087f71dfaca5e17684f8b8298c5d5f24c7ca08d3bfe40bdb345bb13ad3576d35a8f5895b5e0a77ff6ba256f77944db4327fad234100a7ca1965a
7
- data.tar.gz: 9473c68f8da638de6c04d93476564583a28e885dafcea23c4349c9eb2170be8b15f335b3729ecb4d2f27887d0e6c4bbe0e147f12f7959a641a518d115634a9c2
6
+ metadata.gz: 9954f178afb06b6d43dc1e3cda5241d3a4c8d7ad57bf43efede58aba563abcfcbc4a56bdc2941b9ac1c9983bb15274de0bfd16fc35fb1b8b4be118f3e4c090c4
7
+ data.tar.gz: f7e0486214763d90a26ab03df63be2a45495bb5569b60143b6728da9ce6f81d71a4ac68eb551f2ab32519a29a5c8c0623e227a58ade6b9928db0e7bdf412eaf9
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 0.1.6 (2026-02-19)
2
+
3
+ - Fixed memory leaks
4
+
5
+ ## 0.1.5 (2026-01-02)
6
+
7
+ - Synced with sqlite3-ruby 2.9.0
8
+
1
9
  ## 0.1.4 (2025-06-09)
2
10
 
3
11
  - Synced with sqlite3-ruby 2.7.0
@@ -19,7 +19,7 @@ module SQLite3
19
19
  inst_ptr = CApi.sqlite3_aggregate_context(ctx, 8)
20
20
 
21
21
  if inst_ptr.null?
22
- fatal "SQLite is out-of-merory"
22
+ fatal "SQLite is out-of-memory"
23
23
  end
24
24
 
25
25
  if inst_ptr.read_pointer.null?
@@ -129,6 +129,9 @@ module SQLite3
129
129
  SQLITE_TRACE_ROW = 0x04
130
130
  SQLITE_TRACE_CLOSE = 0x08
131
131
 
132
+ SQLITE_FCNTL_FILE_POINTER = 7
133
+ SQLITE_FCNTL_JOURNAL_POINTER = 28
134
+
132
135
  attach_function :sqlite3_aggregate_context, [:pointer, :int], :pointer
133
136
  attach_function :sqlite3_backup_finish, [:pointer], :int
134
137
  attach_function :sqlite3_backup_init, [:pointer, :string, :pointer, :string], :pointer
@@ -141,6 +144,7 @@ module SQLite3
141
144
  attach_function :sqlite3_bind_null, [:pointer, :int], :int
142
145
  attach_function :sqlite3_bind_parameter_count, [:pointer], :int
143
146
  attach_function :sqlite3_bind_parameter_index, [:pointer, :string], :int
147
+ attach_function :sqlite3_bind_parameter_name, [:pointer, :int], :string
144
148
  attach_function :sqlite3_bind_text, [:pointer, :int, :string, :int, :pointer], :int
145
149
  attach_function :sqlite3_bind_text16, [:pointer, :int, :pointer, :int, :pointer], :int
146
150
  attach_function :sqlite3_busy_handler, [:pointer, :pointer, :pointer], :int
@@ -168,9 +172,9 @@ module SQLite3
168
172
  attach_function :sqlite3_errmsg, [:pointer], :string
169
173
  attach_function :sqlite3_error_offset, [:pointer], :int
170
174
  attach_function :sqlite3_exec, [:pointer, :string, :pointer, :pointer, :pointer], :int
171
- attach_function :sqlite3_expanded_sql, [:pointer], :string
175
+ attach_function :sqlite3_expanded_sql, [:pointer], :pointer
172
176
  attach_function :sqlite3_extended_result_codes, [:pointer, :int], :int
173
- attach_function :sqlite3_file_control, [:pointer, :string, :int, :pointer], :int
177
+ attach_function :sqlite3_file_control, [:pointer, :pointer, :int, :pointer], :int
174
178
  attach_function :sqlite3_finalize, [:pointer], :int
175
179
  attach_function :sqlite3_free, [:pointer], :void
176
180
  attach_function :sqlite3_get_autocommit, [:pointer], :int
@@ -204,6 +208,13 @@ module SQLite3
204
208
  attach_function :sqlite3_value_text, [:pointer], :pointer
205
209
  attach_function :sqlite3_value_type, [:pointer], :int
206
210
 
211
+ HAVE_SQLITE3_DB_NAME = begin
212
+ attach_function :sqlite3_db_name, [:pointer, :int], :pointer
213
+ true
214
+ rescue ::FFI::NotFoundError
215
+ false
216
+ end
217
+
207
218
  HAVE_SQLITE3_ENABLE_LOAD_EXTENSION = begin
208
219
  attach_function :sqlite3_enable_load_extension, [:pointer, :int], :int
209
220
  true
@@ -169,8 +169,31 @@ module SQLite3
169
169
  end
170
170
 
171
171
  def discard_db
172
+ sfile = ::FFI::MemoryPointer.new(:pointer)
173
+
172
174
  FFI::CApi.sqlite3_db_release_memory(@db)
173
- # TODO sqlite3_file_control
175
+
176
+ if FFI::CApi::HAVE_SQLITE3_DB_NAME
177
+ j_db = 0
178
+ while !(db_name = FFI::CApi.sqlite3_db_name(@db, j_db)).null?
179
+ status = FFI::CApi.sqlite3_file_control(@db, db_name, FFI::CApi::SQLITE_FCNTL_FILE_POINTER, sfile)
180
+ if status == 0
181
+ # TODO
182
+ end
183
+ j_db += 1
184
+ end
185
+ else
186
+ status = FFI::CApi.sqlite3_file_control(@db, nil, FFI::CApi::SQLITE_FCNTL_FILE_POINTER, sfile)
187
+ if status == 0
188
+ # TODO
189
+ end
190
+ end
191
+
192
+ status = FFI::CApi.sqlite3_file_control(@db, nil, FFI::CApi::SQLITE_FCNTL_JOURNAL_POINTER, sfile)
193
+ if status == 0
194
+ # TODO
195
+ end
196
+
174
197
  @db = nil
175
198
  @discarded = true
176
199
  end
@@ -178,7 +201,7 @@ module SQLite3
178
201
  def close_or_discard_db
179
202
  unless @db.nil?
180
203
  if @readonly || @owner == Process.pid
181
- FFI::CApi.sqlite3_close_v2(@db)
204
+ @db.free
182
205
  @db = nil
183
206
  else
184
207
  discard_db
@@ -191,14 +214,15 @@ module SQLite3
191
214
  end
192
215
 
193
216
  def open_v2(file, flags, zvfs)
217
+ @owner = Process.pid
194
218
  db = ::FFI::MemoryPointer.new(:pointer)
195
219
  status = FFI::CApi.sqlite3_open_v2(FFI.string_value(file), db, flags, zvfs)
196
220
  @db = db.read_pointer
221
+ @db = ::FFI::AutoPointer.new(db.read_pointer, FFI::CApi.method(:sqlite3_close_v2))
197
222
  FFI.check(@db, status)
198
223
  if (flags & FFI::CApi::SQLITE_OPEN_READONLY) != 0
199
224
  @readonly = true
200
225
  end
201
- @owner = Process.pid
202
226
  self
203
227
  end
204
228
 
@@ -228,9 +252,10 @@ module SQLite3
228
252
  end
229
253
 
230
254
  def open16(file)
255
+ @owner = Process.pid
231
256
  db = ::FFI::MemoryPointer.new(:pointer)
232
257
  status = FFI::CApi.sqlite3_open16(utf16_string_value_ptr(file), db)
233
- @db = db.read_pointer
258
+ @db = ::FFI::AutoPointer.new(db.read_pointer, FFI::CApi.method(:sqlite3_close_v2))
234
259
  FFI.check(@db, status)
235
260
  status
236
261
  end
@@ -10,7 +10,7 @@ module SQLite3
10
10
  status = FFI::CApi.sqlite3_prepare_v2(db, sql, sql.bytesize, stmt, tail)
11
11
  FFI.check_prepare(db, status, sql)
12
12
 
13
- @stmt = stmt.read_pointer
13
+ @stmt = ::FFI::AutoPointer.new(stmt.read_pointer, FFI::CApi.method(:sqlite3_finalize))
14
14
  @db.instance_variable_set(:@stmt_deadline, nil)
15
15
 
16
16
  tail.read_pointer.read_string.force_encoding(Encoding::UTF_8)
@@ -19,7 +19,7 @@ module SQLite3
19
19
  def close
20
20
  require_open_stmt
21
21
 
22
- FFI::CApi.sqlite3_finalize(@stmt)
22
+ @stmt.free
23
23
  @stmt = nil
24
24
  end
25
25
 
@@ -178,6 +178,23 @@ module SQLite3
178
178
  FFI::CApi.sqlite3_bind_parameter_count(@stmt)
179
179
  end
180
180
 
181
+ def named_params
182
+ require_live_db
183
+ require_open_stmt
184
+
185
+ param_count = FFI::CApi.sqlite3_bind_parameter_count(@stmt)
186
+ params = []
187
+
188
+ 1.upto(param_count) do |i|
189
+ name = FFI::CApi.sqlite3_bind_parameter_name(@stmt, i)
190
+ if name && name[0] != "?"
191
+ param = FFI.interned_utf8_cstr(name[1..])
192
+ params << param
193
+ end
194
+ end
195
+ params.freeze
196
+ end
197
+
181
198
  STMT_STAT_SYMBOLS = {
182
199
  fullscan_steps: FFI::CApi::SQLITE_STMTSTATUS_FULLSCAN_STEP,
183
200
  sorts: FFI::CApi::SQLITE_STMTSTATUS_SORT,
@@ -222,7 +239,11 @@ module SQLite3
222
239
  require_live_db
223
240
  require_open_stmt
224
241
 
225
- FFI::CApi.sqlite3_expanded_sql(@stmt).force_encoding(Encoding::UTF_8).freeze
242
+ expanded_sql = FFI::CApi.sqlite3_expanded_sql(@stmt)
243
+ rb_expanded_sql = expanded_sql.read_string.force_encoding(Encoding::UTF_8).freeze
244
+ FFI::CApi.sqlite3_free(expanded_sql)
245
+
246
+ rb_expanded_sql
226
247
  end
227
248
 
228
249
  private
@@ -1,5 +1,5 @@
1
1
  module SQLite3
2
2
  module FFI
3
- VERSION = "0.1.4"
3
+ VERSION = "0.1.6"
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.7.0"
3
+ VERSION = "2.9.0"
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.4
4
+ version: 0.1.6
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: 3.6.7
80
+ rubygems_version: 4.0.3
81
81
  specification_version: 4
82
82
  summary: A drop-in replacement for the sqlite3 gem for JRuby
83
83
  test_files: []