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.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -7
  3. data/.travis.yml +91 -61
  4. data/Gemfile +20 -15
  5. data/README.md +12 -17
  6. data/Rakefile +29 -40
  7. data/appveyor.yml +1 -1
  8. data/arel_extensions.gemspec +3 -3
  9. data/functions.html +3 -3
  10. data/gemfiles/rails3.gemfile +9 -9
  11. data/gemfiles/rails4.gemfile +13 -13
  12. data/gemfiles/rails5_0.gemfile +13 -13
  13. data/gemfiles/rails5_1_4.gemfile +13 -13
  14. data/gemfiles/rails5_2.gemfile +13 -13
  15. data/init/mssql.sql +4 -4
  16. data/init/mysql.sql +38 -38
  17. data/init/postgresql.sql +21 -21
  18. data/lib/arel_extensions.rb +19 -69
  19. data/lib/arel_extensions/attributes.rb +1 -0
  20. data/lib/arel_extensions/boolean_functions.rb +14 -55
  21. data/lib/arel_extensions/common_sql_functions.rb +8 -7
  22. data/lib/arel_extensions/comparators.rb +15 -14
  23. data/lib/arel_extensions/date_duration.rb +5 -4
  24. data/lib/arel_extensions/insert_manager.rb +16 -17
  25. data/lib/arel_extensions/math.rb +12 -11
  26. data/lib/arel_extensions/math_functions.rb +22 -29
  27. data/lib/arel_extensions/nodes.rb +1 -1
  28. data/lib/arel_extensions/nodes/abs.rb +1 -0
  29. data/lib/arel_extensions/nodes/blank.rb +1 -0
  30. data/lib/arel_extensions/nodes/case.rb +8 -11
  31. data/lib/arel_extensions/nodes/cast.rb +2 -4
  32. data/lib/arel_extensions/nodes/ceil.rb +1 -1
  33. data/lib/arel_extensions/nodes/change_case.rb +0 -0
  34. data/lib/arel_extensions/nodes/coalesce.rb +3 -2
  35. data/lib/arel_extensions/nodes/collate.rb +2 -1
  36. data/lib/arel_extensions/nodes/concat.rb +16 -7
  37. data/lib/arel_extensions/nodes/date_diff.rb +13 -10
  38. data/lib/arel_extensions/nodes/duration.rb +3 -0
  39. data/lib/arel_extensions/nodes/find_in_set.rb +1 -0
  40. data/lib/arel_extensions/nodes/floor.rb +1 -1
  41. data/lib/arel_extensions/nodes/format.rb +8 -34
  42. data/lib/arel_extensions/nodes/formatted_number.rb +23 -22
  43. data/lib/arel_extensions/nodes/function.rb +16 -25
  44. data/lib/arel_extensions/nodes/json.rb +36 -43
  45. data/lib/arel_extensions/nodes/length.rb +1 -0
  46. data/lib/arel_extensions/nodes/levenshtein_distance.rb +0 -0
  47. data/lib/arel_extensions/nodes/locate.rb +1 -0
  48. data/lib/arel_extensions/nodes/log10.rb +2 -1
  49. data/lib/arel_extensions/nodes/matches.rb +6 -4
  50. data/lib/arel_extensions/nodes/md5.rb +1 -0
  51. data/lib/arel_extensions/nodes/power.rb +5 -5
  52. data/lib/arel_extensions/nodes/rand.rb +1 -0
  53. data/lib/arel_extensions/nodes/repeat.rb +4 -2
  54. data/lib/arel_extensions/nodes/replace.rb +6 -22
  55. data/lib/arel_extensions/nodes/round.rb +6 -5
  56. data/lib/arel_extensions/nodes/soundex.rb +15 -15
  57. data/lib/arel_extensions/nodes/std.rb +21 -18
  58. data/lib/arel_extensions/nodes/substring.rb +16 -8
  59. data/lib/arel_extensions/nodes/then.rb +0 -0
  60. data/lib/arel_extensions/nodes/trim.rb +5 -3
  61. data/lib/arel_extensions/nodes/union.rb +5 -2
  62. data/lib/arel_extensions/nodes/union_all.rb +3 -0
  63. data/lib/arel_extensions/nodes/wday.rb +4 -0
  64. data/lib/arel_extensions/null_functions.rb +7 -5
  65. data/lib/arel_extensions/predications.rb +34 -35
  66. data/lib/arel_extensions/railtie.rb +5 -5
  67. data/lib/arel_extensions/set_functions.rb +4 -2
  68. data/lib/arel_extensions/string_functions.rb +22 -43
  69. data/lib/arel_extensions/tasks.rb +5 -5
  70. data/lib/arel_extensions/version.rb +1 -1
  71. data/lib/arel_extensions/visitors.rb +60 -68
  72. data/lib/arel_extensions/visitors/ibm_db.rb +12 -5
  73. data/lib/arel_extensions/visitors/mssql.rb +57 -63
  74. data/lib/arel_extensions/visitors/mysql.rb +98 -149
  75. data/lib/arel_extensions/visitors/oracle.rb +68 -71
  76. data/lib/arel_extensions/visitors/oracle12.rb +15 -2
  77. data/lib/arel_extensions/visitors/postgresql.rb +63 -116
  78. data/lib/arel_extensions/visitors/sqlite.rb +70 -83
  79. data/lib/arel_extensions/visitors/to_sql.rb +109 -141
  80. data/test/database.yml +0 -2
  81. data/test/helper.rb +18 -0
  82. data/test/real_db_test.rb +43 -28
  83. data/test/support/fake_record.rb +2 -2
  84. data/test/test_comparators.rb +12 -9
  85. data/test/visitors/test_bulk_insert_oracle.rb +8 -8
  86. data/test/visitors/test_bulk_insert_sqlite.rb +10 -9
  87. data/test/visitors/test_bulk_insert_to_sql.rb +10 -8
  88. data/test/visitors/test_oracle.rb +42 -42
  89. data/test/visitors/test_to_sql.rb +196 -361
  90. data/test/with_ar/all_agnostic_test.rb +160 -195
  91. data/test/with_ar/insert_agnostic_test.rb +4 -3
  92. data/test/with_ar/test_bulk_sqlite.rb +9 -6
  93. data/test/with_ar/test_math_sqlite.rb +12 -8
  94. data/test/with_ar/test_string_mysql.rb +11 -5
  95. data/test/with_ar/test_string_sqlite.rb +12 -4
  96. metadata +11 -22
  97. data/.github/workflows/ruby.yml +0 -102
  98. data/gemfiles/rails6.gemfile +0 -30
  99. data/gemfiles/rails6_1.gemfile +0 -30
  100. data/gemspecs/arel_extensions-v1.gemspec +0 -28
  101. data/gemspecs/arel_extensions-v2.gemspec +0 -28
  102. data/generate_gems.sh +0 -15
  103. data/lib/arel_extensions/nodes/aggregate_function.rb +0 -13
  104. data/lib/arel_extensions/nodes/sum.rb +0 -7
  105. data/lib/arel_extensions/visitors/convert_format.rb +0 -37
  106. data/test/arelx_test_helper.rb +0 -26
  107. data/version_v1.rb +0 -3
  108. 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
+
@@ -1,15 +1,19 @@
1
1
  module ArelExtensions
2
2
  module Nodes
3
3
  class Wday < Function
4
+
5
+
4
6
  def initialize other, aliaz = nil
5
7
  tab = Array.new
6
8
  tab << other
7
9
  super(tab, aliaz)
8
10
  end
9
11
 
12
+
10
13
  def date
11
14
  @expressions.first
12
15
  end
16
+
13
17
  end
14
18
  end
15
19
  end
@@ -3,21 +3,23 @@ require 'arel_extensions/nodes/is_null'
3
3
 
4
4
  module ArelExtensions
5
5
  module NullFunctions
6
- # ISNULL function lets you return an alternative value when an expression is NULL.
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
- # ISNOTNULL function lets you return an alternative value when an expression is NOT NULL.
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
- # If all occurrences of expr evaluate to null, then the function returns null.
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 = nil
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 = nil,case_sensitive = nil)
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 = nil)
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(*other) # In should handle nil element in the Array
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
- nils, values = other.partition{ |v| v.nil? }
32
- ranges, values = values.partition{ |v| v.is_a?(Range) || v.is_a?(Arel::SelectManager)}
33
- # In order of (imagined) decreasing efficiency: nil, values, and then more complex.
34
- clauses =
35
- nils.uniq.map { |r| self.in(r) } \
36
- + (case values.uniq.size
37
- when 0 then []
38
- when 1 then [values[0].is_a?(Arel::Nodes::Grouping) ? self.in(values[0]) : self.eq(values[0])]
39
- else [Arel::Nodes::In.new(self, quoted_array(values))] end) \
40
- + ranges.uniq.map { |r| self.in(r) }
41
- clauses.empty? ? Arel.false : clauses.reduce(&:or)
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, quoted_node(other))
46
+ Arel::Nodes::In.new(self,quoted_node(other))
48
47
  end
49
48
  end
50
49
 
51
- def not_in(*other) # In should handle nil element in the Array
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
- nils, values = other.partition{ |v| v.nil? }
60
- ranges, values = values.partition{ |v| v.is_a?(Range) || v.is_a?(Arel::SelectManager)}
61
- # In order of (imagined) decreasing efficiency: nil, values, and then more complex.
62
- clauses =
63
- nils.uniq.map { |r| self.not_in(r) } \
64
- + (case values.uniq.size
65
- when 0 then []
66
- when 1 then [values[0].is_a?(Arel::Nodes::Grouping) ? self.not_in(values[0]) : self.not_eq(values[0])]
67
- else [Arel::Nodes::NotIn.new(self, quoted_array(values))] end) \
68
- + ranges.uniq.map { |r| self.not_in(r) }
69
- Arel::Nodes::And.new clauses
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} cannot be converted to CONCAT arg")
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
@@ -1,9 +1,9 @@
1
1
  require 'rails'
2
2
 
3
3
  module ArelExtensions
4
- class Railtie < Rails::Railtie
5
- rake_tasks do
6
- load 'arel_extensions/tasks.rb'
7
- end
8
- end
4
+ class Railtie < Rails::Railtie
5
+ rake_tasks do
6
+ load 'arel_extensions/tasks.rb'
7
+ end
8
+ end
9
9
  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
- class Arel::Nodes::Union
26
+ Arel::Nodes::Union.class_eval do
25
27
  include ArelExtensions::SetFunctions
26
28
  end
27
29
 
28
- class Arel::Nodes::UnionAll
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' # if Arel::VERSION.to_i < 7
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
- # *FindInSet function .......
22
+
23
+ #*FindInSet function .......
23
24
  def &(other)
24
25
  ArelExtensions::Nodes::FindInSet.new [other, self]
25
26
  end
26
27
 
27
- # LENGTH function returns the length of the value in a text field.
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
- # LOCATE function returns the first starting position of a string in another string.
33
- # If string1 or string2 is NULL then it returns NULL. If string1 not found in string2 then it returns 0.
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
- # SOUNDEX function returns a character string containing the phonetic representation of char.
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 = false,ci = false, option = nil
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
- # REPLACE function replaces a sequence of characters in a string with another set of characters, not case-sensitive.
120
- def replace pattern, substitute
121
- if pattern.is_a? Regexp
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
- # concat elements of a group, separated by sep and ordered by a list of Ascending or Descending
137
- def group_concat(sep = nil, *orders, group: nil, order: nil)
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(self, sep, group: group, order: (order || order_tabs))
127
+ ArelExtensions::Nodes::GroupConcat.new [self, sep, order_tabs]
149
128
  end
150
129
 
151
- # Function returns a string after removing left, right or the both prefixes or suffixes int argument
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
- 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
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.to_sym)
9
+ ActiveRecord::Base.establish_connection(Rails.env)
10
10
  CommonSqlFunctions.new(ActiveRecord::Base.connection).add_sql_functions(@env_db)
11
- end
11
+ end
12
12
  end
@@ -1,3 +1,3 @@
1
1
  module ArelExtensions
2
- VERSION = "1.2.23".freeze
2
+ VERSION = "2.0.0.rc3".freeze
3
3
  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
- if defined?(Arel::Visitors::Oracle)
8
- require 'arel_extensions/visitors/oracle'
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
- class Arel::Visitors::MSSQL
16
- include ArelExtensions::Visitors::MSSQL
17
-
18
- alias_method(:old_visit_Arel_Nodes_As, :visit_Arel_Nodes_As) rescue nil
19
- def visit_Arel_Nodes_As o, collector
20
- if o.left.is_a?(Arel::Nodes::Binary)
21
- collector << '('
22
- collector = visit o.left, collector
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
- alias_method(:old_visit_Arel_Nodes_SelectStatement, :visit_Arel_Nodes_SelectStatement) rescue nil
34
- def visit_Arel_Nodes_SelectStatement o, collector
35
- if !collector.value.blank? && o.limit.blank? && o.offset.blank?
36
- o = o.dup
37
- o.orders = []
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
- begin
44
- require 'arel_sqlserver'
45
- if Arel::VERSION.to_i == 6
46
- if Arel::Visitors::VISITORS['sqlserver'] && Arel::Visitors::VISITORS['sqlserver'] != Arel::Visitors::MSSQL
47
- Arel::Visitors::VISITORS['sqlserver'].class_eval do
48
- include ArelExtensions::Visitors::MSSQL
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
- alias_method(:old_visit_Arel_Nodes_SelectStatement, :visit_Arel_Nodes_SelectStatement) rescue nil
51
- def visit_Arel_Nodes_SelectStatement o, collector
52
- if !collector.value.blank? && o.limit.blank? && o.offset.blank?
53
- o = o.dup
54
- o.orders = []
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
- alias_method(:old_visit_Arel_Nodes_As, :visit_Arel_Nodes_As) rescue nil
60
- def visit_Arel_Nodes_As o, collector
61
- if o.left.is_a?(Arel::Nodes::Binary)
62
- collector << '('
63
- collector = visit o.left, collector
64
- collector << ')'
65
- else
66
- collector = visit o.left, collector
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
- alias_method(:old_primary_Key_From_Table, :primary_Key_From_Table) rescue nil
75
- def primary_Key_From_Table t
76
- return unless t
77
-
78
- column_name = @connection.schema_cache.primary_keys(t.name) ||
79
- @connection.schema_cache.columns_hash(t.name).first.try(:second).try(:name)
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