Skip to content

Commit

Permalink
Merge pull request #8 from localytics/null-adapter
Browse files Browse the repository at this point in the history
Null adapter
  • Loading branch information
kddnewton authored Feb 3, 2017
2 parents ec847ae + be17ca1 commit 5060b5b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
31 changes: 31 additions & 0 deletions lib/odbc_adapter/adapters/null_odbc_adapter.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions lib/odbc_adapter/registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5060b5b

Please sign in to comment.