Namespace
Methods
S
T
Included Modules
Instance Public methods
setup()
   # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
18 def setup
19   @conn = Base.sqlite3_connection database: ":memory:",
20                                   adapter: "sqlite3",
21                                   timeout: 100
22 
23   @connection_handler = ActiveRecord::Base.connection_handler
24 end
test_add_column_with_custom_primary_key()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
493 def test_add_column_with_custom_primary_key
494   connection = Barcode.connection
495   connection.create_table :barcodes, id: false, force: true do |t|
496     t.integer :dummy
497   end
498   connection.add_column :barcodes, :id, :string, primary_key: true
499 
500   assert_equal "id", connection.primary_key("barcodes")
501 
502   custom_pk = Barcode.columns_hash["id"]
503 
504   assert_equal :string, custom_pk.type
505   assert_not custom_pk.null
506 ensure
507   Barcode.reset_column_information
508 end
test_bad_connection()
   # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
26 def test_bad_connection
27   assert_raise ActiveRecord::NoDatabaseError do
28     connection = ActiveRecord::Base.sqlite3_connection(adapter: "sqlite3", database: "/tmp/should/_not/_exist/-cinco-dog.db")
29     connection.drop_table "ex", if_exists: true
30   end
31 end
test_bad_timeout()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
112 def test_bad_timeout
113   assert_raises(TypeError) do
114     Base.sqlite3_connection database: ":memory:",
115                             adapter: "sqlite3",
116                             timeout: "usa"
117   end
118 end
test_column_types()
   # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
72       def test_column_types
73         owner = Owner.create!(name: "hello".encode("ascii-8bit"))
74         owner.reload
75         select = Owner.columns.map { |c| "typeof(#{c.name})" }.join ", "
76         result = Owner.connection.exec_query <<~SQL
77           SELECT #{select}
78           FROM   #{Owner.table_name}
79           WHERE  #{Owner.primary_key} = #{owner.id}
80         SQL
81 
82         assert_not(result.rows.first.include?("blob"), "should not store blobs")
83       ensure
84         owner.delete
85       end
test_columns()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
301 def test_columns
302   with_example_table do
303     columns = @conn.columns("ex").sort_by(&:name)
304     assert_equal 2, columns.length
305     assert_equal %w{ id number }.sort, columns.map(&:name)
306     assert_equal [nil, nil], columns.map(&:default)
307     assert_equal [true, true], columns.map(&:null)
308   end
309 end
test_columns_with_default()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
311 def test_columns_with_default
312   with_example_table "id integer PRIMARY KEY AUTOINCREMENT, number integer default 10" do
313     column = @conn.columns("ex").find { |x|
314       x.name == "number"
315     }
316     assert_equal "10", column.default
317   end
318 end
test_columns_with_not_null()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
320 def test_columns_with_not_null
321   with_example_table "id integer PRIMARY KEY AUTOINCREMENT, number integer not null" do
322     column = @conn.columns("ex").find { |x| x.name == "number" }
323     assert_not column.null, "column should not be null"
324   end
325 end
test_complicated_expression()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
384 def test_complicated_expression
385   with_example_table do
386     @conn.execute "CREATE INDEX expression ON ex (id % 10, (CASE WHEN number > 0 THEN max(id, number) END))WHERE(id > 1000)"
387     index = @conn.indexes("ex").find { |idx| idx.name == "expression" }
388     assert_equal "id % 10, (CASE WHEN number > 0 THEN max(id, number) END)", index.columns
389     assert_equal "(id > 1000)", index.where
390   end
391 end
test_compound_index()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
358 def test_compound_index
359   with_example_table do
360     @conn.add_index "ex", %w{ id number }, name: "fun"
361     index = @conn.indexes("ex").find { |idx| idx.name == "fun" }
362     assert_equal %w{ id number }.sort, index.columns.sort
363   end
364 end
test_connect()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
128 def test_connect
129   assert @conn, "should have connection"
130 end
test_connect_memory_with_url()
   # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
57 def test_connect_memory_with_url
58   original_connection = ActiveRecord::Base.remove_connection
59   url = "sqlite3::memory:"
60   ActiveRecord::Base.establish_connection(url)
61   assert ActiveRecord::Base.connection
62 ensure
63   ActiveRecord::Base.establish_connection(original_connection)
64 end
test_connect_with_url()
   # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
45 def test_connect_with_url
46   original_connection = ActiveRecord::Base.remove_connection
47   tf = Tempfile.open "whatever"
48   url = "sqlite3:#{tf.path}"
49   ActiveRecord::Base.establish_connection(url)
50   assert ActiveRecord::Base.connection
51 ensure
52   tf.close
53   tf.unlink
54   ActiveRecord::Base.establish_connection(original_connection)
55 end
test_connection_no_db()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
106 def test_connection_no_db
107   assert_raises(ArgumentError) do
108     Base.sqlite3_connection { }
109   end
110 end
test_copy_table_with_composite_primary_keys()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
436 def test_copy_table_with_composite_primary_keys
437   connection = Barcode.connection
438   connection.create_table(:barcodes, primary_key: ["region", "code"], force: true) do |t|
439     t.string :region
440     t.string :code
441     t.text :other_attr
442   end
443   region = "US"
444   code = "214fe0c2-dd47-46df-b53b-66090b3c1d40"
445   Barcode.create!(region: region, code: code, other_attr: "xxx")
446 
447   connection.remove_column("barcodes", "other_attr")
448 
449   assert_equal ["region", "code"], connection.primary_keys("barcodes")
450 
451   barcode = Barcode.first
452   assert_equal region, barcode.region
453   assert_equal code, barcode.code
454 ensure
455   Barcode.reset_column_information
456 end
test_copy_table_with_existing_records_have_custom_primary_key()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
421 def test_copy_table_with_existing_records_have_custom_primary_key
422   connection = Barcode.connection
423   connection.create_table(:barcodes, primary_key: "code", id: :string, limit: 42, force: true) do |t|
424     t.text :other_attr
425   end
426   code = "214fe0c2-dd47-46df-b53b-66090b3c1d40"
427   Barcode.create!(code: code, other_attr: "xxx")
428 
429   connection.remove_column("barcodes", "other_attr")
430 
431   assert_equal code, Barcode.first.id
432 ensure
433   Barcode.reset_column_information
434 end
test_custom_primary_key_in_change_table()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
474 def test_custom_primary_key_in_change_table
475   connection = Barcode.connection
476   connection.create_table :barcodes, id: false, force: true do |t|
477     t.integer :dummy
478   end
479   connection.change_table :barcodes do |t|
480     t.primary_key :id, :string
481   end
482 
483   assert_equal "id", connection.primary_key("barcodes")
484 
485   custom_pk = Barcode.columns_hash["id"]
486 
487   assert_equal :string, custom_pk.type
488   assert_not custom_pk.null
489 ensure
490   Barcode.reset_column_information
491 end
test_custom_primary_key_in_create_table()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
458 def test_custom_primary_key_in_create_table
459   connection = Barcode.connection
460   connection.create_table :barcodes, id: false, force: true do |t|
461     t.primary_key :id, :string
462   end
463 
464   assert_equal "id", connection.primary_key("barcodes")
465 
466   custom_pk = Barcode.columns_hash["id"]
467 
468   assert_equal :string, custom_pk.type
469   assert_not custom_pk.null
470 ensure
471   Barcode.reset_column_information
472 end
test_database_exists_returns_false_when_the_database_does_not_exist()
   # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
33 def test_database_exists_returns_false_when_the_database_does_not_exist
34   assert_not SQLite3Adapter.database_exists?(adapter: "sqlite3", database: "non_extant_db"),
35     "expected non_extant_db to not exist"
36 end
test_database_exists_returns_true_for_an_in_memory_db()
   # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
67 def test_database_exists_returns_true_for_an_in_memory_db
68   assert SQLite3Adapter.database_exists?(database: ":memory:"),
69     "Expected in memory database to exist"
70 end
test_database_exists_returns_true_when_databae_exists()
   # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
38 def test_database_exists_returns_true_when_databae_exists
39   config = ActiveRecord::Base.configurations["arunit"]
40   assert SQLite3Adapter.database_exists?(config),
41     "expected #{config[:database]} to exist"
42 end
test_db_is_not_readonly_when_readonly_option_is_false()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
557 def test_db_is_not_readonly_when_readonly_option_is_false
558   conn = Base.sqlite3_connection database: ":memory:",
559                                  adapter: "sqlite3",
560                                  readonly: false
561 
562   assert_not_predicate conn.raw_connection, :readonly?
563 end
test_db_is_not_readonly_when_readonly_option_is_unspecified()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
565 def test_db_is_not_readonly_when_readonly_option_is_unspecified
566   conn = Base.sqlite3_connection database: ":memory:",
567                                  adapter: "sqlite3"
568 
569   assert_not_predicate conn.raw_connection, :readonly?
570 end
test_db_is_readonly_when_readonly_option_is_true()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
572 def test_db_is_readonly_when_readonly_option_is_true
573   conn = Base.sqlite3_connection database: ":memory:",
574                                  adapter: "sqlite3",
575                                  readonly: true
576 
577   assert_predicate conn.raw_connection, :readonly?
578 end
test_doesnt_error_when_a_read_query_with_leading_chars_is_called_while_preventing_writes()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
646 def test_doesnt_error_when_a_read_query_with_leading_chars_is_called_while_preventing_writes
647   with_example_table "id int, data string" do
648     @conn.execute("INSERT INTO ex (data) VALUES ('138853948594')")
649 
650     @connection_handler.while_preventing_writes do
651       assert_equal 1, @conn.execute("  SELECT data from ex WHERE data = '138853948594'").count
652     end
653   end
654 end
test_doesnt_error_when_a_select_query_is_called_while_preventing_writes()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
636 def test_doesnt_error_when_a_select_query_is_called_while_preventing_writes
637   with_example_table "id int, data string" do
638     @conn.execute("INSERT INTO ex (data) VALUES ('138853948594')")
639 
640     @connection_handler.while_preventing_writes do
641       assert_equal 1, @conn.execute("SELECT data from ex WHERE data = '138853948594'").count
642     end
643   end
644 end
test_encoding()

sqlite3 defaults to UTF-8 encoding

    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
133 def test_encoding
134   assert_equal "UTF-8", @conn.encoding
135 end
test_errors_when_a_delete_query_is_called_while_preventing_writes()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
612 def test_errors_when_a_delete_query_is_called_while_preventing_writes
613   with_example_table "id int, data string" do
614     @conn.execute("INSERT INTO ex (data) VALUES ('138853948594')")
615 
616     assert_raises(ActiveRecord::ReadOnlyError) do
617       @connection_handler.while_preventing_writes do
618         @conn.execute("DELETE FROM ex where data = '138853948594'")
619       end
620     end
621   end
622 end
test_errors_when_a_replace_query_is_called_while_preventing_writes()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
624 def test_errors_when_a_replace_query_is_called_while_preventing_writes
625   with_example_table "id int, data string" do
626     @conn.execute("INSERT INTO ex (data) VALUES ('138853948594')")
627 
628     assert_raises(ActiveRecord::ReadOnlyError) do
629       @connection_handler.while_preventing_writes do
630         @conn.execute("REPLACE INTO ex (data) VALUES ('249823948')")
631       end
632     end
633   end
634 end
test_errors_when_an_insert_query_is_called_while_preventing_writes()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
590 def test_errors_when_an_insert_query_is_called_while_preventing_writes
591   with_example_table "id int, data string" do
592     assert_raises(ActiveRecord::ReadOnlyError) do
593       @connection_handler.while_preventing_writes do
594         @conn.execute("INSERT INTO ex (data) VALUES ('138853948594')")
595       end
596     end
597   end
598 end
test_errors_when_an_update_query_is_called_while_preventing_writes()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
600 def test_errors_when_an_update_query_is_called_while_preventing_writes
601   with_example_table "id int, data string" do
602     @conn.execute("INSERT INTO ex (data) VALUES ('138853948594')")
603 
604     assert_raises(ActiveRecord::ReadOnlyError) do
605       @connection_handler.while_preventing_writes do
606         @conn.execute("UPDATE ex SET data = '9989' WHERE data = '138853948594'")
607       end
608     end
609   end
610 end
test_exec_insert()
   # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
87 def test_exec_insert
88   with_example_table do
89     vals = [Relation::QueryAttribute.new("number", 10, Type::Value.new)]
90     @conn.exec_insert("insert into ex (number) VALUES (?)", "SQL", vals)
91 
92     result = @conn.exec_query(
93       "select number from ex where number = ?", "SQL", vals)
94 
95     assert_equal 1, result.rows.length
96     assert_equal 10, result.rows.first.first
97   end
98 end
test_exec_no_binds()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
137 def test_exec_no_binds
138   with_example_table "id int, data string" do
139     result = @conn.exec_query("SELECT id, data FROM ex")
140     assert_equal 0, result.rows.length
141     assert_equal 2, result.columns.length
142     assert_equal %w{ id data }, result.columns
143 
144     @conn.exec_query('INSERT INTO ex (id, data) VALUES (1, "foo")')
145     result = @conn.exec_query("SELECT id, data FROM ex")
146     assert_equal 1, result.rows.length
147     assert_equal 2, result.columns.length
148 
149     assert_equal [[1, "foo"]], result.rows
150   end
151 end
test_exec_query_typecasts_bind_vals()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
166 def test_exec_query_typecasts_bind_vals
167   with_example_table "id int, data string" do
168     @conn.exec_query('INSERT INTO ex (id, data) VALUES (1, "foo")')
169 
170     result = @conn.exec_query(
171       "SELECT id, data FROM ex WHERE id = ?", nil, [Relation::QueryAttribute.new("id", "1-fuu", Type::Integer.new)])
172 
173     assert_equal 1, result.rows.length
174     assert_equal 2, result.columns.length
175 
176     assert_equal [[1, "foo"]], result.rows
177   end
178 end
test_exec_query_with_binds()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
153 def test_exec_query_with_binds
154   with_example_table "id int, data string" do
155     @conn.exec_query('INSERT INTO ex (id, data) VALUES (1, "foo")')
156     result = @conn.exec_query(
157       "SELECT id, data FROM ex WHERE id = ?", nil, [Relation::QueryAttribute.new(nil, 1, Type::Value.new)])
158 
159     assert_equal 1, result.rows.length
160     assert_equal 2, result.columns.length
161 
162     assert_equal [[1, "foo"]], result.rows
163   end
164 end
test_execute()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
204 def test_execute
205   with_example_table do
206     @conn.execute "INSERT INTO ex (number) VALUES (10)"
207     records = @conn.execute "SELECT * FROM ex"
208     assert_equal 1, records.length
209 
210     record = records.first
211     assert_equal 10, record["number"]
212     assert_equal 1, record["id"]
213   end
214 end
test_expression_index()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
367 def test_expression_index
368   with_example_table do
369     @conn.add_index "ex", "max(id, number)", name: "expression"
370     index = @conn.indexes("ex").find { |idx| idx.name == "expression" }
371     assert_equal "max(id, number)", index.columns
372   end
373 end
test_expression_index_with_where()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
375 def test_expression_index_with_where
376   with_example_table do
377     @conn.add_index "ex", "id % 10, max(id, number)", name: "expression", where: "id > 1000"
378     index = @conn.indexes("ex").find { |idx| idx.name == "expression" }
379     assert_equal "id % 10, max(id, number)", index.columns
380     assert_equal "id > 1000", index.where
381   end
382 end
test_index()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
339 def test_index
340   with_example_table do
341     @conn.add_index "ex", "id", unique: true, name: "fun"
342     index = @conn.indexes("ex").find { |idx| idx.name == "fun" }
343 
344     assert_equal "ex", index.table
345     assert index.unique, "index is unique"
346     assert_equal ["id"], index.columns
347   end
348 end
test_indexes_logs()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
327 def test_indexes_logs
328   with_example_table do
329     assert_logged [["PRAGMA index_list(\"ex\")", "SCHEMA", []]] do
330       @conn.indexes("ex")
331     end
332   end
333 end
test_insert_id_value_returned()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
230 def test_insert_id_value_returned
231   with_example_table do
232     sql = "INSERT INTO ex (number) VALUES (10)"
233     idval = "vuvuzela"
234     id = @conn.insert(sql, nil, nil, idval)
235     assert_equal idval, id
236   end
237 end
test_insert_logged()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
220 def test_insert_logged
221   with_example_table do
222     sql = "INSERT INTO ex (number) VALUES (10)"
223     name = "foo"
224     assert_logged [[sql, name, []]] do
225       @conn.insert(sql, name)
226     end
227   end
228 end
test_nil_timeout()

connection is OK with a nil timeout

    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
121 def test_nil_timeout
122   conn = Base.sqlite3_connection database: ":memory:",
123                                  adapter: "sqlite3",
124                                  timeout: nil
125   assert conn, "made a connection"
126 end
test_no_indexes()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
335 def test_no_indexes
336   assert_equal [], @conn.indexes("items")
337 end
test_no_primary_key()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
411 def test_no_primary_key
412   with_example_table "number integer not null" do
413     assert_nil @conn.primary_key("ex")
414   end
415 end
test_non_unique_index()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
350 def test_non_unique_index
351   with_example_table do
352     @conn.add_index "ex", "id", name: "fun"
353     index = @conn.indexes("ex").find { |idx| idx.name == "fun" }
354     assert_not index.unique, "index is not unique"
355   end
356 end
test_not_everything_an_expression()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
393 def test_not_everything_an_expression
394   with_example_table do
395     @conn.add_index "ex", "id, max(id, number)", name: "expression"
396     index = @conn.indexes("ex").find { |idx| idx.name == "expression" }
397     assert_equal "id, max(id, number)", index.columns
398   end
399 end
test_primary_key()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
402 def test_primary_key
403   with_example_table do
404     assert_equal "id", @conn.primary_key("ex")
405     with_example_table "internet integer PRIMARY KEY AUTOINCREMENT, number integer not null", "foos" do
406       assert_equal "internet", @conn.primary_key("foos")
407     end
408   end
409 end
test_primary_key_returns_nil_for_no_pk()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
100 def test_primary_key_returns_nil_for_no_pk
101   with_example_table "id int, data string" do
102     assert_nil @conn.primary_key("ex")
103   end
104 end
test_quote_binary_column_escapes_it()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
180       def test_quote_binary_column_escapes_it
181         DualEncoding.connection.execute(<<~SQL)
182           CREATE TABLE IF NOT EXISTS dual_encodings (
183             id integer PRIMARY KEY AUTOINCREMENT,
184             name varchar(255),
185             data binary
186           )
187         SQL
188         str = (+"\x80").force_encoding("ASCII-8BIT")
189         binary = DualEncoding.new name: "いただきます!", data: str
190         binary.save!
191         assert_equal str, binary.data
192       ensure
193         DualEncoding.connection.drop_table "dual_encodings", if_exists: true
194       end
test_quote_string()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
216 def test_quote_string
217   assert_equal "''", @conn.quote_string("'")
218 end
test_remove_column_preserves_partial_indexes()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
510 def test_remove_column_preserves_partial_indexes
511   connection = Barcode.connection
512   connection.create_table :barcodes, force: true do |t|
513     t.string :code
514     t.string :region
515     t.boolean :bool_attr
516 
517     t.index :code, unique: true, where: :bool_attr, name: "partial"
518   end
519   connection.remove_column :barcodes, :region
520 
521   index = connection.indexes("barcodes").find { |idx| idx.name == "partial" }
522   assert_equal "bool_attr", index.where
523 ensure
524   Barcode.reset_column_information
525 end
test_respond_to_disable_extension()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
535 def test_respond_to_disable_extension
536   assert_respond_to @conn, :disable_extension
537 end
test_respond_to_enable_extension()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
531 def test_respond_to_enable_extension
532   assert_respond_to @conn, :enable_extension
533 end
test_select_rows()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
239 def test_select_rows
240   with_example_table do
241     2.times do |i|
242       @conn.create "INSERT INTO ex (number) VALUES (#{i})"
243     end
244     rows = @conn.select_rows "select number, id from ex"
245     assert_equal [[0, 1], [1, 2]], rows
246   end
247 end
test_select_rows_logged()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
249 def test_select_rows_logged
250   with_example_table do
251     sql = "select * from ex"
252     name = "foo"
253     assert_logged [[sql, name, []]] do
254       @conn.select_rows sql, name
255     end
256   end
257 end
test_statement_closed()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
539 def test_statement_closed
540   db = ::SQLite3::Database.new(ActiveRecord::Base.
541                              configurations["arunit"]["database"])
542   statement = ::SQLite3::Statement.new(db,
543                                      "CREATE TABLE statement_test (number integer not null)")
544   statement.stub(:step, -> { raise ::SQLite3::BusyException.new("busy") }) do
545     assert_called(statement, :columns, returns: []) do
546       assert_called(statement, :close) do
547         ::SQLite3::Statement.stub(:new, statement) do
548           assert_raises ActiveRecord::StatementInvalid do
549             @conn.exec_query "select * from statement_test"
550           end
551         end
552       end
553     end
554   end
555 end
test_supports_extensions()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
527 def test_supports_extensions
528   assert_not @conn.supports_extensions?, "does not support extensions"
529 end
test_table_exists_logs_name()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
290       def test_table_exists_logs_name
291         with_example_table do
292           sql = <<~SQL
293             SELECT name FROM sqlite_master WHERE name <> 'sqlite_sequence' AND name = 'ex' AND type IN ('table')
294           SQL
295           assert_logged [[sql.squish, "SCHEMA", []]] do
296             assert @conn.table_exists?("ex")
297           end
298         end
299       end
test_tables()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
272 def test_tables
273   with_example_table do
274     assert_equal %w{ ex }, @conn.tables
275     with_example_table "id integer PRIMARY KEY AUTOINCREMENT, number integer", "people" do
276       assert_equal %w{ ex people }.sort, @conn.tables.sort
277     end
278   end
279 end
test_tables_logs_name()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
281       def test_tables_logs_name
282         sql = <<~SQL
283           SELECT name FROM sqlite_master WHERE name <> 'sqlite_sequence' AND type IN ('table')
284         SQL
285         assert_logged [[sql.squish, "SCHEMA", []]] do
286           @conn.tables
287         end
288       end
test_transaction()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
259 def test_transaction
260   with_example_table do
261     count_sql = "select count(*) from ex"
262 
263     @conn.begin_db_transaction
264     @conn.create "INSERT INTO ex (number) VALUES (10)"
265 
266     assert_equal 1, @conn.select_rows(count_sql).first.first
267     @conn.rollback_db_transaction
268     assert_equal 0, @conn.select_rows(count_sql).first.first
269   end
270 end
test_type_cast_should_not_mutate_encoding()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
196 def test_type_cast_should_not_mutate_encoding
197   name = (+"hello").force_encoding(Encoding::ASCII_8BIT)
198   Owner.create(name: name)
199   assert_equal Encoding::ASCII_8BIT, name.encoding
200 ensure
201   Owner.delete_all
202 end
test_writes_are_not_permitted_to_readonly_databases()
    # File activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
580 def test_writes_are_not_permitted_to_readonly_databases
581   conn = Base.sqlite3_connection database: ":memory:",
582                                  adapter: "sqlite3",
583                                  readonly: true
584 
585   assert_raises(ActiveRecord::StatementInvalid, /SQLite3::ReadOnlyException/) do
586     conn.execute("CREATE TABLE test(id integer)")
587   end
588 end