From a25b9cbc391e7040fbbbccc932339cb57d11e531 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Sun, 26 Sep 2010 16:06:37 -0700 Subject: caching quoted values --- lib/arel.rb | 4 ++++ lib/arel/visitors/to_sql.rb | 12 +++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/arel.rb b/lib/arel.rb index 519940c1a5..f3dbb47ea3 100644 --- a/lib/arel.rb +++ b/lib/arel.rb @@ -29,3 +29,7 @@ require 'arel/sql_literal' module Arel VERSION = '2.0.0.dev' end + +def sql raw_sql + Arel::Nodes::SqlLiteral.new raw_sql +end diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index 5ec811a53a..b9379da8cc 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -4,8 +4,10 @@ module Arel module Visitors class ToSql def initialize engine - @engine = engine - @connection = nil + @engine = engine + @connection = nil + @quoted_tables = {} + @quoted_columns = {} end def accept object @@ -67,7 +69,7 @@ module Arel def visit_Arel_Nodes_SelectStatement o [ - o.cores.map { |x| visit x }.join, + o.cores.map { |x| visit_Arel_Nodes_SelectCore x }.join, ("ORDER BY #{o.orders.map { |x| visit x }.join(', ')}" unless o.orders.empty?), ("LIMIT #{o.limit}" if o.limit), (visit(o.offset) if o.offset), @@ -262,11 +264,11 @@ module Arel end def quote_table_name name - @connection.quote_table_name name + @quoted_tables[name] ||= @connection.quote_table_name(name) end def quote_column_name name - @connection.quote_column_name name + @quoted_columns[name] ||= @connection.quote_column_name(name) end end end -- cgit v1.2.3