Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Columns quoting proposal. #85

Closed
wants to merge 1 commit into from

3 participants

@mperrando

Related to rails/rails#2601

This is only a proposal to support column quoting in the SELECT and ORDER
parts of the select statement.
It lacks of tests, correct exception generation and I don'y know what else! :)

I don't know either the full impact on activerecord, even if I am using
inside a rails project without problems (at the moment).

I committed it on a branch derived from the v2.2.1 tag, but I tried a merge on the master branch without conflicts.

@mperrando mperrando Columns quoting proposal.
This is only a proposal to support column quoting in the SELECT and ORDER
parts of the select statement.
It lacks of tests, correct exception generation and I don'y know what else! :)

I don't know either the full impact on activerecord, even if I am using
inside a rails project without problems (at the moment).
7139502
@tamird

obsolete, good to close

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 27, 2011
  1. @mperrando

    Columns quoting proposal.

    mperrando authored
    This is only a proposal to support column quoting in the SELECT and ORDER
    parts of the select statement.
    It lacks of tests, correct exception generation and I don'y know what else! :)
    
    I don't know either the full impact on activerecord, even if I am using
    inside a rails project without problems (at the moment).
This page is out of date. Refresh to see the latest.
View
1  lib/arel/nodes.rb
@@ -10,6 +10,7 @@
require 'arel/nodes/terminal'
require 'arel/nodes/true'
require 'arel/nodes/false'
+require 'arel/nodes/column_name'
# unary
require 'arel/nodes/unary'
View
29 lib/arel/nodes/column_name.rb
@@ -0,0 +1,29 @@
+module Arel
+ module Nodes
+ class ColumnName <Arel::Nodes::Node
+ @@error = "column name specifier must be in the form: [<table>.]<name>[ ASC| DESC]"
+ attr_reader :name, :table_name, :direction
+ def initialize val
+ s = val.split ' '
+ if 2 == s.size
+ raise @@error unless %w(ASC DESC).include?(s[1])
+ @direction = s[1]
+ tc = s[0]
+ else
+ tc = val
+ end
+ vals = tc.split '.'
+ case vals.size
+ when 1
+ @name = vals[0]
+ when 2
+ @name = vals[1]
+ @table_name = vals[0]
+ else
+ raise @@error
+ end
+ end
+ end
+ end
+end
+
View
7 lib/arel/select_manager.rb
@@ -127,10 +127,8 @@ def having *exprs
end
def project *projections
- # FIXME: converting these to SQLLiterals is probably not good, but
- # rails tests require it.
@ctx.projections.concat projections.map { |x|
- [Symbol, String].include?(x.class) ? SqlLiteral.new(x.to_s) : x
+ [Symbol, String].include?(x.class) ? Arel::Nodes::ColumnName.new(x.to_s) : x
}
self
end
@@ -140,9 +138,8 @@ def projections= projections
end
def order *expr
- # FIXME: We SHOULD NOT be converting these to SqlLiteral automatically
@ast.orders.concat expr.map { |x|
- String === x || Symbol === x ? Nodes::SqlLiteral.new(x.to_s) : x
+ [Symbol, String].include?(x.class) ? Arel::Nodes::ColumnName.new(x.to_s) : x
}
self
end
View
8 lib/arel/visitors/to_sql.rb
@@ -155,6 +155,14 @@ def visit_Arel_Nodes_Distinct o
'DISTINCT'
end
+ def visit_Arel_Nodes_ColumnName o
+ parts = []
+ parts << "#{quote_table_name o.table_name}." if o.table_name
+ parts << quote_column_name(o.name)
+ parts << " #{o.direction}" if o.direction
+ parts.join
+ end
+
def visit_Arel_Nodes_DistinctOn o
raise NotImplementedError, 'DISTINCT ON not implemented for this db'
end
Something went wrong with that request. Please try again.