May 20
Rails and Sybase Adapative Server Anywhere (SQLAnywhere) - Part 2
As discussed in the Rails and Sybase Adapative Server Anywhere (SQLAnywhere) article I had to modify the odbc_adapter.rb code to allow the adapter to be used with my SybaseASA DB. Making the change to the adapter code directly is not an acceptable solution and until the developers of the adapter apply the change I had to come up with an alternate solution.
The solution I came up with was to monkey-patch the method responsible for checking the DB type to allow SybaseASA to be seen as a valid DB. I added the following code to my environment.rb:
# Monkeypatch the ODBC Adapter so that it will work with SybaseASA
# see http://odbc-rails.rubyforge.org/index.html
module ActiveRecord
module ConnectionAdapters
class ODBCAdapter < AbstractAdapter
alias :orig_dbmsNameToSym :dbmsNameToSymdef dbmsNameToSym(dbmsName, dbmsVer)
begin
# Call original method
symbl = orig_dbmsNameToSym(dbmsName, dbmsVer)
rescue ActiveRecord::ActiveRecordError
# Catch exception if db not found in existing list, check
# if SybaseASA, if not raise exception
if dbmsName =~ /adaptiveserveranywhere/i
symbl = :sqlanywhere
else
raise ActiveRecord::ActiveRecordError, "ODBCAdapter: Unsupported database (#{dbmsName})"
end
end
return symbl
endend
end
end


May 20th, 2008 at 10:29 am
[…] Rails ODBC Adapter with Sybase Adaptive Server Anywhere (SybaseASA) […]