1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

fixing ibm db

This commit is contained in:
Aaron Patterson 2014-04-08 21:15:15 -07:00
parent 1360259961
commit 4861bc62cf
2 changed files with 10 additions and 4 deletions

View file

@ -3,8 +3,10 @@ module Arel
class IBM_DB < Arel::Visitors::ToSql
private
def visit_Arel_Nodes_Limit o
"FETCH FIRST #{visit o.expr } ROWS ONLY"
def visit_Arel_Nodes_Limit o, collector
collector << "FETCH FIRST "
collector = visit o.expr, collector
collector << " ROWS ONLY"
end
end

View file

@ -7,10 +7,14 @@ module Arel
@visitor = IBM_DB.new Table.engine.connection
end
def compile node
@visitor.accept(node, Collectors::SQLString.new).value
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 = compile(stmt)
sql.must_be_like "SELECT FETCH FIRST 1 ROWS ONLY"
end
@ -20,7 +24,7 @@ module Arel
stmt.relation = table
stmt.limit = Nodes::Limit.new(Nodes.build_quoted(1))
stmt.key = table[:id]
sql = @visitor.accept(stmt)
sql = compile(stmt)
sql.must_be_like "UPDATE \"users\" WHERE \"users\".\"id\" IN (SELECT \"users\".\"id\" FROM \"users\" FETCH FIRST 1 ROWS ONLY)"
end