mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
adding an oracle visitor
This commit is contained in:
parent
7615bd7f92
commit
487df1771d
7 changed files with 57 additions and 3 deletions
|
@ -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'
|
||||
|
|
6
lib/arel/nodes/less_than_or_equal.rb
Normal file
6
lib/arel/nodes/less_than_or_equal.rb
Normal file
|
@ -0,0 +1,6 @@
|
|||
module Arel
|
||||
module Nodes
|
||||
class LessThanOrEqual < Arel::Nodes::Binary
|
||||
end
|
||||
end
|
||||
end
|
|
@ -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|
|
||||
|
|
15
lib/arel/visitors/oracle.rb
Normal file
15
lib/arel/visitors/oracle.rb
Normal file
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -15,6 +15,10 @@ module Arel
|
|||
@config = { :adapter => 'sqlite3' }
|
||||
end
|
||||
|
||||
def with_connection
|
||||
yield self
|
||||
end
|
||||
|
||||
def connection
|
||||
self
|
||||
end
|
||||
|
|
22
spec/arel/visitors/oracle_spec.rb
Normal file
22
spec/arel/visitors/oracle_spec.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
require 'spec_helper'
|
||||
|
||||
module Arel
|
||||
module Visitors
|
||||
describe 'the oracle visitor' do
|
||||
before do
|
||||
@visitor = Oracle.new Table.engine
|
||||
end
|
||||
|
||||
describe 'Nodes::SelectStatement' do
|
||||
describe 'limit' do
|
||||
it 'adds a rownum clause' do
|
||||
stmt = Nodes::SelectStatement.new
|
||||
stmt.limit = 10
|
||||
sql = @visitor.accept stmt
|
||||
sql.should be_like %{ SELECT WHERE ROWNUM <= 10 }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue