arel_extensions 1.3.1 → 1.3.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 +24 -4
  7. data/Rakefile +4 -4
  8. data/TODO +0 -1
  9. data/arel_extensions.gemspec +12 -12
  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 +1 -1
  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 +139 -118
  84. data/lib/arel_extensions/visitors/mysql.rb +145 -144
  85. data/lib/arel_extensions/visitors/oracle.rb +136 -128
  86. data/lib/arel_extensions/visitors/oracle12.rb +16 -16
  87. data/lib/arel_extensions/visitors/postgresql.rb +147 -136
  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 -14
  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 +415 -313
  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,16 +13,21 @@ 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
- '%d' => 'DD', '%e' => '', '%j' => '', '%w' => 'dw', '%A' => '', # day, weekday
18
- '%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
19
20
  '%M' => 'mi', '%S' => 'ss', '%L' => 'ms', '%N' => 'ns', '%z' => 'tz'
20
21
  }.freeze
21
22
 
22
23
  LOADED_VISITOR::DATE_FORMAT_FORMAT = {
23
- 'YY' => '0#', 'MM' => '0#', 'DD' => '0#', 'hh' => '0#', 'mi' => '0#', 'ss' => '0#'
24
+ 'YY' => '0#', 'MM' => '0#', 'DD' => '0#', 'hh' => '0#', 'mi' => '0#', 'ss' => '0#', 'iso_week' => '0#'
24
25
  }
25
26
 
27
+ LOADED_VISITOR::DATE_NAME = [
28
+ '%B', '%A'
29
+ ]
30
+
26
31
  LOADED_VISITOR::DATE_FORMAT_REGEX =
27
32
  Regexp.new(
28
33
  LOADED_VISITOR::DATE_FORMAT_DIRECTIVES
@@ -34,7 +39,7 @@ module ArelExtensions
34
39
  # TODO; all others... http://www.sql-server-helper.com/tips/date-formats.aspx
35
40
  LOADED_VISITOR::DATE_CONVERT_FORMATS = {
36
41
  'YYYY-MM-DD' => 120,
37
- 'YY-MM-DD' => 120,
42
+ 'YY-MM-DD' => 120,
38
43
  'MM/DD/YYYY' => 101,
39
44
  'MM-DD-YYYY' => 110,
40
45
  'YYYY/MM/DD' => 111,
@@ -46,63 +51,63 @@ module ArelExtensions
46
51
 
47
52
  # Math Functions
48
53
  def visit_ArelExtensions_Nodes_Ceil o, collector
49
- collector << "CEILING("
54
+ collector << 'CEILING('
50
55
  collector = visit o.expr, collector
51
- collector << ")"
56
+ collector << ')'
52
57
  collector
53
58
  end
54
59
 
55
60
  def visit_ArelExtensions_Nodes_Log10 o, collector
56
- collector << "LOG10("
61
+ collector << 'LOG10('
57
62
  o.expressions.each_with_index { |arg, i|
58
63
  collector << Arel::Visitors::ToSql::COMMA if i != 0
59
64
  collector = visit arg, collector
60
65
  }
61
- collector << ")"
66
+ collector << ')'
62
67
  collector
63
68
  end
64
69
 
65
70
  def visit_ArelExtensions_Nodes_Power o, collector
66
- collector << "POWER("
71
+ collector << 'POWER('
67
72
  o.expressions.each_with_index { |arg, i|
68
73
  collector << Arel::Visitors::ToSql::COMMA if i != 0
69
74
  collector = visit arg, collector
70
75
  }
71
- collector << ")"
76
+ collector << ')'
72
77
  collector
73
78
  end
74
79
 
75
80
  def visit_ArelExtensions_Nodes_IsNull o, collector
76
- collector << "("
81
+ collector << '('
77
82
  collector = visit o.expr, collector
78
- collector << " IS NULL)"
83
+ collector << ' IS NULL)'
79
84
  collector
80
85
  end
81
86
 
82
87
  def visit_ArelExtensions_Nodes_IsNotNull o, collector
83
- collector << "("
88
+ collector << '('
84
89
  collector = visit o.expr, collector
85
- collector << " IS NOT NULL)"
90
+ collector << ' IS NOT NULL)'
86
91
  collector
87
92
  end
88
93
 
89
94
  def visit_ArelExtensions_Nodes_Concat o, collector
90
- collector << "CONCAT("
95
+ collector << 'CONCAT('
91
96
  o.expressions.each_with_index { |arg, i|
92
97
  collector << LOADED_VISITOR::COMMA if i != 0
93
98
  collector = visit arg, collector
94
99
  }
95
- collector << ")"
100
+ collector << ')'
96
101
  collector
97
102
  end
98
103
 
99
104
  def visit_ArelExtensions_Nodes_Repeat o, collector
100
- collector << "REPLICATE("
105
+ collector << 'REPLICATE('
101
106
  o.expressions.each_with_index { |arg, i|
102
107
  collector << Arel::Visitors::ToSql::COMMA if i != 0
103
108
  collector = visit arg, collector
104
109
  }
105
- collector << ")"
110
+ collector << ')'
106
111
  collector
107
112
  end
108
113
 
@@ -122,28 +127,28 @@ module ArelExtensions
122
127
  collector << ')'
123
128
  else
124
129
  da = ArelExtensions::Nodes::DateAdd.new([])
125
- collector << "DATEADD("
130
+ collector << 'DATEADD('
126
131
  collector = visit da.mssql_datepart(o.right), collector
127
132
  collector << LOADED_VISITOR::COMMA
128
- collector << "-("
133
+ collector << '-('
129
134
  collector = visit da.mssql_value(o.right), collector
130
- collector << ")"
135
+ collector << ')'
131
136
  collector << LOADED_VISITOR::COMMA
132
137
  collector = visit o.left, collector
133
- collector << ")"
138
+ collector << ')'
134
139
  collector
135
140
  end
136
141
  collector
137
142
  end
138
143
 
139
144
  def visit_ArelExtensions_Nodes_DateAdd o, collector
140
- collector << "DATEADD("
145
+ collector << 'DATEADD('
141
146
  collector = visit o.mssql_datepart(o.right), collector
142
147
  collector << LOADED_VISITOR::COMMA
143
148
  collector = visit o.mssql_value(o.right), collector
144
149
  collector << LOADED_VISITOR::COMMA
145
150
  collector = visit o.left, collector
146
- collector << ")"
151
+ collector << ')'
147
152
  collector
148
153
  end
149
154
 
@@ -159,47 +164,47 @@ module ArelExtensions
159
164
  collector << 'CONVERT(datetime,' if conv
160
165
  collector = visit o.right, collector
161
166
  collector << ')' if conv
162
- collector << ")"
167
+ collector << ')'
163
168
  end
164
169
  collector
165
170
  end
166
171
 
167
172
  def visit_ArelExtensions_Nodes_Length o, collector
168
173
  if o.bytewise
169
- collector << "(DATALENGTH("
174
+ collector << '(DATALENGTH('
170
175
  collector = visit o.expr, collector
171
- collector << ") / ISNULL(NULLIF(DATALENGTH(LEFT(COALESCE("
176
+ collector << ') / ISNULL(NULLIF(DATALENGTH(LEFT(COALESCE('
172
177
  collector = visit o.expr, collector
173
178
  collector << ", '#' ), 1 )), 0), 1))"
174
179
  collector
175
180
  else
176
- collector << "LEN("
181
+ collector << 'LEN('
177
182
  collector = visit o.expr, collector
178
- collector << ")"
183
+ collector << ')'
179
184
  collector
180
185
  end
181
186
  end
182
187
 
183
188
  def visit_ArelExtensions_Nodes_Round o, collector
184
- collector << "ROUND("
189
+ collector << 'ROUND('
185
190
  o.expressions.each_with_index { |arg, i|
186
191
  collector << LOADED_VISITOR::COMMA if i != 0
187
192
  collector = visit arg, collector
188
193
  }
189
194
  if o.expressions.length == 1
190
195
  collector << LOADED_VISITOR::COMMA
191
- collector << "0"
196
+ collector << '0'
192
197
  end
193
- collector << ")"
198
+ collector << ')'
194
199
  collector
195
200
  end
196
201
 
197
202
  def visit_ArelExtensions_Nodes_Locate o, collector
198
- collector << "CHARINDEX("
203
+ collector << 'CHARINDEX('
199
204
  collector = visit o.right, collector
200
205
  collector << LOADED_VISITOR::COMMA
201
206
  collector = visit o.left, collector
202
- collector << ")"
207
+ collector << ')'
203
208
  collector
204
209
  end
205
210
 
@@ -217,15 +222,15 @@ module ArelExtensions
217
222
  def visit_ArelExtensions_Nodes_Trim o, collector
218
223
  collector << 'TRIM( '
219
224
  collector = visit o.right, collector
220
- collector << " FROM "
225
+ collector << ' FROM '
221
226
  collector = visit o.left, collector
222
- collector << ")"
227
+ collector << ')'
223
228
  collector
224
229
  end
225
230
 
226
231
  def visit_ArelExtensions_Nodes_Ltrim o, collector
227
232
  if o.right
228
- collector << "REPLACE(REPLACE(LTRIM(REPLACE(REPLACE("
233
+ collector << 'REPLACE(REPLACE(LTRIM(REPLACE(REPLACE('
229
234
  collector = visit o.left, collector
230
235
  collector << ", ' ', '~'), "
231
236
  collector = visit o.right, collector
@@ -233,16 +238,16 @@ module ArelExtensions
233
238
  collector = visit o.right, collector
234
239
  collector << "), '~', ' ')"
235
240
  else
236
- collector << "LTRIM("
241
+ collector << 'LTRIM('
237
242
  collector = visit o.left, collector
238
- collector << ")"
243
+ collector << ')'
239
244
  end
240
245
  collector
241
246
  end
242
247
 
243
248
  def visit_ArelExtensions_Nodes_Rtrim o, collector
244
249
  if o.right
245
- collector << "REPLACE(REPLACE(RTRIM(REPLACE(REPLACE("
250
+ collector << 'REPLACE(REPLACE(RTRIM(REPLACE(REPLACE('
246
251
  collector = visit o.left, collector
247
252
  collector << ", ' ', '~'), "
248
253
  collector = visit o.right, collector
@@ -250,9 +255,9 @@ module ArelExtensions
250
255
  collector = visit o.right, collector
251
256
  collector << "), '~', ' ')"
252
257
  else
253
- collector << "RTRIM("
258
+ collector << 'RTRIM('
254
259
  collector = visit o.left, collector
255
- collector << ")"
260
+ collector << ')'
256
261
  end
257
262
  collector
258
263
  end
@@ -276,9 +281,16 @@ module ArelExtensions
276
281
  collector << ' '
277
282
  end
278
283
  collector = visit o.left, collector
279
- if o.time_zone
280
- collector << ") AT TIME ZONE 'UTC' AT TIME ZONE "
281
- collector = visit o.time_zone, collector
284
+ case o.time_zone
285
+ when Hash
286
+ src_tz, dst_tz = o.time_zone.first
287
+ collector << ') AT TIME ZONE '
288
+ collector = visit Arel.quoted(src_tz), collector
289
+ collector << ' AT TIME ZONE '
290
+ collector = visit Arel.quoted(dst_tz), collector
291
+ when String
292
+ collector << ') AT TIME ZONE '
293
+ collector = visit Arel.quoted(o.time_zone), collector
282
294
  end
283
295
  collector << LOADED_VISITOR::COMMA
284
296
  collector << fmt.to_s
@@ -286,7 +298,7 @@ module ArelExtensions
286
298
  collector
287
299
  else
288
300
  s = StringScanner.new o.iso_format
289
- collector << "("
301
+ collector << '('
290
302
  sep = ''
291
303
  while !s.eos?
292
304
  collector << sep
@@ -295,10 +307,11 @@ module ArelExtensions
295
307
  when s.scan(LOADED_VISITOR::DATE_FORMAT_REGEX)
296
308
  dir = LOADED_VISITOR::DATE_FORMAT_DIRECTIVES[s.matched]
297
309
  fmt = LOADED_VISITOR::DATE_FORMAT_FORMAT[dir]
310
+ date_name = LOADED_VISITOR::DATE_NAME.include?(s.matched)
298
311
  collector << 'TRIM('
299
312
  collector << 'FORMAT(' if fmt
300
- collector << 'STR(' if !fmt
301
- collector << 'DATEPART('
313
+ collector << 'STR(' if !fmt && !date_name
314
+ collector << (date_name ? 'DATENAME(' : 'DATEPART(')
302
315
  collector << dir
303
316
  collector << LOADED_VISITOR::COMMA
304
317
  if o.time_zone
@@ -307,18 +320,25 @@ module ArelExtensions
307
320
  collector << ' '
308
321
  end
309
322
  collector = visit o.left, collector
310
- if o.time_zone
311
- collector << ") AT TIME ZONE 'UTC' AT TIME ZONE "
312
- collector = visit o.time_zone, collector
323
+ case o.time_zone
324
+ when Hash
325
+ src_tz, dst_tz = o.time_zone.first.first, o.time_zone.first.second
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
330
+ when String
331
+ collector << ') AT TIME ZONE '
332
+ collector = visit Arel.quoted(o.time_zone), collector
313
333
  end
314
334
  collector << ')'
315
- collector << ')' if !fmt
335
+ collector << ')' if !fmt && !date_name
316
336
  collector << LOADED_VISITOR::COMMA << "'#{fmt}')" if fmt
317
337
  collector << ')'
318
338
  when s.scan(/^%%/)
319
- collector = visit Arel::Nodes.build_quoted('%'), collector
339
+ collector = visit Arel.quoted('%'), collector
320
340
  when s.scan(/[^%]+|./)
321
- collector = visit Arel::Nodes.build_quoted(s.matched), collector
341
+ collector = visit Arel.quoted(s.matched), collector
322
342
  end
323
343
  end
324
344
  collector << ')'
@@ -327,22 +347,22 @@ module ArelExtensions
327
347
  end
328
348
 
329
349
  def visit_ArelExtensions_Nodes_Replace o, collector
330
- collector << "REPLACE("
350
+ collector << 'REPLACE('
331
351
  o.expressions.each_with_index { |arg, i|
332
352
  collector << LOADED_VISITOR::COMMA if i != 0
333
353
  collector = visit arg, collector
334
354
  }
335
- collector << ")"
355
+ collector << ')'
336
356
  collector
337
357
  end
338
358
 
339
359
  def visit_ArelExtensions_Nodes_FindInSet o, collector
340
- collector << "dbo.FIND_IN_SET("
360
+ collector << 'dbo.FIND_IN_SET('
341
361
  o.expressions.each_with_index { |arg, i|
342
362
  collector << LOADED_VISITOR::COMMA if i != 0
343
363
  collector = visit arg, collector
344
364
  }
345
- collector << ")"
365
+ collector << ')'
346
366
  collector
347
367
  end
348
368
 
@@ -385,9 +405,9 @@ module ArelExtensions
385
405
  end
386
406
 
387
407
  def visit_ArelExtensions_Nodes_AiIMatches o, collector
388
- collector = visit o.left.collate(true,true), collector
408
+ collector = visit o.left.collate(true, true), collector
389
409
  collector << ' LIKE '
390
- collector = visit o.right.collate(true,true), collector
410
+ collector = visit o.right.collate(true, true), collector
391
411
  if o.escape
392
412
  collector << ' ESCAPE '
393
413
  visit o.escape, collector
@@ -434,7 +454,7 @@ module ArelExtensions
434
454
  else
435
455
  collector = visit o.left, collector
436
456
  end
437
- collector << " AS "
457
+ collector << ' AS '
438
458
 
439
459
  # sometimes these values are already quoted, if they are, don't double quote it
440
460
  quote = o.right.is_a?(Arel::Nodes::SqlLiteral) && o.right[0] != '"' && o.right[-1] != '"'
@@ -461,108 +481,109 @@ module ArelExtensions
461
481
 
462
482
  # TODO;
463
483
  def visit_ArelExtensions_Nodes_GroupConcat o, collector
464
- collector << "(STRING_AGG("
484
+ collector << '(STRING_AGG('
465
485
  collector = visit o.left, collector
466
486
  collector << Arel::Visitors::Oracle::COMMA
467
487
  collector =
468
488
  if o.separator && o.separator != 'NULL'
469
489
  visit o.separator, collector
470
490
  else
471
- visit Arel::Nodes.build_quoted(','), collector
491
+ visit Arel.quoted(','), collector
472
492
  end
473
- collector << ") WITHIN GROUP (ORDER BY "
493
+ collector << ') WITHIN GROUP (ORDER BY '
474
494
  if o.order.present?
475
- o.order.each_with_index do |order,i|
495
+ o.order.each_with_index do |order, i|
476
496
  collector << Arel::Visitors::Oracle::COMMA if i != 0
477
497
  collector = visit order, collector
478
498
  end
479
499
  else
480
500
  collector = visit o.left, collector
481
501
  end
482
- collector << "))"
502
+ collector << '))'
483
503
  collector
484
504
  end
485
505
 
486
506
  def visit_ArelExtensions_Nodes_MD5 o, collector
487
507
  collector << "LOWER(CONVERT(NVARCHAR(32),HashBytes('MD5',CONVERT(VARCHAR,"
488
508
  collector = visit o.left, collector
489
- collector << ")),2))"
509
+ collector << ')),2))'
490
510
  collector
491
511
  end
492
512
 
493
513
  def visit_ArelExtensions_Nodes_Cast o, collector
494
- case o.as_attr
495
- when :string
496
- as_attr = Arel::Nodes::SqlLiteral.new('varchar')
497
- when :time
498
- as_attr = Arel::Nodes::SqlLiteral.new('time')
499
- when :date
500
- as_attr = Arel::Nodes::SqlLiteral.new('date')
501
- when :datetime
502
- as_attr = Arel::Nodes::SqlLiteral.new('datetime')
503
- when :number,:decimal, :float
504
- as_attr = Arel::Nodes::SqlLiteral.new('decimal(10,6)')
505
- when :int
506
- collector << "CAST(CAST("
507
- collector = visit o.left, collector
508
- collector << " AS decimal(10,0)) AS int)"
509
- return collector
510
- when :binary
511
- as_attr = Arel::Nodes::SqlLiteral.new('binary')
512
- else
513
- as_attr = Arel::Nodes::SqlLiteral.new(o.as_attr.to_s)
514
- end
515
- 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('
516
537
  collector = visit o.left, collector
517
- collector << " AS "
518
- collector = visit as_attr, collector
519
- collector << ")"
538
+ collector << ' AS '
539
+ collector = visit Arel::Nodes::SqlLiteral.new(as_attr), collector
540
+ collector << ')'
520
541
  collector
521
542
  end
522
543
 
523
544
  def visit_ArelExtensions_Nodes_FormattedNumber o, collector
524
545
  col = o.left.coalesce(0)
525
- locale = Arel::Nodes.build_quoted(o.locale.tr('_','-'))
526
- param = Arel::Nodes.build_quoted("N#{o.precision}")
527
- 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).
528
549
  then('-').
529
550
  else(o.flags.include?('+') ? '+' : (o.flags.include?(' ') ? ' ' : ''))
530
551
  sign_length = o.flags.include?('+') || o.flags.include?(' ') ?
531
- Arel::Nodes.build_quoted(1) :
532
- ArelExtensions::Nodes::Case.new.when(col<0).then(1).else(0)
552
+ Arel.quoted(1) :
553
+ Arel.when(col < 0).then(1).else(0)
533
554
 
534
555
  number =
535
556
  if o.scientific_notation
536
557
  ArelExtensions::Nodes::Concat.new([
537
- Arel::Nodes::NamedFunction.new('FORMAT',[
538
- 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),
539
560
  param,
540
561
  locale
541
562
  ]),
542
563
  o.type,
543
- Arel::Nodes::NamedFunction.new('FORMAT',[
564
+ Arel::Nodes::NamedFunction.new('FORMAT', [
544
565
  col.abs.log10.floor,
545
- Arel::Nodes.build_quoted('N0'),
566
+ Arel.quoted('N0'),
546
567
  locale
547
568
  ])
548
569
  ])
549
570
  else
550
- Arel::Nodes::NamedFunction.new('FORMAT',[
551
- Arel::Nodes.build_quoted(col.abs),
571
+ Arel::Nodes::NamedFunction.new('FORMAT', [
572
+ Arel.quoted(col.abs),
552
573
  param,
553
574
  locale
554
575
  ])
555
576
  end
556
577
 
557
- repeated_char = (o.width == 0) ? Arel::Nodes.build_quoted('') : ArelExtensions::Nodes::Case.new().
558
- when(Arel::Nodes.build_quoted(o.width).abs-(number.length+sign_length)>0).
559
- 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(
560
581
  o.flags.include?('-') ? ' ' : (o.flags.include?('0') ? '0' : ' ')
561
- ).repeat(Arel::Nodes.build_quoted(o.width).abs-(number.length+sign_length))
582
+ ).repeat(Arel.quoted(o.width).abs - (number.length + sign_length))
562
583
  ).
563
584
  else('')
564
- before = (!o.flags.include?('0'))&&(!o.flags.include?('-')) ? repeated_char : ''
565
- 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 : ''
566
587
  after = o.flags.include?('-') ? repeated_char : ''
567
588
  full_number =
568
589
  ArelExtensions::Nodes::Concat.new([
@@ -572,27 +593,27 @@ module ArelExtensions
572
593
  number,
573
594
  after
574
595
  ])
575
- 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
576
597
  collector
577
598
  end
578
599
 
579
600
  def visit_ArelExtensions_Nodes_Std o, collector
580
- collector << (o.unbiased_estimator ? "STDEV(" : "STDEVP(")
601
+ collector << (o.unbiased_estimator ? 'STDEV(' : 'STDEVP(')
581
602
  visit o.left, collector
582
- collector << ")"
603
+ collector << ')'
583
604
  collector
584
605
  end
585
606
 
586
607
  def visit_ArelExtensions_Nodes_Variance o, collector
587
- collector << (o.unbiased_estimator ? "VAR(" : "VARP(")
608
+ collector << (o.unbiased_estimator ? 'VAR(' : 'VARP(')
588
609
  visit o.left, collector
589
- collector << ")"
610
+ collector << ')'
590
611
  collector
591
612
  end
592
613
 
593
614
 
594
615
  def visit_ArelExtensions_Nodes_LevenshteinDistance o, collector
595
- collector << "dbo.LEVENSHTEIN_DISTANCE("
616
+ collector << 'dbo.LEVENSHTEIN_DISTANCE('
596
617
  collector = visit o.left, collector
597
618
  collector << Arel::Visitors::ToSql::COMMA
598
619
  collector = visit o.right, collector
@@ -601,14 +622,14 @@ module ArelExtensions
601
622
  end
602
623
 
603
624
 
604
- def visit_ArelExtensions_Nodes_JsonGet o,collector
625
+ def visit_ArelExtensions_Nodes_JsonGet o, collector
605
626
  collector << 'JSON_VALUE('
606
627
  collector = visit o.dict, collector
607
628
  collector << Arel::Visitors::MySQL::COMMA
608
629
  if o.key.is_a?(Integer)
609
630
  collector << "\"$[#{o.key}]\""
610
631
  else
611
- collector = visit Arel::Nodes.build_quoted('$.')+o.key, collector
632
+ collector = visit Arel.quoted('$.') + o.key, collector
612
633
  end
613
634
  collector << ')'
614
635
  collector