Git Product home page Git Product logo

odbc_adapter's Introduction

ODBCAdapter

Build Status Gem

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.

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 which works for earlier versions of Rails.

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.

Add this line to your application's Gemfile:

gem 'odbc_adapter'

And then execute:

$ bundle

Or install it yourself as:

$ gem install odbc_adapter

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:

development:
  adapter:  odbc
  dsn: MyDatabaseDSN

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

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.

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.

Testing Using a Docker Container Because ODBC on Mac is Hard

Tested on Sierra.

Run from project root:

bundle package
docker build -f Dockerfile.dev -t odbc-dev .

# Local mount mysql directory to avoid some permissions problems
mkdir -p /tmp/mysql
docker run -it --rm -v $(pwd):/workspace -v /tmp/mysql:/var/lib/mysql odbc-dev:latest

# In container
docker/test.sh

Contributing

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

License

The gem is available as open source under the terms of the MIT License.

odbc_adapter's People

Contributors

bwarminski avatar kddnewton avatar mshearer76 avatar prurph avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

odbc_adapter's Issues

codepage ANSI_X3.4-1968.:

Hi i'm have some issue with this adapter. Have you any idea what can cause this issues

I'm using the DSN to connect to Exasol and it successfully connected
in the rails console i can call my Company.count and i get the number of rows in the database but when i Company.where(company_id: 2222) i get this error

info:
rails 5
ruby 2.4.1
i'm user docker for development

ActiveRecord::StatementInvalid: ODBC::Error: S1000 (1) [EXASOL][EXASolution driver]Character set conversion error or output buffer to small: Invalid or incomplete multibyte or wide character column 5, cursor position 1, codepage ANSI_X3.4-1968.:

Postgresql 10.10?

I'm having problems running the tests against a Postgresql 10.10 database. The tests run just fine in the docker container, which uses Postgresql 9.4.x

Against a 10.10 postgres db I get this error

   ODBC_UTF8::Error: INTERN (0) [RubyODBC]Too much parameters: SELECT  "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 

Is this a problem with postgres 10.10, or is it another problem? I'm running client and db inside Ubuntu 18.04

Compatibility with Rails 5.2

This gem is not compatible with rails 5.2 especailly because of the the disappearance of arel/visitors/bind_visitor. Is there any plan to update this gem?

I have made some quick fix on my side to have a workaround. Is it worst to make a PR?

(S1C00 (11470) [Simba][ODBC] (11470) Transactions are not supported.)

I have tried to connect to databricks using odbc_driver and able to establish connection and able to perform reads as well,
but facing issue while doing writes. when I tried to update any record and save it using ORM I'm receiving the error (S1C00 (11470) [Simba][ODBC] (11470) Transactions are not supported.)

I'm able to do inserts and updates using raw queries by overriding the active record methods, but I would like to find out what can be done here without overriding the methods like save and destroy/delete

undefined method `extract_table_ref_from_insert_sql' in sql_for_insert

Hi there!
We have been using the 4.x version of the adapter and we recently decided to upgrade to upgrade to Rails 5. We are getting undefined method extract_table_ref_from_insert_sql' in sql_for_insert when we try to do something like Model.save!`. I noticed that this method was removed between 4.x and 5.x. Do you recommend including this method in the odbc.rb initializer or do you recommend a different approach?

ID columns contain nil

I'm using a simple User.first to load a row from Snowflake but the id always contains nil:

User.first
  # <User id:nil, username: "bob>

the underlying query is returning correct data though:

User.connection.exec_query('select * from user limit 1')
  # {:id => "5", :username => "bob" ...}

Doing a step-by-step object construction yields this error:

h = User.connection.exec_query('select * from user limit 1').to_a[0]
User.new(h)
# ActiveModel::MissingAttributeError: can't write unknown attribute `ID`
# from /Users/bob/.rvm/gems/ruby-2.4.2/gems/activerecord-5.1.7/lib/active_record/attribute.rb:205:in `with_value_from_database'-

Is this something specific to the id column that needs an initializer setting?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.