Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merged pull request #46 from semmons99/master.

replace 'LIMIT n' with 'FETCH FIRST n ROWS ONLY' when using ibm_db
  • Loading branch information...
commit dd07005dceb6641214f7d1166f75acbd379fb570 2 parents 9095380 + c2e7f36
Aaron Patterson tenderlove authored
2  lib/arel/visitors.rb
View
@@ -10,6 +10,7 @@
require 'arel/visitors/where_sql'
require 'arel/visitors/order_clauses'
require 'arel/visitors/dot'
+require 'arel/visitors/ibm_db'
module Arel
module Visitors
@@ -22,6 +23,7 @@ module Visitors
'oracle_enhanced' => Arel::Visitors::Oracle,
'sqlite' => Arel::Visitors::SQLite,
'sqlite3' => Arel::Visitors::SQLite,
+ 'ibm_db' => Arel::Visitors::IBM_DB,
}
ENGINE_VISITORS = Hash.new do |hash, engine|
12 lib/arel/visitors/ibm_db.rb
View
@@ -0,0 +1,12 @@
+module Arel
+ module Visitors
+ class IBM_DB < Arel::Visitors::ToSql
+ private
+
+ def visit_Arel_Nodes_Limit o
+ "FETCH FIRST #{visit o.expr} ROWS ONLY"
+ end
+
+ end
+ end
+end
27 test/visitors/test_ibm_db.rb
View
@@ -0,0 +1,27 @@
+require 'helper'
+
+module Arel
+ module Visitors
+ describe 'the ibm_db visitor' do
+ before do
+ @visitor = IBM_DB.new Table.engine
+ end
+
+ it 'uses FETCH FIRST n ROWS to limit results' do
+ stmt = Nodes::SelectStatement.new
+ stmt.limit = Nodes::Limit.new(1)
+ sql = @visitor.accept(stmt)
+ sql.must_be_like "SELECT FETCH FIRST 1 ROWS ONLY"
+ end
+
+ it 'uses FETCH FIRST n ROWS in updates with a limit' do
+ stmt = Nodes::UpdateStatement.new
+ stmt.limit = Nodes::Limit.new(1)
+ stmt.key = 'id'
+ sql = @visitor.accept(stmt)
+ sql.must_be_like "UPDATE NULL WHERE 'id' IN (SELECT 'id' FETCH FIRST 1 ROWS ONLY)"
+ end
+
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.