From 68a95542e1a7a79d9777223fbffd2b982fed0268 Mon Sep 17 00:00:00 2001 From: Ernie Miller Date: Sat, 16 Mar 2013 19:20:11 -0400 Subject: Make visitors threadsafe by removing @last_column The last_column feature of the ToSql visitor and its descendants is what enabled quoting based on the column last visited -- in other words, if you have a standard condition like an equality with a string attribute on the left side and an integer on the right side, then when ARel visits the node, it'll first visit the left side attribute, setting the column of the string attribute as the last column, and resulting in the right side of the condition getting the appropriate quoting. The downside is that this means that visitors can't be shared between threads, because of the state mutation. It also makes for some really weird behavior in the event that the visitor visits a node that happens to contain an attribute you weren't expecting to be there, since it'll potentially quote something based on that attribute. So, it prevents reversing an equality condition. column = value will work, but not value = column, since the last column wouldn't be the column you're hoping for. This is a first pass at fixing this by changing the signature of the visit methods to accept the currently-relevant attribute, if any. --- lib/arel/visitors/ibm_db.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/arel/visitors/ibm_db.rb') diff --git a/lib/arel/visitors/ibm_db.rb b/lib/arel/visitors/ibm_db.rb index 0c26a3ae9e..13af27df71 100644 --- a/lib/arel/visitors/ibm_db.rb +++ b/lib/arel/visitors/ibm_db.rb @@ -3,8 +3,8 @@ module Arel class IBM_DB < Arel::Visitors::ToSql private - def visit_Arel_Nodes_Limit o - "FETCH FIRST #{visit o.expr} ROWS ONLY" + def visit_Arel_Nodes_Limit o, a + "FETCH FIRST #{visit o.expr, a} ROWS ONLY" end end -- cgit v1.2.3