Sha256: ab125a9716c0fdb2f526e6c85a29cd6cafe664f6f9343106f10c135c9558c830

Contents?: true

Size: 1.58 KB

Versions: 24

Compression:

Stored size: 1.58 KB

Contents

ArJdbc::ConnectionMethods.module_eval do
  def sqlite3_connection(config)
    config[:adapter_spec] ||= ::ArJdbc::SQLite3
    config[:adapter_class] = ActiveRecord::ConnectionAdapters::SQLite3Adapter unless config.key?(:adapter_class)

    return jndi_connection(config) if jndi_config?(config)

    begin
      require 'jdbc/sqlite3'
      ::Jdbc::SQLite3.load_driver(:require) if defined?(::Jdbc::SQLite3.load_driver)
    rescue LoadError # assuming driver.jar is on the class-path
    end

    parse_sqlite3_config!(config)
    database = config[:database] # NOTE: "jdbc:sqlite::memory:" syntax is supported
    config[:url] ||= "jdbc:sqlite:#{database == ':memory:' ? '' : database}"
    config[:driver] ||= defined?(::Jdbc::SQLite3.driver_name) ? ::Jdbc::SQLite3.driver_name : 'org.sqlite.JDBC'
    config[:connection_alive_sql] ||= 'SELECT 1'

    options = ( config[:properties] ||= {} )
    # NOTE: configuring from JDBC properties not supported on 3.7.2 :
    options['busy_timeout'] ||= config[:timeout] if config.key?(:timeout)

    jdbc_connection(config)
  end
  alias_method :jdbcsqlite3_connection, :sqlite3_connection

  private

  def parse_sqlite3_config!(config)
    database = ( config[:database] ||= config[:dbfile] ) # allow Rails relative path :
    if database != ':memory:' && defined?(Rails.root) || Object.const_defined?(:RAILS_ROOT)
      rails_root = defined?(Rails.root) ? Rails.root : RAILS_ROOT
      config[:database] = File.expand_path(database, rails_root.to_s)
      dirname = File.dirname(config[:database])
      Dir.mkdir(dirname) unless File.directory?(dirname)
    end
  end

end

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
activerecord-jdbc-adapter-1.3.25 lib/arjdbc/sqlite3/connection_methods.rb
activerecord-jdbc-adapter-51.0 lib/arjdbc/sqlite3/connection_methods.rb
activerecord-jdbc-adapter-1.3.24 lib/arjdbc/sqlite3/connection_methods.rb
neo-activerecord-jdbc-adapter-5.0.pre2 lib/arjdbc/sqlite3/connection_methods.rb
activerecord-jdbc-adapter-1.3.23 lib/arjdbc/sqlite3/connection_methods.rb
activerecord-jdbc-adapter-1.3.22 lib/arjdbc/sqlite3/connection_methods.rb
activerecord-jdbc-adapter-5.0.pre1 lib/arjdbc/sqlite3/connection_methods.rb
activerecord-jdbc-adapter-1.3.21 lib/arjdbc/sqlite3/connection_methods.rb
activerecord-jdbc-adapter-1.3.20 lib/arjdbc/sqlite3/connection_methods.rb
activerecord-jdbc-adapter-1.3.19 lib/arjdbc/sqlite3/connection_methods.rb
activerecord-jdbc-adapter-1.3.18 lib/arjdbc/sqlite3/connection_methods.rb
activerecord-jdbc-adapter-1.3.17 lib/arjdbc/sqlite3/connection_methods.rb
activerecord-jdbc-adapter-1.3.16 lib/arjdbc/sqlite3/connection_methods.rb
activerecord-jdbc-adapter-1.3.15 lib/arjdbc/sqlite3/connection_methods.rb
activerecord-jdbc-adapter-1.3.14 lib/arjdbc/sqlite3/connection_methods.rb
activerecord-jdbc-adapter-1.3.13 lib/arjdbc/sqlite3/connection_methods.rb
activerecord-jdbc-adapter-1.3.12 lib/arjdbc/sqlite3/connection_methods.rb
activerecord-jdbc-adapter-1.3.11 lib/arjdbc/sqlite3/connection_methods.rb
activerecord-jdbc-adapter-1.3.10 lib/arjdbc/sqlite3/connection_methods.rb
activerecord-jdbc-adapter-1.3.9 lib/arjdbc/sqlite3/connection_methods.rb