Class: ActiveRecord::ConnectionAdapters::SQLite3Adapter

Inherits:
AbstractAdapter
  • Object
show all
Includes:
ActiveRecord::ConnectionAdapters::SQLite3::DatabaseStatements, ActiveRecord::ConnectionAdapters::SQLite3::Quoting, ActiveRecord::ConnectionAdapters::SQLite3::SchemaStatements, ArJdbc::Abstract::ConnectionManagement, ArJdbc::Abstract::Core, ArJdbc::Abstract::DatabaseStatements, ArJdbc::Abstract::StatementCache, ArJdbc::Abstract::TransactionSupport, ArJdbc::SQLite3, ArJdbc::SQLite3Config
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

ADAPTER_NAME =
"SQLite"
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::ConnectionAdapters, ArJdbc::SQLite3::DEFAULT_PRAGMAS, ArJdbc::SQLite3::DEFERRABLE_REGEX, ArJdbc::SQLite3::FK_REGEX, ArJdbc::SQLite3::ForeignKeyDefinition, 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::SQLite3Config

#build_connection_config

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, #connected?, #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?, #supports_virtual_columns?, #use_insert_returning?

Methods included from ArJdbc::Abstract::Core

#jdbc_connection

Constructor Details

#initializeSQLite3Adapter

Returns a new instance of SQLite3Adapter.



861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
# File 'lib/arjdbc/sqlite3/adapter.rb', line 861

def initialize(...)
  super

  @memory_database = false
  case @config[:database].to_s
  when ""
    raise ArgumentError, "No database file specified. Missing argument: database"
  when ":memory:"
    @memory_database = true
  end

  # assign arjdbc extra connection params
  conn_params = build_connection_config(@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)


894
895
896
897
898
899
900
901
902
# File 'lib/arjdbc/sqlite3/adapter.rb', line 894

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



820
821
822
823
824
825
826
827
828
# File 'lib/arjdbc/sqlite3/adapter.rb', line 820

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



830
831
832
# File 'lib/arjdbc/sqlite3/adapter.rb', line 830

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

.new_client(conn_params, adapter_instance) ⇒ Object



816
817
818
# File 'lib/arjdbc/sqlite3/adapter.rb', line 816

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

.represent_boolean_as_integer=(value) ⇒ Object

:nodoc:



884
885
886
887
888
889
890
891
892
# File 'lib/arjdbc/sqlite3/adapter.rb', line 884

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)


909
910
911
912
913
# File 'lib/arjdbc/sqlite3/adapter.rb', line 909

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



918
919
920
921
# File 'lib/arjdbc/sqlite3/adapter.rb', line 918

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



923
924
925
# File 'lib/arjdbc/sqlite3/adapter.rb', line 923

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



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

class_attribute :strict_strings_by_default, default: false

#supports_transaction_isolation?Boolean

Returns:

  • (Boolean)


905
906
907
# File 'lib/arjdbc/sqlite3/adapter.rb', line 905

def supports_transaction_isolation?
  false
end