arel_extensions 1.3.2 → 1.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +1 -2
- data/.github/workflows/ruby.yml +43 -91
- data/.gitignore +7 -6
- data/.rubocop.yml +62 -1
- data/Gemfile +11 -11
- data/README.md +1 -1
- data/Rakefile +4 -4
- data/TODO +0 -1
- data/appveyor.yml +73 -0
- data/arel_extensions.gemspec +12 -12
- data/gemfiles/rails3.gemfile +10 -10
- data/gemfiles/rails4.gemfile +14 -14
- data/gemfiles/rails5_0.gemfile +13 -13
- data/gemfiles/rails5_1_4.gemfile +13 -13
- data/gemfiles/rails5_2.gemfile +15 -14
- data/gemfiles/rails6.gemfile +13 -12
- data/gemfiles/rails6_1.gemfile +13 -12
- data/gemfiles/rails7.gemfile +9 -8
- data/gemspecs/arel_extensions-v1.gemspec +12 -12
- data/gemspecs/arel_extensions-v2.gemspec +11 -11
- data/init/mssql.sql +0 -0
- data/init/mysql.sql +0 -0
- data/init/oracle.sql +0 -0
- data/init/postgresql.sql +0 -0
- data/init/sqlite.sql +0 -0
- data/lib/arel_extensions/attributes.rb +2 -2
- data/lib/arel_extensions/boolean_functions.rb +2 -4
- data/lib/arel_extensions/common_sql_functions.rb +12 -12
- data/lib/arel_extensions/comparators.rb +14 -14
- data/lib/arel_extensions/date_duration.rb +7 -7
- data/lib/arel_extensions/helpers.rb +19 -16
- data/lib/arel_extensions/insert_manager.rb +1 -1
- data/lib/arel_extensions/math.rb +44 -31
- data/lib/arel_extensions/math_functions.rb +18 -18
- data/lib/arel_extensions/nodes/abs.rb +0 -0
- data/lib/arel_extensions/nodes/aggregate_function.rb +0 -0
- data/lib/arel_extensions/nodes/blank.rb +1 -1
- data/lib/arel_extensions/nodes/case.rb +4 -6
- data/lib/arel_extensions/nodes/cast.rb +5 -5
- data/lib/arel_extensions/nodes/ceil.rb +0 -0
- data/lib/arel_extensions/nodes/change_case.rb +0 -0
- data/lib/arel_extensions/nodes/coalesce.rb +1 -1
- data/lib/arel_extensions/nodes/collate.rb +9 -9
- data/lib/arel_extensions/nodes/concat.rb +2 -2
- data/lib/arel_extensions/nodes/date_diff.rb +10 -10
- data/lib/arel_extensions/nodes/duration.rb +0 -0
- data/lib/arel_extensions/nodes/find_in_set.rb +0 -0
- data/lib/arel_extensions/nodes/floor.rb +0 -0
- data/lib/arel_extensions/nodes/format.rb +0 -0
- data/lib/arel_extensions/nodes/formatted_number.rb +2 -2
- data/lib/arel_extensions/nodes/function.rb +21 -21
- data/lib/arel_extensions/nodes/is_null.rb +0 -0
- data/lib/arel_extensions/nodes/json.rb +7 -7
- data/lib/arel_extensions/nodes/length.rb +0 -0
- data/lib/arel_extensions/nodes/levenshtein_distance.rb +1 -1
- data/lib/arel_extensions/nodes/locate.rb +1 -1
- data/lib/arel_extensions/nodes/log10.rb +0 -0
- data/lib/arel_extensions/nodes/matches.rb +1 -1
- data/lib/arel_extensions/nodes/md5.rb +0 -0
- data/lib/arel_extensions/nodes/power.rb +0 -0
- data/lib/arel_extensions/nodes/rand.rb +0 -0
- data/lib/arel_extensions/nodes/repeat.rb +2 -2
- data/lib/arel_extensions/nodes/replace.rb +2 -2
- data/lib/arel_extensions/nodes/round.rb +0 -0
- data/lib/arel_extensions/nodes/soundex.rb +2 -2
- data/lib/arel_extensions/nodes/std.rb +0 -0
- data/lib/arel_extensions/nodes/substring.rb +1 -1
- data/lib/arel_extensions/nodes/sum.rb +0 -0
- data/lib/arel_extensions/nodes/then.rb +1 -1
- data/lib/arel_extensions/nodes/trim.rb +2 -2
- data/lib/arel_extensions/nodes/union.rb +4 -4
- data/lib/arel_extensions/nodes/union_all.rb +3 -3
- data/lib/arel_extensions/nodes/wday.rb +0 -0
- data/lib/arel_extensions/nodes.rb +0 -0
- data/lib/arel_extensions/null_functions.rb +0 -0
- data/lib/arel_extensions/predications.rb +10 -10
- data/lib/arel_extensions/railtie.rb +1 -1
- data/lib/arel_extensions/set_functions.rb +3 -3
- data/lib/arel_extensions/string_functions.rb +8 -8
- data/lib/arel_extensions/tasks.rb +2 -2
- data/lib/arel_extensions/version.rb +1 -1
- data/lib/arel_extensions/visitors/convert_format.rb +0 -0
- data/lib/arel_extensions/visitors/ibm_db.rb +20 -20
- data/lib/arel_extensions/visitors/mssql.rb +150 -130
- data/lib/arel_extensions/visitors/mysql.rb +147 -149
- data/lib/arel_extensions/visitors/oracle.rb +141 -135
- data/lib/arel_extensions/visitors/oracle12.rb +16 -16
- data/lib/arel_extensions/visitors/postgresql.rb +147 -139
- data/lib/arel_extensions/visitors/sqlite.rb +85 -87
- data/lib/arel_extensions/visitors/to_sql.rb +146 -148
- data/lib/arel_extensions/visitors.rb +7 -7
- data/lib/arel_extensions.rb +56 -32
- data/test/arelx_test_helper.rb +14 -13
- data/test/database.yml +5 -5
- data/test/real_db_test.rb +81 -81
- data/test/support/fake_record.rb +2 -2
- data/test/test_comparators.rb +5 -5
- data/test/visitors/test_bulk_insert_oracle.rb +5 -5
- data/test/visitors/test_bulk_insert_sqlite.rb +5 -5
- data/test/visitors/test_bulk_insert_to_sql.rb +5 -5
- data/test/visitors/test_oracle.rb +14 -14
- data/test/visitors/test_to_sql.rb +87 -87
- data/test/with_ar/all_agnostic_test.rb +411 -306
- data/test/with_ar/insert_agnostic_test.rb +19 -16
- data/test/with_ar/test_bulk_sqlite.rb +5 -5
- data/test/with_ar/test_math_sqlite.rb +12 -12
- data/test/with_ar/test_string_mysql.rb +20 -20
- data/test/with_ar/test_string_sqlite.rb +20 -20
- data/version_v1.rb +1 -1
- data/version_v2.rb +1 -1
- metadata +3 -9
- data/.travis/oracle/download.js +0 -152
- data/.travis/oracle/download.sh +0 -30
- data/.travis/oracle/download_ojdbc.js +0 -116
- data/.travis/oracle/install.sh +0 -34
- data/.travis/setup_accounts.sh +0 -9
- data/.travis/sqlite3/extension-functions.sh +0 -6
- data/.travis.yml +0 -193
@@ -6,30 +6,31 @@ module ArelExtensions
|
|
6
6
|
DATE_MAPPING = {'d' => 'DAY', 'm' => 'MONTH', 'w' => 'IW', 'y' => 'YEAR', 'wd' => 'D', 'h' => 'HOUR', 'mn' => 'MINUTE', 's' => 'SECOND'}
|
7
7
|
DATE_FORMAT_DIRECTIVES = {
|
8
8
|
'%Y' => 'YYYY', '%C' => 'CC', '%y' => 'YY', '%m' => 'MM', '%B' => 'Month', '%^B' => 'MONTH', '%b' => 'Mon', '%^b' => 'MON',
|
9
|
-
'%
|
9
|
+
'%V' => 'IW', '%G' => 'IYYY', # ISO week number and year of week
|
10
|
+
'%d' => 'DD', '%e' => 'FMDD', '%j' => 'DDD', '%w' => '', '%a' => 'Dy', '%A' => 'Day', # day, weekday
|
10
11
|
'%H' => 'HH24', '%k' => '', '%I' => 'HH', '%l' => '', '%P' => 'am', '%p' => 'AM', # hours
|
11
12
|
'%M' => 'MI', '%S' => 'SS', '%L' => 'MS', '%N' => 'US', '%z' => 'tz' # seconds, subseconds
|
12
13
|
}
|
13
|
-
NUMBER_COMMA_MAPPING = {
|
14
|
+
NUMBER_COMMA_MAPPING = {'en_US' => '.,', 'fr_FR' => ',', 'sv_SE' => ', '}
|
14
15
|
|
15
16
|
def visit_ArelExtensions_Nodes_Log10 o, collector
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
collector << 'LOG('
|
18
|
+
o.expressions.each_with_index { |arg, i|
|
19
|
+
collector << Arel::Visitors::ToSql::COMMA if i != 0
|
20
|
+
collector = visit arg, collector
|
21
|
+
}
|
22
|
+
collector << ',10)'
|
23
|
+
collector
|
23
24
|
end
|
24
25
|
|
25
26
|
def visit_ArelExtensions_Nodes_Power o, collector
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
27
|
+
collector << 'POWER('
|
28
|
+
o.expressions.each_with_index { |arg, i|
|
29
|
+
collector << Arel::Visitors::ToSql::COMMA if i != 0
|
30
|
+
collector = visit arg, collector
|
31
|
+
}
|
32
|
+
collector << ')'
|
33
|
+
collector
|
33
34
|
end
|
34
35
|
|
35
36
|
def visit_ArelExtensions_Nodes_Concat o, collector
|
@@ -107,54 +108,54 @@ module ArelExtensions
|
|
107
108
|
end
|
108
109
|
|
109
110
|
def visit_ArelExtensions_Nodes_Collate o, collector
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
111
|
+
if o.ai
|
112
|
+
collector << 'NLSSORT('
|
113
|
+
collector = visit o.expressions.first, collector
|
114
|
+
collector << COMMA
|
115
|
+
collector << "'NLS_SORT = BINARY_AI NLS_COMP = LINGUISTIC'"
|
116
|
+
collector << ')'
|
117
|
+
elsif o.ci
|
118
|
+
collector << 'NLSSORT('
|
119
|
+
collector = visit o.expressions.first, collector
|
120
|
+
collector << COMMA
|
121
|
+
collector << "'NLS_SORT = BINARY_CI NLS_COMP = LINGUISTIC'"
|
122
|
+
collector << ')'
|
123
|
+
else
|
124
|
+
collector = visit o.expressions.first, collector
|
125
|
+
end
|
125
126
|
collector
|
126
127
|
end
|
127
128
|
|
128
129
|
def visit_ArelExtensions_Nodes_GroupConcat o, collector
|
129
|
-
collector <<
|
130
|
+
collector << '(LISTAGG('
|
130
131
|
collector = visit o.left, collector
|
131
132
|
collector << COMMA
|
132
133
|
collector =
|
133
134
|
if o.separator && o.separator != 'NULL'
|
134
135
|
visit o.separator, collector
|
135
136
|
else
|
136
|
-
visit Arel
|
137
|
+
visit Arel.quoted(','), collector
|
137
138
|
end
|
138
|
-
collector <<
|
139
|
+
collector << ') WITHIN GROUP (ORDER BY '
|
139
140
|
if !o.order.blank?
|
140
|
-
o.order.each_with_index do |order,i|
|
141
|
+
o.order.each_with_index do |order, i|
|
141
142
|
collector << COMMA if i != 0
|
142
143
|
collector = visit order, collector
|
143
144
|
end
|
144
145
|
else
|
145
146
|
collector = visit o.left, collector
|
146
147
|
end
|
147
|
-
collector <<
|
148
|
+
collector << '))'
|
148
149
|
collector
|
149
150
|
end
|
150
151
|
|
151
152
|
def visit_ArelExtensions_Nodes_Coalesce o, collector
|
152
|
-
collector <<
|
153
|
+
collector << 'COALESCE('
|
153
154
|
o.expressions.each_with_index { |arg, i|
|
154
155
|
collector << COMMA if i != 0
|
155
156
|
if i > 0 && o.left_node_type == :text
|
156
157
|
if arg == '' || (arg.is_a?(Arel::Nodes::Quoted) && (arg.expr == ''))
|
157
|
-
collector <<
|
158
|
+
collector << 'NULL'
|
158
159
|
else
|
159
160
|
collector << 'TO_CLOB('
|
160
161
|
collector = visit arg, collector
|
@@ -164,12 +165,12 @@ module ArelExtensions
|
|
164
165
|
collector = visit arg, collector
|
165
166
|
end
|
166
167
|
}
|
167
|
-
collector <<
|
168
|
+
collector << ')'
|
168
169
|
collector
|
169
170
|
end
|
170
171
|
|
171
172
|
def visit_ArelExtensions_Nodes_MD5 o, collector
|
172
|
-
collector <<
|
173
|
+
collector << 'LOWER (RAWTOHEX (DBMS_OBFUSCATION_TOOLKIT.md5(input => UTL_I18N.STRING_TO_RAW('
|
173
174
|
collector = visit o.left, collector
|
174
175
|
collector << ", 'AL32UTF8'))))"
|
175
176
|
collector
|
@@ -184,7 +185,7 @@ module ArelExtensions
|
|
184
185
|
collector << 'TO_DATE(' if lc
|
185
186
|
collector = visit o.left, collector
|
186
187
|
collector << ')' if lc
|
187
|
-
collector <<
|
188
|
+
collector << ' - '
|
188
189
|
collector << 'TO_DATE(' if rc
|
189
190
|
collector = visit o.right, collector
|
190
191
|
collector << ')' if rc
|
@@ -218,16 +219,16 @@ module ArelExtensions
|
|
218
219
|
def visit_ArelExtensions_Nodes_Duration o, collector
|
219
220
|
case o.left
|
220
221
|
when 'wd', 'w'
|
221
|
-
collector <<
|
222
|
+
collector << 'TO_CHAR('
|
222
223
|
collector = visit o.right, collector
|
223
224
|
collector << COMMA
|
224
|
-
collector = visit Arel
|
225
|
+
collector = visit Arel.quoted(DATE_MAPPING[o.left]), collector
|
225
226
|
else
|
226
227
|
right = case o.left
|
227
|
-
when 'd','m','y'
|
228
|
+
when 'd', 'm', 'y'
|
228
229
|
interval = 'DAY'
|
229
230
|
o.right.cast(:date)
|
230
|
-
when 'h','mn','s'
|
231
|
+
when 'h', 'mn', 's'
|
231
232
|
interval = 'SECOND'
|
232
233
|
o.right.cast(:datetime)
|
233
234
|
when /i\z/
|
@@ -243,7 +244,7 @@ module ArelExtensions
|
|
243
244
|
collector << "EXTRACT(#{DATE_MAPPING[o.left]} FROM "
|
244
245
|
collector = visit right, collector
|
245
246
|
end
|
246
|
-
collector <<
|
247
|
+
collector << ')'
|
247
248
|
collector << " * (INTERVAL '1' #{interval})" if interval && o.with_interval
|
248
249
|
collector
|
249
250
|
end
|
@@ -251,45 +252,45 @@ module ArelExtensions
|
|
251
252
|
def visit_ArelExtensions_Nodes_Cast o, collector
|
252
253
|
case o.as_attr
|
253
254
|
when :string
|
254
|
-
collector <<
|
255
|
+
collector << 'TO_CHAR('
|
255
256
|
collector = visit o.left, collector
|
256
|
-
collector <<
|
257
|
+
collector << ')'
|
257
258
|
return collector
|
258
259
|
when :text
|
259
|
-
collector <<
|
260
|
+
collector << 'TO_CLOB('
|
260
261
|
collector = visit o.left, collector
|
261
|
-
collector <<
|
262
|
+
collector << ')'
|
262
263
|
return collector
|
263
264
|
when :ntext
|
264
|
-
collector <<
|
265
|
+
collector << 'TO_NCLOB('
|
265
266
|
collector = visit o.left, collector
|
266
|
-
collector <<
|
267
|
+
collector << ')'
|
267
268
|
return collector
|
268
269
|
when :time
|
269
270
|
if (o.left.respond_to?(:return_type) && o.left.return_type == :string) || o.left.is_a?(Arel::Nodes::Quoted)
|
270
|
-
collector <<
|
271
|
+
collector << 'TO_DATE('
|
271
272
|
collector = visit o.left, collector
|
272
273
|
collector << ",'HH24:MI:SS')"
|
273
274
|
else
|
274
|
-
collector <<
|
275
|
+
collector << 'TO_DATE(TO_CHAR('
|
275
276
|
collector = visit o.left, collector
|
276
277
|
collector << ",'HH24:MI:SS'),'HH24:MI:SS')"
|
277
278
|
end
|
278
279
|
return collector
|
279
280
|
when :number, :decimal
|
280
|
-
collector <<
|
281
|
+
collector << 'TO_NUMBER('
|
281
282
|
collector = visit o.left, collector
|
282
|
-
collector <<
|
283
|
+
collector << ')'
|
283
284
|
return collector
|
284
285
|
when :datetime
|
285
286
|
as_attr = Arel::Nodes::SqlLiteral.new('timestamp')
|
286
287
|
when :date
|
287
288
|
if (o.left.respond_to?(:return_type) && o.left.return_type == :string) || o.left.is_a?(Arel::Nodes::Quoted)
|
288
|
-
collector <<
|
289
|
+
collector << 'TO_DATE('
|
289
290
|
collector = visit o.left, collector
|
290
291
|
collector << ",'YYYY-MM-DD')"
|
291
292
|
else
|
292
|
-
collector <<
|
293
|
+
collector << 'TO_DATE(TO_CHAR('
|
293
294
|
collector = visit o.left, collector
|
294
295
|
collector << ",'YYYY-MM-DD'),'YYYY-MM-DD')"
|
295
296
|
end
|
@@ -299,18 +300,18 @@ module ArelExtensions
|
|
299
300
|
else
|
300
301
|
as_attr = Arel::Nodes::SqlLiteral.new(o.as_attr.to_s)
|
301
302
|
end
|
302
|
-
collector <<
|
303
|
+
collector << 'CAST('
|
303
304
|
collector = visit o.left, collector
|
304
|
-
collector <<
|
305
|
+
collector << ' AS '
|
305
306
|
collector = visit as_attr, collector
|
306
|
-
collector <<
|
307
|
+
collector << ')'
|
307
308
|
collector
|
308
309
|
end
|
309
310
|
|
310
311
|
def visit_ArelExtensions_Nodes_Length o, collector
|
311
312
|
collector << "LENGTH#{o.bytewise ? 'B' : ''}("
|
312
313
|
collector = visit o.expr, collector
|
313
|
-
collector <<
|
314
|
+
collector << ')'
|
314
315
|
collector
|
315
316
|
end
|
316
317
|
|
@@ -327,18 +328,18 @@ module ArelExtensions
|
|
327
328
|
end
|
328
329
|
|
329
330
|
def visit_ArelExtensions_Nodes_Rand o, collector
|
330
|
-
collector <<
|
331
|
+
collector << 'DBMS_RANDOM.VALUE('
|
331
332
|
if o.left && o.right
|
332
333
|
collector = visit o.left, collector
|
333
334
|
collector << COMMA
|
334
335
|
collector = visit o.right, collector
|
335
336
|
end
|
336
|
-
collector <<
|
337
|
+
collector << ')'
|
337
338
|
collector
|
338
339
|
end
|
339
340
|
|
340
341
|
def visit_Arel_Nodes_Regexp o, collector
|
341
|
-
collector <<
|
342
|
+
collector << ' REGEXP_LIKE('
|
342
343
|
collector = visit o.left, collector
|
343
344
|
collector << COMMA
|
344
345
|
collector = visit o.right, collector
|
@@ -347,7 +348,7 @@ module ArelExtensions
|
|
347
348
|
end
|
348
349
|
|
349
350
|
def visit_Arel_Nodes_NotRegexp o, collector
|
350
|
-
collector <<
|
351
|
+
collector << ' NOT REGEXP_LIKE('
|
351
352
|
collector = visit o.left, collector
|
352
353
|
collector << COMMA
|
353
354
|
collector = visit o.right, collector
|
@@ -356,22 +357,22 @@ module ArelExtensions
|
|
356
357
|
end
|
357
358
|
|
358
359
|
def visit_ArelExtensions_Nodes_Locate o, collector
|
359
|
-
collector <<
|
360
|
+
collector << 'INSTR('
|
360
361
|
o.expressions.each_with_index { |arg, i|
|
361
362
|
collector << COMMA if i != 0
|
362
363
|
collector = visit arg, collector
|
363
364
|
}
|
364
|
-
collector <<
|
365
|
+
collector << ')'
|
365
366
|
collector
|
366
367
|
end
|
367
368
|
|
368
369
|
def visit_ArelExtensions_Nodes_Substring o, collector
|
369
|
-
collector <<
|
370
|
+
collector << 'SUBSTR('
|
370
371
|
o.expressions.each_with_index { |arg, i|
|
371
372
|
collector << COMMA if i != 0
|
372
373
|
collector = visit arg, collector
|
373
374
|
}
|
374
|
-
collector <<
|
375
|
+
collector << ')'
|
375
376
|
collector
|
376
377
|
end
|
377
378
|
|
@@ -390,14 +391,14 @@ module ArelExtensions
|
|
390
391
|
collector << COMMA
|
391
392
|
collector << 'COALESCE(dbms_lob.GETLENGTH('
|
392
393
|
collector = visit o.left, collector
|
393
|
-
collector <<
|
394
|
+
collector << '), 0)'
|
394
395
|
collector << COMMA
|
395
396
|
collector << '1)'
|
396
397
|
else
|
397
398
|
collector = visit o.left, collector
|
398
399
|
end
|
399
400
|
collector << ')' if o.left.is_a? ArelExtensions::Nodes::Trim
|
400
|
-
collector <<
|
401
|
+
collector << ')'
|
401
402
|
collector
|
402
403
|
end
|
403
404
|
|
@@ -410,7 +411,7 @@ module ArelExtensions
|
|
410
411
|
end
|
411
412
|
collector << ' FROM '
|
412
413
|
collector = visit o.left, collector
|
413
|
-
collector <<
|
414
|
+
collector << ')'
|
414
415
|
collector
|
415
416
|
end
|
416
417
|
|
@@ -423,7 +424,7 @@ module ArelExtensions
|
|
423
424
|
end
|
424
425
|
collector << ' FROM '
|
425
426
|
collector = visit o.left, collector
|
426
|
-
collector <<
|
427
|
+
collector << ')'
|
427
428
|
collector
|
428
429
|
end
|
429
430
|
|
@@ -446,46 +447,46 @@ module ArelExtensions
|
|
446
447
|
|
447
448
|
def visit_ArelExtensions_Nodes_Format o, collector
|
448
449
|
fmt = ArelExtensions::Visitors::strftime_to_format(o.iso_format, DATE_FORMAT_DIRECTIVES)
|
449
|
-
collector <<
|
450
|
-
collector <<
|
450
|
+
collector << 'TO_CHAR('
|
451
|
+
collector << 'CAST(' if o.time_zone
|
451
452
|
collector = visit o.left, collector
|
452
453
|
case o.time_zone
|
453
454
|
when Hash
|
454
455
|
src_tz, dst_tz = o.time_zone.first
|
455
456
|
collector << ' as timestamp) at time zone '
|
456
|
-
collector = visit Arel
|
457
|
-
|
458
|
-
collector = visit Arel
|
457
|
+
collector = visit Arel.quoted(src_tz), collector
|
458
|
+
collector < ' at time zone '
|
459
|
+
collector = visit Arel.quoted(dst_tz), collector
|
459
460
|
when String
|
460
461
|
collector << ' as timestamp) at time zone '
|
461
|
-
collector = visit Arel
|
462
|
+
collector = visit Arel.quoted(o.time_zone), collector
|
462
463
|
end
|
463
464
|
collector << COMMA
|
464
|
-
collector = visit Arel
|
465
|
-
collector <<
|
465
|
+
collector = visit Arel.quoted(fmt), collector
|
466
|
+
collector << ')'
|
466
467
|
collector
|
467
468
|
end
|
468
469
|
|
469
470
|
def visit_ArelExtensions_Nodes_Repeat o, collector
|
470
|
-
collector <<
|
471
|
+
collector << 'LPAD('
|
471
472
|
collector = visit o.expressions[0], collector # can't put empty string, otherwise it wouldn't work
|
472
473
|
collector << Arel::Visitors::ToSql::COMMA
|
473
474
|
collector = visit o.expressions[1], collector
|
474
475
|
collector << Arel::Visitors::ToSql::COMMA
|
475
476
|
collector = visit o.expressions[0], collector
|
476
|
-
collector <<
|
477
|
+
collector << ')'
|
477
478
|
collector
|
478
479
|
end
|
479
480
|
|
480
481
|
# add primary_key if not present, avoid zip
|
481
482
|
if Arel::VERSION.to_i < 7
|
482
483
|
def visit_ArelExtensions_InsertManager_BulkValues o, collector
|
483
|
-
collector <<
|
484
|
+
collector << '('
|
484
485
|
o.left.each_with_index do |row, idx| # values
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
486
|
+
collector << ' UNION ALL ' if idx != 0
|
487
|
+
collector << '(SELECT '
|
488
|
+
len = row.length - 1
|
489
|
+
row.zip(o.cols).each_with_index { |(value, attr), i|
|
489
490
|
case value
|
490
491
|
when Arel::Nodes::SqlLiteral, Arel::Nodes::BindParam
|
491
492
|
collector = visit value, collector
|
@@ -493,18 +494,18 @@ module ArelExtensions
|
|
493
494
|
collector << quote(value, attr && column_for(attr)).to_s
|
494
495
|
end
|
495
496
|
collector << COMMA unless i == len
|
496
|
-
|
497
|
-
|
497
|
+
}
|
498
|
+
collector << ' FROM DUAL)'
|
498
499
|
end
|
499
|
-
collector <<
|
500
|
+
collector << ')'
|
500
501
|
collector
|
501
502
|
end
|
502
503
|
else
|
503
504
|
def visit_ArelExtensions_InsertManager_BulkValues o, collector
|
504
|
-
collector <<
|
505
|
+
collector << '('
|
505
506
|
o.left.each_with_index do |row, idx|
|
506
|
-
collector <<
|
507
|
-
collector <<
|
507
|
+
collector << ' UNION ALL ' if idx != 0
|
508
|
+
collector << '(SELECT '
|
508
509
|
len = row.length - 1
|
509
510
|
row.zip(o.cols).each_with_index { |(value, attr), i|
|
510
511
|
case value
|
@@ -519,7 +520,7 @@ module ArelExtensions
|
|
519
520
|
}
|
520
521
|
collector << ' FROM DUAL)'
|
521
522
|
end
|
522
|
-
collector <<
|
523
|
+
collector << ')'
|
523
524
|
collector
|
524
525
|
end
|
525
526
|
end
|
@@ -529,7 +530,7 @@ module ArelExtensions
|
|
529
530
|
if element.is_a?(Time)
|
530
531
|
ArelExtensions::Nodes::Format.new [element, '%H:%M:%S']
|
531
532
|
elsif element.is_a?(Arel::Attributes::Attribute)
|
532
|
-
col =
|
533
|
+
col = Arel.column_of(element.relation.table_name, element.name.to_s)
|
533
534
|
if col && (col.type == :time)
|
534
535
|
ArelExtensions::Nodes::Format.new [element, '%H:%M:%S']
|
535
536
|
else
|
@@ -544,7 +545,7 @@ module ArelExtensions
|
|
544
545
|
remove_method(:visit_Arel_Nodes_GreaterThanOrEqual) rescue nil
|
545
546
|
def visit_Arel_Nodes_GreaterThanOrEqual o, collector
|
546
547
|
collector = visit get_time_converted(o.left), collector
|
547
|
-
collector <<
|
548
|
+
collector << ' >= '
|
548
549
|
collector = visit get_time_converted(o.right), collector
|
549
550
|
collector
|
550
551
|
end
|
@@ -552,7 +553,7 @@ module ArelExtensions
|
|
552
553
|
remove_method(:visit_Arel_Nodes_GreaterThan) rescue nil
|
553
554
|
def visit_Arel_Nodes_GreaterThan o, collector
|
554
555
|
collector = visit get_time_converted(o.left), collector
|
555
|
-
collector <<
|
556
|
+
collector << ' > '
|
556
557
|
collector = visit get_time_converted(o.right), collector
|
557
558
|
collector
|
558
559
|
end
|
@@ -560,7 +561,7 @@ module ArelExtensions
|
|
560
561
|
remove_method(:visit_Arel_Nodes_LessThanOrEqual) rescue nil
|
561
562
|
def visit_Arel_Nodes_LessThanOrEqual o, collector
|
562
563
|
collector = visit get_time_converted(o.left), collector
|
563
|
-
collector <<
|
564
|
+
collector << ' <= '
|
564
565
|
collector = visit get_time_converted(o.right), collector
|
565
566
|
collector
|
566
567
|
end
|
@@ -568,7 +569,7 @@ module ArelExtensions
|
|
568
569
|
remove_method(:visit_Arel_Nodes_LessThan) rescue nil
|
569
570
|
def visit_Arel_Nodes_LessThan o, collector
|
570
571
|
collector = visit get_time_converted(o.left), collector
|
571
|
-
collector <<
|
572
|
+
collector << ' < '
|
572
573
|
collector = visit get_time_converted(o.right), collector
|
573
574
|
collector
|
574
575
|
end
|
@@ -580,15 +581,15 @@ module ArelExtensions
|
|
580
581
|
o = o.dup
|
581
582
|
o.orders = []
|
582
583
|
end
|
583
|
-
old_visit_Arel_Nodes_SelectStatement(o,collector)
|
584
|
+
old_visit_Arel_Nodes_SelectStatement(o, collector)
|
584
585
|
end
|
585
586
|
|
586
587
|
alias_method(:old_visit_Arel_Nodes_TableAlias, :visit_Arel_Nodes_TableAlias) rescue nil
|
587
588
|
def visit_Arel_Nodes_TableAlias o, collector
|
588
589
|
if o.name.length > 30
|
589
|
-
o = Arel::Table.new(o.table_name).alias(
|
590
|
+
o = Arel::Table.new(o.table_name).alias(Arel.shorten(o.name))
|
590
591
|
end
|
591
|
-
old_visit_Arel_Nodes_TableAlias(o,collector)
|
592
|
+
old_visit_Arel_Nodes_TableAlias(o, collector)
|
592
593
|
end
|
593
594
|
|
594
595
|
alias_method(:old_visit_Arel_Nodes_As, :visit_Arel_Nodes_As) rescue nil
|
@@ -600,7 +601,7 @@ module ArelExtensions
|
|
600
601
|
else
|
601
602
|
collector = visit o.left, collector
|
602
603
|
end
|
603
|
-
quote =
|
604
|
+
quote = /(\A".*"\z)|\A[a-zA-Z_]*\z/.match?(o.right.to_s) ? '' : '"'
|
604
605
|
collector << " AS #{quote}"
|
605
606
|
collector = visit o.right, collector
|
606
607
|
collector << "#{quote}"
|
@@ -624,47 +625,52 @@ module ArelExtensions
|
|
624
625
|
col = o.left.coalesce(0)
|
625
626
|
comma = NUMBER_COMMA_MAPPING[o.locale] || '.,'
|
626
627
|
comma_in_format = o.precision == 0 ? '' : 'D'
|
627
|
-
nines_after = (1..o.precision-1).map{'9'}.join('')+'0'
|
628
|
+
nines_after = (1..o.precision - 1).map{'9'}.join('') + '0'
|
628
629
|
if comma.length == 1
|
629
|
-
options = Arel
|
630
|
-
nines_before = (
|
630
|
+
options = Arel.quoted("NLS_NUMERIC_CHARACTERS = '#{comma} '")
|
631
|
+
nines_before = ('999' * 4 + '990')
|
631
632
|
else
|
632
|
-
options = Arel
|
633
|
-
nines_before = (
|
633
|
+
options = Arel.quoted("NLS_NUMERIC_CHARACTERS = '#{comma}'")
|
634
|
+
nines_before = ('999G' * 4 + '990')
|
634
635
|
end
|
635
|
-
sign =
|
636
|
+
sign = Arel.when(col < 0).
|
636
637
|
then('-').
|
637
638
|
else(o.flags.include?('+') ? '+' : (o.flags.include?(' ') ? ' ' : ''))
|
638
639
|
sign_length = o.flags.include?('+') || o.flags.include?(' ') ?
|
639
|
-
Arel
|
640
|
-
|
640
|
+
Arel.quoted(1) :
|
641
|
+
Arel.when(col < 0).then(1).else(0)
|
641
642
|
|
642
643
|
if o.scientific_notation
|
643
|
-
number = Arel::Nodes::NamedFunction.new('TO_CHAR',[
|
644
|
-
Arel
|
645
|
-
Arel
|
644
|
+
number = Arel::Nodes::NamedFunction.new('TO_CHAR', [
|
645
|
+
Arel.quoted(col.abs),
|
646
|
+
Arel.quoted("FM#{nines_before}#{comma_in_format}#{nines_after}EEEE"),
|
646
647
|
options
|
647
648
|
])
|
648
649
|
if o.type == 'e'
|
649
|
-
number = number.replace('E','e')
|
650
|
+
number = number.replace('E', 'e')
|
650
651
|
end
|
651
652
|
else
|
652
|
-
number = Arel::Nodes::NamedFunction.new('TO_CHAR',[
|
653
|
-
Arel
|
654
|
-
Arel
|
653
|
+
number = Arel::Nodes::NamedFunction.new('TO_CHAR', [
|
654
|
+
Arel.quoted(col.abs),
|
655
|
+
Arel.quoted("FM#{nines_before}#{comma_in_format}#{nines_after}"),
|
655
656
|
options
|
656
657
|
])
|
657
658
|
end
|
658
659
|
|
659
|
-
repeated_char =
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
660
|
+
repeated_char =
|
661
|
+
if o.width == 0
|
662
|
+
Arel.quoted('')
|
663
|
+
else
|
664
|
+
Arel
|
665
|
+
.when(Arel.quoted(o.width).abs - (number.length + sign_length) > 0)
|
666
|
+
.then(Arel.quoted(
|
667
|
+
o.flags.include?('-') ? ' ' : (o.flags.include?('0') ? '0' : ' ')
|
668
|
+
).repeat(Arel.quoted(o.width).abs - (number.length + sign_length))
|
669
|
+
)
|
670
|
+
.else('')
|
671
|
+
end
|
672
|
+
before = !o.flags.include?('0') && !o.flags.include?('-') ? repeated_char : ''
|
673
|
+
middle = o.flags.include?('0') && !o.flags.include?('-') ? repeated_char : ''
|
668
674
|
after = o.flags.include?('-') ? repeated_char : ''
|
669
675
|
full_number = ArelExtensions::Nodes::Concat.new([
|
670
676
|
before,
|
@@ -673,26 +679,26 @@ module ArelExtensions
|
|
673
679
|
number,
|
674
680
|
after
|
675
681
|
])
|
676
|
-
collector = visit ArelExtensions::Nodes::Concat.new([Arel
|
682
|
+
collector = visit ArelExtensions::Nodes::Concat.new([Arel.quoted(o.prefix), full_number, Arel.quoted(o.suffix)]), collector
|
677
683
|
collector
|
678
684
|
end
|
679
685
|
|
680
686
|
def visit_ArelExtensions_Nodes_Std o, collector
|
681
|
-
collector << (o.unbiased_estimator ?
|
687
|
+
collector << (o.unbiased_estimator ? 'STDDEV_SAMP(' : 'STDDEV_POP(')
|
682
688
|
visit o.left, collector
|
683
|
-
collector <<
|
689
|
+
collector << ')'
|
684
690
|
collector
|
685
691
|
end
|
686
692
|
|
687
693
|
def visit_ArelExtensions_Nodes_Variance o, collector
|
688
|
-
collector << (o.unbiased_estimator ?
|
694
|
+
collector << (o.unbiased_estimator ? 'VAR_SAMP(' : 'VAR_POP(')
|
689
695
|
visit o.left, collector
|
690
|
-
collector <<
|
696
|
+
collector << ')'
|
691
697
|
collector
|
692
698
|
end
|
693
699
|
|
694
700
|
def visit_ArelExtensions_Nodes_LevenshteinDistance o, collector
|
695
|
-
collector <<
|
701
|
+
collector << 'UTL_MATCH.edit_distance('
|
696
702
|
collector = visit o.left, collector
|
697
703
|
collector << Arel::Visitors::ToSql::COMMA
|
698
704
|
collector = visit o.right, collector
|