]> source.dussan.org Git - sonarqube.git/blob
8e4d9769f55aacdde737744db61dd7bac1ef68e1
[sonarqube.git] /
1 # Don't need to load native sqlite3 adapter
2 $LOADED_FEATURES << "active_record/connection_adapters/sqlite_adapter.rb"
3 $LOADED_FEATURES << "active_record/connection_adapters/sqlite3_adapter.rb"
4
5 class ActiveRecord::Base
6   class << self
7     def sqlite3_connection(config)
8       require "arjdbc/sqlite3"
9
10       parse_sqlite3_config!(config)
11       database = config[:database]
12       database = '' if database == ':memory:'
13       config[:url] ||= "jdbc:sqlite:#{database}"
14       config[:driver] ||= "org.sqlite.JDBC"
15       config[:adapter_class] = ActiveRecord::ConnectionAdapters::SQLite3Adapter
16       jdbc_connection(config)
17     end
18
19     def parse_sqlite3_config!(config)
20       config[:database] ||= config[:dbfile]
21
22       # Allow database path relative to RAILS_ROOT, but only if
23       # the database path is not the special path that tells
24       # Sqlite to build a database only in memory.
25       rails_root_defined = defined?(Rails.root) || Object.const_defined?(:RAILS_ROOT)
26       if rails_root_defined && ':memory:' != config[:database]
27         rails_root = defined?(Rails.root) ? Rails.root : RAILS_ROOT
28         config[:database] = File.expand_path(config[:database], rails_root)
29       end
30     end
31
32     alias_method :jdbcsqlite3_connection, :sqlite3_connection
33   end
34 end