arel_extensions 1.2.23 → 2.0.0.rc3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -7
- data/.travis.yml +91 -61
- data/Gemfile +20 -15
- data/README.md +12 -17
- data/Rakefile +29 -40
- data/appveyor.yml +1 -1
- data/arel_extensions.gemspec +3 -3
- data/functions.html +3 -3
- data/gemfiles/rails3.gemfile +9 -9
- data/gemfiles/rails4.gemfile +13 -13
- data/gemfiles/rails5_0.gemfile +13 -13
- data/gemfiles/rails5_1_4.gemfile +13 -13
- data/gemfiles/rails5_2.gemfile +13 -13
- data/init/mssql.sql +4 -4
- data/init/mysql.sql +38 -38
- data/init/postgresql.sql +21 -21
- data/lib/arel_extensions.rb +19 -69
- data/lib/arel_extensions/attributes.rb +1 -0
- data/lib/arel_extensions/boolean_functions.rb +14 -55
- data/lib/arel_extensions/common_sql_functions.rb +8 -7
- data/lib/arel_extensions/comparators.rb +15 -14
- data/lib/arel_extensions/date_duration.rb +5 -4
- data/lib/arel_extensions/insert_manager.rb +16 -17
- data/lib/arel_extensions/math.rb +12 -11
- data/lib/arel_extensions/math_functions.rb +22 -29
- data/lib/arel_extensions/nodes.rb +1 -1
- data/lib/arel_extensions/nodes/abs.rb +1 -0
- data/lib/arel_extensions/nodes/blank.rb +1 -0
- data/lib/arel_extensions/nodes/case.rb +8 -11
- data/lib/arel_extensions/nodes/cast.rb +2 -4
- data/lib/arel_extensions/nodes/ceil.rb +1 -1
- data/lib/arel_extensions/nodes/change_case.rb +0 -0
- data/lib/arel_extensions/nodes/coalesce.rb +3 -2
- data/lib/arel_extensions/nodes/collate.rb +2 -1
- data/lib/arel_extensions/nodes/concat.rb +16 -7
- data/lib/arel_extensions/nodes/date_diff.rb +13 -10
- data/lib/arel_extensions/nodes/duration.rb +3 -0
- data/lib/arel_extensions/nodes/find_in_set.rb +1 -0
- data/lib/arel_extensions/nodes/floor.rb +1 -1
- data/lib/arel_extensions/nodes/format.rb +8 -34
- data/lib/arel_extensions/nodes/formatted_number.rb +23 -22
- data/lib/arel_extensions/nodes/function.rb +16 -25
- data/lib/arel_extensions/nodes/json.rb +36 -43
- data/lib/arel_extensions/nodes/length.rb +1 -0
- data/lib/arel_extensions/nodes/levenshtein_distance.rb +0 -0
- data/lib/arel_extensions/nodes/locate.rb +1 -0
- data/lib/arel_extensions/nodes/log10.rb +2 -1
- data/lib/arel_extensions/nodes/matches.rb +6 -4
- data/lib/arel_extensions/nodes/md5.rb +1 -0
- data/lib/arel_extensions/nodes/power.rb +5 -5
- data/lib/arel_extensions/nodes/rand.rb +1 -0
- data/lib/arel_extensions/nodes/repeat.rb +4 -2
- data/lib/arel_extensions/nodes/replace.rb +6 -22
- data/lib/arel_extensions/nodes/round.rb +6 -5
- data/lib/arel_extensions/nodes/soundex.rb +15 -15
- data/lib/arel_extensions/nodes/std.rb +21 -18
- data/lib/arel_extensions/nodes/substring.rb +16 -8
- data/lib/arel_extensions/nodes/then.rb +0 -0
- data/lib/arel_extensions/nodes/trim.rb +5 -3
- data/lib/arel_extensions/nodes/union.rb +5 -2
- data/lib/arel_extensions/nodes/union_all.rb +3 -0
- data/lib/arel_extensions/nodes/wday.rb +4 -0
- data/lib/arel_extensions/null_functions.rb +7 -5
- data/lib/arel_extensions/predications.rb +34 -35
- data/lib/arel_extensions/railtie.rb +5 -5
- data/lib/arel_extensions/set_functions.rb +4 -2
- data/lib/arel_extensions/string_functions.rb +22 -43
- data/lib/arel_extensions/tasks.rb +5 -5
- data/lib/arel_extensions/version.rb +1 -1
- data/lib/arel_extensions/visitors.rb +60 -68
- data/lib/arel_extensions/visitors/ibm_db.rb +12 -5
- data/lib/arel_extensions/visitors/mssql.rb +57 -63
- data/lib/arel_extensions/visitors/mysql.rb +98 -149
- data/lib/arel_extensions/visitors/oracle.rb +68 -71
- data/lib/arel_extensions/visitors/oracle12.rb +15 -2
- data/lib/arel_extensions/visitors/postgresql.rb +63 -116
- data/lib/arel_extensions/visitors/sqlite.rb +70 -83
- data/lib/arel_extensions/visitors/to_sql.rb +109 -141
- data/test/database.yml +0 -2
- data/test/helper.rb +18 -0
- data/test/real_db_test.rb +43 -28
- data/test/support/fake_record.rb +2 -2
- data/test/test_comparators.rb +12 -9
- data/test/visitors/test_bulk_insert_oracle.rb +8 -8
- data/test/visitors/test_bulk_insert_sqlite.rb +10 -9
- data/test/visitors/test_bulk_insert_to_sql.rb +10 -8
- data/test/visitors/test_oracle.rb +42 -42
- data/test/visitors/test_to_sql.rb +196 -361
- data/test/with_ar/all_agnostic_test.rb +160 -195
- data/test/with_ar/insert_agnostic_test.rb +4 -3
- data/test/with_ar/test_bulk_sqlite.rb +9 -6
- data/test/with_ar/test_math_sqlite.rb +12 -8
- data/test/with_ar/test_string_mysql.rb +11 -5
- data/test/with_ar/test_string_sqlite.rb +12 -4
- metadata +11 -22
- data/.github/workflows/ruby.yml +0 -102
- data/gemfiles/rails6.gemfile +0 -30
- data/gemfiles/rails6_1.gemfile +0 -30
- data/gemspecs/arel_extensions-v1.gemspec +0 -28
- data/gemspecs/arel_extensions-v2.gemspec +0 -28
- data/generate_gems.sh +0 -15
- data/lib/arel_extensions/nodes/aggregate_function.rb +0 -13
- data/lib/arel_extensions/nodes/sum.rb +0 -7
- data/lib/arel_extensions/visitors/convert_format.rb +0 -37
- data/test/arelx_test_helper.rb +0 -26
- data/version_v1.rb +0 -3
- data/version_v2.rb +0 -3
@@ -1,21 +1,24 @@
|
|
1
1
|
module ArelExtensions
|
2
2
|
module Nodes
|
3
3
|
class Union < Arel::Nodes::Union
|
4
|
+
|
4
5
|
def initialize left,right
|
5
6
|
return super(left,right)
|
6
7
|
end
|
7
8
|
|
8
9
|
def +(other)
|
9
|
-
return ArelExtensions::Nodes::Union.new(self,other)
|
10
|
+
return ArelExtensions::Nodes::Union.new(self,other)
|
10
11
|
end
|
11
12
|
|
12
13
|
def union(other)
|
13
|
-
return ArelExtensions::Nodes::UnionAll.new(self,other)
|
14
|
+
return ArelExtensions::Nodes::UnionAll.new(self,other)
|
14
15
|
end
|
15
16
|
|
16
17
|
def as other
|
17
18
|
Arel::Nodes::TableAlias.new Arel::Nodes::Grouping.new(self), Arel::Nodes::SqlLiteral.new(other.to_s)
|
18
19
|
end
|
19
20
|
end
|
21
|
+
|
20
22
|
end
|
21
23
|
end
|
24
|
+
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module ArelExtensions
|
2
2
|
module Nodes
|
3
3
|
class UnionAll < Arel::Nodes::UnionAll
|
4
|
+
|
4
5
|
def initialize left,right
|
5
6
|
return super(left,right)
|
6
7
|
end
|
@@ -13,5 +14,7 @@ module ArelExtensions
|
|
13
14
|
Arel::Nodes::TableAlias.new Arel::Nodes::Grouping.new(self), Arel::Nodes::SqlLiteral.new(other.to_s)
|
14
15
|
end
|
15
16
|
end
|
17
|
+
|
16
18
|
end
|
17
19
|
end
|
20
|
+
|
@@ -3,21 +3,23 @@ require 'arel_extensions/nodes/is_null'
|
|
3
3
|
|
4
4
|
module ArelExtensions
|
5
5
|
module NullFunctions
|
6
|
-
|
6
|
+
|
7
|
+
#ISNULL function lets you return an alternative value when an expression is NULL.
|
7
8
|
def is_null
|
8
9
|
ArelExtensions::Nodes::IsNull.new [self]
|
9
10
|
end
|
10
|
-
|
11
|
-
#
|
11
|
+
|
12
|
+
#ISNOTNULL function lets you return an alternative value when an expression is NOT NULL.
|
12
13
|
def is_not_null
|
13
14
|
ArelExtensions::Nodes::IsNotNull.new [self]
|
14
15
|
end
|
15
|
-
|
16
|
+
|
16
17
|
# returns the first non-null expr in the expression list. You must specify at least two expressions.
|
17
|
-
#
|
18
|
+
#If all occurrences of expr evaluate to null, then the function returns null.
|
18
19
|
def coalesce *args
|
19
20
|
args.unshift(self)
|
20
21
|
ArelExtensions::Nodes::Coalesce.new args
|
21
22
|
end
|
23
|
+
|
22
24
|
end
|
23
25
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
module ArelExtensions
|
2
2
|
module Predications
|
3
|
-
def when right, expression
|
3
|
+
def when right, expression=nil
|
4
4
|
ArelExtensions::Nodes::Case.new(self).when(right,expression)
|
5
5
|
end
|
6
6
|
|
7
|
-
def matches(other, escape
|
7
|
+
def matches(other, escape=nil,case_sensitive= nil)
|
8
8
|
if Arel::VERSION.to_i < 7
|
9
9
|
Arel::Nodes::Matches.new(self, Arel::Nodes.build_quoted(other), escape)
|
10
10
|
else
|
@@ -12,7 +12,7 @@ module ArelExtensions
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
def imatches(other, escape
|
15
|
+
def imatches(other, escape=nil)
|
16
16
|
ArelExtensions::Nodes::IMatches.new(self, other, escape)
|
17
17
|
end
|
18
18
|
|
@@ -20,53 +20,51 @@ module ArelExtensions
|
|
20
20
|
ArelExtensions::Nodes::Cast.new([self,right])
|
21
21
|
end
|
22
22
|
|
23
|
-
def in(
|
24
|
-
other = other.first if other.length <= 1
|
23
|
+
def in(other) #In should handle nil element in the Array
|
25
24
|
case other
|
26
25
|
when Range
|
27
26
|
self.between(other)
|
28
|
-
when Arel::Nodes::Grouping, ArelExtensions::Nodes::Union, ArelExtensions::Nodes::UnionAll
|
29
|
-
Arel::Nodes::In.new(self, quoted_node(other))
|
30
27
|
when Enumerable
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
28
|
+
if other.include?(nil)
|
29
|
+
other.delete(nil)
|
30
|
+
case other.length
|
31
|
+
when 0
|
32
|
+
self.is_null
|
33
|
+
when 1
|
34
|
+
self.is_null.or(self==other[0])
|
35
|
+
else
|
36
|
+
self.is_null.or(Arel::Nodes::In.new(self,quoted_array(other)))
|
37
|
+
end
|
38
|
+
else
|
39
|
+
Arel::Nodes::In.new(self,quoted_array(other))
|
40
|
+
end
|
42
41
|
when nil
|
43
42
|
self.is_null
|
44
43
|
when Arel::SelectManager
|
45
44
|
Arel::Nodes::In.new(self, other.ast)
|
46
45
|
else
|
47
|
-
Arel::Nodes::In.new(self,
|
46
|
+
Arel::Nodes::In.new(self,quoted_node(other))
|
48
47
|
end
|
49
48
|
end
|
50
49
|
|
51
|
-
def not_in(
|
52
|
-
other = other.first if other.length <= 1
|
50
|
+
def not_in(other) #In should handle nil element in the Array
|
53
51
|
case other
|
54
52
|
when Range
|
55
53
|
Arel::Nodes::Not.new(self.between(other))
|
56
|
-
when Arel::Nodes::Grouping, ArelExtensions::Nodes::Union, ArelExtensions::Nodes::UnionAll
|
57
|
-
Arel::Nodes::NotIn.new(self, quoted_node(other))
|
58
54
|
when Enumerable
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
55
|
+
if other.include?(nil)
|
56
|
+
other.delete(nil)
|
57
|
+
case other.length
|
58
|
+
when 0
|
59
|
+
self.is_not_null
|
60
|
+
when 1
|
61
|
+
self.is_not_null.and(self!=other[0])
|
62
|
+
else
|
63
|
+
self.is_not_null.and(Arel::Nodes::NotIn.new(self,quoted_array(other)))
|
64
|
+
end
|
65
|
+
else
|
66
|
+
Arel::Nodes::NotIn.new(self,quoted_array(other))
|
67
|
+
end
|
70
68
|
when nil
|
71
69
|
self.is_not_null
|
72
70
|
when Arel::SelectManager
|
@@ -93,8 +91,9 @@ module ArelExtensions
|
|
93
91
|
when ActiveSupport::Duration
|
94
92
|
object.to_i
|
95
93
|
else
|
96
|
-
raise(ArgumentError, "#{object.class}
|
94
|
+
raise(ArgumentError, "#{object.class} can not be converted to CONCAT arg")
|
97
95
|
end
|
98
96
|
end
|
97
|
+
|
99
98
|
end
|
100
99
|
end
|
@@ -3,6 +3,7 @@ require 'arel_extensions/nodes/union_all'
|
|
3
3
|
|
4
4
|
module ArelExtensions
|
5
5
|
module SetFunctions
|
6
|
+
|
6
7
|
def +(other)
|
7
8
|
ArelExtensions::Nodes::Union.new(self,other)
|
8
9
|
end
|
@@ -18,13 +19,14 @@ module ArelExtensions
|
|
18
19
|
def uniq
|
19
20
|
self
|
20
21
|
end
|
22
|
+
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
24
|
-
|
26
|
+
Arel::Nodes::Union.class_eval do
|
25
27
|
include ArelExtensions::SetFunctions
|
26
28
|
end
|
27
29
|
|
28
|
-
|
30
|
+
Arel::Nodes::UnionAll.class_eval do
|
29
31
|
include ArelExtensions::SetFunctions
|
30
32
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'arel_extensions/nodes/concat' #
|
1
|
+
require 'arel_extensions/nodes/concat' #if Arel::VERSION.to_i < 7
|
2
2
|
require 'arel_extensions/nodes/length'
|
3
3
|
require 'arel_extensions/nodes/locate'
|
4
4
|
require 'arel_extensions/nodes/substring'
|
@@ -19,18 +19,19 @@ require 'arel_extensions/nodes/md5'
|
|
19
19
|
|
20
20
|
module ArelExtensions
|
21
21
|
module StringFunctions
|
22
|
-
|
22
|
+
|
23
|
+
#*FindInSet function .......
|
23
24
|
def &(other)
|
24
25
|
ArelExtensions::Nodes::FindInSet.new [other, self]
|
25
26
|
end
|
26
27
|
|
27
|
-
#
|
28
|
+
#LENGTH function returns the length of the value in a text field.
|
28
29
|
def length
|
29
30
|
ArelExtensions::Nodes::Length.new [self]
|
30
31
|
end
|
31
32
|
|
32
|
-
#
|
33
|
-
#
|
33
|
+
#LOCATE function returns the first starting position of a string in another string.
|
34
|
+
#If string1 or string2 is NULL then it returns NULL. If string1 not found in string2 then it returns 0.
|
34
35
|
def locate val
|
35
36
|
ArelExtensions::Nodes::Locate.new [self, val]
|
36
37
|
end
|
@@ -50,7 +51,7 @@ module ArelExtensions
|
|
50
51
|
end
|
51
52
|
end
|
52
53
|
|
53
|
-
#
|
54
|
+
#SOUNDEX function returns a character string containing the phonetic representation of char.
|
54
55
|
def soundex
|
55
56
|
ArelExtensions::Nodes::Soundex.new [self]
|
56
57
|
end
|
@@ -63,19 +64,6 @@ module ArelExtensions
|
|
63
64
|
grouping_any :imatches, others, escape
|
64
65
|
end
|
65
66
|
|
66
|
-
# def grouping_any method, others, *extra
|
67
|
-
# puts "*******************"
|
68
|
-
# puts method
|
69
|
-
# puts others.inspect
|
70
|
-
# puts extra.inspect
|
71
|
-
# puts "-------------------"
|
72
|
-
# res = super(method,others,*extra)
|
73
|
-
# puts res.to_sql
|
74
|
-
# puts res.inspect
|
75
|
-
# puts "*******************"
|
76
|
-
# res
|
77
|
-
# end
|
78
|
-
|
79
67
|
def imatches_all others, escape = nil
|
80
68
|
grouping_all :imatches, others, escape, escape
|
81
69
|
end
|
@@ -104,7 +92,7 @@ module ArelExtensions
|
|
104
92
|
ArelExtensions::Nodes::SMatches.new(self,other)
|
105
93
|
end
|
106
94
|
|
107
|
-
def ai_collate
|
95
|
+
def ai_collate
|
108
96
|
ArelExtensions::Nodes::Collate.new(self,nil,true,false)
|
109
97
|
end
|
110
98
|
|
@@ -112,43 +100,34 @@ module ArelExtensions
|
|
112
100
|
ArelExtensions::Nodes::Collate.new(self,nil,false,true)
|
113
101
|
end
|
114
102
|
|
115
|
-
def collate ai
|
103
|
+
def collate ai=false,ci=false, option=nil
|
116
104
|
ArelExtensions::Nodes::Collate.new(self,option,ai,ci)
|
117
105
|
end
|
118
106
|
|
119
|
-
#
|
120
|
-
def replace
|
121
|
-
|
122
|
-
ArelExtensions::Nodes::RegexpReplace.new self, pattern, substitute
|
123
|
-
else
|
124
|
-
ArelExtensions::Nodes::Replace.new self, pattern, substitute
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
def regexp_replace pattern, substitute
|
129
|
-
ArelExtensions::Nodes::RegexpReplace.new self, pattern, substitute
|
107
|
+
#REPLACE function replaces a sequence of characters in a string with another set of characters, not case-sensitive.
|
108
|
+
def replace left, right
|
109
|
+
ArelExtensions::Nodes::Replace.new [self, left, right]
|
130
110
|
end
|
131
|
-
|
111
|
+
|
132
112
|
def concat other
|
133
113
|
ArelExtensions::Nodes::Concat.new [self, other]
|
134
114
|
end
|
135
115
|
|
136
|
-
#
|
137
|
-
def group_concat
|
138
|
-
if orders.present?
|
139
|
-
warn("Warning : ArelExtensions: group_concat: you should now use the kwarg 'order' to specify an order in the group_concat.")
|
140
|
-
end
|
116
|
+
#concat elements of a group, separated by sep and ordered by a list of Ascending or Descending
|
117
|
+
def group_concat sep = nil, *orders
|
141
118
|
order_tabs = [orders].flatten.map{ |o|
|
142
119
|
if o.is_a?(Arel::Nodes::Ascending) || o.is_a?(Arel::Nodes::Descending)
|
143
120
|
o
|
144
121
|
elsif o.respond_to?(:asc)
|
145
122
|
o.asc
|
123
|
+
else
|
124
|
+
nil
|
146
125
|
end
|
147
126
|
}.compact
|
148
|
-
ArelExtensions::Nodes::GroupConcat.new
|
127
|
+
ArelExtensions::Nodes::GroupConcat.new [self, sep, order_tabs]
|
149
128
|
end
|
150
129
|
|
151
|
-
#
|
130
|
+
#Function returns a string after removing left, right or the both prefixes or suffixes int argument
|
152
131
|
def trim other = ' '
|
153
132
|
ArelExtensions::Nodes::Trim.new [self, other]
|
154
133
|
end
|
@@ -176,11 +155,11 @@ module ArelExtensions
|
|
176
155
|
def not_blank
|
177
156
|
ArelExtensions::Nodes::NotBlank.new [self]
|
178
157
|
end
|
179
|
-
|
180
|
-
def repeat other = 1
|
158
|
+
|
159
|
+
def repeat other = 1
|
181
160
|
ArelExtensions::Nodes::Repeat.new [self, other]
|
182
161
|
end
|
183
|
-
|
162
|
+
|
184
163
|
def levenshtein_distance other
|
185
164
|
ArelExtensions::Nodes::LevenshteinDistance.new [self, other]
|
186
165
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
namespace :arel_extensions do
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
desc 'Install DB functions into current DB'
|
3
|
+
task :install_functions => :environment do
|
4
|
+
@env_db = if ENV['DB'] == 'oracle' && ((defined?(RUBY_ENGINE) && RUBY_ENGINE == "rbx") || (RUBY_PLATFORM == 'java')) # not supported
|
5
5
|
(RUBY_PLATFORM == 'java' ? "jdbc-sqlite" : 'sqlite')
|
6
6
|
else
|
7
7
|
ENV['DB'] || ActiveRecord::Base.connection.adapter_name
|
8
8
|
end
|
9
|
-
ActiveRecord::Base.establish_connection(Rails.env
|
9
|
+
ActiveRecord::Base.establish_connection(Rails.env)
|
10
10
|
CommonSqlFunctions.new(ActiveRecord::Base.connection).add_sql_functions(@env_db)
|
11
|
-
|
11
|
+
end
|
12
12
|
end
|
@@ -1,89 +1,81 @@
|
|
1
|
-
require 'arel_extensions/visitors/convert_format'
|
2
1
|
require 'arel_extensions/visitors/to_sql'
|
3
2
|
require 'arel_extensions/visitors/mysql'
|
3
|
+
require 'arel_extensions/visitors/oracle'
|
4
|
+
require 'arel_extensions/visitors/oracle12'
|
4
5
|
require 'arel_extensions/visitors/postgresql'
|
5
6
|
require 'arel_extensions/visitors/sqlite'
|
7
|
+
require 'arel_extensions/visitors/mssql'
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
require 'arel_extensions/visitors/oracle12'
|
10
|
-
end
|
11
|
-
|
12
|
-
if defined?(Arel::Visitors::MSSQL)
|
13
|
-
require 'arel_extensions/visitors/mssql'
|
9
|
+
Arel::Visitors::MSSQL.class_eval do
|
10
|
+
include ArelExtensions::Visitors::MSSQL
|
14
11
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
collector << ')'
|
24
|
-
else
|
25
|
-
collector = visit o.left, collector
|
26
|
-
end
|
27
|
-
collector << " AS ["
|
28
|
-
collector = visit o.right, collector
|
29
|
-
collector << "]"
|
30
|
-
collector
|
12
|
+
alias_method :old_visit_Arel_Nodes_As, :visit_Arel_Nodes_As
|
13
|
+
def visit_Arel_Nodes_As o, collector
|
14
|
+
if o.left.is_a?(Arel::Nodes::Binary)
|
15
|
+
collector << '('
|
16
|
+
collector = visit o.left, collector
|
17
|
+
collector << ')'
|
18
|
+
else
|
19
|
+
collector = visit o.left, collector
|
31
20
|
end
|
21
|
+
collector << " AS ["
|
22
|
+
collector = visit o.right, collector
|
23
|
+
collector << "]"
|
24
|
+
collector
|
25
|
+
end
|
32
26
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
39
|
-
old_visit_Arel_Nodes_SelectStatement(o,collector)
|
27
|
+
alias_method :old_visit_Arel_Nodes_SelectStatement, :visit_Arel_Nodes_SelectStatement
|
28
|
+
def visit_Arel_Nodes_SelectStatement o, collector
|
29
|
+
if !collector.value.blank? && o.limit.blank? && o.offset.blank?
|
30
|
+
o = o.dup
|
31
|
+
o.orders = []
|
40
32
|
end
|
33
|
+
old_visit_Arel_Nodes_SelectStatement(o,collector)
|
41
34
|
end
|
35
|
+
end
|
42
36
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
37
|
+
begin
|
38
|
+
require 'arel_sqlserver'
|
39
|
+
if Arel::VERSION.to_i == 6
|
40
|
+
if Arel::Visitors::VISITORS['sqlserver'] && Arel::Visitors::VISITORS['sqlserver'] != Arel::Visitors::MSSQL
|
41
|
+
Arel::Visitors::VISITORS['sqlserver'].class_eval do
|
42
|
+
include ArelExtensions::Visitors::MSSQL
|
49
43
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
end
|
56
|
-
old_visit_Arel_Nodes_SelectStatement(o,collector)
|
44
|
+
alias_method :old_visit_Arel_Nodes_SelectStatement, :visit_Arel_Nodes_SelectStatement
|
45
|
+
def visit_Arel_Nodes_SelectStatement o, collector
|
46
|
+
if !collector.value.blank? && o.limit.blank? && o.offset.blank?
|
47
|
+
o = o.dup
|
48
|
+
o.orders = []
|
57
49
|
end
|
50
|
+
old_visit_Arel_Nodes_SelectStatement(o,collector)
|
51
|
+
end
|
58
52
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
end
|
68
|
-
collector << " AS ["
|
69
|
-
collector = visit o.right, collector
|
70
|
-
collector << "]"
|
71
|
-
collector
|
53
|
+
alias_method :old_visit_Arel_Nodes_As, :visit_Arel_Nodes_As
|
54
|
+
def visit_Arel_Nodes_As o, collector
|
55
|
+
if o.left.is_a?(Arel::Nodes::Binary)
|
56
|
+
collector << '('
|
57
|
+
collector = visit o.left, collector
|
58
|
+
collector << ')'
|
59
|
+
else
|
60
|
+
collector = visit o.left, collector
|
72
61
|
end
|
62
|
+
collector << " AS ["
|
63
|
+
collector = visit o.right, collector
|
64
|
+
collector << "]"
|
65
|
+
collector
|
66
|
+
end
|
73
67
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
column_name ? t[column_name] : nil
|
81
|
-
end
|
68
|
+
alias_method :old_primary_Key_From_Table, :primary_Key_From_Table
|
69
|
+
def primary_Key_From_Table t
|
70
|
+
return unless t
|
71
|
+
column_name = @connection.schema_cache.primary_keys(t.name) ||
|
72
|
+
@connection.schema_cache.columns_hash(t.name).first.try(:second).try(:name)
|
73
|
+
column_name ? t[column_name] : nil
|
82
74
|
end
|
83
75
|
end
|
84
76
|
end
|
85
|
-
rescue LoadError
|
86
|
-
rescue => e
|
87
|
-
e
|
88
77
|
end
|
78
|
+
rescue LoadError
|
79
|
+
rescue => e
|
80
|
+
e
|
89
81
|
end
|