arel_extensions 2.1.3 → 2.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +1 -2
  3. data/.github/workflows/ruby.yml +4 -4
  4. data/.rubocop.yml +25 -1
  5. data/Gemfile +10 -10
  6. data/README.md +1 -2
  7. data/Rakefile +4 -4
  8. data/TODO +0 -1
  9. data/arel_extensions.gemspec +11 -11
  10. data/gemfiles/rails3.gemfile +10 -10
  11. data/gemfiles/rails4.gemfile +13 -13
  12. data/gemfiles/rails5_0.gemfile +12 -12
  13. data/gemfiles/rails5_1_4.gemfile +12 -12
  14. data/gemfiles/rails5_2.gemfile +13 -13
  15. data/gemfiles/rails6.gemfile +11 -11
  16. data/gemfiles/rails6_1.gemfile +11 -11
  17. data/gemfiles/rails7.gemfile +7 -7
  18. data/gemspecs/arel_extensions-v1.gemspec +12 -12
  19. data/gemspecs/arel_extensions-v2.gemspec +11 -11
  20. data/init/mssql.sql +0 -0
  21. data/init/mysql.sql +0 -0
  22. data/init/oracle.sql +0 -0
  23. data/init/postgresql.sql +0 -0
  24. data/init/sqlite.sql +0 -0
  25. data/lib/arel_extensions/attributes.rb +2 -2
  26. data/lib/arel_extensions/boolean_functions.rb +2 -4
  27. data/lib/arel_extensions/common_sql_functions.rb +10 -10
  28. data/lib/arel_extensions/comparators.rb +14 -14
  29. data/lib/arel_extensions/date_duration.rb +7 -7
  30. data/lib/arel_extensions/helpers.rb +16 -13
  31. data/lib/arel_extensions/insert_manager.rb +1 -1
  32. data/lib/arel_extensions/math.rb +16 -18
  33. data/lib/arel_extensions/math_functions.rb +18 -18
  34. data/lib/arel_extensions/nodes/abs.rb +0 -0
  35. data/lib/arel_extensions/nodes/aggregate_function.rb +0 -0
  36. data/lib/arel_extensions/nodes/blank.rb +1 -1
  37. data/lib/arel_extensions/nodes/case.rb +4 -6
  38. data/lib/arel_extensions/nodes/cast.rb +3 -3
  39. data/lib/arel_extensions/nodes/ceil.rb +0 -0
  40. data/lib/arel_extensions/nodes/change_case.rb +0 -0
  41. data/lib/arel_extensions/nodes/coalesce.rb +0 -0
  42. data/lib/arel_extensions/nodes/collate.rb +9 -9
  43. data/lib/arel_extensions/nodes/concat.rb +2 -2
  44. data/lib/arel_extensions/nodes/date_diff.rb +6 -6
  45. data/lib/arel_extensions/nodes/duration.rb +0 -0
  46. data/lib/arel_extensions/nodes/find_in_set.rb +0 -0
  47. data/lib/arel_extensions/nodes/floor.rb +0 -0
  48. data/lib/arel_extensions/nodes/format.rb +0 -0
  49. data/lib/arel_extensions/nodes/formatted_number.rb +2 -2
  50. data/lib/arel_extensions/nodes/function.rb +21 -21
  51. data/lib/arel_extensions/nodes/is_null.rb +0 -0
  52. data/lib/arel_extensions/nodes/json.rb +7 -7
  53. data/lib/arel_extensions/nodes/length.rb +0 -0
  54. data/lib/arel_extensions/nodes/levenshtein_distance.rb +1 -1
  55. data/lib/arel_extensions/nodes/locate.rb +0 -0
  56. data/lib/arel_extensions/nodes/log10.rb +0 -0
  57. data/lib/arel_extensions/nodes/matches.rb +1 -1
  58. data/lib/arel_extensions/nodes/md5.rb +0 -0
  59. data/lib/arel_extensions/nodes/power.rb +0 -0
  60. data/lib/arel_extensions/nodes/rand.rb +0 -0
  61. data/lib/arel_extensions/nodes/repeat.rb +0 -0
  62. data/lib/arel_extensions/nodes/replace.rb +2 -2
  63. data/lib/arel_extensions/nodes/round.rb +0 -0
  64. data/lib/arel_extensions/nodes/soundex.rb +2 -2
  65. data/lib/arel_extensions/nodes/std.rb +0 -0
  66. data/lib/arel_extensions/nodes/substring.rb +0 -0
  67. data/lib/arel_extensions/nodes/sum.rb +0 -0
  68. data/lib/arel_extensions/nodes/then.rb +0 -0
  69. data/lib/arel_extensions/nodes/trim.rb +0 -0
  70. data/lib/arel_extensions/nodes/union.rb +4 -4
  71. data/lib/arel_extensions/nodes/union_all.rb +3 -3
  72. data/lib/arel_extensions/nodes/wday.rb +0 -0
  73. data/lib/arel_extensions/nodes.rb +0 -0
  74. data/lib/arel_extensions/null_functions.rb +0 -0
  75. data/lib/arel_extensions/predications.rb +10 -10
  76. data/lib/arel_extensions/railtie.rb +1 -1
  77. data/lib/arel_extensions/set_functions.rb +3 -3
  78. data/lib/arel_extensions/string_functions.rb +8 -8
  79. data/lib/arel_extensions/tasks.rb +2 -2
  80. data/lib/arel_extensions/version.rb +1 -1
  81. data/lib/arel_extensions/visitors/convert_format.rb +0 -0
  82. data/lib/arel_extensions/visitors/ibm_db.rb +19 -19
  83. data/lib/arel_extensions/visitors/mssql.rb +127 -121
  84. data/lib/arel_extensions/visitors/mysql.rb +137 -145
  85. data/lib/arel_extensions/visitors/oracle.rb +128 -128
  86. data/lib/arel_extensions/visitors/oracle12.rb +16 -16
  87. data/lib/arel_extensions/visitors/postgresql.rb +139 -137
  88. data/lib/arel_extensions/visitors/sqlite.rb +83 -85
  89. data/lib/arel_extensions/visitors/to_sql.rb +143 -148
  90. data/lib/arel_extensions/visitors.rb +7 -7
  91. data/lib/arel_extensions.rb +46 -32
  92. data/test/arelx_test_helper.rb +14 -13
  93. data/test/database.yml +5 -5
  94. data/test/real_db_test.rb +78 -78
  95. data/test/support/fake_record.rb +1 -1
  96. data/test/test_comparators.rb +5 -5
  97. data/test/visitors/test_bulk_insert_oracle.rb +4 -4
  98. data/test/visitors/test_bulk_insert_sqlite.rb +4 -4
  99. data/test/visitors/test_bulk_insert_to_sql.rb +4 -4
  100. data/test/visitors/test_oracle.rb +14 -14
  101. data/test/visitors/test_to_sql.rb +82 -82
  102. data/test/with_ar/all_agnostic_test.rb +364 -299
  103. data/test/with_ar/insert_agnostic_test.rb +17 -14
  104. data/test/with_ar/test_bulk_sqlite.rb +4 -4
  105. data/test/with_ar/test_math_sqlite.rb +12 -12
  106. data/test/with_ar/test_string_mysql.rb +20 -20
  107. data/test/with_ar/test_string_sqlite.rb +20 -20
  108. data/version_v1.rb +1 -1
  109. data/version_v2.rb +1 -1
  110. metadata +2 -9
  111. data/.travis/oracle/download.js +0 -152
  112. data/.travis/oracle/download.sh +0 -30
  113. data/.travis/oracle/download_ojdbc.js +0 -116
  114. data/.travis/oracle/install.sh +0 -34
  115. data/.travis/setup_accounts.sh +0 -9
  116. data/.travis/sqlite3/extension-functions.sh +0 -6
  117. data/.travis.yml +0 -193
@@ -13,10 +13,10 @@ module ArelExtensions
13
13
  }.freeze
14
14
 
15
15
  LOADED_VISITOR::DATE_FORMAT_DIRECTIVES = {
16
- '%Y' => 'YYYY', '%C' => '', '%y' => 'YY', '%m' => 'MM', '%B' => '', '%b' => '', '%^b' => '', # year, month
17
- '%V' => 'iso_week', '%G' => '', # ISO week number and year of week
18
- '%d' => 'DD', '%e' => '', '%j' => '', '%w' => 'dw', '%A' => '', # day, weekday
19
- '%H' => 'hh', '%k' => '', '%I' => '', '%l' => '', '%P' => '', '%p' => '', # hours
16
+ '%Y' => 'YYYY', '%C' => '', '%y' => 'YY', '%m' => 'MM', '%B' => 'month', '%^B' => '', '%b' => '', '%^b' => '', # year, month
17
+ '%V' => 'iso_week', '%G' => '', # ISO week number and year of week
18
+ '%d' => 'DD', '%e' => '' , '%j' => '' , '%w' => 'dw', %'a' => '', '%A' => 'weekday', # day, weekday
19
+ '%H' => 'hh', '%k' => '' , '%I' => '' , '%l' => '' , '%P' => '', '%p' => '', # hours
20
20
  '%M' => 'mi', '%S' => 'ss', '%L' => 'ms', '%N' => 'ns', '%z' => 'tz'
21
21
  }.freeze
22
22
 
@@ -24,6 +24,10 @@ module ArelExtensions
24
24
  'YY' => '0#', 'MM' => '0#', 'DD' => '0#', 'hh' => '0#', 'mi' => '0#', 'ss' => '0#', 'iso_week' => '0#'
25
25
  }
26
26
 
27
+ LOADED_VISITOR::DATE_NAME = [
28
+ '%B', '%A'
29
+ ]
30
+
27
31
  LOADED_VISITOR::DATE_FORMAT_REGEX =
28
32
  Regexp.new(
29
33
  LOADED_VISITOR::DATE_FORMAT_DIRECTIVES
@@ -35,7 +39,7 @@ module ArelExtensions
35
39
  # TODO; all others... http://www.sql-server-helper.com/tips/date-formats.aspx
36
40
  LOADED_VISITOR::DATE_CONVERT_FORMATS = {
37
41
  'YYYY-MM-DD' => 120,
38
- 'YY-MM-DD' => 120,
42
+ 'YY-MM-DD' => 120,
39
43
  'MM/DD/YYYY' => 101,
40
44
  'MM-DD-YYYY' => 110,
41
45
  'YYYY/MM/DD' => 111,
@@ -47,63 +51,63 @@ module ArelExtensions
47
51
 
48
52
  # Math Functions
49
53
  def visit_ArelExtensions_Nodes_Ceil o, collector
50
- collector << "CEILING("
54
+ collector << 'CEILING('
51
55
  collector = visit o.expr, collector
52
- collector << ")"
56
+ collector << ')'
53
57
  collector
54
58
  end
55
59
 
56
60
  def visit_ArelExtensions_Nodes_Log10 o, collector
57
- collector << "LOG10("
61
+ collector << 'LOG10('
58
62
  o.expressions.each_with_index { |arg, i|
59
63
  collector << Arel::Visitors::ToSql::COMMA if i != 0
60
64
  collector = visit arg, collector
61
65
  }
62
- collector << ")"
66
+ collector << ')'
63
67
  collector
64
68
  end
65
69
 
66
70
  def visit_ArelExtensions_Nodes_Power o, collector
67
- collector << "POWER("
71
+ collector << 'POWER('
68
72
  o.expressions.each_with_index { |arg, i|
69
73
  collector << Arel::Visitors::ToSql::COMMA if i != 0
70
74
  collector = visit arg, collector
71
75
  }
72
- collector << ")"
76
+ collector << ')'
73
77
  collector
74
78
  end
75
79
 
76
80
  def visit_ArelExtensions_Nodes_IsNull o, collector
77
- collector << "("
81
+ collector << '('
78
82
  collector = visit o.expr, collector
79
- collector << " IS NULL)"
83
+ collector << ' IS NULL)'
80
84
  collector
81
85
  end
82
86
 
83
87
  def visit_ArelExtensions_Nodes_IsNotNull o, collector
84
- collector << "("
88
+ collector << '('
85
89
  collector = visit o.expr, collector
86
- collector << " IS NOT NULL)"
90
+ collector << ' IS NOT NULL)'
87
91
  collector
88
92
  end
89
93
 
90
94
  def visit_ArelExtensions_Nodes_Concat o, collector
91
- collector << "CONCAT("
95
+ collector << 'CONCAT('
92
96
  o.expressions.each_with_index { |arg, i|
93
97
  collector << LOADED_VISITOR::COMMA if i != 0
94
98
  collector = visit arg, collector
95
99
  }
96
- collector << ")"
100
+ collector << ')'
97
101
  collector
98
102
  end
99
103
 
100
104
  def visit_ArelExtensions_Nodes_Repeat o, collector
101
- collector << "REPLICATE("
105
+ collector << 'REPLICATE('
102
106
  o.expressions.each_with_index { |arg, i|
103
107
  collector << Arel::Visitors::ToSql::COMMA if i != 0
104
108
  collector = visit arg, collector
105
109
  }
106
- collector << ")"
110
+ collector << ')'
107
111
  collector
108
112
  end
109
113
 
@@ -123,28 +127,28 @@ module ArelExtensions
123
127
  collector << ')'
124
128
  else
125
129
  da = ArelExtensions::Nodes::DateAdd.new([])
126
- collector << "DATEADD("
130
+ collector << 'DATEADD('
127
131
  collector = visit da.mssql_datepart(o.right), collector
128
132
  collector << LOADED_VISITOR::COMMA
129
- collector << "-("
133
+ collector << '-('
130
134
  collector = visit da.mssql_value(o.right), collector
131
- collector << ")"
135
+ collector << ')'
132
136
  collector << LOADED_VISITOR::COMMA
133
137
  collector = visit o.left, collector
134
- collector << ")"
138
+ collector << ')'
135
139
  collector
136
140
  end
137
141
  collector
138
142
  end
139
143
 
140
144
  def visit_ArelExtensions_Nodes_DateAdd o, collector
141
- collector << "DATEADD("
145
+ collector << 'DATEADD('
142
146
  collector = visit o.mssql_datepart(o.right), collector
143
147
  collector << LOADED_VISITOR::COMMA
144
148
  collector = visit o.mssql_value(o.right), collector
145
149
  collector << LOADED_VISITOR::COMMA
146
150
  collector = visit o.left, collector
147
- collector << ")"
151
+ collector << ')'
148
152
  collector
149
153
  end
150
154
 
@@ -160,47 +164,47 @@ module ArelExtensions
160
164
  collector << 'CONVERT(datetime,' if conv
161
165
  collector = visit o.right, collector
162
166
  collector << ')' if conv
163
- collector << ")"
167
+ collector << ')'
164
168
  end
165
169
  collector
166
170
  end
167
171
 
168
172
  def visit_ArelExtensions_Nodes_Length o, collector
169
173
  if o.bytewise
170
- collector << "(DATALENGTH("
174
+ collector << '(DATALENGTH('
171
175
  collector = visit o.expr, collector
172
- collector << ") / ISNULL(NULLIF(DATALENGTH(LEFT(COALESCE("
176
+ collector << ') / ISNULL(NULLIF(DATALENGTH(LEFT(COALESCE('
173
177
  collector = visit o.expr, collector
174
178
  collector << ", '#' ), 1 )), 0), 1))"
175
179
  collector
176
180
  else
177
- collector << "LEN("
181
+ collector << 'LEN('
178
182
  collector = visit o.expr, collector
179
- collector << ")"
183
+ collector << ')'
180
184
  collector
181
185
  end
182
186
  end
183
187
 
184
188
  def visit_ArelExtensions_Nodes_Round o, collector
185
- collector << "ROUND("
189
+ collector << 'ROUND('
186
190
  o.expressions.each_with_index { |arg, i|
187
191
  collector << LOADED_VISITOR::COMMA if i != 0
188
192
  collector = visit arg, collector
189
193
  }
190
194
  if o.expressions.length == 1
191
195
  collector << LOADED_VISITOR::COMMA
192
- collector << "0"
196
+ collector << '0'
193
197
  end
194
- collector << ")"
198
+ collector << ')'
195
199
  collector
196
200
  end
197
201
 
198
202
  def visit_ArelExtensions_Nodes_Locate o, collector
199
- collector << "CHARINDEX("
203
+ collector << 'CHARINDEX('
200
204
  collector = visit o.right, collector
201
205
  collector << LOADED_VISITOR::COMMA
202
206
  collector = visit o.left, collector
203
- collector << ")"
207
+ collector << ')'
204
208
  collector
205
209
  end
206
210
 
@@ -218,15 +222,15 @@ module ArelExtensions
218
222
  def visit_ArelExtensions_Nodes_Trim o, collector
219
223
  collector << 'TRIM( '
220
224
  collector = visit o.right, collector
221
- collector << " FROM "
225
+ collector << ' FROM '
222
226
  collector = visit o.left, collector
223
- collector << ")"
227
+ collector << ')'
224
228
  collector
225
229
  end
226
230
 
227
231
  def visit_ArelExtensions_Nodes_Ltrim o, collector
228
232
  if o.right
229
- collector << "REPLACE(REPLACE(LTRIM(REPLACE(REPLACE("
233
+ collector << 'REPLACE(REPLACE(LTRIM(REPLACE(REPLACE('
230
234
  collector = visit o.left, collector
231
235
  collector << ", ' ', '~'), "
232
236
  collector = visit o.right, collector
@@ -234,16 +238,16 @@ module ArelExtensions
234
238
  collector = visit o.right, collector
235
239
  collector << "), '~', ' ')"
236
240
  else
237
- collector << "LTRIM("
241
+ collector << 'LTRIM('
238
242
  collector = visit o.left, collector
239
- collector << ")"
243
+ collector << ')'
240
244
  end
241
245
  collector
242
246
  end
243
247
 
244
248
  def visit_ArelExtensions_Nodes_Rtrim o, collector
245
249
  if o.right
246
- collector << "REPLACE(REPLACE(RTRIM(REPLACE(REPLACE("
250
+ collector << 'REPLACE(REPLACE(RTRIM(REPLACE(REPLACE('
247
251
  collector = visit o.left, collector
248
252
  collector << ", ' ', '~'), "
249
253
  collector = visit o.right, collector
@@ -251,9 +255,9 @@ module ArelExtensions
251
255
  collector = visit o.right, collector
252
256
  collector << "), '~', ' ')"
253
257
  else
254
- collector << "RTRIM("
258
+ collector << 'RTRIM('
255
259
  collector = visit o.left, collector
256
- collector << ")"
260
+ collector << ')'
257
261
  end
258
262
  collector
259
263
  end
@@ -281,12 +285,12 @@ module ArelExtensions
281
285
  when Hash
282
286
  src_tz, dst_tz = o.time_zone.first
283
287
  collector << ') AT TIME ZONE '
284
- collector = visit Arel::Nodes.build_quoted(src_tz), collector
288
+ collector = visit Arel.quoted(src_tz), collector
285
289
  collector << ' AT TIME ZONE '
286
- collector = visit Arel::Nodes.build_quoted(dst_tz), collector
290
+ collector = visit Arel.quoted(dst_tz), collector
287
291
  when String
288
292
  collector << ') AT TIME ZONE '
289
- collector = visit Arel::Nodes.build_quoted(o.time_zone), collector
293
+ collector = visit Arel.quoted(o.time_zone), collector
290
294
  end
291
295
  collector << LOADED_VISITOR::COMMA
292
296
  collector << fmt.to_s
@@ -294,7 +298,7 @@ module ArelExtensions
294
298
  collector
295
299
  else
296
300
  s = StringScanner.new o.iso_format
297
- collector << "("
301
+ collector << '('
298
302
  sep = ''
299
303
  while !s.eos?
300
304
  collector << sep
@@ -303,10 +307,11 @@ module ArelExtensions
303
307
  when s.scan(LOADED_VISITOR::DATE_FORMAT_REGEX)
304
308
  dir = LOADED_VISITOR::DATE_FORMAT_DIRECTIVES[s.matched]
305
309
  fmt = LOADED_VISITOR::DATE_FORMAT_FORMAT[dir]
310
+ date_name = LOADED_VISITOR::DATE_NAME.include?(s.matched)
306
311
  collector << 'TRIM('
307
312
  collector << 'FORMAT(' if fmt
308
- collector << 'STR(' if !fmt
309
- collector << 'DATEPART('
313
+ collector << 'STR(' if !fmt && !date_name
314
+ collector << (date_name ? 'DATENAME(' : 'DATEPART(')
310
315
  collector << dir
311
316
  collector << LOADED_VISITOR::COMMA
312
317
  if o.time_zone
@@ -318,22 +323,22 @@ module ArelExtensions
318
323
  case o.time_zone
319
324
  when Hash
320
325
  src_tz, dst_tz = o.time_zone.first.first, o.time_zone.first.second
321
- collector << ") AT TIME ZONE "
322
- collector = visit Arel::Nodes.build_quoted(src_tz), collector
323
- collector << " AT TIME ZONE "
324
- collector = visit Arel::Nodes.build_quoted(dst_tz), collector
326
+ collector << ') AT TIME ZONE '
327
+ collector = visit Arel.quoted(src_tz), collector
328
+ collector << ' AT TIME ZONE '
329
+ collector = visit Arel.quoted(dst_tz), collector
325
330
  when String
326
- collector << ") AT TIME ZONE "
327
- collector = visit Arel::Nodes.build_quoted(o.time_zone), collector
331
+ collector << ') AT TIME ZONE '
332
+ collector = visit Arel.quoted(o.time_zone), collector
328
333
  end
329
334
  collector << ')'
330
- collector << ')' if !fmt
335
+ collector << ')' if !fmt && !date_name
331
336
  collector << LOADED_VISITOR::COMMA << "'#{fmt}')" if fmt
332
337
  collector << ')'
333
338
  when s.scan(/^%%/)
334
- collector = visit Arel::Nodes.build_quoted('%'), collector
339
+ collector = visit Arel.quoted('%'), collector
335
340
  when s.scan(/[^%]+|./)
336
- collector = visit Arel::Nodes.build_quoted(s.matched), collector
341
+ collector = visit Arel.quoted(s.matched), collector
337
342
  end
338
343
  end
339
344
  collector << ')'
@@ -342,22 +347,22 @@ module ArelExtensions
342
347
  end
343
348
 
344
349
  def visit_ArelExtensions_Nodes_Replace o, collector
345
- collector << "REPLACE("
350
+ collector << 'REPLACE('
346
351
  o.expressions.each_with_index { |arg, i|
347
352
  collector << LOADED_VISITOR::COMMA if i != 0
348
353
  collector = visit arg, collector
349
354
  }
350
- collector << ")"
355
+ collector << ')'
351
356
  collector
352
357
  end
353
358
 
354
359
  def visit_ArelExtensions_Nodes_FindInSet o, collector
355
- collector << "dbo.FIND_IN_SET("
360
+ collector << 'dbo.FIND_IN_SET('
356
361
  o.expressions.each_with_index { |arg, i|
357
362
  collector << LOADED_VISITOR::COMMA if i != 0
358
363
  collector = visit arg, collector
359
364
  }
360
- collector << ")"
365
+ collector << ')'
361
366
  collector
362
367
  end
363
368
 
@@ -400,9 +405,9 @@ module ArelExtensions
400
405
  end
401
406
 
402
407
  def visit_ArelExtensions_Nodes_AiIMatches o, collector
403
- collector = visit o.left.collate(true,true), collector
408
+ collector = visit o.left.collate(true, true), collector
404
409
  collector << ' LIKE '
405
- collector = visit o.right.collate(true,true), collector
410
+ collector = visit o.right.collate(true, true), collector
406
411
  if o.escape
407
412
  collector << ' ESCAPE '
408
413
  visit o.escape, collector
@@ -449,7 +454,7 @@ module ArelExtensions
449
454
  else
450
455
  collector = visit o.left, collector
451
456
  end
452
- collector << " AS "
457
+ collector << ' AS '
453
458
 
454
459
  # sometimes these values are already quoted, if they are, don't double quote it
455
460
  quote = o.right.is_a?(Arel::Nodes::SqlLiteral) && o.right[0] != '"' && o.right[-1] != '"'
@@ -476,108 +481,109 @@ module ArelExtensions
476
481
 
477
482
  # TODO;
478
483
  def visit_ArelExtensions_Nodes_GroupConcat o, collector
479
- collector << "(STRING_AGG("
484
+ collector << '(STRING_AGG('
480
485
  collector = visit o.left, collector
481
486
  collector << Arel::Visitors::Oracle::COMMA
482
487
  collector =
483
488
  if o.separator && o.separator != 'NULL'
484
489
  visit o.separator, collector
485
490
  else
486
- visit Arel::Nodes.build_quoted(','), collector
491
+ visit Arel.quoted(','), collector
487
492
  end
488
- collector << ") WITHIN GROUP (ORDER BY "
493
+ collector << ') WITHIN GROUP (ORDER BY '
489
494
  if o.order.present?
490
- o.order.each_with_index do |order,i|
495
+ o.order.each_with_index do |order, i|
491
496
  collector << Arel::Visitors::Oracle::COMMA if i != 0
492
497
  collector = visit order, collector
493
498
  end
494
499
  else
495
500
  collector = visit o.left, collector
496
501
  end
497
- collector << "))"
502
+ collector << '))'
498
503
  collector
499
504
  end
500
505
 
501
506
  def visit_ArelExtensions_Nodes_MD5 o, collector
502
507
  collector << "LOWER(CONVERT(NVARCHAR(32),HashBytes('MD5',CONVERT(VARCHAR,"
503
508
  collector = visit o.left, collector
504
- collector << ")),2))"
509
+ collector << ')),2))'
505
510
  collector
506
511
  end
507
512
 
508
513
  def visit_ArelExtensions_Nodes_Cast o, collector
509
- case o.as_attr
510
- when :string
511
- as_attr = Arel::Nodes::SqlLiteral.new('varchar')
512
- when :time
513
- as_attr = Arel::Nodes::SqlLiteral.new('time')
514
- when :date
515
- as_attr = Arel::Nodes::SqlLiteral.new('date')
516
- when :datetime
517
- as_attr = Arel::Nodes::SqlLiteral.new('datetime')
518
- when :number,:decimal, :float
519
- as_attr = Arel::Nodes::SqlLiteral.new('decimal(10,6)')
520
- when :int
521
- collector << "CAST(CAST("
522
- collector = visit o.left, collector
523
- collector << " AS decimal(10,0)) AS int)"
524
- return collector
525
- when :binary
526
- as_attr = Arel::Nodes::SqlLiteral.new('binary')
527
- else
528
- as_attr = Arel::Nodes::SqlLiteral.new(o.as_attr.to_s)
529
- end
530
- collector << "CAST("
514
+ as_attr =
515
+ case o.as_attr
516
+ when :string
517
+ 'varchar'
518
+ when :time
519
+ 'time'
520
+ when :date
521
+ 'date'
522
+ when :datetime
523
+ 'datetime'
524
+ when :number, :decimal, :float
525
+ 'decimal(10,6)'
526
+ when :int
527
+ collector << 'CAST(CAST('
528
+ collector = visit o.left, collector
529
+ collector << ' AS decimal(10,0)) AS int)'
530
+ return collector
531
+ when :binary
532
+ 'binary'
533
+ else
534
+ o.as_attr.to_s
535
+ end
536
+ collector << 'CAST('
531
537
  collector = visit o.left, collector
532
- collector << " AS "
533
- collector = visit as_attr, collector
534
- collector << ")"
538
+ collector << ' AS '
539
+ collector = visit Arel::Nodes::SqlLiteral.new(as_attr), collector
540
+ collector << ')'
535
541
  collector
536
542
  end
537
543
 
538
544
  def visit_ArelExtensions_Nodes_FormattedNumber o, collector
539
545
  col = o.left.coalesce(0)
540
- locale = Arel::Nodes.build_quoted(o.locale.tr('_','-'))
541
- param = Arel::Nodes.build_quoted("N#{o.precision}")
542
- sign = ArelExtensions::Nodes::Case.new.when(col<0).
546
+ locale = Arel.quoted(o.locale.tr('_', '-'))
547
+ param = Arel.quoted("N#{o.precision}")
548
+ sign = Arel.when(col < 0).
543
549
  then('-').
544
550
  else(o.flags.include?('+') ? '+' : (o.flags.include?(' ') ? ' ' : ''))
545
551
  sign_length = o.flags.include?('+') || o.flags.include?(' ') ?
546
- Arel::Nodes.build_quoted(1) :
547
- ArelExtensions::Nodes::Case.new.when(col<0).then(1).else(0)
552
+ Arel.quoted(1) :
553
+ Arel.when(col < 0).then(1).else(0)
548
554
 
549
555
  number =
550
556
  if o.scientific_notation
551
557
  ArelExtensions::Nodes::Concat.new([
552
- Arel::Nodes::NamedFunction.new('FORMAT',[
553
- col.abs/Arel::Nodes.build_quoted(10).pow(col.abs.log10.floor),
558
+ Arel::Nodes::NamedFunction.new('FORMAT', [
559
+ col.abs / Arel.quoted(10).pow(col.abs.log10.floor),
554
560
  param,
555
561
  locale
556
562
  ]),
557
563
  o.type,
558
- Arel::Nodes::NamedFunction.new('FORMAT',[
564
+ Arel::Nodes::NamedFunction.new('FORMAT', [
559
565
  col.abs.log10.floor,
560
- Arel::Nodes.build_quoted('N0'),
566
+ Arel.quoted('N0'),
561
567
  locale
562
568
  ])
563
569
  ])
564
570
  else
565
- Arel::Nodes::NamedFunction.new('FORMAT',[
566
- Arel::Nodes.build_quoted(col.abs),
571
+ Arel::Nodes::NamedFunction.new('FORMAT', [
572
+ Arel.quoted(col.abs),
567
573
  param,
568
574
  locale
569
575
  ])
570
576
  end
571
577
 
572
- repeated_char = (o.width == 0) ? Arel::Nodes.build_quoted('') : ArelExtensions::Nodes::Case.new().
573
- when(Arel::Nodes.build_quoted(o.width).abs-(number.length+sign_length)>0).
574
- then(Arel::Nodes.build_quoted(
578
+ repeated_char = (o.width == 0) ? Arel.quoted('') : ArelExtensions::Nodes::Case.new.
579
+ when(Arel.quoted(o.width).abs - (number.length + sign_length) > 0).
580
+ then(Arel.quoted(
575
581
  o.flags.include?('-') ? ' ' : (o.flags.include?('0') ? '0' : ' ')
576
- ).repeat(Arel::Nodes.build_quoted(o.width).abs-(number.length+sign_length))
582
+ ).repeat(Arel.quoted(o.width).abs - (number.length + sign_length))
577
583
  ).
578
584
  else('')
579
- before = (!o.flags.include?('0'))&&(!o.flags.include?('-')) ? repeated_char : ''
580
- middle = (o.flags.include?('0'))&&(!o.flags.include?('-')) ? repeated_char : ''
585
+ before = (!o.flags.include?('0')) && (!o.flags.include?('-')) ? repeated_char : ''
586
+ middle = (o.flags.include?('0')) && (!o.flags.include?('-')) ? repeated_char : ''
581
587
  after = o.flags.include?('-') ? repeated_char : ''
582
588
  full_number =
583
589
  ArelExtensions::Nodes::Concat.new([
@@ -587,27 +593,27 @@ module ArelExtensions
587
593
  number,
588
594
  after
589
595
  ])
590
- collector = visit ArelExtensions::Nodes::Concat.new([Arel::Nodes.build_quoted(o.prefix),full_number,Arel::Nodes.build_quoted(o.suffix)]), collector
596
+ collector = visit ArelExtensions::Nodes::Concat.new([Arel.quoted(o.prefix), full_number, Arel.quoted(o.suffix)]), collector
591
597
  collector
592
598
  end
593
599
 
594
600
  def visit_ArelExtensions_Nodes_Std o, collector
595
- collector << (o.unbiased_estimator ? "STDEV(" : "STDEVP(")
601
+ collector << (o.unbiased_estimator ? 'STDEV(' : 'STDEVP(')
596
602
  visit o.left, collector
597
- collector << ")"
603
+ collector << ')'
598
604
  collector
599
605
  end
600
606
 
601
607
  def visit_ArelExtensions_Nodes_Variance o, collector
602
- collector << (o.unbiased_estimator ? "VAR(" : "VARP(")
608
+ collector << (o.unbiased_estimator ? 'VAR(' : 'VARP(')
603
609
  visit o.left, collector
604
- collector << ")"
610
+ collector << ')'
605
611
  collector
606
612
  end
607
613
 
608
614
 
609
615
  def visit_ArelExtensions_Nodes_LevenshteinDistance o, collector
610
- collector << "dbo.LEVENSHTEIN_DISTANCE("
616
+ collector << 'dbo.LEVENSHTEIN_DISTANCE('
611
617
  collector = visit o.left, collector
612
618
  collector << Arel::Visitors::ToSql::COMMA
613
619
  collector = visit o.right, collector
@@ -616,14 +622,14 @@ module ArelExtensions
616
622
  end
617
623
 
618
624
 
619
- def visit_ArelExtensions_Nodes_JsonGet o,collector
625
+ def visit_ArelExtensions_Nodes_JsonGet o, collector
620
626
  collector << 'JSON_VALUE('
621
627
  collector = visit o.dict, collector
622
628
  collector << Arel::Visitors::MySQL::COMMA
623
629
  if o.key.is_a?(Integer)
624
630
  collector << "\"$[#{o.key}]\""
625
631
  else
626
- collector = visit Arel::Nodes.build_quoted('$.')+o.key, collector
632
+ collector = visit Arel.quoted('$.') + o.key, collector
627
633
  end
628
634
  collector << ')'
629
635
  collector