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.
- checksums.yaml +4 -4
- data/.codeclimate.yml +1 -2
- data/.github/workflows/ruby.yml +4 -4
- data/.rubocop.yml +25 -1
- data/Gemfile +10 -10
- data/README.md +24 -4
- data/Rakefile +4 -4
- data/TODO +0 -1
- data/arel_extensions.gemspec +12 -12
- data/gemfiles/rails3.gemfile +10 -10
- data/gemfiles/rails4.gemfile +13 -13
- data/gemfiles/rails5_0.gemfile +12 -12
- data/gemfiles/rails5_1_4.gemfile +12 -12
- data/gemfiles/rails5_2.gemfile +13 -13
- data/gemfiles/rails6.gemfile +11 -11
- data/gemfiles/rails6_1.gemfile +11 -11
- data/gemfiles/rails7.gemfile +7 -7
- 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 +10 -10
- data/lib/arel_extensions/comparators.rb +14 -14
- data/lib/arel_extensions/date_duration.rb +7 -7
- data/lib/arel_extensions/helpers.rb +16 -13
- data/lib/arel_extensions/insert_manager.rb +1 -1
- data/lib/arel_extensions/math.rb +16 -18
- 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 +3 -3
- 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 +0 -0
- 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 +6 -6
- 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 +1 -1
- 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 +0 -0
- 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 +0 -0
- 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 +0 -0
- data/lib/arel_extensions/nodes/sum.rb +0 -0
- data/lib/arel_extensions/nodes/then.rb +0 -0
- data/lib/arel_extensions/nodes/trim.rb +0 -0
- 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 +19 -19
- data/lib/arel_extensions/visitors/mssql.rb +139 -118
- data/lib/arel_extensions/visitors/mysql.rb +145 -144
- data/lib/arel_extensions/visitors/oracle.rb +136 -128
- data/lib/arel_extensions/visitors/oracle12.rb +16 -16
- data/lib/arel_extensions/visitors/postgresql.rb +147 -136
- data/lib/arel_extensions/visitors/sqlite.rb +83 -85
- data/lib/arel_extensions/visitors/to_sql.rb +143 -148
- data/lib/arel_extensions/visitors.rb +7 -7
- data/lib/arel_extensions.rb +46 -32
- data/test/arelx_test_helper.rb +14 -14
- data/test/database.yml +5 -5
- data/test/real_db_test.rb +78 -78
- data/test/support/fake_record.rb +1 -1
- data/test/test_comparators.rb +5 -5
- data/test/visitors/test_bulk_insert_oracle.rb +4 -4
- data/test/visitors/test_bulk_insert_sqlite.rb +4 -4
- data/test/visitors/test_bulk_insert_to_sql.rb +4 -4
- data/test/visitors/test_oracle.rb +14 -14
- data/test/visitors/test_to_sql.rb +82 -82
- data/test/with_ar/all_agnostic_test.rb +415 -313
- data/test/with_ar/insert_agnostic_test.rb +17 -14
- data/test/with_ar/test_bulk_sqlite.rb +4 -4
- 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 +2 -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
@@ -8,7 +8,8 @@ module ArelExtensions
|
|
8
8
|
|
9
9
|
DATE_FORMAT_DIRECTIVES = { # ISO C / POSIX
|
10
10
|
'%Y' => '%Y', '%C' => '', '%y' => '%y', '%m' => '%m', '%B' => '%M', '%b' => '%b', '%^b' => '%b', # year, month
|
11
|
-
'%
|
11
|
+
'%V' => '%v', '%G' => '%x', # ISO week number and year of week
|
12
|
+
'%d' => '%d', '%e' => '%e', '%j' => '%j', '%w' => '%w', '%a' => '%a', '%A' => '%W', # day, weekday
|
12
13
|
'%H' => '%H', '%k' => '%k', '%I' => '%I', '%l' => '%l', '%P' => '%p', '%p' => '%p', # hours
|
13
14
|
'%M' => '%i', '%S' => '%S', '%L' => '', '%N' => '%f', '%z' => ''
|
14
15
|
}.freeze
|
@@ -16,22 +17,22 @@ module ArelExtensions
|
|
16
17
|
|
17
18
|
# Math functions
|
18
19
|
def visit_ArelExtensions_Nodes_Log10 o, collector
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
20
|
+
collector << 'LOG10('
|
21
|
+
o.expressions.each_with_index { |arg, i|
|
22
|
+
collector << Arel::Visitors::ToSql::COMMA if i != 0
|
23
|
+
collector = visit arg, collector
|
24
|
+
}
|
25
|
+
collector << ')'
|
26
|
+
collector
|
26
27
|
end
|
27
28
|
|
28
29
|
def visit_ArelExtensions_Nodes_Power o, collector
|
29
|
-
collector <<
|
30
|
+
collector << 'POW('
|
30
31
|
o.expressions.each_with_index { |arg, i|
|
31
32
|
collector << Arel::Visitors::ToSql::COMMA if i != 0
|
32
33
|
collector = visit arg, collector
|
33
34
|
}
|
34
|
-
collector <<
|
35
|
+
collector << ')'
|
35
36
|
collector
|
36
37
|
end
|
37
38
|
|
@@ -44,10 +45,9 @@ module ArelExtensions
|
|
44
45
|
collector << ')'
|
45
46
|
if o.escape
|
46
47
|
collector << ' ESCAPE '
|
47
|
-
visit o.escape, collector
|
48
|
-
else
|
49
|
-
collector
|
48
|
+
collector = visit o.escape, collector
|
50
49
|
end
|
50
|
+
collector
|
51
51
|
end
|
52
52
|
|
53
53
|
def visit_ArelExtensions_Nodes_AiMatches o, collector
|
@@ -56,10 +56,9 @@ module ArelExtensions
|
|
56
56
|
collector = visit o.right.ai_collate, collector
|
57
57
|
if o.escape
|
58
58
|
collector << ' ESCAPE '
|
59
|
-
visit o.escape, collector
|
60
|
-
else
|
61
|
-
collector
|
59
|
+
collector = visit o.escape, collector
|
62
60
|
end
|
61
|
+
collector
|
63
62
|
end
|
64
63
|
|
65
64
|
def visit_ArelExtensions_Nodes_AiIMatches o, collector
|
@@ -68,22 +67,20 @@ module ArelExtensions
|
|
68
67
|
collector = visit o.right.ai_collate, collector
|
69
68
|
if o.escape
|
70
69
|
collector << ' ESCAPE '
|
71
|
-
visit o.escape, collector
|
72
|
-
else
|
73
|
-
collector
|
70
|
+
collector = visit o.escape, collector
|
74
71
|
end
|
72
|
+
collector
|
75
73
|
end
|
76
74
|
|
77
75
|
def visit_ArelExtensions_Nodes_SMatches o, collector
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
end
|
76
|
+
collector = visit o.left.collate, collector
|
77
|
+
collector << ' LIKE '
|
78
|
+
collector = visit o.right.collate, collector
|
79
|
+
if o.escape
|
80
|
+
collector << ' ESCAPE '
|
81
|
+
collector = visit o.escape, collector
|
82
|
+
end
|
83
|
+
collector
|
87
84
|
end
|
88
85
|
|
89
86
|
def visit_ArelExtensions_Nodes_IDoesNotMatch o, collector
|
@@ -94,10 +91,9 @@ module ArelExtensions
|
|
94
91
|
collector << ')'
|
95
92
|
if o.escape
|
96
93
|
collector << ' ESCAPE '
|
97
|
-
visit o.escape, collector
|
98
|
-
else
|
99
|
-
collector
|
94
|
+
collector = visit o.escape, collector
|
100
95
|
end
|
96
|
+
collector
|
101
97
|
end
|
102
98
|
|
103
99
|
def visit_ArelExtensions_Nodes_Collate o, collector
|
@@ -105,7 +101,7 @@ module ArelExtensions
|
|
105
101
|
case o.expressions.first
|
106
102
|
when Arel::Attributes::Attribute
|
107
103
|
case o.option
|
108
|
-
when 'latin1','utf8'
|
104
|
+
when 'latin1', 'utf8'
|
109
105
|
o.option
|
110
106
|
else
|
111
107
|
Arel::Table.engine.connection.charset || 'utf8'
|
@@ -127,27 +123,27 @@ module ArelExtensions
|
|
127
123
|
end
|
128
124
|
|
129
125
|
def visit_ArelExtensions_Nodes_Concat o, collector
|
130
|
-
collector <<
|
126
|
+
collector << 'CONCAT('
|
131
127
|
o.expressions.each_with_index { |arg, i|
|
132
128
|
collector << COMMA if i != 0
|
133
129
|
if (arg.is_a?(Numeric)) || (arg.is_a?(Arel::Attributes::Attribute))
|
134
|
-
collector <<
|
130
|
+
collector << 'CAST('
|
135
131
|
collector = visit arg, collector
|
136
|
-
collector <<
|
132
|
+
collector << ' AS char)'
|
137
133
|
else
|
138
134
|
collector = visit arg, collector
|
139
135
|
end
|
140
136
|
}
|
141
|
-
collector <<
|
137
|
+
collector << ')'
|
142
138
|
collector
|
143
139
|
end
|
144
140
|
|
145
141
|
def visit_ArelExtensions_Nodes_GroupConcat o, collector
|
146
|
-
collector <<
|
142
|
+
collector << 'GROUP_CONCAT('
|
147
143
|
collector = visit o.left, collector
|
148
144
|
if !o.order.blank?
|
149
145
|
collector << ' ORDER BY '
|
150
|
-
o.order.each_with_index do |order,i|
|
146
|
+
o.order.each_with_index do |order, i|
|
151
147
|
collector << Arel::Visitors::ToSql::COMMA if i != 0
|
152
148
|
collector = visit order, collector
|
153
149
|
end
|
@@ -156,77 +152,85 @@ module ArelExtensions
|
|
156
152
|
collector << ' SEPARATOR '
|
157
153
|
collector = visit o.separator, collector
|
158
154
|
end
|
159
|
-
collector <<
|
155
|
+
collector << ')'
|
160
156
|
collector
|
161
157
|
end
|
162
158
|
|
163
159
|
def visit_ArelExtensions_Nodes_Trim o, collector
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
160
|
+
collector << 'TRIM(' # BOTH
|
161
|
+
collector = visit o.right, collector
|
162
|
+
collector << ' FROM '
|
163
|
+
collector = visit o.left, collector
|
164
|
+
collector << ')'
|
165
|
+
collector
|
170
166
|
end
|
171
167
|
|
172
168
|
def visit_ArelExtensions_Nodes_Ltrim o, collector
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
169
|
+
collector << 'TRIM(LEADING '
|
170
|
+
collector = visit o.right, collector
|
171
|
+
collector << ' FROM '
|
172
|
+
collector = visit o.left, collector
|
173
|
+
collector << ')'
|
174
|
+
collector
|
179
175
|
end
|
180
176
|
|
181
177
|
def visit_ArelExtensions_Nodes_Rtrim o, collector
|
182
178
|
collector << 'TRIM(TRAILING '
|
183
179
|
collector = visit o.right, collector
|
184
|
-
collector <<
|
180
|
+
collector << ' FROM '
|
185
181
|
collector = visit o.left, collector
|
186
|
-
collector <<
|
182
|
+
collector << ')'
|
187
183
|
collector
|
188
184
|
end
|
189
185
|
|
190
186
|
def visit_ArelExtensions_Nodes_Repeat o, collector
|
191
|
-
collector <<
|
187
|
+
collector << 'REPEAT('
|
192
188
|
o.expressions.each_with_index { |arg, i|
|
193
189
|
collector << Arel::Visitors::ToSql::COMMA if i != 0
|
194
190
|
collector = visit arg, collector
|
195
191
|
}
|
196
|
-
collector <<
|
192
|
+
collector << ')'
|
197
193
|
collector
|
198
194
|
end
|
199
195
|
|
200
196
|
def visit_ArelExtensions_Nodes_RegexpReplace o, collector
|
201
197
|
if !regexp_replace_supported?
|
202
|
-
warn(
|
198
|
+
warn('Warning: ArelExtensions: REGEXP_REPLACE does not seem to be available in the current version of the DBMS, it might crash')
|
203
199
|
end
|
204
|
-
super(o,collector)
|
200
|
+
super(o, collector)
|
205
201
|
end
|
206
202
|
|
207
203
|
def visit_ArelExtensions_Nodes_Format o, collector
|
208
204
|
case o.col_type
|
209
205
|
when :date, :datetime, :time
|
210
206
|
fmt = ArelExtensions::Visitors::strftime_to_format(o.iso_format, DATE_FORMAT_DIRECTIVES)
|
211
|
-
collector <<
|
212
|
-
collector <<
|
207
|
+
collector << 'DATE_FORMAT('
|
208
|
+
collector << 'CONVERT_TZ(' if o.time_zone
|
213
209
|
collector = visit o.left, collector
|
214
|
-
|
210
|
+
case o.time_zone
|
211
|
+
when Hash
|
212
|
+
src_tz, dst_tz = o.time_zone.first
|
213
|
+
collector << COMMA
|
214
|
+
collector = visit Arel.quoted(src_tz), collector
|
215
|
+
collector << COMMA
|
216
|
+
collector = visit Arel.quoted(dst_tz), collector
|
217
|
+
collector << ')'
|
218
|
+
when String
|
215
219
|
collector << COMMA << "'UTC'" << COMMA
|
216
|
-
collector = visit o.time_zone, collector
|
220
|
+
collector = visit Arel.quoted(o.time_zone), collector
|
217
221
|
collector << ')'
|
218
222
|
end
|
219
223
|
collector << COMMA
|
220
|
-
collector = visit Arel
|
221
|
-
collector <<
|
224
|
+
collector = visit Arel.quoted(fmt), collector
|
225
|
+
collector << ')'
|
222
226
|
when :integer, :float, :decimal
|
223
|
-
collector <<
|
227
|
+
collector << 'FORMAT('
|
224
228
|
collector = visit o.left, collector
|
225
229
|
collector << Arel::Visitors::ToSql::COMMA
|
226
230
|
collector << '2'
|
227
231
|
collector << Arel::Visitors::ToSql::COMMA
|
228
232
|
collector = visit o.right, collector
|
229
|
-
collector <<
|
233
|
+
collector << ')'
|
230
234
|
else
|
231
235
|
collector = visit o.left, collector
|
232
236
|
end
|
@@ -244,7 +248,7 @@ module ArelExtensions
|
|
244
248
|
collector = visit o.right, collector
|
245
249
|
collector << COMMA
|
246
250
|
collector = visit o.left, collector
|
247
|
-
collector <<
|
251
|
+
collector << ')'
|
248
252
|
else
|
249
253
|
collector << '('
|
250
254
|
collector = visit o.left, collector
|
@@ -264,81 +268,79 @@ module ArelExtensions
|
|
264
268
|
end
|
265
269
|
|
266
270
|
def visit_ArelExtensions_Nodes_DateAdd o, collector
|
267
|
-
collector <<
|
271
|
+
collector << 'DATE_ADD('
|
268
272
|
collector = visit o.left, collector
|
269
273
|
collector << COMMA
|
270
274
|
collector = visit o.mysql_value(o.right), collector
|
271
|
-
collector <<
|
275
|
+
collector << ')'
|
272
276
|
collector
|
273
277
|
end
|
274
278
|
|
275
279
|
def visit_ArelExtensions_Nodes_Duration o, collector
|
276
280
|
if o.left == 'wd'
|
277
|
-
collector <<
|
281
|
+
collector << '(WEEKDAY('
|
278
282
|
collector = visit o.right, collector
|
279
|
-
collector <<
|
283
|
+
collector << ') + 1) % 7'
|
280
284
|
else
|
281
285
|
if o.with_interval
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
end
|
286
|
+
interval =
|
287
|
+
case o.left
|
288
|
+
when 'd', 'm', 'y'
|
289
|
+
'DAY'
|
290
|
+
when 'h', 'mn', 's'
|
291
|
+
'SECOND'
|
292
|
+
when /i\z/
|
293
|
+
DATE_MAPPING[o.left[0..-2]]
|
294
|
+
end
|
292
295
|
end
|
293
|
-
collector <<
|
296
|
+
collector << ' INTERVAL ' if o.with_interval && interval
|
294
297
|
collector << "#{DATE_MAPPING[o.left]}("
|
295
298
|
collector = visit o.right, collector
|
296
|
-
collector <<
|
299
|
+
collector << ')'
|
297
300
|
collector << " #{interval} " if o.with_interval && interval
|
298
301
|
end
|
299
302
|
collector
|
300
303
|
end
|
301
304
|
|
302
305
|
def visit_ArelExtensions_Nodes_IsNull o, collector
|
303
|
-
collector <<
|
306
|
+
collector << 'ISNULL('
|
304
307
|
collector = visit o.expr, collector
|
305
|
-
collector <<
|
308
|
+
collector << ')'
|
306
309
|
collector
|
307
310
|
end
|
308
311
|
|
309
312
|
def visit_ArelExtensions_Nodes_IsNotNull o, collector
|
310
|
-
|
313
|
+
collector << 'NOT ISNULL('
|
311
314
|
collector = visit o.expr, collector
|
312
|
-
collector <<
|
315
|
+
collector << ')'
|
313
316
|
collector
|
314
317
|
end
|
315
318
|
|
316
319
|
def visit_ArelExtensions_Nodes_Wday o, collector
|
317
|
-
collector <<
|
320
|
+
collector << '(WEEKDAY('
|
318
321
|
collector = visit o.date, collector
|
319
|
-
collector <<
|
322
|
+
collector << ') + 1) % 7'
|
320
323
|
collector
|
321
324
|
end
|
322
325
|
|
323
326
|
def visit_ArelExtensions_Nodes_Cast o, collector
|
324
|
-
collector << "CAST("
|
325
|
-
collector = visit o.left, collector
|
326
|
-
collector << " AS "
|
327
327
|
as_attr =
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
collector = visit
|
341
|
-
collector <<
|
328
|
+
case o.as_attr
|
329
|
+
when :binary then 'binary'
|
330
|
+
when :date then 'date'
|
331
|
+
when :datetime then 'datetime'
|
332
|
+
when :int then 'signed'
|
333
|
+
when :number, :decimal then 'decimal(20,6)'
|
334
|
+
when :string then 'char'
|
335
|
+
when :time then 'time'
|
336
|
+
else o.as_attr.to_s
|
337
|
+
end
|
338
|
+
|
339
|
+
collector << 'CAST('
|
340
|
+
collector = visit o.left, collector
|
341
|
+
collector << ' AS '
|
342
|
+
collector = visit Arel::Nodes::SqlLiteral.new(as_attr), collector
|
343
|
+
collector << ')'
|
342
344
|
collector
|
343
345
|
end
|
344
346
|
|
@@ -348,7 +350,7 @@ module ArelExtensions
|
|
348
350
|
o = o.dup
|
349
351
|
o.orders = []
|
350
352
|
end
|
351
|
-
old_visit_Arel_Nodes_SelectStatement(o,collector)
|
353
|
+
old_visit_Arel_Nodes_SelectStatement(o, collector)
|
352
354
|
end
|
353
355
|
|
354
356
|
alias_method(:old_visit_Arel_Nodes_As, :visit_Arel_Nodes_As) rescue nil
|
@@ -360,7 +362,7 @@ module ArelExtensions
|
|
360
362
|
else
|
361
363
|
collector = visit o.left, collector
|
362
364
|
end
|
363
|
-
collector <<
|
365
|
+
collector << ' AS '
|
364
366
|
|
365
367
|
# sometimes these values are already quoted, if they are, don't double quote it
|
366
368
|
quote = o.right.is_a?(Arel::Nodes::SqlLiteral) && o.right[0] != '`' && o.right[-1] != '`'
|
@@ -370,13 +372,12 @@ module ArelExtensions
|
|
370
372
|
collector << '`' if quote
|
371
373
|
|
372
374
|
collector
|
373
|
-
collector
|
374
375
|
end
|
375
376
|
|
376
377
|
def visit_ArelExtensions_Nodes_FormattedNumber o, collector
|
377
378
|
col = o.left.coalesce(0)
|
378
|
-
params = o.locale ? [o.precision,Arel
|
379
|
-
sign =
|
379
|
+
params = o.locale ? [o.precision, Arel.quoted(o.locale)] : [o.precision]
|
380
|
+
sign = Arel.when(col < 0).
|
380
381
|
then('-').
|
381
382
|
else(o.flags.include?('+') ? '+' : (o.flags.include?(' ') ? ' ' : ''))
|
382
383
|
sign_length = ArelExtensions::Nodes::Length.new([sign])
|
@@ -384,28 +385,28 @@ module ArelExtensions
|
|
384
385
|
number =
|
385
386
|
if o.scientific_notation
|
386
387
|
ArelExtensions::Nodes::Concat.new([
|
387
|
-
Arel::Nodes::NamedFunction.new('FORMAT',[
|
388
|
-
col.abs/Arel
|
389
|
-
]+params),
|
388
|
+
Arel::Nodes::NamedFunction.new('FORMAT', [
|
389
|
+
col.abs / Arel.quoted(10).pow(col.abs.log10.floor)
|
390
|
+
] + params),
|
390
391
|
o.type,
|
391
|
-
Arel::Nodes::NamedFunction.new('FORMAT',[
|
392
|
+
Arel::Nodes::NamedFunction.new('FORMAT', [
|
392
393
|
col.abs.log10.floor,
|
393
394
|
0
|
394
395
|
])
|
395
396
|
])
|
396
397
|
else
|
397
|
-
Arel::Nodes::NamedFunction.new('FORMAT',[col.abs]+params)
|
398
|
+
Arel::Nodes::NamedFunction.new('FORMAT', [col.abs] + params)
|
398
399
|
end
|
399
400
|
|
400
|
-
repeated_char = (o.width == 0) ? Arel
|
401
|
-
when(Arel
|
402
|
-
then(Arel
|
401
|
+
repeated_char = (o.width == 0) ? Arel.quoted('') : ArelExtensions::Nodes::Case.new.
|
402
|
+
when(Arel.quoted(o.width).abs - (number.length + sign_length) > 0).
|
403
|
+
then(Arel.quoted(
|
403
404
|
o.flags.include?('-') ? ' ' : (o.flags.include?('0') ? '0' : ' ')
|
404
|
-
).repeat(Arel
|
405
|
+
).repeat(Arel.quoted(o.width).abs - (number.length + sign_length))
|
405
406
|
).
|
406
407
|
else('')
|
407
|
-
before = (!o.flags.include?('0'))&&(!o.flags.include?('-')) ? repeated_char : ''
|
408
|
-
middle = (o.flags.include?('0'))&&(!o.flags.include?('-')) ? repeated_char : ''
|
408
|
+
before = (!o.flags.include?('0')) && (!o.flags.include?('-')) ? repeated_char : ''
|
409
|
+
middle = (o.flags.include?('0')) && (!o.flags.include?('-')) ? repeated_char : ''
|
409
410
|
after = o.flags.include?('-') ? repeated_char : ''
|
410
411
|
full_number = ArelExtensions::Nodes::Concat.new([
|
411
412
|
before,
|
@@ -414,45 +415,45 @@ module ArelExtensions
|
|
414
415
|
number,
|
415
416
|
after
|
416
417
|
])
|
417
|
-
collector = visit ArelExtensions::Nodes::Concat.new([Arel
|
418
|
+
collector = visit ArelExtensions::Nodes::Concat.new([Arel.quoted(o.prefix), full_number, Arel.quoted(o.suffix)]), collector
|
418
419
|
collector
|
419
420
|
end
|
420
421
|
|
421
422
|
def visit_Aggregate_For_AggregateFunction o, collector
|
422
423
|
if !window_supported?
|
423
|
-
|
424
|
-
|
424
|
+
warn('Warning: ArelExtensions: Window Functions are not available in the current version of the DBMS.')
|
425
|
+
return collector
|
425
426
|
end
|
426
427
|
|
427
428
|
if !o.order.empty? || !o.group.empty?
|
428
|
-
collector <<
|
429
|
+
collector << ' OVER ('
|
429
430
|
if !o.group.empty?
|
430
|
-
collector <<
|
431
|
+
collector << ' PARTITION BY ('
|
431
432
|
visit o.group, collector
|
432
|
-
collector <<
|
433
|
+
collector << ')'
|
433
434
|
end
|
434
435
|
if !o.order.empty?
|
435
|
-
collector <<
|
436
|
+
collector << ' ORDER BY ('
|
436
437
|
visit o.order, collector
|
437
|
-
collector <<
|
438
|
+
collector << ')'
|
438
439
|
end
|
439
|
-
collector <<
|
440
|
+
collector << ')'
|
440
441
|
end
|
441
442
|
collector
|
442
443
|
end
|
443
444
|
|
444
445
|
def visit_ArelExtensions_Nodes_Std o, collector
|
445
|
-
collector << (o.unbiased_estimator ?
|
446
|
+
collector << (o.unbiased_estimator ? 'STDDEV_SAMP(' : 'STDDEV_POP(')
|
446
447
|
visit o.left, collector
|
447
|
-
collector <<
|
448
|
+
collector << ')'
|
448
449
|
visit_Aggregate_For_AggregateFunction o, collector
|
449
450
|
collector
|
450
451
|
end
|
451
452
|
|
452
453
|
def visit_ArelExtensions_Nodes_Variance o, collector
|
453
|
-
collector << (o.unbiased_estimator ?
|
454
|
+
collector << (o.unbiased_estimator ? 'VAR_SAMP(' : 'VAR_POP(')
|
454
455
|
visit o.left, collector
|
455
|
-
collector <<
|
456
|
+
collector << ')'
|
456
457
|
visit_Aggregate_For_AggregateFunction o, collector
|
457
458
|
collector
|
458
459
|
end
|
@@ -484,13 +485,13 @@ module ArelExtensions
|
|
484
485
|
# corresponding mysql version of the current mariadb version (which is not very helpful most of the time)
|
485
486
|
end
|
486
487
|
|
487
|
-
def visit_ArelExtensions_Nodes_Json o,collector
|
488
|
+
def visit_ArelExtensions_Nodes_Json o, collector
|
488
489
|
return super if !json_supported?
|
489
490
|
|
490
491
|
case o.dict
|
491
492
|
when Array
|
492
493
|
collector << 'JSON_ARRAY('
|
493
|
-
o.dict.each.with_index do |v,i|
|
494
|
+
o.dict.each.with_index do |v, i|
|
494
495
|
if i != 0
|
495
496
|
collector << COMMA
|
496
497
|
end
|
@@ -499,7 +500,7 @@ module ArelExtensions
|
|
499
500
|
collector << ')'
|
500
501
|
when Hash
|
501
502
|
collector << 'JSON_OBJECT('
|
502
|
-
o.dict.each.with_index do |(k,v),i|
|
503
|
+
o.dict.each.with_index do |(k, v), i|
|
503
504
|
if i != 0
|
504
505
|
collector << COMMA
|
505
506
|
end
|
@@ -514,9 +515,9 @@ module ArelExtensions
|
|
514
515
|
collector
|
515
516
|
end
|
516
517
|
|
517
|
-
def visit_ArelExtensions_Nodes_JsonMerge o,collector
|
518
|
+
def visit_ArelExtensions_Nodes_JsonMerge o, collector
|
518
519
|
collector << 'JSON_MERGE_PATCH('
|
519
|
-
o.expressions.each.with_index do |v,i|
|
520
|
+
o.expressions.each.with_index do |v, i|
|
520
521
|
if i != 0
|
521
522
|
collector << COMMA
|
522
523
|
end
|
@@ -526,27 +527,27 @@ module ArelExtensions
|
|
526
527
|
collector
|
527
528
|
end
|
528
529
|
|
529
|
-
def visit_ArelExtensions_Nodes_JsonGet o,collector
|
530
|
+
def visit_ArelExtensions_Nodes_JsonGet o, collector
|
530
531
|
collector << 'JSON_EXTRACT('
|
531
532
|
collector = visit o.dict, collector
|
532
533
|
collector << COMMA
|
533
534
|
if o.key.is_a?(Integer)
|
534
535
|
collector << "\"$[#{o.key}]\""
|
535
536
|
else
|
536
|
-
collector = visit Arel
|
537
|
+
collector = visit Arel.quoted('$.') + o.key, collector
|
537
538
|
end
|
538
539
|
collector << ')'
|
539
540
|
collector
|
540
541
|
end
|
541
542
|
|
542
|
-
def visit_ArelExtensions_Nodes_JsonSet o,collector
|
543
|
+
def visit_ArelExtensions_Nodes_JsonSet o, collector
|
543
544
|
collector << 'JSON_SET('
|
544
545
|
collector = visit o.dict, collector
|
545
546
|
collector << COMMA
|
546
547
|
if o.key.is_a?(Integer)
|
547
548
|
collector << "\"$[#{o.key}]\""
|
548
549
|
else
|
549
|
-
collector = visit Arel
|
550
|
+
collector = visit Arel.quoted('$.') + o.key, collector
|
550
551
|
end
|
551
552
|
collector << COMMA
|
552
553
|
collector = visit o.value, collector
|
@@ -565,7 +566,7 @@ module ArelExtensions
|
|
565
566
|
case o.dict
|
566
567
|
when Hash
|
567
568
|
collector << 'JSON_MERGE_PATCH(' if o.dict.length > 1
|
568
|
-
o.dict.each.with_index do |(k,v),i|
|
569
|
+
o.dict.each.with_index do |(k, v), i|
|
569
570
|
if i != 0
|
570
571
|
collector << COMMA
|
571
572
|
end
|