aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-04-11 10:02:28 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2011-04-11 10:02:28 -0700
commitd7ed2338b13821aba6cabf204bbd7f6b3e851644 (patch)
tree401434d6e5c37faab20b670b2f2978abc3d90fc7
parent0505df1dbfaab15acac25fad0c0d1b8510e4065a (diff)
downloadrails-d7ed2338b13821aba6cabf204bbd7f6b3e851644.tar.gz
rails-d7ed2338b13821aba6cabf204bbd7f6b3e851644.tar.bz2
rails-d7ed2338b13821aba6cabf204bbd7f6b3e851644.zip
adding a Bin node to emit mysql BINARY keywords
-rw-r--r--lib/arel/nodes/unary.rb1
-rw-r--r--lib/arel/visitors/mysql.rb4
-rw-r--r--lib/arel/visitors/to_sql.rb4
-rw-r--r--test/nodes/test_bin.rb23
4 files changed, 32 insertions, 0 deletions
diff --git a/lib/arel/nodes/unary.rb b/lib/arel/nodes/unary.rb
index 1b1dcb1053..1c834913fa 100644
--- a/lib/arel/nodes/unary.rb
+++ b/lib/arel/nodes/unary.rb
@@ -10,6 +10,7 @@ module Arel
end
%w{
+ Bin
Group
Grouping
Having
diff --git a/lib/arel/visitors/mysql.rb b/lib/arel/visitors/mysql.rb
index 4f029245ac..763cf11aad 100644
--- a/lib/arel/visitors/mysql.rb
+++ b/lib/arel/visitors/mysql.rb
@@ -2,6 +2,10 @@ module Arel
module Visitors
class MySQL < Arel::Visitors::ToSql
private
+ def visit_Arel_Nodes_Bin o
+ "BINARY #{visit o.expr}"
+ end
+
def visit_Arel_Nodes_Lock o
visit o.expr
end
diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb
index d1175df2a0..061e46a436 100644
--- a/lib/arel/visitors/to_sql.rb
+++ b/lib/arel/visitors/to_sql.rb
@@ -133,6 +133,10 @@ key on UpdateManager using UpdateManager#key=
].compact.join ' '
end
+ def visit_Arel_Nodes_Bin o
+ visit o.expr
+ end
+
def visit_Arel_Nodes_With o
"WITH #{o.children.map { |x| visit x }.join(', ')}"
end
diff --git a/test/nodes/test_bin.rb b/test/nodes/test_bin.rb
new file mode 100644
index 0000000000..b06aeb0b0d
--- /dev/null
+++ b/test/nodes/test_bin.rb
@@ -0,0 +1,23 @@
+require 'helper'
+
+module Arel
+ module Nodes
+ class TestBin < MiniTest::Unit::TestCase
+ def test_new
+ assert Arel::Nodes::Bin.new('zomg')
+ end
+
+ def test_default_to_sql
+ viz = Arel::Visitors::ToSql.new Table.engine
+ node = Arel::Nodes::Bin.new(Arel.sql('zomg'))
+ assert_equal 'zomg', viz.accept(node)
+ end
+
+ def test_mysql_to_sql
+ viz = Arel::Visitors::MySQL.new Table.engine
+ node = Arel::Nodes::Bin.new(Arel.sql('zomg'))
+ assert_equal 'BINARY zomg', viz.accept(node)
+ end
+ end
+ end
+end