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 +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/sqlite3/ffi/aggregator.rb +1 -1
- data/lib/sqlite3/ffi/c_api.rb +13 -2
- data/lib/sqlite3/ffi/database.rb +29 -4
- data/lib/sqlite3/ffi/statement.rb +24 -3
- data/lib/sqlite3/ffi/version.rb +1 -1
- data/lib/sqlite3/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4a7ab9e95562191fa0a9dbc1e41206379def028455f2bf5d76332829034bd2ef
|
|
4
|
+
data.tar.gz: 7866ba35fb73f902f8c1511046ebbbbe684a537358dd0a8513a0ef5facbbcbb6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9954f178afb06b6d43dc1e3cda5241d3a4c8d7ad57bf43efede58aba563abcfcbc4a56bdc2941b9ac1c9983bb15274de0bfd16fc35fb1b8b4be118f3e4c090c4
|
|
7
|
+
data.tar.gz: f7e0486214763d90a26ab03df63be2a45495bb5569b60143b6728da9ce6f81d71a4ac68eb551f2ab32519a29a5c8c0623e227a58ade6b9928db0e7bdf412eaf9
|
data/CHANGELOG.md
CHANGED
data/lib/sqlite3/ffi/c_api.rb
CHANGED
|
@@ -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], :
|
|
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, :
|
|
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
|
data/lib/sqlite3/ffi/database.rb
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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)
|
|
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
|
data/lib/sqlite3/ffi/version.rb
CHANGED
data/lib/sqlite3/version.rb
CHANGED
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
|
+
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:
|
|
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: []
|