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