patch rails sql server odbc driver
patch ODBCColumn with alias_method_chain
Here’s a quick-fix if you’re using the ODBC Adapter for Active Record gem/plugin and are getting errors with rake db:migrate when your schema includes a sql server sql_variant.
module ActiveRecord module ConnectionAdapters class ODBCColumn < Column def mapSqlTypeToGenericType_with_sql_variant(odbcSqlType, nativeType, scale, booleanColSurrogate, rawPrecision, nativeTypes) # sql_variant causes 'Unsupported ODBC SQL type [-150]' error # use Rails' generic type :string return :string if nativeType.to_sym == :sql_variant mapSqlTypeToGenericType_without_sql_variant(odbcSqlType, nativeType, scale, booleanColSurrogate, rawPrecision, nativeTypes) end alias_method_chain :mapSqlTypeToGenericType, :sql_variant end end end
This, of course, is simply a "lazy" effort to bypass the error, which is due to the lack of a Rails generic db type for sql_variant. As shown above, I simply turn :sql_variant into a :string. If you need a permanent solution for variant types, you'll have to research ODBC equivalents for that sql server type. I simply wanted to prevent migration errors on a legacy column that will shortly be removed. Copy the above into a ruby file in your lib dir and require in environment.rb. Done!
Posted by Luke on Friday, March 28, 2008

