diff --git a/README.md b/README.md index 52cb01ed..ad97edd8 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ 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 currently works for connecting using ODBC to MySQL 5 and PostgreSQL 9 databases. You can also register your own adapter using the `ODBCAdapter.register` function to connect to a database of your choice. +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. 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/registry.rb b/lib/odbc_adapter/registry.rb index 39170378..1bb7264e 100644 --- a/lib/odbc_adapter/registry.rb +++ b/lib/odbc_adapter/registry.rb @@ -16,8 +16,7 @@ def adapter_for(reported_name) adapter if reported_name =~ pattern end - raise ArgumentError, "ODBCAdapter: Unsupported database (#{reported_name})" if found.nil? - normalize_adapter(found.last) + normalize_adapter(found && found.last || :Null) end def register(pattern, superclass = Object, &block)