Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.2.x] Backport null adapter #19

Open
wants to merge 2 commits into
base: v4.2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

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/dbms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down