From 8d04c28b619212f99e6ce534f75ebda59bb200a1 Mon Sep 17 00:00:00 2001 From: Yasuo Honda Date: Thu, 25 Sep 2014 19:38:35 +0900 Subject: Extract visit_Arel_Nodes_SelectOptions --- lib/arel/visitors/to_sql.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib/arel/visitors') diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index ba176a552c..d7ed7abd5d 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -219,11 +219,15 @@ module Arel } end + visit_Arel_Nodes_SelectOptions(o, collector) + + collector + end + + def visit_Arel_Nodes_SelectOptions o, collector collector = maybe_visit o.limit, collector collector = maybe_visit o.offset, collector collector = maybe_visit o.lock, collector - - collector end def visit_Arel_Nodes_SelectCore o, collector -- cgit v1.2.3 From 0e1427e917a4e47dce9f02ad9309600073622c73 Mon Sep 17 00:00:00 2001 From: Yasuo Honda Date: Tue, 4 Nov 2014 04:44:01 +0900 Subject: Create Arel::Visitors::Oracle12 to provide better top-N query to support `FETCH FIRST n ROWS` and `OFFSET` for Oracle 12c database --- lib/arel/visitors/oracle12.rb | 53 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 lib/arel/visitors/oracle12.rb (limited to 'lib/arel/visitors') diff --git a/lib/arel/visitors/oracle12.rb b/lib/arel/visitors/oracle12.rb new file mode 100644 index 0000000000..4a42343c9b --- /dev/null +++ b/lib/arel/visitors/oracle12.rb @@ -0,0 +1,53 @@ +module Arel + module Visitors + class Oracle12 < Arel::Visitors::ToSql + private + + def visit_Arel_Nodes_SelectStatement o, collector + # Oracle does not allow LIMIT clause with select for update + if o.limit && o.lock + o = o.dup + o.limit = [] + end + + super + end + + def visit_Arel_Nodes_SelectOptions o, collector + collector = maybe_visit o.offset, collector + collector = maybe_visit o.limit, collector + collector = maybe_visit o.lock, collector + end + + def visit_Arel_Nodes_Limit o, collector + collector << "FETCH FIRST " + collector = visit o.expr, collector + collector << " ROWS ONLY" + end + + def visit_Arel_Nodes_Offset o, collector + collector << "OFFSET " + visit o.expr, collector + collector << " ROWS" + end + + def visit_Arel_Nodes_Except o, collector + collector << "( " + collector = infix_value o, collector, " MINUS " + collector << " )" + end + + def visit_Arel_Nodes_UpdateStatement o, collector + # Oracle does not allow ORDER BY/LIMIT in UPDATEs. + if o.orders.any? && o.limit.nil? + # However, there is no harm in silently eating the ORDER BY clause if no LIMIT has been provided, + # otherwise let the user deal with the error + o = o.dup + o.orders = [] + end + + super + end + end + end +end -- cgit v1.2.3