diff --git a/README.md b/README.md index 6390a403..bff38dfe 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,11 @@ [![Build Status](https://travis-ci.com/localytics/odbc_adapter.svg?token=kQUiABmGkzyHdJdMnCnv&branch=master)](https://travis-ci.com/localytics/odbc_adapter) -An ActiveRecord ODBC adapter. +An ActiveRecord ODBC adapter. Master branch is working off of edge Rails. Previous work has been done to make it compatible with Rails 3.2 and 4.2; for those versions use the 3.2.x or 4.2.x gem releases. + +This adapter will work for basic queries for most DBMSs out of the box, without support for migrations. Full support is built-in for MySQL 5 and PostgreSQL 9 databases. You can register your own adapter to get more support for your DBMS using the `ODBCAdapter.register` function. + +A lot of this work is based on [OpenLink's ActiveRecord adapter](http://odbc-rails.rubyforge.org/) which works for earlier versions of Rails. ## Installation diff --git a/lib/odbc_adapter/adapters/null_odbc_adapter.rb b/lib/odbc_adapter/adapters/null_odbc_adapter.rb new file mode 100644 index 00000000..1a179905 --- /dev/null +++ b/lib/odbc_adapter/adapters/null_odbc_adapter.rb @@ -0,0 +1,31 @@ +module ODBCAdapter + module Adapters + # A default adapter used for databases that are no explicitly listed in the + # registry. This allows for minimal support for DBMSs for which we don't + # have an explicit adapter. + class NullODBCAdapter < ActiveRecord::ConnectionAdapters::ODBCAdapter + class BindSubstitution < Arel::Visitors::ToSql + include Arel::Visitors::BindVisitor + end + + # Using a BindVisitor so that the SQL string gets substituted before it is + # sent to the DBMS (to attempt to get as much coverage as possible for + # DBMSs we don't support). + def arel_visitor + BindSubstitution.new(self) + end + + # Explicitly turning off prepared_statements in the null adapter because + # there isn't really a standard on which substitution character to use. + def prepared_statements + false + end + + # Turning off support for migrations because there is no information to + # go off of for what syntax the DBMS will expect. + def supports_migrations? + false + end + end + end +end diff --git a/lib/odbc_adapter/dbms.rb b/lib/odbc_adapter/dbms.rb index d5ede8c9..d59cd21a 100644 --- a/lib/odbc_adapter/dbms.rb +++ b/lib/odbc_adapter/dbms.rb @@ -42,8 +42,7 @@ def adapter adapter if reported =~ pattern end - raise ArgumentError, "ODBCAdapter: Unsupported database (#{reported})" if found.nil? - found.last + (found && found.last) || :Null end end end