Sha256: 2bf25ea45a4fcc2b8c7ce774349c7d8d1631ebe7566fe6d9adb7a6971a0315d8

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

ArJdbc::ConnectionMethods.module_eval do
  def mysql_connection(config)
    begin
      require 'jdbc/mysql'
      ::Jdbc::MySQL.load_driver(:require) if defined?(::Jdbc::MySQL.load_driver)
    rescue LoadError # assuming driver.jar is on the class-path
    end

    config[:username] = 'root' unless config.key?(:username)
    config[:port] ||= 3306
    config[:url] ||= "jdbc:mysql://#{config[:host]}:#{config[:port]}/#{config[:database]}"
    config[:driver] ||= defined?(::Jdbc::MySQL.driver_name) ? ::Jdbc::MySQL.driver_name : 'com.mysql.jdbc.Driver'
    config[:adapter_spec] ||= ::ArJdbc::MySQL
    config[:adapter_class] = ActiveRecord::ConnectionAdapters::MysqlAdapter unless config.key?(:adapter_class)

    options = (config[:options] ||= {})
    options['zeroDateTimeBehavior'] ||= 'convertToNull'
    options['jdbcCompliantTruncation'] ||= 'false'
    options['useUnicode'] ||= 'true'
    options['characterEncoding'] = config[:encoding] || 'utf8'

    jdbc_connection(config)
  end
  alias_method :jdbcmysql_connection, :mysql_connection
  alias_method :mysql2_connection, :mysql_connection
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
activerecord-jdbc-adapter-1.3.1 lib/arjdbc/mysql/connection_methods.rb
activerecord-jdbc-adapter-1.3.0 lib/arjdbc/mysql/connection_methods.rb