sqlanywhere / activerecord-sqlanywhere-adapter Goto Github PK
View Code? Open in Web Editor NEWAn adapter that allows ActiveRecord to communicate with SQL Anywhere
Home Page: http://sqlanywhere.rubyforge.org/
License: Other
An adapter that allows ActiveRecord to communicate with SQL Anywhere
Home Page: http://sqlanywhere.rubyforge.org/
License: Other
=SQL Anywhere Ruby Driver This is a native SQL Anywhere driver for Ruby. This library wraps the functionality provided by the SQL Anywhere DBCAPI library. This driver is intended to be a base-level library to be used by interface libraries such as Ruby-DBI and ActiveRecord. This driver can be used with SQL Anywhere 10 and later versions. This driver is licensed under the Apache License, Version 2. The official code repository is located on GitHub. The repository can be cloned with: git clone git://github.com/sqlanywhere/sqlanywhere.git ==Build Instructions ===Requirements * C Compiler * Ruby * RubyGem Package manager ===All Platforms To build the library (.so), use: rake To build and install the gem, use: rake gem rake install The other rake tasks are rake clean -> Cleans up all temp files (ex *.~) rake clobber -> Cleans up all built files (ex *.gem, *.o, *.so) ===Additional Install Notes for Windows The popular One-Click Ruby Installer for Windows (RubyInstaller) is built using Microsoft Visual C++ 6.0. Since problems can arise by combining binaries from different compilers, we advise you use this compiler. If you want to use a more recent version of the MS C++ compiler, you will need to make a few changes: 1. Open the file: <RUBY DIR>\lib\ruby\1.8\i386-mswin32\config.h, and comment out the first three lines so they look like: //#if _MSC_VER != 1200 //#error MSC version unmatch //#endif This removes the check for C++ Version 6.0 2. Open <tt>rakefile</tt> and set: APPLY_MANIFEST = true This will add the manifest to the compiled binaries. By default, rake will attempt to use Microsoft <tt>nmake</tt> when building under Windows. To use another make program, set: USE_NMAKE_ON_WIN = FALSE ==Running Unit Tests 1. Change to the the <tt>test</tt> directory cd test 2. Create a testing database: dbinit test 3. Start the testing database: dbeng12 test.db 4. Create the test schema: dbisql -c "eng=test;uid=dba;pwd=sql" test.sql 5. Run the unit tests: ruby sqlanywhere_test.rb <b>If the tests fail to run, make sure you have set up the SQL Anywhere environment variables correctly.</b> For more information, review the online documentation here [http://dcx.sybase.com/index.html#1200/en/dbadmin/da-envvar.html]. ==Sample This script makes a connection, prints <tt>Successful Ruby Connection</tt> to the SQL Anywhere console, then disconnects. # load the SQLAnywhere gem begin require 'rubygems' gem 'sqlanywhere' unless defined? SQLAnywhere require 'sqlanywhere' end end # create an interface api = SQLAnywhere::SQLAnywhereInterface.new() # initialize the interface (loads the DLL/SO) SQLAnywhere::API.sqlany_initialize_interface( api ) # initialize our api object api.sqlany_init() # create a connection conn = api.sqlany_new_connection() # establish a connection api.sqlany_connect(conn, "uid=dba;pwd=sql") # execute a query without a result set api.sqlany_execute_immediate(conn, "MESSAGE 'Successful Ruby Connection'") # disconnect from the database api.sqlany_disconnect(conn) # free the connection resources api.sqlany_free_connection(conn) # free resources the api object uses api.sqlany_fini() # close the interface SQLAnywhere::API.sqlany_finalize_interface( api )
The SQL Anywhere ActiveRecord driver uses the ConnectionAdapters::Column interface which has been removed in recent versions of ActiveRecord. The driver will not load on ActiveRecord 5.1.4.
This fork here works great right now for Rails 4.1: https://github.com/jgrevzie/activerecord-sqlanywhere-adapter/tree/rails40
However in Rails 4.2, Arel 6.0.0 was introduced. With that came a whole lot of structural changes. The activerecord-fb-adapter
implemented these changes by switching the Adapter based on the Arel version like so:
if Arel::VERSION < "6.0.0"
require 'arel/visitors/fb'
else
require 'arel/visitors/fb_collector'
end
The original 'arel/visitors/fb' lives here: https://github.com/rowland/activerecord-fb-adapter/blob/master/lib/arel/visitors/fb.rb
The new 'arel/visitors/fb_collector' lives here: https://github.com/rowland/activerecord-fb-adapter/blob/master/lib/arel/visitors/fb_collector.rb
Tagging @jgrevzie in hopes he sees this since he did such a great job with the other updates.
Unfortunately I'm brand new to the project that uses this gem so I don't have a test suite built up to ensure I wouldn't be breaking anything if I tried the implementation myself. I'm posting this in case it inspires someone else to take a stab at it. Maybe I'll come back to this in the future once I've gotten a bit more into it!
Hi Eric
It doesn't look like the adapter works in Rails 3.1.
When I try to fetch all records from a table through ActiveRecord, I get this error when calling "MyModel.all":
wrong number of arguments (3 for 2)
activerecord-sqlanywhere-adapter (1.0.0) lib/active_record/connection_adapters/sqlanywhere_adapter.rb:437:in `select'
activerecord (3.1.1.rc2) lib/active_record/connection_adapters/abstract/database_statements.rb:18:in `select_all'
activerecord (3.1.1.rc2) lib/active_record/connection_adapters/abstract/query_cache.rb:61:in `block in select_all'
activerecord (3.1.1.rc2) lib/active_record/connection_adapters/abstract/query_cache.rb:75:in `cache_sql'
activerecord (3.1.1.rc2) lib/active_record/connection_adapters/abstract/query_cache.rb:61:in `select_all'
activerecord (3.1.1.rc2) lib/active_record/base.rb:470:in `find_by_sql'
activerecord (3.1.1.rc2) lib/active_record/relation.rb:111:in `to_a'
activerecord (3.1.1.rc2) lib/active_record/relation/finder_methods.rb:159:in `all'
activerecord (3.1.1.rc2) lib/active_record/base.rb:441:in `all'
I have tested against ActiveRecord v3.0.10 and the same code runs fine there
Hello
Most AR-adapters have a way to set encoding. Is this possible with this one?
Alternatively, does the adapter support odbc mode, so I can set encoding on the odbc connection instead?
Regards,
-S
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.