提交 9cd009b3 编写于 作者: A Aaron Patterson

Merge branch 'master' of github.com:rails/arel

* 'master' of github.com:rails/arel:
  replace 'LIMIT n' with 'FETCH FIRST n ROWS ONLY' when using ibm_db
  Generate more sqlish queue.
......@@ -42,7 +42,17 @@ def in other
Nodes::Between.new(self, Nodes::And.new([other.begin, other.end]))
end
else
Nodes::In.new self, other
if other.include?(nil)
if other.size > 1
set = Nodes::In.new self, other.compact
null = Nodes::Equality.new self, nil
Nodes::Or.new set, null
else
Nodes::Equality.new self, nil
end
else
Nodes::In.new self, other
end
end
end
......
......@@ -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|
......
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
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册