arel 2.0.2 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +7 -0
- data/arel.gemspec +1 -1
- data/lib/arel.rb +1 -1
- data/lib/arel/attributes.rb +1 -1
- data/lib/arel/attributes/attribute.rb +7 -6
- data/lib/arel/visitors/oracle.rb +21 -8
- data/lib/arel/visitors/to_sql.rb +1 -0
- data/test/test_attributes.rb +5 -0
- data/test/visitors/test_oracle.rb +12 -0
- data/test/visitors/test_to_sql.rb +4 -0
- metadata +4 -4
data/History.txt
CHANGED
data/arel.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{arel}
|
5
|
-
s.version = "2.0.
|
5
|
+
s.version = "2.0.2.20101111111102"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Aaron Patterson", "Bryan Halmkamp", "Emilio Tagua", "Nick Kallen"]
|
data/lib/arel.rb
CHANGED
data/lib/arel/attributes.rb
CHANGED
@@ -5,12 +5,13 @@ module Arel
|
|
5
5
|
include Arel::Predications
|
6
6
|
end
|
7
7
|
|
8
|
-
class String
|
9
|
-
class Time
|
10
|
-
class Boolean
|
11
|
-
class Decimal
|
12
|
-
class Float
|
13
|
-
class Integer
|
8
|
+
class String < Attribute; end
|
9
|
+
class Time < Attribute; end
|
10
|
+
class Boolean < Attribute; end
|
11
|
+
class Decimal < Attribute; end
|
12
|
+
class Float < Attribute; end
|
13
|
+
class Integer < Attribute; end
|
14
|
+
class Undefined < Attribute; end
|
14
15
|
end
|
15
16
|
|
16
17
|
Attribute = Attributes::Attribute
|
data/lib/arel/visitors/oracle.rb
CHANGED
@@ -70,19 +70,14 @@ module Arel
|
|
70
70
|
/DISTINCT.*FIRST_VALUE/ === projection
|
71
71
|
end
|
72
72
|
end
|
73
|
-
#
|
73
|
+
# Previous version with join and split broke ORDER BY clause
|
74
74
|
# if it contained functions with several arguments (separated by ',').
|
75
|
-
# Currently splitting is done only if there is no function calls
|
76
75
|
#
|
77
76
|
# orders = o.orders.map { |x| visit x }.join(', ').split(',')
|
78
77
|
orders = o.orders.map do |x|
|
79
78
|
string = visit x
|
80
|
-
|
81
|
-
|
82
|
-
string
|
83
|
-
# if no function call then comma splits several ORDER BY columns
|
84
|
-
elsif string.include?(',')
|
85
|
-
string.split(',')
|
79
|
+
if string.include?(',')
|
80
|
+
split_order_string(string)
|
86
81
|
else
|
87
82
|
string
|
88
83
|
end
|
@@ -94,6 +89,24 @@ module Arel
|
|
94
89
|
end
|
95
90
|
o
|
96
91
|
end
|
92
|
+
|
93
|
+
# Split string by commas but count opening and closing brackets
|
94
|
+
# and ignore commas inside brackets.
|
95
|
+
def split_order_string(string)
|
96
|
+
array = []
|
97
|
+
i = 0
|
98
|
+
string.split(',').each do |part|
|
99
|
+
if array[i]
|
100
|
+
array[i] << ',' << part
|
101
|
+
else
|
102
|
+
# to ensure that array[i] will be String and not Arel::Nodes::SqlLiteral
|
103
|
+
array[i] = '' << part
|
104
|
+
end
|
105
|
+
i += 1 if array[i].count('(') == array[i].count(')')
|
106
|
+
end
|
107
|
+
array
|
108
|
+
end
|
109
|
+
|
97
110
|
end
|
98
111
|
end
|
99
112
|
end
|
data/lib/arel/visitors/to_sql.rb
CHANGED
@@ -281,6 +281,7 @@ module Arel
|
|
281
281
|
alias :visit_TrueClass :visit_String
|
282
282
|
alias :visit_NilClass :visit_String
|
283
283
|
alias :visit_ActiveSupport_StringInquirer :visit_String
|
284
|
+
alias :visit_Class :visit_String
|
284
285
|
|
285
286
|
def quote value, column = nil
|
286
287
|
@connection.quote value, column
|
data/test/test_attributes.rb
CHANGED
@@ -3,6 +3,11 @@ require 'helper'
|
|
3
3
|
module Arel
|
4
4
|
describe 'Attributes' do
|
5
5
|
describe 'for' do
|
6
|
+
it 'deals with unknown column types' do
|
7
|
+
column = Struct.new(:type).new :crazy
|
8
|
+
Attributes.for(column).must_equal Attributes::Undefined
|
9
|
+
end
|
10
|
+
|
6
11
|
it 'returns the correct constant for strings' do
|
7
12
|
[:string, :text, :binary].each do |type|
|
8
13
|
column = Struct.new(:type).new type
|
@@ -43,6 +43,18 @@ module Arel
|
|
43
43
|
}
|
44
44
|
end
|
45
45
|
|
46
|
+
it 'splits orders with commas and function calls' do
|
47
|
+
# *sigh*
|
48
|
+
select = "DISTINCT foo.id, FIRST_VALUE(projects.name) OVER (foo) AS alias_0__"
|
49
|
+
stmt = Nodes::SelectStatement.new
|
50
|
+
stmt.cores.first.projections << Nodes::SqlLiteral.new(select)
|
51
|
+
stmt.orders << Nodes::SqlLiteral.new('NVL(LOWER(bar, foo), foo) DESC, UPPER(baz)')
|
52
|
+
sql = @visitor.accept(stmt)
|
53
|
+
sql.must_be_like %{
|
54
|
+
SELECT #{select} ORDER BY alias_0__ DESC, alias_1__
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
46
58
|
describe 'Nodes::SelectStatement' do
|
47
59
|
describe 'limit' do
|
48
60
|
it 'adds a rownum clause' do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 2.0.
|
9
|
+
- 3
|
10
|
+
version: 2.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Aaron Patterson
|
@@ -18,7 +18,7 @@ autorequire:
|
|
18
18
|
bindir: bin
|
19
19
|
cert_chain: []
|
20
20
|
|
21
|
-
date: 2010-11-
|
21
|
+
date: 2010-11-16 00:00:00 -08:00
|
22
22
|
default_executable:
|
23
23
|
dependencies:
|
24
24
|
- !ruby/object:Gem::Dependency
|