 |
Forums |
Admin Start New Thread
By: Ralf Vitasek
DSN-less connections [ reply ] 2007-04-24 11:29
|
i needed to get the odbc adapter to work with connection strings too (not just system dsn's)
so i hacked in the logic from odbc.rb to the connection adapter. i haven't yet fully tested it but this is what i now have:
def self.odbc_connection(config) #:nodoc:
config = config.symbolize_keys
if config.has_key?(:dsn)
dsn = config[:dsn]
else
raise ActiveRecordError, "No data source name (DSN) specified."
end
username = config[:username] ? config[:username].to_s : nil
password = config[:password] ? config[:password].to_s : nil
trace = config[:trace].nil? ? false : config[:trace]
conv_num_lits = config[:convert_numeric_literals].nil? ? false : config[:convert_numeric_literals]
emulate_bools = config[:emulate_booleans].nil? ? false : config[:emulate_booleans]
driver_attrs = dsn.split(';')
if driver_attrs.length.eql?(1) # try system dsn
conn = ODBC::connect(dsn, username, password)
else # try connection string
driver = ::ODBC::Driver.new
driver.name = 'DSN-less'
driver_attrs.each do |param|
attr = param.split('=')
driver.attrs[attr[0]] = attr[1] if attr.length.eql?(2)
end
conn = ::ODBC::Database.new.drvconnect(driver)
end
conn.autocommit = true
ConnectionAdapters::ODBCAdapter.new(conn, {:dsn => dsn, :username => username,
:password => password, :trace => trace, :conv_num_lits => conv_num_lits,
:emulate_booleans => emulate_bools}, logger)
end
would be great if this functonality could be included in the next release
|
|
 |