Class: ActiveRecord::Base
- Inherits:
-
Object
- Object
- ActiveRecord::Base
- Defined in:
- lib/active_record/connection_adapters/openbase_adapter.rb
Direct Known Subclasses
Class Method Summary collapse
-
.openbase_connection(config) ⇒ Object
Establishes a connection to the database that’s used by all Active Record objects.
Class Method Details
.openbase_connection(config) ⇒ Object
Establishes a connection to the database that’s used by all Active Record objects
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/active_record/connection_adapters/openbase_adapter.rb', line 6 def self.openbase_connection(config) # :nodoc: require_library_or_gem 'openbase' unless self.class.const_defined?(:OpenBase) config = config.symbolize_keys host = config[:host] username = config[:username].to_s password = config[:password].to_s if config.has_key?(:database) database = config[:database] else raise ArgumentError, "No database specified. Missing argument: database." end oba = ConnectionAdapters::OpenBaseAdapter.new( OpenBase.new(database, host, username, password), logger ) if oba.raw_connection.connected? unless oba.tables.include?(ConnectionAdapters::OpenBaseAdapter::COLUMN_SUPPORT_TABLE) oba.execute(<<-SQL,"Creating OpenBase Column Support Table") CREATE TABLE #{ConnectionAdapters::OpenBaseAdapter::COLUMN_SUPPORT_TABLE} (name char, type char, precision int, scale int) SQL end oba.select_all("SELECT * FROM #{ConnectionAdapters::OpenBaseAdapter::COLUMN_SUPPORT_TABLE}").each do |col| ConnectionAdapters::OpenBaseAdapter::DECIMAL_COLUMNS.store(col["name"],[col["precision"],col["scale"]]) end end oba end |