@@ -97,6 +97,10 @@ def supports_json?
97
97
true
98
98
end
99
99
100
+ def supports_common_table_expressions?
101
+ database_version >= "3.8.3"
102
+ end
103
+
100
104
def supports_insert_on_conflict?
101
105
database_version >= "3.24.0"
102
106
end
@@ -154,7 +158,9 @@ def disable_referential_integrity # :nodoc:
154
158
# DATABASE STATEMENTS ======================================
155
159
#++
156
160
157
- READ_QUERY = ActiveRecord ::ConnectionAdapters ::AbstractAdapter . build_read_query_regexp ( :begin , :commit , :explain , :select , :pragma , :release , :savepoint , :rollback ) # :nodoc:
161
+ READ_QUERY = ActiveRecord ::ConnectionAdapters ::AbstractAdapter . build_read_query_regexp (
162
+ :begin , :commit , :explain , :select , :pragma , :release , :savepoint , :rollback , :with
163
+ ) # :nodoc:
158
164
private_constant :READ_QUERY
159
165
160
166
def write_query? ( sql ) # :nodoc:
@@ -317,11 +323,17 @@ def get_database_version # :nodoc:
317
323
SQLite3Adapter ::Version . new ( query_value ( "SELECT sqlite_version(*)" ) )
318
324
end
319
325
326
+ def build_truncate_statement ( table_name )
327
+ "DELETE FROM #{ quote_table_name ( table_name ) } "
328
+ end
329
+
320
330
def build_truncate_statements ( *table_names )
321
- truncate_tables = table_names . map do |table_name |
322
- "DELETE FROM #{ quote_table_name ( table_name ) } "
323
- end
324
- combine_multi_statements ( truncate_tables )
331
+ table_names . flatten . map { |table_name | build_truncate_statement table_name }
332
+ end
333
+
334
+ def truncate ( table_name , name = nil )
335
+ ActiveRecord ::Base . clear_query_caches_for_current_thread if @query_cache_enabled
336
+ execute ( build_truncate_statement ( table_name ) , name )
325
337
end
326
338
327
339
def check_version
@@ -352,7 +364,8 @@ def table_structure(table_name)
352
364
# See: https://www.sqlite.org/lang_altertable.html
353
365
# SQLite has an additional restriction on the ALTER TABLE statement
354
366
def invalid_alter_table_type? ( type , options )
355
- type . to_sym == :primary_key || options [ :primary_key ]
367
+ type . to_sym == :primary_key || options [ :primary_key ] ||
368
+ options [ :null ] == false && options [ :default ] . nil?
356
369
end
357
370
358
371
def alter_table ( table_name , foreign_keys = foreign_keys ( table_name ) , **options )
0 commit comments