aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/arel/nodes.rb1
-rw-r--r--lib/arel/nodes/less_than_or_equal.rb6
-rw-r--r--lib/arel/visitors.rb8
-rw-r--r--lib/arel/visitors/oracle.rb15
-rw-r--r--lib/arel/visitors/to_sql.rb4
5 files changed, 31 insertions, 3 deletions
diff --git a/lib/arel/nodes.rb b/lib/arel/nodes.rb
index fade666ff7..6ed05fb31b 100644
--- a/lib/arel/nodes.rb
+++ b/lib/arel/nodes.rb
@@ -9,6 +9,7 @@ require 'arel/nodes/and'
require 'arel/nodes/greater_than'
require 'arel/nodes/greater_than_or_equal'
require 'arel/nodes/less_than'
+require 'arel/nodes/less_than_or_equal'
require 'arel/nodes/in'
require 'arel/nodes/lock'
diff --git a/lib/arel/nodes/less_than_or_equal.rb b/lib/arel/nodes/less_than_or_equal.rb
new file mode 100644
index 0000000000..55449d12f1
--- /dev/null
+++ b/lib/arel/nodes/less_than_or_equal.rb
@@ -0,0 +1,6 @@
+module Arel
+ module Nodes
+ class LessThanOrEqual < Arel::Nodes::Binary
+ end
+ end
+end
diff --git a/lib/arel/visitors.rb b/lib/arel/visitors.rb
index 879635575b..deb4a4f991 100644
--- a/lib/arel/visitors.rb
+++ b/lib/arel/visitors.rb
@@ -1,6 +1,7 @@
require 'arel/visitors/to_sql'
require 'arel/visitors/postgresql'
require 'arel/visitors/mysql'
+require 'arel/visitors/oracle'
require 'arel/visitors/join_sql'
require 'arel/visitors/order_clauses'
require 'arel/visitors/dot'
@@ -8,9 +9,10 @@ require 'arel/visitors/dot'
module Arel
module Visitors
VISITORS = {
- 'postgresql' => Arel::Visitors::PostgreSQL,
- 'mysql' => Arel::Visitors::MySQL,
- 'mysql2' => Arel::Visitors::MySQL,
+ 'postgresql' => Arel::Visitors::PostgreSQL,
+ 'mysql' => Arel::Visitors::MySQL,
+ 'mysql2' => Arel::Visitors::MySQL,
+ 'oracle_enhanced' => Arel::Visitors::Oracle,
}
ENGINE_VISITORS = Hash.new do |hash, engine|
diff --git a/lib/arel/visitors/oracle.rb b/lib/arel/visitors/oracle.rb
new file mode 100644
index 0000000000..840a7a9ace
--- /dev/null
+++ b/lib/arel/visitors/oracle.rb
@@ -0,0 +1,15 @@
+module Arel
+ module Visitors
+ class Oracle < Arel::Visitors::ToSql
+ def visit_Arel_Nodes_SelectStatement o
+ if o.limit
+ o.cores.last.wheres.push Nodes::LessThanOrEqual.new(
+ Nodes::SqlLiteral.new('ROWNUM'), o.limit
+ )
+ o.limit = nil
+ end
+ super
+ end
+ end
+ end
+end
diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb
index 69c7736a4b..5ec811a53a 100644
--- a/lib/arel/visitors/to_sql.rb
+++ b/lib/arel/visitors/to_sql.rb
@@ -148,6 +148,10 @@ module Arel
"#{visit o.left} > #{visit o.right}"
end
+ def visit_Arel_Nodes_LessThanOrEqual o
+ "#{visit o.left} <= #{visit o.right}"
+ end
+
def visit_Arel_Nodes_LessThan o
"#{visit o.left} < #{visit o.right}"
end