sqlite3-ffi 0.1.5 → 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 +4 -0
- data/lib/sqlite3/ffi/c_api.rb +12 -2
- data/lib/sqlite3/ffi/database.rb +29 -4
- data/lib/sqlite3/ffi/statement.rb +7 -3
- data/lib/sqlite3/ffi/version.rb +1 -1
- metadata +1 -1
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
|
|
@@ -169,9 +172,9 @@ module SQLite3
|
|
|
169
172
|
attach_function :sqlite3_errmsg, [:pointer], :string
|
|
170
173
|
attach_function :sqlite3_error_offset, [:pointer], :int
|
|
171
174
|
attach_function :sqlite3_exec, [:pointer, :string, :pointer, :pointer, :pointer], :int
|
|
172
|
-
attach_function :sqlite3_expanded_sql, [:pointer], :
|
|
175
|
+
attach_function :sqlite3_expanded_sql, [:pointer], :pointer
|
|
173
176
|
attach_function :sqlite3_extended_result_codes, [:pointer, :int], :int
|
|
174
|
-
attach_function :sqlite3_file_control, [:pointer, :
|
|
177
|
+
attach_function :sqlite3_file_control, [:pointer, :pointer, :int, :pointer], :int
|
|
175
178
|
attach_function :sqlite3_finalize, [:pointer], :int
|
|
176
179
|
attach_function :sqlite3_free, [:pointer], :void
|
|
177
180
|
attach_function :sqlite3_get_autocommit, [:pointer], :int
|
|
@@ -205,6 +208,13 @@ module SQLite3
|
|
|
205
208
|
attach_function :sqlite3_value_text, [:pointer], :pointer
|
|
206
209
|
attach_function :sqlite3_value_type, [:pointer], :int
|
|
207
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
|
+
|
|
208
218
|
HAVE_SQLITE3_ENABLE_LOAD_EXTENSION = begin
|
|
209
219
|
attach_function :sqlite3_enable_load_extension, [:pointer, :int], :int
|
|
210
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
|
|
|
@@ -239,7 +239,11 @@ module SQLite3
|
|
|
239
239
|
require_live_db
|
|
240
240
|
require_open_stmt
|
|
241
241
|
|
|
242
|
-
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
|
|
243
247
|
end
|
|
244
248
|
|
|
245
249
|
private
|
data/lib/sqlite3/ffi/version.rb
CHANGED