arel_extensions 1.2.25 → 2.0.0.rc3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -7
- data/.travis.yml +91 -61
- data/Gemfile +20 -15
- data/README.md +12 -17
- data/Rakefile +29 -40
- data/appveyor.yml +1 -1
- data/arel_extensions.gemspec +3 -3
- data/functions.html +3 -3
- data/gemfiles/rails3.gemfile +9 -9
- data/gemfiles/rails4.gemfile +13 -13
- data/gemfiles/rails5_0.gemfile +13 -13
- data/gemfiles/rails5_1_4.gemfile +13 -13
- data/gemfiles/rails5_2.gemfile +13 -13
- data/init/mssql.sql +4 -4
- data/init/mysql.sql +38 -38
- data/init/postgresql.sql +21 -21
- data/lib/arel_extensions/attributes.rb +1 -0
- data/lib/arel_extensions/boolean_functions.rb +14 -55
- data/lib/arel_extensions/common_sql_functions.rb +8 -7
- data/lib/arel_extensions/comparators.rb +15 -14
- data/lib/arel_extensions/date_duration.rb +5 -4
- data/lib/arel_extensions/insert_manager.rb +16 -17
- data/lib/arel_extensions/math.rb +12 -11
- data/lib/arel_extensions/math_functions.rb +22 -29
- data/lib/arel_extensions/nodes/abs.rb +1 -0
- data/lib/arel_extensions/nodes/blank.rb +1 -0
- data/lib/arel_extensions/nodes/case.rb +8 -11
- data/lib/arel_extensions/nodes/cast.rb +2 -4
- data/lib/arel_extensions/nodes/ceil.rb +1 -1
- data/lib/arel_extensions/nodes/change_case.rb +0 -0
- data/lib/arel_extensions/nodes/coalesce.rb +3 -2
- data/lib/arel_extensions/nodes/collate.rb +2 -1
- data/lib/arel_extensions/nodes/concat.rb +16 -7
- data/lib/arel_extensions/nodes/date_diff.rb +13 -10
- data/lib/arel_extensions/nodes/duration.rb +3 -0
- data/lib/arel_extensions/nodes/find_in_set.rb +1 -0
- data/lib/arel_extensions/nodes/floor.rb +1 -1
- data/lib/arel_extensions/nodes/format.rb +8 -34
- data/lib/arel_extensions/nodes/formatted_number.rb +23 -22
- data/lib/arel_extensions/nodes/function.rb +16 -25
- data/lib/arel_extensions/nodes/json.rb +36 -43
- data/lib/arel_extensions/nodes/length.rb +0 -5
- data/lib/arel_extensions/nodes/levenshtein_distance.rb +0 -0
- data/lib/arel_extensions/nodes/locate.rb +1 -0
- data/lib/arel_extensions/nodes/log10.rb +2 -1
- data/lib/arel_extensions/nodes/matches.rb +6 -4
- data/lib/arel_extensions/nodes/md5.rb +1 -0
- data/lib/arel_extensions/nodes/power.rb +5 -5
- data/lib/arel_extensions/nodes/rand.rb +1 -0
- data/lib/arel_extensions/nodes/repeat.rb +4 -2
- data/lib/arel_extensions/nodes/replace.rb +6 -22
- data/lib/arel_extensions/nodes/round.rb +6 -5
- data/lib/arel_extensions/nodes/soundex.rb +15 -15
- data/lib/arel_extensions/nodes/std.rb +21 -18
- data/lib/arel_extensions/nodes/substring.rb +16 -8
- data/lib/arel_extensions/nodes/then.rb +0 -0
- data/lib/arel_extensions/nodes/trim.rb +5 -3
- data/lib/arel_extensions/nodes/union.rb +5 -2
- data/lib/arel_extensions/nodes/union_all.rb +3 -0
- data/lib/arel_extensions/nodes/wday.rb +4 -0
- data/lib/arel_extensions/nodes.rb +1 -1
- data/lib/arel_extensions/null_functions.rb +7 -5
- data/lib/arel_extensions/predications.rb +34 -35
- data/lib/arel_extensions/railtie.rb +5 -5
- data/lib/arel_extensions/set_functions.rb +4 -2
- data/lib/arel_extensions/string_functions.rb +23 -52
- data/lib/arel_extensions/tasks.rb +5 -5
- data/lib/arel_extensions/version.rb +1 -1
- data/lib/arel_extensions/visitors/ibm_db.rb +12 -5
- data/lib/arel_extensions/visitors/mssql.rb +58 -64
- data/lib/arel_extensions/visitors/mysql.rb +98 -149
- data/lib/arel_extensions/visitors/oracle.rb +70 -73
- data/lib/arel_extensions/visitors/oracle12.rb +15 -2
- data/lib/arel_extensions/visitors/postgresql.rb +63 -116
- data/lib/arel_extensions/visitors/sqlite.rb +70 -83
- data/lib/arel_extensions/visitors/to_sql.rb +110 -142
- data/lib/arel_extensions/visitors.rb +60 -68
- data/lib/arel_extensions.rb +19 -81
- data/test/database.yml +0 -2
- data/test/helper.rb +18 -0
- data/test/real_db_test.rb +43 -28
- data/test/support/fake_record.rb +2 -2
- data/test/test_comparators.rb +12 -9
- data/test/visitors/test_bulk_insert_oracle.rb +8 -8
- data/test/visitors/test_bulk_insert_sqlite.rb +10 -9
- data/test/visitors/test_bulk_insert_to_sql.rb +10 -8
- data/test/visitors/test_oracle.rb +42 -42
- data/test/visitors/test_to_sql.rb +196 -361
- data/test/with_ar/all_agnostic_test.rb +160 -195
- data/test/with_ar/insert_agnostic_test.rb +4 -3
- data/test/with_ar/test_bulk_sqlite.rb +9 -6
- data/test/with_ar/test_math_sqlite.rb +12 -8
- data/test/with_ar/test_string_mysql.rb +11 -5
- data/test/with_ar/test_string_sqlite.rb +12 -4
- metadata +11 -22
- data/.github/workflows/ruby.yml +0 -102
- data/gemfiles/rails6.gemfile +0 -30
- data/gemfiles/rails6_1.gemfile +0 -30
- data/gemspecs/arel_extensions-v1.gemspec +0 -28
- data/gemspecs/arel_extensions-v2.gemspec +0 -28
- data/generate_gems.sh +0 -15
- data/lib/arel_extensions/nodes/aggregate_function.rb +0 -13
- data/lib/arel_extensions/nodes/sum.rb +0 -7
- data/lib/arel_extensions/visitors/convert_format.rb +0 -37
- data/test/arelx_test_helper.rb +0 -26
- data/version_v1.rb +0 -3
- data/version_v2.rb +0 -3
@@ -1,21 +1,22 @@
|
|
1
|
-
#
|
1
|
+
#require 'oracle_visitor'
|
2
2
|
module ArelExtensions
|
3
3
|
module Visitors
|
4
|
-
|
4
|
+
Arel::Visitors::Oracle.class_eval do
|
5
|
+
|
5
6
|
SPECIAL_CHARS = {"\t" => 'CHR(9)', "\n" => 'CHR(10)', "\r" => 'CHR(13)'}
|
6
|
-
DATE_MAPPING = {'d' => 'DAY', 'm' => 'MONTH', 'w' => 'IW', 'y' => 'YEAR', 'wd' => 'D', 'h' => 'HOUR', 'mn' => 'MINUTE', 's' => 'SECOND'}
|
7
|
-
DATE_FORMAT_DIRECTIVES = {
|
8
|
-
'%Y' => '
|
7
|
+
Arel::Visitors::Oracle::DATE_MAPPING = {'d' => 'DAY', 'm' => 'MONTH', 'w' => 'IW', 'y' => 'YEAR', 'wd' => 'D', 'h' => 'HOUR', 'mn' => 'MINUTE', 's' => 'SECOND'}
|
8
|
+
Arel::Visitors::Oracle::DATE_FORMAT_DIRECTIVES = {
|
9
|
+
'%Y' => 'IYYY', '%C' => 'CC', '%y' => 'YY', '%m' => 'MM', '%B' => 'Month', '%^B' => 'MONTH', '%b' => 'Mon', '%^b' => 'MON',
|
9
10
|
'%d' => 'DD', '%e' => 'FMDD', '%j' => 'DDD', '%w' => '', '%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 = { 'en_US' => '.,', 'fr_FR' => ',', 'sv_SE' => ', ' }
|
14
|
+
Arel::Visitors::Oracle::NUMBER_COMMA_MAPPING = { 'en_US' => '.,', 'fr_FR' => ',', 'sv_SE' => ', ' }
|
14
15
|
|
15
16
|
def visit_ArelExtensions_Nodes_Log10 o, collector
|
16
17
|
collector << "LOG("
|
17
18
|
o.expressions.each_with_index { |arg, i|
|
18
|
-
collector << Arel::Visitors::ToSql::COMMA
|
19
|
+
collector << Arel::Visitors::ToSql::COMMA unless i == 0
|
19
20
|
collector = visit arg, collector
|
20
21
|
}
|
21
22
|
collector << ",10)"
|
@@ -25,7 +26,7 @@ module ArelExtensions
|
|
25
26
|
def visit_ArelExtensions_Nodes_Power o, collector
|
26
27
|
collector << "POWER("
|
27
28
|
o.expressions.each_with_index { |arg, i|
|
28
|
-
collector << Arel::Visitors::ToSql::COMMA
|
29
|
+
collector << Arel::Visitors::ToSql::COMMA unless i == 0
|
29
30
|
collector = visit arg, collector
|
30
31
|
}
|
31
32
|
collector << ")"
|
@@ -92,6 +93,7 @@ module ArelExtensions
|
|
92
93
|
end
|
93
94
|
end
|
94
95
|
|
96
|
+
|
95
97
|
def visit_ArelExtensions_Nodes_IDoesNotMatch o, collector
|
96
98
|
collector << 'LOWER('
|
97
99
|
collector = visit o.left, collector
|
@@ -110,35 +112,34 @@ module ArelExtensions
|
|
110
112
|
if o.ai
|
111
113
|
collector << "NLSSORT("
|
112
114
|
collector = visit o.expressions.first, collector
|
113
|
-
collector << COMMA
|
115
|
+
collector << Arel::Visitors::Oracle::COMMA
|
114
116
|
collector << "'NLS_SORT = BINARY_AI NLS_COMP = LINGUISTIC'"
|
115
117
|
collector << ")"
|
116
118
|
elsif o.ci
|
117
119
|
collector << "NLSSORT("
|
118
120
|
collector = visit o.expressions.first, collector
|
119
|
-
collector << COMMA
|
121
|
+
collector << Arel::Visitors::Oracle::COMMA
|
120
122
|
collector << "'NLS_SORT = BINARY_CI NLS_COMP = LINGUISTIC'"
|
121
123
|
collector << ")"
|
122
124
|
else
|
123
125
|
collector = visit o.expressions.first, collector
|
124
126
|
end
|
125
|
-
|
127
|
+
collector
|
126
128
|
end
|
127
129
|
|
128
130
|
def visit_ArelExtensions_Nodes_GroupConcat o, collector
|
129
131
|
collector << "(LISTAGG("
|
130
132
|
collector = visit o.left, collector
|
131
|
-
collector << COMMA
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
end
|
133
|
+
collector << Arel::Visitors::Oracle::COMMA
|
134
|
+
if o.right && o.right != 'NULL'
|
135
|
+
collector = visit o.right, collector
|
136
|
+
else
|
137
|
+
collector = visit Arel::Nodes.build_quoted(','), collector
|
138
|
+
end
|
138
139
|
collector << ") WITHIN GROUP (ORDER BY "
|
139
|
-
if !o.
|
140
|
-
o.
|
141
|
-
collector << COMMA
|
140
|
+
if !o.orders.blank?
|
141
|
+
o.orders.each_with_index do |order,i|
|
142
|
+
collector << Arel::Visitors::Oracle::COMMA unless i == 0
|
142
143
|
collector = visit order, collector
|
143
144
|
end
|
144
145
|
else
|
@@ -151,9 +152,9 @@ module ArelExtensions
|
|
151
152
|
def visit_ArelExtensions_Nodes_Coalesce o, collector
|
152
153
|
collector << "COALESCE("
|
153
154
|
o.expressions.each_with_index { |arg, i|
|
154
|
-
collector << COMMA
|
155
|
+
collector << Arel::Visitors::Oracle::COMMA unless i == 0
|
155
156
|
if i > 0 && o.left_node_type == :text
|
156
|
-
if arg == ''
|
157
|
+
if arg == '' || (arg.is_a?(Arel::Nodes::Quoted) && (arg.expr == ''))
|
157
158
|
collector << "NULL"
|
158
159
|
else
|
159
160
|
collector << 'TO_CLOB('
|
@@ -194,7 +195,7 @@ module ArelExtensions
|
|
194
195
|
collector << 'TO_DATE(' if lc
|
195
196
|
collector = visit o.left, collector
|
196
197
|
collector << ')' if lc
|
197
|
-
collector << COMMA
|
198
|
+
collector << Arel::Visitors::Oracle::COMMA
|
198
199
|
collector << "'DDD') = "
|
199
200
|
collector << 'TO_DATE(' if lc
|
200
201
|
collector = visit o.left, collector
|
@@ -220,8 +221,8 @@ module ArelExtensions
|
|
220
221
|
when 'wd', 'w'
|
221
222
|
collector << "TO_CHAR("
|
222
223
|
collector = visit o.right, collector
|
223
|
-
collector << COMMA
|
224
|
-
collector = visit Arel::Nodes.build_quoted(DATE_MAPPING[o.left]), collector
|
224
|
+
collector << Arel::Visitors::Oracle::COMMA
|
225
|
+
collector = visit Arel::Nodes.build_quoted(Arel::Visitors::Oracle::DATE_MAPPING[o.left]), collector
|
225
226
|
else
|
226
227
|
right = case o.left
|
227
228
|
when 'd','m','y'
|
@@ -231,7 +232,7 @@ module ArelExtensions
|
|
231
232
|
interval = 'SECOND'
|
232
233
|
o.right.cast(:datetime)
|
233
234
|
when /i\z/
|
234
|
-
interval = DATE_MAPPING[o.left[0..-2]]
|
235
|
+
interval = Arel::Visitors::Oracle::DATE_MAPPING[o.left[0..-2]]
|
235
236
|
collector << '('
|
236
237
|
collector = visit o.right, collector
|
237
238
|
collector << ") * (INTERVAL '1' #{interval})"
|
@@ -240,7 +241,7 @@ module ArelExtensions
|
|
240
241
|
interval = nil
|
241
242
|
o.right
|
242
243
|
end
|
243
|
-
collector << "EXTRACT(#{DATE_MAPPING[o.left]} FROM "
|
244
|
+
collector << "EXTRACT(#{Arel::Visitors::Oracle::DATE_MAPPING[o.left]} FROM "
|
244
245
|
collector = visit right, collector
|
245
246
|
end
|
246
247
|
collector << ")"
|
@@ -255,16 +256,6 @@ module ArelExtensions
|
|
255
256
|
collector = visit o.left, collector
|
256
257
|
collector << ")"
|
257
258
|
return collector
|
258
|
-
when :text
|
259
|
-
collector << "TO_CLOB("
|
260
|
-
collector = visit o.left, collector
|
261
|
-
collector << ")"
|
262
|
-
return collector
|
263
|
-
when :ntext
|
264
|
-
collector << "TO_NCLOB("
|
265
|
-
collector = visit o.left, collector
|
266
|
-
collector << ")"
|
267
|
-
return collector
|
268
259
|
when :time
|
269
260
|
if (o.left.respond_to?(:return_type) && o.left.return_type == :string) || o.left.is_a?(Arel::Nodes::Quoted)
|
270
261
|
collector << "TO_DATE("
|
@@ -308,7 +299,7 @@ module ArelExtensions
|
|
308
299
|
end
|
309
300
|
|
310
301
|
def visit_ArelExtensions_Nodes_Length o, collector
|
311
|
-
collector << "LENGTH
|
302
|
+
collector << "LENGTH("
|
312
303
|
collector = visit o.expr, collector
|
313
304
|
collector << ")"
|
314
305
|
collector
|
@@ -330,7 +321,7 @@ module ArelExtensions
|
|
330
321
|
collector << "DBMS_RANDOM.VALUE("
|
331
322
|
if o.left && o.right
|
332
323
|
collector = visit o.left, collector
|
333
|
-
collector << COMMA
|
324
|
+
collector << Arel::Visitors::Oracle::COMMA
|
334
325
|
collector = visit o.right, collector
|
335
326
|
end
|
336
327
|
collector << ")"
|
@@ -340,7 +331,7 @@ module ArelExtensions
|
|
340
331
|
def visit_Arel_Nodes_Regexp o, collector
|
341
332
|
collector << " REGEXP_LIKE("
|
342
333
|
collector = visit o.left, collector
|
343
|
-
collector << COMMA
|
334
|
+
collector << Arel::Visitors::Oracle::COMMA
|
344
335
|
collector = visit o.right, collector
|
345
336
|
collector << ')'
|
346
337
|
collector
|
@@ -349,7 +340,7 @@ module ArelExtensions
|
|
349
340
|
def visit_Arel_Nodes_NotRegexp o, collector
|
350
341
|
collector << " NOT REGEXP_LIKE("
|
351
342
|
collector = visit o.left, collector
|
352
|
-
collector << COMMA
|
343
|
+
collector << Arel::Visitors::Oracle::COMMA
|
353
344
|
collector = visit o.right, collector
|
354
345
|
collector << ')'
|
355
346
|
collector
|
@@ -358,7 +349,7 @@ module ArelExtensions
|
|
358
349
|
def visit_ArelExtensions_Nodes_Locate o, collector
|
359
350
|
collector << "INSTR("
|
360
351
|
o.expressions.each_with_index { |arg, i|
|
361
|
-
collector << COMMA
|
352
|
+
collector << Arel::Visitors::Oracle::COMMA unless i == 0
|
362
353
|
collector = visit arg, collector
|
363
354
|
}
|
364
355
|
collector << ")"
|
@@ -368,7 +359,7 @@ module ArelExtensions
|
|
368
359
|
def visit_ArelExtensions_Nodes_Substring o, collector
|
369
360
|
collector << "SUBSTR("
|
370
361
|
o.expressions.each_with_index { |arg, i|
|
371
|
-
collector << COMMA
|
362
|
+
collector << Arel::Visitors::Oracle::COMMA unless i == 0
|
372
363
|
collector = visit arg, collector
|
373
364
|
}
|
374
365
|
collector << ")"
|
@@ -387,11 +378,11 @@ module ArelExtensions
|
|
387
378
|
if o.type_of_attribute(o.left) == :text
|
388
379
|
collector << 'dbms_lob.SUBSTR('
|
389
380
|
collector = visit o.left, collector
|
390
|
-
collector << COMMA
|
381
|
+
collector << Arel::Visitors::Oracle::COMMA
|
391
382
|
collector << 'COALESCE(dbms_lob.GETLENGTH('
|
392
383
|
collector = visit o.left, collector
|
393
384
|
collector << "), 0)"
|
394
|
-
collector << COMMA
|
385
|
+
collector << Arel::Visitors::Oracle::COMMA
|
395
386
|
collector << '1)'
|
396
387
|
else
|
397
388
|
collector = visit o.left, collector
|
@@ -438,25 +429,28 @@ module ArelExtensions
|
|
438
429
|
def visit_ArelExtensions_Nodes_DateAdd o, collector
|
439
430
|
collector << '('
|
440
431
|
collector = visit o.left, collector
|
441
|
-
collector << ' + '
|
432
|
+
collector << ' + '# (o.right.value >= 0 ? ' + ' : ' - ')
|
442
433
|
collector = visit o.oracle_value(o.right), collector
|
443
434
|
collector << ')'
|
444
435
|
collector
|
445
436
|
end
|
446
437
|
|
447
438
|
def visit_ArelExtensions_Nodes_Format o, collector
|
448
|
-
fmt = ArelExtensions::Visitors::strftime_to_format(o.iso_format, DATE_FORMAT_DIRECTIVES)
|
449
439
|
collector << "TO_CHAR("
|
450
440
|
collector = visit o.left, collector
|
451
|
-
collector << COMMA
|
452
|
-
|
441
|
+
collector << Arel::Visitors::Oracle::COMMA
|
442
|
+
|
443
|
+
f = o.iso_format.gsub(/\ (\w+)/, ' "\1"')
|
444
|
+
Arel::Visitors::Oracle::DATE_FORMAT_DIRECTIVES.each { |d, r| f.gsub!(d, r) }
|
445
|
+
collector = visit Arel::Nodes.build_quoted(f), collector
|
446
|
+
|
453
447
|
collector << ")"
|
454
448
|
collector
|
455
449
|
end
|
456
450
|
|
457
451
|
def visit_ArelExtensions_Nodes_Repeat o, collector
|
458
452
|
collector << "LPAD("
|
459
|
-
collector = visit o.expressions[0], collector #
|
453
|
+
collector = visit o.expressions[0], collector #can't put empty string, otherwise it wouldn't work
|
460
454
|
collector << Arel::Visitors::ToSql::COMMA
|
461
455
|
collector = visit o.expressions[1], collector
|
462
456
|
collector << Arel::Visitors::ToSql::COMMA
|
@@ -465,24 +459,26 @@ module ArelExtensions
|
|
465
459
|
collector
|
466
460
|
end
|
467
461
|
|
468
|
-
|
462
|
+
# add primary_key if not present, avoid zip
|
469
463
|
if Arel::VERSION.to_i < 7
|
470
464
|
def visit_ArelExtensions_InsertManager_BulkValues o, collector
|
471
465
|
collector << "("
|
472
466
|
o.left.each_with_index do |row, idx| # values
|
473
467
|
collector << " UNION ALL " if idx != 0
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
468
|
+
collector << "(SELECT "
|
469
|
+
v = Arel::Nodes::Values.new(row, o.cols)
|
470
|
+
len = v.expressions.length - 1
|
471
|
+
v.expressions.each_with_index { |value, i|
|
472
|
+
case value
|
473
|
+
when Arel::Nodes::SqlLiteral, Arel::Nodes::BindParam
|
474
|
+
collector = visit value, collector
|
475
|
+
else
|
476
|
+
attr = v.columns[i]
|
477
|
+
collector << quote(value, attr && column_for(attr)).to_s
|
478
|
+
end
|
479
|
+
collector << Arel::Visitors::Oracle::COMMA unless i == len
|
480
|
+
}
|
481
|
+
collector << ' FROM DUAL)'
|
486
482
|
end
|
487
483
|
collector << ")"
|
488
484
|
collector
|
@@ -494,16 +490,15 @@ module ArelExtensions
|
|
494
490
|
collector << " UNION ALL " if idx != 0
|
495
491
|
collector << "(SELECT "
|
496
492
|
len = row.length - 1
|
497
|
-
row.
|
493
|
+
row.each_with_index { |value, i|
|
494
|
+
attr = o.cols[i]
|
498
495
|
case value
|
499
496
|
when Arel::Nodes::SqlLiteral, Arel::Nodes::BindParam
|
500
497
|
collector = visit value, collector
|
501
|
-
when Integer
|
502
|
-
collector << value.to_s
|
503
498
|
else
|
504
499
|
collector << (attr && attr.able_to_type_cast? ? quote(attr.type_cast_for_database(value)) : quote(value).to_s)
|
505
500
|
end
|
506
|
-
collector << COMMA unless i == len
|
501
|
+
collector << Arel::Visitors::Oracle::COMMA unless i == len
|
507
502
|
}
|
508
503
|
collector << ' FROM DUAL)'
|
509
504
|
end
|
@@ -562,7 +557,7 @@ module ArelExtensions
|
|
562
557
|
end
|
563
558
|
|
564
559
|
|
565
|
-
alias_method
|
560
|
+
alias_method :old_visit_Arel_Nodes_SelectStatement, :visit_Arel_Nodes_SelectStatement
|
566
561
|
def visit_Arel_Nodes_SelectStatement o, collector
|
567
562
|
if !(collector.value.blank? || (collector.value.is_a?(Array) && collector.value[0].blank?)) && o.limit.blank? && o.offset.blank?
|
568
563
|
o = o.dup
|
@@ -571,7 +566,7 @@ module ArelExtensions
|
|
571
566
|
old_visit_Arel_Nodes_SelectStatement(o,collector)
|
572
567
|
end
|
573
568
|
|
574
|
-
alias_method
|
569
|
+
alias_method :old_visit_Arel_Nodes_TableAlias, :visit_Arel_Nodes_TableAlias
|
575
570
|
def visit_Arel_Nodes_TableAlias o, collector
|
576
571
|
if o.name.length > 30
|
577
572
|
o = Arel::Table.new(o.table_name).alias(Base64.urlsafe_encode64(Digest::MD5.new.digest(o.name)).tr('=', '').tr('-', '_'))
|
@@ -579,7 +574,7 @@ module ArelExtensions
|
|
579
574
|
old_visit_Arel_Nodes_TableAlias(o,collector)
|
580
575
|
end
|
581
576
|
|
582
|
-
alias_method
|
577
|
+
alias_method :old_visit_Arel_Nodes_As, :visit_Arel_Nodes_As
|
583
578
|
def visit_Arel_Nodes_As o, collector
|
584
579
|
if o.left.is_a?(Arel::Nodes::Binary)
|
585
580
|
collector << '('
|
@@ -599,7 +594,7 @@ module ArelExtensions
|
|
599
594
|
visit_Arel_Nodes_As o, collector
|
600
595
|
end
|
601
596
|
|
602
|
-
alias_method
|
597
|
+
alias_method :old_visit_Arel_Attributes_Attribute, :visit_Arel_Attributes_Attribute
|
603
598
|
def visit_Arel_Attributes_Attribute o, collector
|
604
599
|
join_name = o.relation.table_alias || o.relation.name
|
605
600
|
if join_name.length > 30
|
@@ -608,9 +603,10 @@ module ArelExtensions
|
|
608
603
|
collector << "#{quote_table_name join_name}.#{quote_column_name o.name}"
|
609
604
|
end
|
610
605
|
|
606
|
+
|
611
607
|
def visit_ArelExtensions_Nodes_FormattedNumber o, collector
|
612
608
|
col = o.left.coalesce(0)
|
613
|
-
comma = NUMBER_COMMA_MAPPING[o.locale] || '.,'
|
609
|
+
comma = Arel::Visitors::Oracle::NUMBER_COMMA_MAPPING[o.locale] || '.,'
|
614
610
|
comma_in_format = o.precision == 0 ? '' : 'D'
|
615
611
|
nines_after = (1..o.precision-1).map{'9'}.join('')+'0'
|
616
612
|
if comma.length == 1
|
@@ -687,6 +683,7 @@ module ArelExtensions
|
|
687
683
|
collector << ')'
|
688
684
|
collector
|
689
685
|
end
|
686
|
+
|
690
687
|
end
|
691
688
|
end
|
692
689
|
end
|
@@ -1,7 +1,19 @@
|
|
1
1
|
module ArelExtensions
|
2
2
|
module Visitors
|
3
|
+
|
3
4
|
Arel::Visitors.send(:remove_const,'Oracle12') if Arel::Visitors.const_defined?('Oracle12')
|
4
5
|
Arel::Visitors.const_set('Oracle12',Class.new(Arel::Visitors::Oracle)).class_eval do
|
6
|
+
def visit_Arel_Nodes_SelectStatement(o, collector)
|
7
|
+
# Oracle does not allow LIMIT clause with select for update
|
8
|
+
if o.limit && o.lock
|
9
|
+
raise ArgumentError, <<-MSG
|
10
|
+
'Combination of limit and lock is not supported.
|
11
|
+
because generated SQL statements
|
12
|
+
`SELECT FOR UPDATE and FETCH FIRST n ROWS` generates ORA-02014.`
|
13
|
+
MSG
|
14
|
+
end
|
15
|
+
super
|
16
|
+
end
|
5
17
|
|
6
18
|
def visit_Arel_Nodes_SelectOptions(o, collector)
|
7
19
|
collector = maybe_visit o.offset, collector
|
@@ -56,7 +68,7 @@ module ArelExtensions
|
|
56
68
|
if i != 0
|
57
69
|
collector << Arel::Visitors::MySQL::COMMA
|
58
70
|
end
|
59
|
-
collector
|
71
|
+
collector = visit v, collector
|
60
72
|
end
|
61
73
|
collector << ')'
|
62
74
|
when Hash
|
@@ -72,7 +84,7 @@ module ArelExtensions
|
|
72
84
|
collector << 'FORMAT JSON'
|
73
85
|
end
|
74
86
|
collector << ')'
|
75
|
-
when String,
|
87
|
+
when String,Numeric,TrueClass,FalseClass
|
76
88
|
collector = visit Arel::Nodes.build_quoted("#{o.dict}"), collector
|
77
89
|
collector << ' FORMAT JSON'
|
78
90
|
when NilClass
|
@@ -85,6 +97,7 @@ module ArelExtensions
|
|
85
97
|
end
|
86
98
|
collector
|
87
99
|
end
|
100
|
+
|
88
101
|
end
|
89
102
|
end
|
90
103
|
end
|