Class: ActiveRecord::ConnectionAdapters::SQLite3Adapter

Inherits:
AbstractAdapter
  • Object
show all
Includes:
ArJdbc::Abstract::ConnectionManagement, ArJdbc::Abstract::Core, ArJdbc::Abstract::DatabaseStatements, ArJdbc::Abstract::StatementCache, ArJdbc::Abstract::TransactionSupport, ArJdbc::SQLite3
Defined in:
lib/arjdbc/sqlite3/adapter.rb

Overview

Currently our adapter is named the same as what AR5 names its adapter. We will need to get this changed at some point so this can be a unique name and we can extend activerecord ActiveRecord::ConnectionAdapters::SQLite3Adapter. Once we can do that we can remove the module SQLite3 above and remove a majority of this file.

Defined Under Namespace

Classes: SQLite3Integer

Constant Summary collapse

TYPE_MAP =
ActiveRecord::Type::TypeMap.new.tap { |m| initialize_type_map(m) }

Constants included from ArJdbc::Abstract::DatabaseStatements

ArJdbc::Abstract::DatabaseStatements::NO_BINDS

Constants included from ArJdbc::SQLite3

ArJdbc::SQLite3::ADAPTER_NAME, ArJdbc::SQLite3::ConnectionAdapters, ArJdbc::SQLite3::IndexDefinition, ArJdbc::SQLite3::NATIVE_DATABASE_TYPES, ArJdbc::SQLite3::Quoting, ArJdbc::SQLite3::RecordNotUnique, ArJdbc::SQLite3::SQLite3Adapter, ArJdbc::SQLite3::SchemaCreation

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ArJdbc::Abstract::TransactionSupport

#begin_db_transaction, #commit_db_transaction, #create_savepoint, #exec_rollback_db_transaction, #exec_rollback_to_savepoint, #release_savepoint, #supports_savepoints?

Methods included from ArJdbc::Abstract::StatementCache

#delete_cached_statement, #fetch_cached_statement

Methods included from ArJdbc::Abstract::DatabaseStatements

#exec_update, #internal_exec_query, #select_all

Methods included from ArJdbc::Abstract::ConnectionManagement

#active?, #disconnect!, #really_valid?

Methods included from ArJdbc::SQLite3

#active?, #add_column, #add_reference, #add_timestamps, #build_insert_sql, #change_column, #change_column_default, #change_column_null, #check_all_foreign_keys_valid!, #check_version, #disable_referential_integrity, #disconnect!, #encoding, #foreign_keys, #get_database_version, #native_database_types, #new_column_from_field, #primary_keys, #remove_column, #remove_columns, #remove_index, #rename_column, #rename_table, #requires_reloading?, #return_value_after_insert?, #shared_cache?, #supports_check_constraints?, #supports_common_table_expressions?, #supports_concurrent_connections?, #supports_datetime_with_precision?, #supports_ddl_transactions?, #supports_explain?, #supports_expression_index?, #supports_foreign_keys?, #supports_index_sort_order?, #supports_insert_on_conflict?, #supports_insert_returning?, #supports_json?, #supports_lazy_transactions?, #supports_partial_index?, #supports_savepoints?, #supports_views?, #use_insert_returning?

Methods included from ArJdbc::Abstract::Core

#jdbc_connection

Constructor Details

#initializeSQLite3Adapter

Returns a new instance of SQLite3Adapter.



749
750
751
752
753
754
755
756
757
758
759
760
761
# File 'lib/arjdbc/sqlite3/adapter.rb', line 749

def initialize(...)
  super

  conn_params = @config.compact

  # NOTE: strict strings is not supported by the jdbc driver yet,
  # hope it will supported soon, I open a issue in their repository.
  #   https://github.com/xerial/sqlite-jdbc/issues/1153
  #
  # @config[:strict] = ConnectionAdapters::SQLite3Adapter.strict_strings_by_default unless @config.key?(:strict)

  @connection_parameters = conn_params
end

Class Method Details

.database_exists?(config) ⇒ Boolean

Returns:

  • (Boolean)


773
774
775
776
777
778
779
780
781
# File 'lib/arjdbc/sqlite3/adapter.rb', line 773

def self.database_exists?(config)
  config = config.symbolize_keys
  if config[:database] == ":memory:"
    return true
  else
    database_file = defined?(Rails.root) ? File.expand_path(config[:database], Rails.root) : config[:database]
    File.exist?(database_file)
  end
end

.dbconsole(config, options = {}) ⇒ Object



831
832
833
834
835
836
837
838
839
# File 'lib/arjdbc/sqlite3/adapter.rb', line 831

def dbconsole(config, options = {})
  args = []

  args << "-#{options[:mode]}" if options[:mode]
  args << "-header" if options[:header]
  args << File.expand_path(config.database, const_defined?(:Rails) && Rails.respond_to?(:root) ? Rails.root : nil)

  find_cmd_and_exec("sqlite3", *args)
end

.jdbc_connection_classObject



823
824
825
# File 'lib/arjdbc/sqlite3/adapter.rb', line 823

def jdbc_connection_class
  ::ActiveRecord::ConnectionAdapters::SQLite3JdbcConnection
end

.new_client(conn_params, adapter_instance) ⇒ Object



827
828
829
# File 'lib/arjdbc/sqlite3/adapter.rb', line 827

def new_client(conn_params, adapter_instance)
  jdbc_connection_class.new(conn_params, adapter_instance)
end

.represent_boolean_as_integer=(value) ⇒ Object

:nodoc:



763
764
765
766
767
768
769
770
771
# File 'lib/arjdbc/sqlite3/adapter.rb', line 763

def self.represent_boolean_as_integer=(value) # :nodoc:
  if value == false
    raise "`.represent_boolean_as_integer=` is now always true, so make sure your application can work with it and remove this settings."
  end

  ActiveSupport::Deprecation.warn(
    "`.represent_boolean_as_integer=` is now always true, so setting this is deprecated and will be removed in Rails 6.1."
  )
end

Instance Method Details

#begin_isolated_db_transaction(isolation) ⇒ Object

Raises:

  • (ActiveRecord::TransactionIsolationError)


788
789
790
791
792
# File 'lib/arjdbc/sqlite3/adapter.rb', line 788

def begin_isolated_db_transaction(isolation)
  raise ActiveRecord::TransactionIsolationError, "SQLite3 only supports the `read_uncommitted` transaction isolation level" if isolation != :read_uncommitted
  raise StandardError, "You need to enable the shared-cache mode in SQLite mode before attempting to change the transaction isolation level" unless shared_cache?
  super
end

#exec_insert(sql, name = nil, binds = [], pk = nil, sequence_name = nil, returning: nil) ⇒ Object

SQLite driver doesn't support all types of insert statements with executeUpdate so make it act like a regular query and the ids will be returned from #last_inserted_id example: INSERT INTO "aircraft" DEFAULT VALUES



797
798
799
800
# File 'lib/arjdbc/sqlite3/adapter.rb', line 797

def exec_insert(sql, name = nil, binds = [], pk = nil, sequence_name = nil, returning: nil)
  sql, binds = sql_for_insert(sql, pk, binds, returning)
  internal_exec_query(sql, name, binds)
end

#jdbc_column_classObject



802
803
804
# File 'lib/arjdbc/sqlite3/adapter.rb', line 802

def jdbc_column_class
  ::ActiveRecord::ConnectionAdapters::SQLite3Column
end

#strict_strings_by_defaultObject

:singleton-method: Configure the SQLite3Adapter to be used in a strict strings mode. This will disable double-quoted string literals, because otherwise typos can silently go unnoticed. For example, it is possible to create an index for a non existing column. If you wish to enable this mode you can add the following line to your application.rb file:

config.active_record.sqlite3_adapter_strict_strings_by_default = true



747
# File 'lib/arjdbc/sqlite3/adapter.rb', line 747

class_attribute :strict_strings_by_default, default: false

#supports_transaction_isolation?Boolean

Returns:

  • (Boolean)


784
785
786
# File 'lib/arjdbc/sqlite3/adapter.rb', line 784

def supports_transaction_isolation?
  false
end