extralite 1.26 → 1.27

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: 459a362b27b2061131a291b8e8b7f73fbc226847f17973de29771af1b3ff694c
4
- data.tar.gz: 0774ca30f4107711a9fe79ffde59e606073bf5f95c0de1f12bc0e1c14876560a
3
+ metadata.gz: a027328ec4af0d01bc81706f4f8e1ea08770a1341d8a36953882244b2d20ed88
4
+ data.tar.gz: 916fabb4a5328e93bcdcb8121b54aa3e958b87915e9b1c9027cccb44941837b9
5
5
  SHA512:
6
- metadata.gz: 6b7ca365d43357ebbdaed90d18299bdae324fc2526c5206c5810c447bf59aecd56202991a5d46290da3097d6a73605297cb6ed769b53e402b6e1d18099c054d0
7
- data.tar.gz: b6f2b2a578896df9154e3db60a0f84a6afc5c0fee6d4a650b259d3f757dda94c763ad37a6d9c6e428cc92db8311acb0861072b63cfd841d3eb6fca2e84dd3d60
6
+ metadata.gz: fc4cd60e38d6e229d5d28ab6e28db3a16f7ddf1ffde53e3f5a97cacebe607158604421016bab34fa5bf96659ab4d0074fffb0f51712e4429d5529f59bbcdec0d
7
+ data.tar.gz: db9905c1c839a4135fe4c1156b3991f8cad5ac438b5c70091be34e8afee7563371e19afe45cd835cec2f83dd26fc92e5855bf7c53c6ee473728b80caabb3e5e1
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 1.27 2023-06-12
2
+
3
+ - Fix execution of prepared statements in Sequel adapter (#23 @gschlager)
4
+ - Update bundled sqlite code to version 3.42.0 (#22 @gschlager)
5
+
1
6
  # 1.26 2023-05-17
2
7
 
3
8
  - Improve documentation
data/Gemfile.lock CHANGED
@@ -1,13 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- extralite (1.26)
4
+ extralite (1.27)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  docile (1.4.0)
10
- json (2.6.1)
10
+ json (2.6.3)
11
11
  minitest (5.15.0)
12
12
  rake (13.0.6)
13
13
  rake-compiler (1.1.6)
data/README.md CHANGED
@@ -14,7 +14,7 @@ with an SQLite3 database, as well as prepared statements.
14
14
  Extralite comes in two flavors: the `extralite` gem which uses the
15
15
  system-installed sqlite3 library, and the `extralite-bundle` gem which bundles
16
16
  the latest version of SQLite
17
- ([3.40.1](https://sqlite.org/releaselog/3_40_1.html)), offering access to the
17
+ ([3.42.0](https://sqlite.org/releaselog/3_42_0.html)), offering access to the
18
18
  latest features and enhancements.
19
19
 
20
20
  ## Features
@@ -1,4 +1,4 @@
1
1
  module Extralite
2
2
  # Extralite version
3
- VERSION = '1.26'
3
+ VERSION = '1.27'
4
4
  end
@@ -94,19 +94,19 @@ module Sequel
94
94
 
95
95
  # @!visibility private
96
96
  USE_EXTENDED_RESULT_CODES = false
97
-
97
+
98
98
  # Database adapter for Sequel
99
99
  class Database < Sequel::Database
100
100
  include ::Sequel::SQLite::DatabaseMethods
101
-
101
+
102
102
  set_adapter_scheme :extralite
103
-
103
+
104
104
  # Mimic the file:// uri, by having 2 preceding slashes specify a relative
105
105
  # path, and 3 preceding slashes specify an absolute path.
106
106
  def self.uri_to_options(uri) # :nodoc:
107
107
  { :database => (uri.host.nil? && uri.path == '/') ? nil : "#{uri.host}#{uri.path}" }
108
108
  end
109
-
109
+
110
110
  private_class_method :uri_to_options
111
111
 
112
112
  # The conversion procs to use for this database
@@ -131,14 +131,14 @@ module Sequel
131
131
  # if USE_EXTENDED_RESULT_CODES
132
132
  # db.extended_result_codes = true
133
133
  # end
134
-
134
+
135
135
  connection_pragmas.each{|s| log_connection_yield(s, db){db.query(s)}}
136
-
136
+
137
137
  class << db
138
138
  attr_reader :prepared_statements
139
139
  end
140
140
  db.instance_variable_set(:@prepared_statements, {})
141
-
141
+
142
142
  db
143
143
  end
144
144
 
@@ -147,7 +147,7 @@ module Sequel
147
147
  c.prepared_statements.each_value{|v| v.first.close }
148
148
  c.close
149
149
  end
150
-
150
+
151
151
  # Run the given SQL with the given arguments and yield each row.
152
152
  def execute(sql, opts=OPTS, &block)
153
153
  _execute(:select, sql, opts, &block)
@@ -157,7 +157,7 @@ module Sequel
157
157
  def execute_dui(sql, opts=OPTS)
158
158
  _execute(:update, sql, opts)
159
159
  end
160
-
160
+
161
161
  # Drop any prepared statements on the connection when executing DDL. This is because
162
162
  # prepared statements lock the table in such a way that you can't drop or alter the
163
163
  # table while a prepared statement that references it still exists.
@@ -168,12 +168,12 @@ module Sequel
168
168
  super
169
169
  end
170
170
  end
171
-
171
+
172
172
  # @!visibility private
173
173
  def execute_insert(sql, opts=OPTS)
174
174
  _execute(:insert, sql, opts)
175
175
  end
176
-
176
+
177
177
  # @!visibility private
178
178
  def freeze
179
179
  @conversion_procs.freeze
@@ -195,13 +195,13 @@ module Sequel
195
195
  end
196
196
 
197
197
  private
198
-
198
+
199
199
  def adapter_initialize
200
200
  @conversion_procs = SQLITE_TYPES.dup
201
201
  @conversion_procs['datetime'] = @conversion_procs['timestamp'] = method(:to_application_timestamp)
202
202
  set_integer_booleans
203
203
  end
204
-
204
+
205
205
  # Yield an available connection. Rescue any Extralite::Error and turn
206
206
  # them into DatabaseErrors.
207
207
  def _execute(type, sql, opts, &block)
@@ -226,7 +226,7 @@ module Sequel
226
226
  raise_error(e)
227
227
  end
228
228
  end
229
-
229
+
230
230
  # The SQLite adapter does not need the pool to convert exceptions.
231
231
  # Also, force the max connections to 1 if a memory database is being
232
232
  # used, as otherwise each connection gets a separate database.
@@ -237,7 +237,7 @@ module Sequel
237
237
  o[:max_connections] = 1 if @opts[:database] == ':memory:' || blank_object?(@opts[:database])
238
238
  o
239
239
  end
240
-
240
+
241
241
  def prepared_statement_argument(arg)
242
242
  case arg
243
243
  when Date, DateTime, Time
@@ -281,9 +281,9 @@ module Sequel
281
281
  log_sql << ")"
282
282
  end
283
283
  if block
284
- log_connection_yield(log_sql, conn, args){cps.execute(ps_args, &block)}
284
+ log_connection_yield(log_sql, conn, args){cps.query(ps_args, &block)}
285
285
  else
286
- log_connection_yield(log_sql, conn, args){cps.execute!(ps_args){|r|}}
286
+ log_connection_yield(log_sql, conn, args){cps.query(ps_args){|r|}}
287
287
  case type
288
288
  when :insert
289
289
  conn.last_insert_rowid
@@ -292,7 +292,7 @@ module Sequel
292
292
  end
293
293
  end
294
294
  end
295
-
295
+
296
296
  # # SQLite3 raises ArgumentError in addition to SQLite3::Exception in
297
297
  # # some cases, such as operations on a closed database.
298
298
  def database_error_classes
@@ -311,7 +311,7 @@ module Sequel
311
311
  end
312
312
  end
313
313
  end
314
-
314
+
315
315
  # Dataset adapter for Sequel
316
316
  class Dataset < Sequel::Dataset
317
317
  include ::Sequel::SQLite::DatasetMethods
@@ -319,9 +319,9 @@ module Sequel
319
319
  # @!visibility private
320
320
  module ArgumentMapper
321
321
  include Sequel::Dataset::ArgumentMapper
322
-
322
+
323
323
  protected
324
-
324
+
325
325
  # Return a hash with the same values as the given hash,
326
326
  # but with the keys converted to strings.
327
327
  def map_to_prepared_args(hash)
@@ -329,16 +329,16 @@ module Sequel
329
329
  hash.each{|k,v| args[k.to_s.gsub('.', '__')] = v}
330
330
  args
331
331
  end
332
-
332
+
333
333
  private
334
-
334
+
335
335
  # SQLite uses a : before the name of the argument for named
336
336
  # arguments.
337
337
  def prepared_arg(k)
338
338
  LiteralString.new("#{prepared_arg_placeholder}#{k.to_s.gsub('.', '__')}")
339
339
  end
340
340
  end
341
-
341
+
342
342
  # @!visibility private
343
343
  BindArgumentMethods = prepared_statements_module(:bind, ArgumentMapper)
344
344
  # @!visibility private
@@ -369,9 +369,9 @@ module Sequel
369
369
  # end
370
370
  # end
371
371
  end
372
-
372
+
373
373
  private
374
-
374
+
375
375
  # The base type name for a given type, without any parenthetical part.
376
376
  def base_type_name(t)
377
377
  (t =~ /^(.*?)\(/ ? $1 : t).downcase if t
data/test/test_sequel.rb CHANGED
@@ -4,21 +4,43 @@ require_relative 'helper'
4
4
  require 'sequel'
5
5
 
6
6
  class SequelExtraliteTest < MiniTest::Test
7
- def test_sequel
8
- db = Sequel.connect('extralite::memory:')
9
- db.create_table :items do
7
+ def setup
8
+ @db = Sequel.connect('extralite::memory:')
9
+ @db.create_table :items do
10
10
  primary_key :id
11
11
  String :name, unique: true, null: false
12
12
  Float :price, null: false
13
13
  end
14
14
 
15
- items = db[:items]
16
-
15
+ items = @db[:items]
17
16
  items.insert(name: 'abc', price: 123)
18
17
  items.insert(name: 'def', price: 456)
19
18
  items.insert(name: 'ghi', price: 789)
19
+ end
20
+
21
+ def teardown
22
+ @db.disconnect
23
+ end
24
+
25
+ def test_sequel
26
+ items = @db[:items]
20
27
 
21
28
  assert_equal 3, items.count
22
29
  assert_equal (123+456+789) / 3, items.avg(:price)
23
30
  end
31
+
32
+ def test_prepared_statement
33
+ items = @db[:items]
34
+ prepared_query = items.where(name: :$name).prepare(:select, :select_by_name)
35
+ prepared_insert = items.prepare(:insert, :insert_with_name_and_price, name: :$name, price: :$price)
36
+
37
+ assert_equal prepared_query.call(name: 'def'), [{ id: 2, name: 'def', price: 456 }]
38
+ assert_equal @db.call(:select_by_name, name: 'def'), [{ id: 2, name: 'def', price: 456 }]
39
+
40
+ id = prepared_insert.call(name: 'jkl', price: 444)
41
+ assert_equal items[id: id], { id: id, name: 'jkl', price: 444 }
42
+
43
+ id = @db.call(:insert_with_name_and_price, name: 'mno', price: 555)
44
+ assert_equal items[id: id], { id: id, name: 'mno', price: 555 }
45
+ end
24
46
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: extralite
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.26'
4
+ version: '1.27'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sharon Rosner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-17 00:00:00.000000000 Z
11
+ date: 2023-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler