aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-04-09 11:58:44 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2014-04-09 11:58:44 -0700
commit9c87737c9abefdf059a06f1213e8dee2d87f308a (patch)
tree461c934bd8bc4163689cddd695cb750d02c162b0 /lib
parent05eda21c4164e394fbb21f705408011ddeb37d56 (diff)
downloadrails-9c87737c9abefdf059a06f1213e8dee2d87f308a.tar.gz
rails-9c87737c9abefdf059a06f1213e8dee2d87f308a.tar.bz2
rails-9c87737c9abefdf059a06f1213e8dee2d87f308a.zip
adding a bind value collector
Diffstat (limited to 'lib')
-rw-r--r--lib/arel/collectors/bind.rb32
-rw-r--r--lib/arel/collectors/sql_string.rb5
-rw-r--r--lib/arel/visitors/to_sql.rb5
3 files changed, 37 insertions, 5 deletions
diff --git a/lib/arel/collectors/bind.rb b/lib/arel/collectors/bind.rb
new file mode 100644
index 0000000000..4309de75c9
--- /dev/null
+++ b/lib/arel/collectors/bind.rb
@@ -0,0 +1,32 @@
+module Arel
+ module Collectors
+ class Bind
+ def initialize
+ @parts = []
+ end
+
+ def << str
+ @parts << str
+ self
+ end
+
+ def add_bind bind
+ @parts << bind
+ self
+ end
+
+ def value; @parts; end
+
+ def substitute_binds bvs
+ bvs = bvs.dup
+ @parts.map do |val|
+ if Arel::Nodes::BindParam === val
+ bvs.shift
+ else
+ val
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/arel/collectors/sql_string.rb b/lib/arel/collectors/sql_string.rb
index 824b0a1712..526de66416 100644
--- a/lib/arel/collectors/sql_string.rb
+++ b/lib/arel/collectors/sql_string.rb
@@ -16,11 +16,8 @@ module Arel
self
end
- def start; self; end
- def finish; self; end
-
def add_bind bind
- self << bind
+ self << bind.to_s
self
end
end
diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb
index fd1332a4db..9cda88454b 100644
--- a/lib/arel/visitors/to_sql.rb
+++ b/lib/arel/visitors/to_sql.rb
@@ -693,7 +693,10 @@ module Arel
def literal o, collector; collector << o.to_s; end
- alias :visit_Arel_Nodes_BindParam :literal
+ def visit_Arel_Nodes_BindParam o, collector
+ collector.add_bind o
+ end
+
alias :visit_Arel_Nodes_SqlLiteral :literal
alias :visit_Bignum :literal
alias :visit_Fixnum :literal