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

Rails 3 support #1

Open
wants to merge 6 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
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ spec = Gem::Specification.new do |s|
s.add_dependency 'ruby-informix', '>= 0.7.3'
s.require_path = 'lib'

s.files = %w(lib/active_record/connection_adapters/informix_adapter.rb)
s.files = %w(lib/active_record/connection_adapters/informix_adapter.rb lib/arel/visitors/informix.rb)

s.author = 'Gerardo Santana Gomez Garrido'
s.email = '[email protected]'
Expand Down
20 changes: 20 additions & 0 deletions activerecord-informix-adapter.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
PKG_NAME = 'activerecord-informix-adapter'
PKG_VERSION = "1.1.1"

Gem::Specification.new do |s|
s.name = PKG_NAME
s.summary = 'Informix adapter for Active Record'
s.description = 'Active Record adapter for connecting to an IBM Informix database'
s.version = PKG_VERSION

s.add_dependency 'activerecord', '>= 1.15.4.7707'
s.add_dependency 'ruby-informix', '>= 0.7.3'
s.require_path = 'lib'

s.files = %w(lib/active_record/connection_adapters/informix_adapter.rb lib/arel/visitors/informix.rb)

s.author = 'Gerardo Santana Gomez Garrido'
s.email = '[email protected]'
s.homepage = 'http://rails-informix.rubyforge.org/'
s.rubyforge_project = 'rails-informix'
end
13 changes: 13 additions & 0 deletions lib/active_record/connection_adapters/informix_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
# POSSIBILITY OF SUCH DAMAGE.

require 'active_record/connection_adapters/abstract_adapter'
require 'arel/visitors/informix'

module ActiveRecord
class Base
Expand Down Expand Up @@ -183,6 +184,18 @@ def commit_db_transaction
def rollback_db_transaction
@connection.rollback
end

def add_limit!(sql, options, scope = :auto)
add_limit_offset!(sql, options)
end

def primary_key(table_name) #:nodoc:
@connection.cursor(<<-end_sql) do |cur|
SELECT FIRST 1 ct.constrname FROM sysconstraints ct, systables st WHERE st.tabid = ct.tabid AND ct.constrtype = 'P' AND st.tabname = '#{table_name}'
end_sql
cur.open.fetch.first
end
end

def add_limit_offset!(sql, options)
if options[:limit]
Expand Down
33 changes: 33 additions & 0 deletions lib/arel/visitors/informix.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'arel'

module Arel
module Visitors
class Informix < Arel::Visitors::ToSql
def visit_Arel_Nodes_SelectStatement o
sql = super(o)
if o.limit
if o.offset
# Modifying the SQL to utilize the skip and limit amounts
sql.gsub!(/SELECT/i,"SELECT SKIP #{visit o.offset} LIMIT #{visit o.limit.expr}")
else
# Modifying the SQL to retrieve only the first #{limit} rows
sql = sql.gsub!("SELECT","SELECT FIRST #{visit o.limit.expr}")
end
# else
# # Modifying the SQL to ensure that no rows will be returned
# sql.gsub!(/SELECT/i,"SELECT * FROM (SELECT")
# sql << ") WHERE 0 = 1"
end
sql
end

def visit_Arel_Nodes_Limit o
end

def visit_Arel_Nodes_Offset o
end
end
end
end

Arel::Visitors::VISITORS['informix'] = Arel::Visitors::Informix