From 53521a9e39b9d8af4165d7703c36dc905f1f8f67 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Fri, 21 Jul 2017 09:11:47 -0400 Subject: Refactor `substitute_binds` to perform substitution immediately I'm honestly not sure if replacing bind params with their concrete values is something that belongs in Arel at all, as it's something that will need to be coupled to the quoting mechanism of the caller, and could just be accomplished by using `Quoted` instead. Still, with the new structure we can provide a much simpler API around substitution. The expectation of the quoter responding to `quote` is a reasonably minimal API. I originally used `DelegateClass` here, with the one line override of `add_bind`, but realized that we have some funky code going on where the collector returns the next collector to use (in practice `self` is always returned, and I don't see why we'd ever want to do this). Removing that would likely be worthwhile, but would be a larger refactoring --- lib/arel/visitors/oracle.rb | 2 +- lib/arel/visitors/oracle12.rb | 2 +- lib/arel/visitors/postgresql.rb | 2 +- lib/arel/visitors/to_sql.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/arel/visitors') diff --git a/lib/arel/visitors/oracle.rb b/lib/arel/visitors/oracle.rb index 3b452836db..c1e41be66f 100644 --- a/lib/arel/visitors/oracle.rb +++ b/lib/arel/visitors/oracle.rb @@ -145,7 +145,7 @@ module Arel end def visit_Arel_Nodes_BindParam o, collector - collector.add_bind(o) { |i| ":a#{i}" } + collector.add_bind(o.value) { |i| ":a#{i}" } end end diff --git a/lib/arel/visitors/oracle12.rb b/lib/arel/visitors/oracle12.rb index ce90e994ae..648047ae61 100644 --- a/lib/arel/visitors/oracle12.rb +++ b/lib/arel/visitors/oracle12.rb @@ -53,7 +53,7 @@ module Arel end def visit_Arel_Nodes_BindParam o, collector - collector.add_bind(o) { |i| ":a#{i}" } + collector.add_bind(o.value) { |i| ":a#{i}" } end end end diff --git a/lib/arel/visitors/postgresql.rb b/lib/arel/visitors/postgresql.rb index f0991a2f11..2a935e4318 100644 --- a/lib/arel/visitors/postgresql.rb +++ b/lib/arel/visitors/postgresql.rb @@ -46,7 +46,7 @@ module Arel end def visit_Arel_Nodes_BindParam o, collector - collector.add_bind(o) { |i| "$#{i}" } + collector.add_bind(o.value) { |i| "$#{i}" } end def visit_Arel_Nodes_GroupingElement o, collector diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index 3f1e390dcc..3ed80c8f06 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -737,7 +737,7 @@ module Arel def literal o, collector; collector << o.to_s; end def visit_Arel_Nodes_BindParam o, collector - collector.add_bind(o) { "?" } + collector.add_bind(o.value) { "?" } end alias :visit_Arel_Nodes_SqlLiteral :literal -- cgit v1.2.3