Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8b6a2c3
QueryTimeoutError only takes one argument.
nickelser Apr 17, 2018
67151a8
Re-enable Travis builds
jbender Feb 20, 2019
39bb90e
rubocop fixes
jbender Feb 20, 2019
294f56b
disable prepared statements for postgres
jbender Feb 20, 2019
f6332c5
Rails 5.2 removed BindVisitor
jbender Feb 20, 2019
e563ec8
remove use of internal method
jbender Feb 20, 2019
f18c447
enable customization of given dsn
jbender Feb 20, 2019
00a0bd9
add snowflake adapter
jbender Feb 20, 2019
34cd3e8
Merge pull request #2 from jbender/travis
nickelser Feb 20, 2019
c85aab1
Merge pull request #3 from jbender/rails-5-2
nickelser Feb 20, 2019
85ecea7
Merge pull request #4 from jbender/snowflake
nickelser Feb 20, 2019
60ecb47
Rails 6 support
LaithAzer Jan 20, 2022
dd95d76
Merge pull request #7 from instacart/laith/rails-6
LaithAzer Jan 21, 2022
052e934
Update Rubocop and move to Github Actions (#8)
mlarraz Mar 15, 2022
9524910
allow rails 7
scashin133 Sep 15, 2022
c61e95c
Merge pull request #10 from instacart/scashin133_rails-7
scashin133 Sep 16, 2022
0309d0c
Update method signature for translate_exception (#11)
mlarraz Nov 23, 2022
45c67e9
Add action to publish to GPR (#12)
mlarraz Apr 11, 2023
d4b5140
v6.0.0: Publish new changes to GPR (#13)
mlarraz Apr 11, 2023
836c31b
Update Rubocop and fix some rules (#17)
mlarraz Apr 3, 2025
65fecd3
Rubocop: Use double-quoted strings (#18)
mlarraz Apr 3, 2025
c9436c0
Use Github Actions for CI (#9)
mlarraz Apr 3, 2025
b6f9c16
Tests passing on Rails 7.0 (#19)
mlarraz Apr 4, 2025
07d2d60
Add nominal support for Rails 7.1 (#20)
mlarraz Apr 15, 2025
ef636d2
Rubocop fixes (#21)
mlarraz Apr 15, 2025
c70e517
Tick 7.0 (#22)
mlarraz Apr 15, 2025
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
80 changes: 80 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: CI

on:
push:
branches:
- master
pull_request:

jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ruby:
- "3.3"
- "3.4"
activerecord:
- "6.1"
- "7.0"
- "7.1"
continue-on-error: ${{ matrix.ruby == 'head' || matrix.activerecord == 'head' }}
name: Ruby ${{ matrix.ruby }} / ActiveRecord ${{ matrix.activerecord }}
services:
postgres:
image: postgres
ports:
- 5432:5432
env:
POSTGRES_HOST_AUTH_METHOD: trust
POSTGRES_DB: odbc_test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
RAILS_VERSION: ${{ matrix.activerecord }}
CONN_STR: 'DRIVER={PostgreSQL ANSI};SERVER=localhost;PORT=5432;DATABASE=odbc_test;UID=postgres;'
PGHOST: localhost
PGUSER: postgres
RAILS_ENV: test
steps:
- uses: actions/checkout@v4
- name: Install Apt Packages
run: >
sudo apt-get install
unixodbc
unixodbc-dev
odbc-postgresql
odbcinst

- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Setup PostgreSQL
run: |
sudo odbcinst -j
sudo cat /usr/share/psqlodbc/odbcinst.ini.template
sudo odbcinst -i -d -f /usr/share/psqlodbc/odbcinst.ini.template
- run: |
bundle exec rake test
RuboCop:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Apt Packages
run: >
sudo apt-get install
unixodbc
unixodbc-dev
odbc-postgresql
odbcinst
- uses: ruby/setup-ruby@v1
with:
ruby-version: ruby
bundler-cache: true
- run: |
bundle exec rubocop --color --format github --format clang
31 changes: 31 additions & 0 deletions .github/workflows/gem-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Ruby Gem

on:
release:
types:
- published

jobs:
build:
name: Build + Publish
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ruby

- name: Publish to Github
run: |
mkdir -p $HOME/.gem
touch $HOME/.gem/credentials
chmod 0600 $HOME/.gem/credentials
printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
gem build *.gemspec
gem push --verbose --key github --host https://rubygems.pkg.github.com/${OWNER} *.gem
env:
GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
OWNER: ${{ github.repository_owner }}

20 changes: 16 additions & 4 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
inherit_from: .rubocop_todo.yml

AllCops:
NewCops: enable
DisplayCopNames: true
DisplayStyleGuide: true
TargetRubyVersion: 2.1
TargetRubyVersion: 3.3
Exclude:
- 'vendor/**/*'

Expand All @@ -20,16 +23,25 @@ Metrics/CyclomaticComplexity:
Metrics/MethodLength:
Enabled: false

Metrics/LineLength:
Enabled: false

Metrics/PerceivedComplexity:
Enabled: false

Style/Documentation:
Enabled: false

Style/StringLiterals:
EnforcedStyle: double_quotes

Style/PercentLiteralDelimiters:
PreferredDelimiters:
default: '[]'
'%r': '{}'

Layout/HashAlignment:
EnforcedColonStyle: table

Layout/FirstArrayElementIndentation:
EnforcedStyle: consistent

Style/TrailingCommaInArguments:
EnforcedStyleForMultiline: comma
86 changes: 86 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2025-04-15 19:53:18 UTC using RuboCop version 1.75.2.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 3
# Configuration parameters: EnforcedStyle, AllowedGems, Include.
# SupportedStyles: Gemfile, gems.rb, gemspec
# Include: **/*.gemspec, **/Gemfile, **/gems.rb
Gemspec/DevelopmentDependencies:
Exclude:
- 'odbc_adapter.gemspec'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: Severity, Include.
# Include: **/*.gemspec
Gemspec/RequireMFA:
Exclude:
- 'odbc_adapter.gemspec'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Lint/AmbiguousOperatorPrecedence:
Exclude:
- 'lib/odbc_adapter/registry.rb'

# Offense count: 1
# Configuration parameters: CountComments, CountAsOne.
Metrics/ModuleLength:
Max: 102

# Offense count: 2
# Configuration parameters: Max, CountKeywordArgs.
Metrics/ParameterLists:
MaxOptionalParameters: 4

# Offense count: 6
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, BlockForwardingName.
# SupportedStyles: anonymous, explicit
Naming/BlockForwarding:
Exclude:
- 'lib/odbc_adapter/adapters/mysql_odbc_adapter.rb'
- 'lib/odbc_adapter/registry.rb'
- 'test/crud_test.rb'

# Offense count: 4
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowOnlyRestArgument, UseAnonymousForwarding, RedundantRestArgumentNames, RedundantKeywordRestArgumentNames, RedundantBlockArgumentNames.
# RedundantRestArgumentNames: args, arguments
# RedundantKeywordRestArgumentNames: kwargs, options, opts
# RedundantBlockArgumentNames: blk, block, proc
Style/ArgumentsForwarding:
Exclude:
- 'lib/odbc_adapter/registry.rb'

# Offense count: 32
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: always, always_true, never
Style/FrozenStringLiteralComment:
Enabled: false

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AllowSplatArgument.
Style/HashConversion:
Exclude:
- 'lib/odbc_adapter/database_metadata.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/MapToHash:
Exclude:
- 'lib/active_record/connection_adapters/odbc_adapter.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AutoCorrect, AllowComments.
Style/RedundantInitialize:
Exclude:
- 'test/registry_test.rb'
29 changes: 0 additions & 29 deletions .travis.yml

This file was deleted.

14 changes: 10 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
source 'https://rubygems.org'
source "https://rubygems.org"

gemspec
gem "activerecord", "~> #{ENV.fetch('RAILS_VERSION', '7.1')}.0"

gem "base64"
gem "bigdecimal"
gem "mutex_m"

gem 'activerecord', '5.0.1'
gem 'pry', '~> 0.11.1'
gem "rake"
gem "rubocop", "~> 1.75.0"

gemspec
66 changes: 52 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
# ODBCAdapter
# ODBCAdapter [![License][license-badge]][license-link]

[![Build Status](https://travis-ci.org/localytics/odbc_adapter.svg?branch=master)](https://travis-ci.org/localytics/odbc_adapter)
[![Gem](https://img.shields.io/gem/v/odbc_adapter.svg)](https://rubygems.org/gems/odbc_adapter)
| ActiveRecord | Gem Version | Branch | Status |
|--------------|-------------|--------|--------|
| `5.x` | `~> '5.0'` | [`master`][5.x-branch] | [![Build Status][5.x-build-badge]][build-link] |
| `4.x` | `~> '4.0'` | [`4.2.x`][4.x-branch] | [![Build Status][4.x-build-badge]][build-link] |

An ActiveRecord ODBC adapter. Master branch is working off of Rails 5.0.1. 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.
## Supported Databases

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.
- PostgreSQL 9
- MySQL 5
- Snowflake

A lot of this work is based on [OpenLink's ActiveRecord adapter](http://odbc-rails.rubyforge.org/) which works for earlier versions of Rails.
You can also register your own adapter to get more support for your DBMS
`ODBCAdapter.register`.

## Installation

Ensure you have the ODBC driver installed on your machine. You will also need the driver for whichever database to which you want ODBC to connect.
Ensure you have the ODBC driver installed on your machine. You will also need
the driver for whichever database to which you want ODBC to connect.

Add this line to your application's Gemfile:

Expand All @@ -29,32 +35,64 @@ Or install it yourself as:

## Usage

Configure your `database.yml` by either using the `dsn` option to point to a DSN that corresponds to a valid entry in your `~/.odbc.ini` file:
Configure your `database.yml` by either using the `dsn` option to point to a DSN
that corresponds to a valid entry in your `~/.odbc.ini` file:

```
```yml
development:
adapter: odbc
dsn: MyDatabaseDSN
```

or by using the `conn_str` option and specifying the entire connection string:

```
```yml
development:
adapter: odbc
conn_str: "DRIVER={PostgreSQL ANSI};SERVER=localhost;PORT=5432;DATABASE=my_database;UID=postgres;"
```

ActiveRecord models that use this connection will now be connecting to the configured database using the ODBC driver.
ActiveRecord models that use this connection will now be connecting to the
configured database using the ODBC driver.

### Extending

Configure your own adapter by registering it in your application's bootstrap
process. For example, you could add the following to a Rails application via
`config/initializers/custom_database_adapter.rb`

```ruby
ODBCAdapter.register(/custom/, ActiveRecord::ConnectionAdapters::ODBCAdapter) do
# Overrides
end
```

```yml
development:
adapter: odbc
dsn: CustomDB
```

## Testing

To run the tests, you'll need the ODBC driver as well as the connection adapter for each database against which you're trying to test. Then run `DSN=MyDatabaseDSN bundle exec rake test` and the test suite will be run by connecting to your database.

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/localytics/odbc_adapter.
Bug reports and pull requests are welcome on [GitHub][github-repo].

## Prior Work

## License
A lot of this work is based on [OpenLink's ActiveRecord adapter][openlink-activerecord-adapter] which works for earlier versions of Rails. 5.0.x compatability work was completed by the [Localytics][localytics-github] team.

The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
[4.x-branch]: https://github.com/localytics/odbc_adapter/tree/v4.2.x
[4.x-build-badge]: https://travis-ci.org/localytics/odbc_adapter.svg?branch=4.2.x
[5.x-branch]: https://github.com/localytics/odbc_adapter/tree/master
[5.x-build-badge]: https://travis-ci.org/localytics/odbc_adapter.svg?branch=master
[build-link]: https://travis-ci.org/localytics/odbc_adapter/branches
[github-repo]: https://github.com/localytics/odbc_adapter
[license-badge]: https://img.shields.io/github/license/localytics/odbc_adapter.svg
[license-link]: https://github.com/localytics/odbc_adapter/blob/master/LICENSE
[localytics-github]: https://github.com/localytics
[openlink-activerecord-adapter]: https://github.com/dosire/activerecord-odbc-adapter
[supported-versions-badge]: https://img.shields.io/badge/active__record-4.x--5.x-green.svg
Loading