@@ -79,9 +79,15 @@ module SQLite3
79
79
boolean : { name : "boolean" } ,
80
80
json : { name : "json" } ,
81
81
}
82
+
83
+ class StatementPool < ConnectionAdapters ::StatementPool # :nodoc:
84
+ alias reset clear
82
85
83
- # DIFFERENCE: class_attribute in original adapter is moved down to our section which is a class
84
- # since we cannot define it here in the module (original source this is a class).
86
+ private
87
+ def dealloc ( stmt )
88
+ stmt . close unless stmt . closed?
89
+ end
90
+ end
85
91
86
92
def initialize ( connection , logger , connection_options , config )
87
93
super ( connection , logger , config )
@@ -101,7 +107,7 @@ def supports_transaction_isolation?
101
107
end
102
108
103
109
def supports_partial_index?
104
- database_version >= "3.9.0"
110
+ true
105
111
end
106
112
107
113
def supports_expression_index?
@@ -144,6 +150,34 @@ def supports_insert_on_conflict?
144
150
alias supports_insert_conflict_target? supports_insert_on_conflict?
145
151
146
152
# DIFFERENCE: active?, reconnect!, disconnect! handles by arjdbc core
153
+ def supports_concurrent_connections?
154
+ !@memory_database
155
+ end
156
+
157
+ def active?
158
+ !@raw_connection . closed?
159
+ end
160
+
161
+ def reconnect! ( restore_transactions : false )
162
+ @lock . synchronize do
163
+ if active?
164
+ @connection . rollback rescue nil
165
+ else
166
+ connect
167
+ end
168
+
169
+ super
170
+ end
171
+ end
172
+ alias :reset! :reconnect!
173
+
174
+ # Disconnects from the database if already connected. Otherwise, this
175
+ # method does nothing.
176
+ def disconnect!
177
+ super
178
+ @connection . close rescue nil
179
+ end
180
+
147
181
148
182
def supports_index_sort_order?
149
183
true
@@ -233,8 +267,8 @@ def primary_keys(table_name) # :nodoc:
233
267
pks . sort_by { |f | f [ "pk" ] } . map { |f | f [ "name" ] }
234
268
end
235
269
236
- def remove_index ( table_name , column_name = nil , **options ) # :nodoc:
237
- return if options [ :if_exists ] && !index_exists? ( table_name , column_name , **options )
270
+ def remove_index ( table_name , column_name = nil , **options ) # :nodoc:
271
+ return if options [ :if_exists ] && !index_exists? ( table_name , column_name , **options )
238
272
239
273
index_name = index_name_for_remove ( table_name , column_name , options )
240
274
@@ -271,6 +305,16 @@ def remove_column(table_name, column_name, type = nil, **options) #:nodoc:
271
305
end
272
306
end
273
307
308
+ def remove_columns ( table_name , *column_names , type : nil , **options ) # :nodoc:
309
+ alter_table ( table_name ) do |definition |
310
+ column_names . each do |column_name |
311
+ definition . remove_column column_name
312
+ end
313
+ column_names = column_names . map ( &:to_s )
314
+ definition . foreign_keys . delete_if { |fk | column_names . include? ( fk . column ) }
315
+ end
316
+ end
317
+
274
318
def change_column_default ( table_name , column_name , default_or_changes ) #:nodoc:
275
319
default = extract_new_default_value ( default_or_changes )
276
320
@@ -380,6 +424,34 @@ def table_structure(table_name)
380
424
end
381
425
alias column_definitions table_structure
382
426
427
+ def extract_value_from_default ( default )
428
+ case default
429
+ when /^null$/i
430
+ nil
431
+ # Quoted types
432
+ when /^'(.*)'$/m
433
+ $1. gsub ( "''" , "'" )
434
+ # Quoted types
435
+ when /^"(.*)"$/m
436
+ $1. gsub ( '""' , '"' )
437
+ # Numeric types
438
+ when /\A -?\d +(\. \d *)?\z /
439
+ $&
440
+ else
441
+ # Anything else is blank or some function
442
+ # and we can't know the value of that, so return nil.
443
+ nil
444
+ end
445
+ end
446
+
447
+ def extract_default_function ( default_value , default )
448
+ default if has_default_function? ( default_value , default )
449
+ end
450
+
451
+ def has_default_function? ( default_value , default )
452
+ !default_value && %r{\w +\( .*\) |CURRENT_TIME|CURRENT_DATE|CURRENT_TIMESTAMP} . match? ( default )
453
+ end
454
+
383
455
# See: https://www.sqlite.org/lang_altertable.html
384
456
# SQLite has an additional restriction on the ALTER TABLE statement
385
457
def invalid_alter_table_type? ( type , options )
@@ -564,6 +636,17 @@ def arel_visitor
564
636
Arel ::Visitors ::SQLite . new ( self )
565
637
end
566
638
639
+ def build_statement_pool
640
+ StatementPool . new ( self . class . type_cast_config_to_integer ( @config [ :statement_limit ] ) )
641
+ end
642
+
643
+ def connect
644
+ @connection = ::SQLite3 ::Database . new (
645
+ @config [ :database ] . to_s ,
646
+ @config . merge ( results_as_hash : true )
647
+ )
648
+ end
649
+
567
650
def configure_connection
568
651
execute ( "PRAGMA foreign_keys = ON" , "SCHEMA" )
569
652
end
0 commit comments