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
@@ -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
|
-
if
|
134
|
-
collector <<
|
129
|
+
if arg.is_a?(Numeric) || arg.is_a?(Arel::Attributes::Attribute)
|
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,85 +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
|
215
211
|
when Hash
|
216
212
|
src_tz, dst_tz = o.time_zone.first
|
217
213
|
collector << COMMA
|
218
|
-
collector = visit Arel
|
214
|
+
collector = visit Arel.quoted(src_tz), collector
|
219
215
|
collector << COMMA
|
220
|
-
collector = visit Arel
|
216
|
+
collector = visit Arel.quoted(dst_tz), collector
|
221
217
|
collector << ')'
|
222
218
|
when String
|
223
219
|
collector << COMMA << "'UTC'" << COMMA
|
224
|
-
collector = visit Arel
|
220
|
+
collector = visit Arel.quoted(o.time_zone), collector
|
225
221
|
collector << ')'
|
226
222
|
end
|
227
223
|
collector << COMMA
|
228
|
-
collector = visit Arel
|
229
|
-
collector <<
|
224
|
+
collector = visit Arel.quoted(fmt), collector
|
225
|
+
collector << ')'
|
230
226
|
when :integer, :float, :decimal
|
231
|
-
collector <<
|
227
|
+
collector << 'FORMAT('
|
232
228
|
collector = visit o.left, collector
|
233
229
|
collector << Arel::Visitors::ToSql::COMMA
|
234
230
|
collector << '2'
|
235
231
|
collector << Arel::Visitors::ToSql::COMMA
|
236
232
|
collector = visit o.right, collector
|
237
|
-
collector <<
|
233
|
+
collector << ')'
|
238
234
|
else
|
239
235
|
collector = visit o.left, collector
|
240
236
|
end
|
@@ -252,7 +248,7 @@ module ArelExtensions
|
|
252
248
|
collector = visit o.right, collector
|
253
249
|
collector << COMMA
|
254
250
|
collector = visit o.left, collector
|
255
|
-
collector <<
|
251
|
+
collector << ')'
|
256
252
|
else
|
257
253
|
collector << '('
|
258
254
|
collector = visit o.left, collector
|
@@ -272,81 +268,79 @@ module ArelExtensions
|
|
272
268
|
end
|
273
269
|
|
274
270
|
def visit_ArelExtensions_Nodes_DateAdd o, collector
|
275
|
-
collector <<
|
271
|
+
collector << 'DATE_ADD('
|
276
272
|
collector = visit o.left, collector
|
277
273
|
collector << COMMA
|
278
274
|
collector = visit o.mysql_value(o.right), collector
|
279
|
-
collector <<
|
275
|
+
collector << ')'
|
280
276
|
collector
|
281
277
|
end
|
282
278
|
|
283
279
|
def visit_ArelExtensions_Nodes_Duration o, collector
|
284
280
|
if o.left == 'wd'
|
285
|
-
collector <<
|
281
|
+
collector << '(WEEKDAY('
|
286
282
|
collector = visit o.right, collector
|
287
|
-
collector <<
|
283
|
+
collector << ') + 1) % 7'
|
288
284
|
else
|
289
285
|
if o.with_interval
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
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
|
300
295
|
end
|
301
|
-
collector <<
|
296
|
+
collector << ' INTERVAL ' if o.with_interval && interval
|
302
297
|
collector << "#{DATE_MAPPING[o.left]}("
|
303
298
|
collector = visit o.right, collector
|
304
|
-
collector <<
|
299
|
+
collector << ')'
|
305
300
|
collector << " #{interval} " if o.with_interval && interval
|
306
301
|
end
|
307
302
|
collector
|
308
303
|
end
|
309
304
|
|
310
305
|
def visit_ArelExtensions_Nodes_IsNull o, collector
|
311
|
-
collector <<
|
306
|
+
collector << 'ISNULL('
|
312
307
|
collector = visit o.expr, collector
|
313
|
-
collector <<
|
308
|
+
collector << ')'
|
314
309
|
collector
|
315
310
|
end
|
316
311
|
|
317
312
|
def visit_ArelExtensions_Nodes_IsNotNull o, collector
|
318
|
-
|
313
|
+
collector << 'NOT ISNULL('
|
319
314
|
collector = visit o.expr, collector
|
320
|
-
collector <<
|
315
|
+
collector << ')'
|
321
316
|
collector
|
322
317
|
end
|
323
318
|
|
324
319
|
def visit_ArelExtensions_Nodes_Wday o, collector
|
325
|
-
collector <<
|
320
|
+
collector << '(WEEKDAY('
|
326
321
|
collector = visit o.date, collector
|
327
|
-
collector <<
|
322
|
+
collector << ') + 1) % 7'
|
328
323
|
collector
|
329
324
|
end
|
330
325
|
|
331
326
|
def visit_ArelExtensions_Nodes_Cast o, collector
|
332
|
-
collector << "CAST("
|
333
|
-
collector = visit o.left, collector
|
334
|
-
collector << " AS "
|
335
327
|
as_attr =
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
collector = visit
|
349
|
-
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 << ')'
|
350
344
|
collector
|
351
345
|
end
|
352
346
|
|
@@ -356,7 +350,7 @@ module ArelExtensions
|
|
356
350
|
o = o.dup
|
357
351
|
o.orders = []
|
358
352
|
end
|
359
|
-
old_visit_Arel_Nodes_SelectStatement(o,collector)
|
353
|
+
old_visit_Arel_Nodes_SelectStatement(o, collector)
|
360
354
|
end
|
361
355
|
|
362
356
|
alias_method(:old_visit_Arel_Nodes_As, :visit_Arel_Nodes_As) rescue nil
|
@@ -368,7 +362,7 @@ module ArelExtensions
|
|
368
362
|
else
|
369
363
|
collector = visit o.left, collector
|
370
364
|
end
|
371
|
-
collector <<
|
365
|
+
collector << ' AS '
|
372
366
|
|
373
367
|
# sometimes these values are already quoted, if they are, don't double quote it
|
374
368
|
quote = o.right.is_a?(Arel::Nodes::SqlLiteral) && o.right[0] != '`' && o.right[-1] != '`'
|
@@ -378,13 +372,12 @@ module ArelExtensions
|
|
378
372
|
collector << '`' if quote
|
379
373
|
|
380
374
|
collector
|
381
|
-
collector
|
382
375
|
end
|
383
376
|
|
384
377
|
def visit_ArelExtensions_Nodes_FormattedNumber o, collector
|
385
378
|
col = o.left.coalesce(0)
|
386
|
-
params = o.locale ? [o.precision,Arel
|
387
|
-
sign =
|
379
|
+
params = o.locale ? [o.precision, Arel.quoted(o.locale)] : [o.precision]
|
380
|
+
sign = Arel.when(col < 0).
|
388
381
|
then('-').
|
389
382
|
else(o.flags.include?('+') ? '+' : (o.flags.include?(' ') ? ' ' : ''))
|
390
383
|
sign_length = ArelExtensions::Nodes::Length.new([sign])
|
@@ -392,28 +385,33 @@ module ArelExtensions
|
|
392
385
|
number =
|
393
386
|
if o.scientific_notation
|
394
387
|
ArelExtensions::Nodes::Concat.new([
|
395
|
-
Arel::Nodes::NamedFunction.new('FORMAT',[
|
396
|
-
col.abs/Arel
|
397
|
-
]+params),
|
388
|
+
Arel::Nodes::NamedFunction.new('FORMAT', [
|
389
|
+
col.abs / Arel.quoted(10).pow(col.abs.log10.floor)
|
390
|
+
] + params),
|
398
391
|
o.type,
|
399
|
-
Arel::Nodes::NamedFunction.new('FORMAT',[
|
392
|
+
Arel::Nodes::NamedFunction.new('FORMAT', [
|
400
393
|
col.abs.log10.floor,
|
401
394
|
0
|
402
395
|
])
|
403
396
|
])
|
404
397
|
else
|
405
|
-
Arel::Nodes::NamedFunction.new('FORMAT',[col.abs]+params)
|
398
|
+
Arel::Nodes::NamedFunction.new('FORMAT', [col.abs] + params)
|
406
399
|
end
|
407
400
|
|
408
|
-
repeated_char =
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
401
|
+
repeated_char =
|
402
|
+
if o.width == 0
|
403
|
+
Arel.quoted('')
|
404
|
+
else
|
405
|
+
Arel
|
406
|
+
.when(Arel.quoted(o.width).abs - (number.length + sign_length) > 0)
|
407
|
+
.then(Arel.quoted(
|
408
|
+
o.flags.include?('-') ? ' ' : (o.flags.include?('0') ? '0' : ' ')
|
409
|
+
).repeat(Arel.quoted(o.width).abs - (number.length + sign_length))
|
410
|
+
)
|
411
|
+
.else('')
|
412
|
+
end
|
413
|
+
before = !o.flags.include?('0') && !o.flags.include?('-') ? repeated_char : ''
|
414
|
+
middle = o.flags.include?('0') && !o.flags.include?('-') ? repeated_char : ''
|
417
415
|
after = o.flags.include?('-') ? repeated_char : ''
|
418
416
|
full_number = ArelExtensions::Nodes::Concat.new([
|
419
417
|
before,
|
@@ -422,45 +420,45 @@ module ArelExtensions
|
|
422
420
|
number,
|
423
421
|
after
|
424
422
|
])
|
425
|
-
collector = visit ArelExtensions::Nodes::Concat.new([Arel
|
423
|
+
collector = visit ArelExtensions::Nodes::Concat.new([Arel.quoted(o.prefix), full_number, Arel.quoted(o.suffix)]), collector
|
426
424
|
collector
|
427
425
|
end
|
428
426
|
|
429
427
|
def visit_Aggregate_For_AggregateFunction o, collector
|
430
428
|
if !window_supported?
|
431
|
-
|
432
|
-
|
429
|
+
warn('Warning: ArelExtensions: Window Functions are not available in the current version of the DBMS.')
|
430
|
+
return collector
|
433
431
|
end
|
434
432
|
|
435
433
|
if !o.order.empty? || !o.group.empty?
|
436
|
-
collector <<
|
434
|
+
collector << ' OVER ('
|
437
435
|
if !o.group.empty?
|
438
|
-
collector <<
|
436
|
+
collector << ' PARTITION BY ('
|
439
437
|
visit o.group, collector
|
440
|
-
collector <<
|
438
|
+
collector << ')'
|
441
439
|
end
|
442
440
|
if !o.order.empty?
|
443
|
-
collector <<
|
441
|
+
collector << ' ORDER BY ('
|
444
442
|
visit o.order, collector
|
445
|
-
collector <<
|
443
|
+
collector << ')'
|
446
444
|
end
|
447
|
-
collector <<
|
445
|
+
collector << ')'
|
448
446
|
end
|
449
447
|
collector
|
450
448
|
end
|
451
449
|
|
452
450
|
def visit_ArelExtensions_Nodes_Std o, collector
|
453
|
-
collector << (o.unbiased_estimator ?
|
451
|
+
collector << (o.unbiased_estimator ? 'STDDEV_SAMP(' : 'STDDEV_POP(')
|
454
452
|
visit o.left, collector
|
455
|
-
collector <<
|
453
|
+
collector << ')'
|
456
454
|
visit_Aggregate_For_AggregateFunction o, collector
|
457
455
|
collector
|
458
456
|
end
|
459
457
|
|
460
458
|
def visit_ArelExtensions_Nodes_Variance o, collector
|
461
|
-
collector << (o.unbiased_estimator ?
|
459
|
+
collector << (o.unbiased_estimator ? 'VAR_SAMP(' : 'VAR_POP(')
|
462
460
|
visit o.left, collector
|
463
|
-
collector <<
|
461
|
+
collector << ')'
|
464
462
|
visit_Aggregate_For_AggregateFunction o, collector
|
465
463
|
collector
|
466
464
|
end
|
@@ -492,13 +490,13 @@ module ArelExtensions
|
|
492
490
|
# corresponding mysql version of the current mariadb version (which is not very helpful most of the time)
|
493
491
|
end
|
494
492
|
|
495
|
-
def visit_ArelExtensions_Nodes_Json o,collector
|
493
|
+
def visit_ArelExtensions_Nodes_Json o, collector
|
496
494
|
return super if !json_supported?
|
497
495
|
|
498
496
|
case o.dict
|
499
497
|
when Array
|
500
498
|
collector << 'JSON_ARRAY('
|
501
|
-
o.dict.each.with_index do |v,i|
|
499
|
+
o.dict.each.with_index do |v, i|
|
502
500
|
if i != 0
|
503
501
|
collector << COMMA
|
504
502
|
end
|
@@ -507,7 +505,7 @@ module ArelExtensions
|
|
507
505
|
collector << ')'
|
508
506
|
when Hash
|
509
507
|
collector << 'JSON_OBJECT('
|
510
|
-
o.dict.each.with_index do |(k,v),i|
|
508
|
+
o.dict.each.with_index do |(k, v), i|
|
511
509
|
if i != 0
|
512
510
|
collector << COMMA
|
513
511
|
end
|
@@ -522,9 +520,9 @@ module ArelExtensions
|
|
522
520
|
collector
|
523
521
|
end
|
524
522
|
|
525
|
-
def visit_ArelExtensions_Nodes_JsonMerge o,collector
|
523
|
+
def visit_ArelExtensions_Nodes_JsonMerge o, collector
|
526
524
|
collector << 'JSON_MERGE_PATCH('
|
527
|
-
o.expressions.each.with_index do |v,i|
|
525
|
+
o.expressions.each.with_index do |v, i|
|
528
526
|
if i != 0
|
529
527
|
collector << COMMA
|
530
528
|
end
|
@@ -534,27 +532,27 @@ module ArelExtensions
|
|
534
532
|
collector
|
535
533
|
end
|
536
534
|
|
537
|
-
def visit_ArelExtensions_Nodes_JsonGet o,collector
|
535
|
+
def visit_ArelExtensions_Nodes_JsonGet o, collector
|
538
536
|
collector << 'JSON_EXTRACT('
|
539
537
|
collector = visit o.dict, collector
|
540
538
|
collector << COMMA
|
541
539
|
if o.key.is_a?(Integer)
|
542
540
|
collector << "\"$[#{o.key}]\""
|
543
541
|
else
|
544
|
-
collector = visit Arel
|
542
|
+
collector = visit Arel.quoted('$.') + o.key, collector
|
545
543
|
end
|
546
544
|
collector << ')'
|
547
545
|
collector
|
548
546
|
end
|
549
547
|
|
550
|
-
def visit_ArelExtensions_Nodes_JsonSet o,collector
|
548
|
+
def visit_ArelExtensions_Nodes_JsonSet o, collector
|
551
549
|
collector << 'JSON_SET('
|
552
550
|
collector = visit o.dict, collector
|
553
551
|
collector << COMMA
|
554
552
|
if o.key.is_a?(Integer)
|
555
553
|
collector << "\"$[#{o.key}]\""
|
556
554
|
else
|
557
|
-
collector = visit Arel
|
555
|
+
collector = visit Arel.quoted('$.') + o.key, collector
|
558
556
|
end
|
559
557
|
collector << COMMA
|
560
558
|
collector = visit o.value, collector
|
@@ -573,7 +571,7 @@ module ArelExtensions
|
|
573
571
|
case o.dict
|
574
572
|
when Hash
|
575
573
|
collector << 'JSON_MERGE_PATCH(' if o.dict.length > 1
|
576
|
-
o.dict.each.with_index do |(k,v),i|
|
574
|
+
o.dict.each.with_index do |(k, v), i|
|
577
575
|
if i != 0
|
578
576
|
collector << COMMA
|
579
577
|
end
|