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

QueryTimeoutError only takes one argument. #20

Open
wants to merge 19 commits into
base: master
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
20 changes: 20 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: CI

on:
push:
branches:
- master
- github_actions
pull_request:

jobs:
RuboCop:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- 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 }}

6 changes: 4 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
inherit_from: .rubocop_todo.yml

AllCops:
DisplayCopNames: true
DisplayStyleGuide: true
TargetRubyVersion: 2.1
TargetRubyVersion: 2.7
Exclude:
- 'vendor/**/*'

Expand All @@ -20,7 +22,7 @@ Metrics/CyclomaticComplexity:
Metrics/MethodLength:
Enabled: false

Metrics/LineLength:
Layout/LineLength:
Enabled: false

Metrics/PerceivedComplexity:
Expand Down
106 changes: 106 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2022-03-14 22:30:45 UTC using RuboCop version 1.26.0.
# 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: 1
# Configuration parameters: Include.
# Include: **/*.gemspec
Gemspec/RequiredRubyVersion:
Exclude:
- 'odbc_adapter.gemspec'

# Offense count: 6
# This cop supports safe auto-correction (--auto-correct).
Layout/EmptyLineAfterGuardClause:
Exclude:
- 'lib/odbc_adapter/adapters/postgresql_odbc_adapter.rb'
- 'lib/odbc_adapter/column_metadata.rb'
- 'lib/odbc_adapter/quoting.rb'
- 'lib/odbc_adapter/registry.rb'
- 'lib/odbc_adapter/schema_statements.rb'

# Offense count: 16
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle.
# SupportedHashRocketStyles: key, separator, table
# SupportedColonStyles: key, separator, table
# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit
Layout/HashAlignment:
Exclude:
- 'lib/odbc_adapter/column_metadata.rb'
- 'lib/odbc_adapter/registry.rb'
- 'lib/odbc_adapter/schema_statements.rb'

# Offense count: 1
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: AllowInHeredoc.
Layout/TrailingWhitespace:
Exclude:
- 'lib/odbc_adapter/adapters/null_odbc_adapter.rb'

# Offense count: 1
Lint/MissingSuper:
Exclude:
- 'test/registry_test.rb'

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

# Offense count: 35
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: always, always_true, never
Style/FrozenStringLiteralComment:
Enabled: false

# Offense count: 5
# This cop supports safe auto-correction (--auto-correct).
Style/IfUnlessModifier:
Exclude:
- 'lib/odbc_adapter/adapters/mysql_odbc_adapter.rb'
- 'lib/odbc_adapter/quoting.rb'
- 'lib/odbc_adapter/schema_statements.rb'

# Offense count: 1
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: literals, strict
Style/MutableConstant:
Exclude:
- 'lib/active_record/connection_adapters/odbc_adapter.rb'

# Offense count: 1
# Configuration parameters: AllowedMethods.
# AllowedMethods: respond_to_missing?
Style/OptionalBooleanParameter:
Exclude:
- 'lib/odbc_adapter/column.rb'

# Offense count: 1
# This cop supports safe auto-correction (--auto-correct).
Style/RedundantRegexpEscape:
Exclude:
- 'lib/odbc_adapter/quoting.rb'

# Offense count: 4
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods.
# AllowedMethods: present?, blank?, presence, try, try!
Style/SafeNavigation:
Exclude:
- 'lib/odbc_adapter/column_metadata.rb'
- 'lib/odbc_adapter/schema_statements.rb'

# Offense count: 2
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: AllowModifier.
Style/SoleNestedConditional:
Exclude:
- 'lib/odbc_adapter/adapters/mysql_odbc_adapter.rb'
- 'lib/odbc_adapter/quoting.rb'
66 changes: 40 additions & 26 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,43 @@
sudo: required
language: ruby
cache: bundler
matrix:
include:
- rvm: 2.3.1
env:
- DB=mysql
- CONN_STR='DRIVER=MySQL;SERVER=localhost;DATABASE=odbc_test;USER=root;PASSWORD=;'
addons:
mysql: "5.5"
apt:
packages:
- unixodbc
- unixodbc-dev
- libmyodbc
- mysql-client
- rvm: 2.3.1
env:
- DB=postgresql
- CONN_STR='DRIVER={PostgreSQL ANSI};SERVER=localhost;PORT=5432;DATABASE=odbc_test;UID=postgres;'
addons:
postgresql: "9.1"
apt:
packages:
- unixodbc
- unixodbc-dev
- odbc-postgresql
before_script: bin/ci-setup

services:
- postgresql
- mysql

addons:
apt:
packages:
- unixodbc
- unixodbc-dev
# MySQL
- libmyodbc
- mysql-client-5.6
# Postgres
- odbc-postgresql

rvm:
- 2.3
- 2.4
- 2.5

env:
- DB=mysql CONN_STR='DRIVER=MySQL;SERVER=localhost;DATABASE=odbc_test;USER=root;PASSWORD=;'
- DB=postgresql CONN_STR='DRIVER={PostgreSQL ANSI};SERVER=localhost;PORT=5432;DATABASE=odbc_test;UID=postgres;'

before_install:
- gem update --system

gemfile:
- gemfiles/active_record_5_0.gemfile
- gemfiles/active_record_5_1.gemfile
- gemfiles/active_record_5_2.gemfile

before_script:
- sh -c "if [ '$DB' = 'mysql' ]; then sudo odbcinst -i -d -f /usr/share/libmyodbc/odbcinst.ini; fi"
- sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'DROP DATABASE IF EXISTS odbc_test; CREATE DATABASE IF NOT EXISTS odbc_test;' -uroot; fi"
- sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'GRANT ALL PRIVILEGES ON *.* TO "root"@"localhost";' -uroot; fi"

- sh -c "if [ '$DB' = 'postgresql' ]; then sudo odbcinst -i -d -f /usr/share/psqlodbc/odbcinst.ini.template; fi"
- sh -c "if [ '$DB' = 'postgresql' ]; then psql -c 'CREATE DATABASE odbc_test;' -U postgres; fi"
3 changes: 0 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
source 'https://rubygems.org'

gemspec

gem 'activerecord', '5.0.1'
gem 'pry', '~> 0.11.1'
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
28 changes: 19 additions & 9 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
require 'bundler/gem_tasks'
require 'rake/testtask'
require 'rubocop/rake_task'

Rake::TestTask.new(:test) do |t|
t.libs << 'test'
t.libs << 'lib'
t.test_files = FileList['test/**/*_test.rb']
task default: %i[test]

desc 'Run rubocop'
task :rubocop do
require 'rubocop/rake_task'

RuboCop::RakeTask.new do |task|
task.patterns = ['lib/**/*.rb']
task.formatters = ['simple']
end
end

RuboCop::RakeTask.new(:rubocop)
Rake::Task[:test].prerequisites << :rubocop
desc 'Run tests'
task :test do
require 'rake/testtask'

task default: :test
Rake::TestTask.new do |task|
task.libs << 'test'
task.libs << 'lib'
task.test_files = FileList['test/**/*_test.rb']
end
end
Loading