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
@@ -13,16 +13,21 @@ module ArelExtensions
|
|
13
13
|
}.freeze
|
14
14
|
|
15
15
|
LOADED_VISITOR::DATE_FORMAT_DIRECTIVES = {
|
16
|
-
'%Y' => 'YYYY', '%C' => '', '%y' => 'YY', '%m' => 'MM', '%B' =>
|
17
|
-
'%
|
18
|
-
'%
|
16
|
+
'%Y' => 'YYYY', '%C' => '', '%y' => 'YY', '%m' => 'MM', '%B' => 'month', '%^B' => '', '%b' => '', '%^b' => '', # year, month
|
17
|
+
'%V' => 'iso_week', '%G' => '', # ISO week number and year of week
|
18
|
+
'%d' => 'DD', '%e' => '' , '%j' => '' , '%w' => 'dw', %'a' => '', '%A' => 'weekday', # day, weekday
|
19
|
+
'%H' => 'hh', '%k' => '' , '%I' => '' , '%l' => '' , '%P' => '', '%p' => '', # hours
|
19
20
|
'%M' => 'mi', '%S' => 'ss', '%L' => 'ms', '%N' => 'ns', '%z' => 'tz'
|
20
21
|
}.freeze
|
21
22
|
|
22
23
|
LOADED_VISITOR::DATE_FORMAT_FORMAT = {
|
23
|
-
'YY' => '0#', 'MM' => '0#', 'DD' => '0#', 'hh' => '0#', 'mi' => '0#', 'ss' => '0#'
|
24
|
+
'YY' => '0#', 'MM' => '0#', 'DD' => '0#', 'hh' => '0#', 'mi' => '0#', 'ss' => '0#', 'iso_week' => '0#'
|
24
25
|
}
|
25
26
|
|
27
|
+
LOADED_VISITOR::DATE_NAME = [
|
28
|
+
'%B', '%A'
|
29
|
+
]
|
30
|
+
|
26
31
|
LOADED_VISITOR::DATE_FORMAT_REGEX =
|
27
32
|
Regexp.new(
|
28
33
|
LOADED_VISITOR::DATE_FORMAT_DIRECTIVES
|
@@ -34,7 +39,7 @@ module ArelExtensions
|
|
34
39
|
# TODO; all others... http://www.sql-server-helper.com/tips/date-formats.aspx
|
35
40
|
LOADED_VISITOR::DATE_CONVERT_FORMATS = {
|
36
41
|
'YYYY-MM-DD' => 120,
|
37
|
-
'YY-MM-DD'
|
42
|
+
'YY-MM-DD' => 120,
|
38
43
|
'MM/DD/YYYY' => 101,
|
39
44
|
'MM-DD-YYYY' => 110,
|
40
45
|
'YYYY/MM/DD' => 111,
|
@@ -46,63 +51,63 @@ module ArelExtensions
|
|
46
51
|
|
47
52
|
# Math Functions
|
48
53
|
def visit_ArelExtensions_Nodes_Ceil o, collector
|
49
|
-
collector <<
|
54
|
+
collector << 'CEILING('
|
50
55
|
collector = visit o.expr, collector
|
51
|
-
collector <<
|
56
|
+
collector << ')'
|
52
57
|
collector
|
53
58
|
end
|
54
59
|
|
55
60
|
def visit_ArelExtensions_Nodes_Log10 o, collector
|
56
|
-
|
61
|
+
collector << 'LOG10('
|
57
62
|
o.expressions.each_with_index { |arg, i|
|
58
63
|
collector << Arel::Visitors::ToSql::COMMA if i != 0
|
59
64
|
collector = visit arg, collector
|
60
65
|
}
|
61
|
-
collector <<
|
66
|
+
collector << ')'
|
62
67
|
collector
|
63
68
|
end
|
64
69
|
|
65
70
|
def visit_ArelExtensions_Nodes_Power o, collector
|
66
|
-
collector <<
|
71
|
+
collector << 'POWER('
|
67
72
|
o.expressions.each_with_index { |arg, i|
|
68
73
|
collector << Arel::Visitors::ToSql::COMMA if i != 0
|
69
74
|
collector = visit arg, collector
|
70
75
|
}
|
71
|
-
collector <<
|
76
|
+
collector << ')'
|
72
77
|
collector
|
73
78
|
end
|
74
79
|
|
75
80
|
def visit_ArelExtensions_Nodes_IsNull o, collector
|
76
|
-
collector <<
|
81
|
+
collector << '('
|
77
82
|
collector = visit o.expr, collector
|
78
|
-
collector <<
|
83
|
+
collector << ' IS NULL)'
|
79
84
|
collector
|
80
85
|
end
|
81
86
|
|
82
87
|
def visit_ArelExtensions_Nodes_IsNotNull o, collector
|
83
|
-
|
88
|
+
collector << '('
|
84
89
|
collector = visit o.expr, collector
|
85
|
-
collector <<
|
90
|
+
collector << ' IS NOT NULL)'
|
86
91
|
collector
|
87
92
|
end
|
88
93
|
|
89
94
|
def visit_ArelExtensions_Nodes_Concat o, collector
|
90
|
-
collector <<
|
95
|
+
collector << 'CONCAT('
|
91
96
|
o.expressions.each_with_index { |arg, i|
|
92
97
|
collector << LOADED_VISITOR::COMMA if i != 0
|
93
98
|
collector = visit arg, collector
|
94
99
|
}
|
95
|
-
collector <<
|
100
|
+
collector << ')'
|
96
101
|
collector
|
97
102
|
end
|
98
103
|
|
99
104
|
def visit_ArelExtensions_Nodes_Repeat o, collector
|
100
|
-
collector <<
|
105
|
+
collector << 'REPLICATE('
|
101
106
|
o.expressions.each_with_index { |arg, i|
|
102
107
|
collector << Arel::Visitors::ToSql::COMMA if i != 0
|
103
108
|
collector = visit arg, collector
|
104
109
|
}
|
105
|
-
collector <<
|
110
|
+
collector << ')'
|
106
111
|
collector
|
107
112
|
end
|
108
113
|
|
@@ -122,28 +127,28 @@ module ArelExtensions
|
|
122
127
|
collector << ')'
|
123
128
|
else
|
124
129
|
da = ArelExtensions::Nodes::DateAdd.new([])
|
125
|
-
collector <<
|
130
|
+
collector << 'DATEADD('
|
126
131
|
collector = visit da.mssql_datepart(o.right), collector
|
127
132
|
collector << LOADED_VISITOR::COMMA
|
128
|
-
collector <<
|
133
|
+
collector << '-('
|
129
134
|
collector = visit da.mssql_value(o.right), collector
|
130
|
-
collector <<
|
135
|
+
collector << ')'
|
131
136
|
collector << LOADED_VISITOR::COMMA
|
132
137
|
collector = visit o.left, collector
|
133
|
-
collector <<
|
138
|
+
collector << ')'
|
134
139
|
collector
|
135
140
|
end
|
136
141
|
collector
|
137
142
|
end
|
138
143
|
|
139
144
|
def visit_ArelExtensions_Nodes_DateAdd o, collector
|
140
|
-
collector <<
|
145
|
+
collector << 'DATEADD('
|
141
146
|
collector = visit o.mssql_datepart(o.right), collector
|
142
147
|
collector << LOADED_VISITOR::COMMA
|
143
148
|
collector = visit o.mssql_value(o.right), collector
|
144
149
|
collector << LOADED_VISITOR::COMMA
|
145
150
|
collector = visit o.left, collector
|
146
|
-
collector <<
|
151
|
+
collector << ')'
|
147
152
|
collector
|
148
153
|
end
|
149
154
|
|
@@ -152,54 +157,54 @@ module ArelExtensions
|
|
152
157
|
collector = visit o.right, collector
|
153
158
|
else
|
154
159
|
left = o.left.end_with?('i') ? o.left[0..-2] : o.left
|
155
|
-
conv = [
|
160
|
+
conv = %w[h mn s].include?(o.left)
|
156
161
|
collector << 'DATEPART('
|
157
162
|
collector << LOADED_VISITOR::DATE_MAPPING[left]
|
158
163
|
collector << LOADED_VISITOR::COMMA
|
159
164
|
collector << 'CONVERT(datetime,' if conv
|
160
165
|
collector = visit o.right, collector
|
161
166
|
collector << ')' if conv
|
162
|
-
collector <<
|
167
|
+
collector << ')'
|
163
168
|
end
|
164
169
|
collector
|
165
170
|
end
|
166
171
|
|
167
172
|
def visit_ArelExtensions_Nodes_Length o, collector
|
168
173
|
if o.bytewise
|
169
|
-
collector <<
|
174
|
+
collector << '(DATALENGTH('
|
170
175
|
collector = visit o.expr, collector
|
171
|
-
collector <<
|
176
|
+
collector << ') / ISNULL(NULLIF(DATALENGTH(LEFT(COALESCE('
|
172
177
|
collector = visit o.expr, collector
|
173
178
|
collector << ", '#' ), 1 )), 0), 1))"
|
174
179
|
collector
|
175
180
|
else
|
176
|
-
collector <<
|
181
|
+
collector << 'LEN('
|
177
182
|
collector = visit o.expr, collector
|
178
|
-
collector <<
|
183
|
+
collector << ')'
|
179
184
|
collector
|
180
185
|
end
|
181
186
|
end
|
182
187
|
|
183
188
|
def visit_ArelExtensions_Nodes_Round o, collector
|
184
|
-
collector <<
|
189
|
+
collector << 'ROUND('
|
185
190
|
o.expressions.each_with_index { |arg, i|
|
186
191
|
collector << LOADED_VISITOR::COMMA if i != 0
|
187
192
|
collector = visit arg, collector
|
188
193
|
}
|
189
194
|
if o.expressions.length == 1
|
190
195
|
collector << LOADED_VISITOR::COMMA
|
191
|
-
collector <<
|
196
|
+
collector << '0'
|
192
197
|
end
|
193
|
-
collector <<
|
198
|
+
collector << ')'
|
194
199
|
collector
|
195
200
|
end
|
196
201
|
|
197
202
|
def visit_ArelExtensions_Nodes_Locate o, collector
|
198
|
-
collector <<
|
203
|
+
collector << 'CHARINDEX('
|
199
204
|
collector = visit o.right, collector
|
200
205
|
collector << LOADED_VISITOR::COMMA
|
201
206
|
collector = visit o.left, collector
|
202
|
-
collector <<
|
207
|
+
collector << ')'
|
203
208
|
collector
|
204
209
|
end
|
205
210
|
|
@@ -215,17 +220,25 @@ module ArelExtensions
|
|
215
220
|
end
|
216
221
|
|
217
222
|
def visit_ArelExtensions_Nodes_Trim o, collector
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
+
# NOTE: in MSSQL's `blank`, o.right is the space char so we need to
|
224
|
+
# account for it.
|
225
|
+
if o.right && !/\A\s\Z/.match(o.right.expr)
|
226
|
+
collector << 'dbo.TrimChar('
|
227
|
+
collector = visit o.left, collector
|
228
|
+
collector << Arel::Visitors::MSSQL::COMMA
|
229
|
+
collector = visit o.right, collector
|
230
|
+
collector << ')'
|
231
|
+
else
|
232
|
+
collector << "LTRIM(RTRIM("
|
233
|
+
collector = visit o.left, collector
|
234
|
+
collector << "))"
|
235
|
+
end
|
223
236
|
collector
|
224
237
|
end
|
225
238
|
|
226
239
|
def visit_ArelExtensions_Nodes_Ltrim o, collector
|
227
240
|
if o.right
|
228
|
-
collector <<
|
241
|
+
collector << 'REPLACE(REPLACE(LTRIM(REPLACE(REPLACE('
|
229
242
|
collector = visit o.left, collector
|
230
243
|
collector << ", ' ', '~'), "
|
231
244
|
collector = visit o.right, collector
|
@@ -233,16 +246,16 @@ module ArelExtensions
|
|
233
246
|
collector = visit o.right, collector
|
234
247
|
collector << "), '~', ' ')"
|
235
248
|
else
|
236
|
-
collector <<
|
249
|
+
collector << 'LTRIM('
|
237
250
|
collector = visit o.left, collector
|
238
|
-
collector <<
|
251
|
+
collector << ')'
|
239
252
|
end
|
240
253
|
collector
|
241
254
|
end
|
242
255
|
|
243
256
|
def visit_ArelExtensions_Nodes_Rtrim o, collector
|
244
257
|
if o.right
|
245
|
-
collector <<
|
258
|
+
collector << 'REPLACE(REPLACE(RTRIM(REPLACE(REPLACE('
|
246
259
|
collector = visit o.left, collector
|
247
260
|
collector << ", ' ', '~'), "
|
248
261
|
collector = visit o.right, collector
|
@@ -250,9 +263,9 @@ module ArelExtensions
|
|
250
263
|
collector = visit o.right, collector
|
251
264
|
collector << "), '~', ' ')"
|
252
265
|
else
|
253
|
-
collector <<
|
266
|
+
collector << 'RTRIM('
|
254
267
|
collector = visit o.left, collector
|
255
|
-
collector <<
|
268
|
+
collector << ')'
|
256
269
|
end
|
257
270
|
collector
|
258
271
|
end
|
@@ -280,12 +293,12 @@ module ArelExtensions
|
|
280
293
|
when Hash
|
281
294
|
src_tz, dst_tz = o.time_zone.first
|
282
295
|
collector << ') AT TIME ZONE '
|
283
|
-
collector = visit Arel
|
296
|
+
collector = visit Arel.quoted(src_tz), collector
|
284
297
|
collector << ' AT TIME ZONE '
|
285
|
-
collector = visit Arel
|
298
|
+
collector = visit Arel.quoted(dst_tz), collector
|
286
299
|
when String
|
287
300
|
collector << ') AT TIME ZONE '
|
288
|
-
collector = visit Arel
|
301
|
+
collector = visit Arel.quoted(o.time_zone), collector
|
289
302
|
end
|
290
303
|
collector << LOADED_VISITOR::COMMA
|
291
304
|
collector << fmt.to_s
|
@@ -293,7 +306,7 @@ module ArelExtensions
|
|
293
306
|
collector
|
294
307
|
else
|
295
308
|
s = StringScanner.new o.iso_format
|
296
|
-
collector <<
|
309
|
+
collector << '('
|
297
310
|
sep = ''
|
298
311
|
while !s.eos?
|
299
312
|
collector << sep
|
@@ -302,10 +315,11 @@ module ArelExtensions
|
|
302
315
|
when s.scan(LOADED_VISITOR::DATE_FORMAT_REGEX)
|
303
316
|
dir = LOADED_VISITOR::DATE_FORMAT_DIRECTIVES[s.matched]
|
304
317
|
fmt = LOADED_VISITOR::DATE_FORMAT_FORMAT[dir]
|
305
|
-
|
318
|
+
date_name = LOADED_VISITOR::DATE_NAME.include?(s.matched)
|
319
|
+
collector << 'LTRIM(RTRIM('
|
306
320
|
collector << 'FORMAT(' if fmt
|
307
|
-
collector << 'STR(' if !fmt
|
308
|
-
collector << 'DATEPART('
|
321
|
+
collector << 'STR(' if !fmt && !date_name
|
322
|
+
collector << (date_name ? 'DATENAME(' : 'DATEPART(')
|
309
323
|
collector << dir
|
310
324
|
collector << LOADED_VISITOR::COMMA
|
311
325
|
if o.time_zone
|
@@ -317,22 +331,22 @@ module ArelExtensions
|
|
317
331
|
case o.time_zone
|
318
332
|
when Hash
|
319
333
|
src_tz, dst_tz = o.time_zone.first.first, o.time_zone.first.second
|
320
|
-
collector <<
|
321
|
-
collector = visit Arel
|
322
|
-
collector <<
|
323
|
-
collector = visit Arel
|
334
|
+
collector << ') AT TIME ZONE '
|
335
|
+
collector = visit Arel.quoted(src_tz), collector
|
336
|
+
collector << ' AT TIME ZONE '
|
337
|
+
collector = visit Arel.quoted(dst_tz), collector
|
324
338
|
when String
|
325
|
-
collector <<
|
326
|
-
collector = visit Arel
|
339
|
+
collector << ') AT TIME ZONE '
|
340
|
+
collector = visit Arel.quoted(o.time_zone), collector
|
327
341
|
end
|
328
342
|
collector << ')'
|
329
|
-
collector << ')' if !fmt
|
343
|
+
collector << ')' if !fmt && !date_name
|
330
344
|
collector << LOADED_VISITOR::COMMA << "'#{fmt}')" if fmt
|
331
|
-
collector << ')'
|
345
|
+
collector << '))'
|
332
346
|
when s.scan(/^%%/)
|
333
|
-
collector = visit Arel
|
347
|
+
collector = visit Arel.quoted('%'), collector
|
334
348
|
when s.scan(/[^%]+|./)
|
335
|
-
collector = visit Arel
|
349
|
+
collector = visit Arel.quoted(s.matched), collector
|
336
350
|
end
|
337
351
|
end
|
338
352
|
collector << ')'
|
@@ -341,22 +355,22 @@ module ArelExtensions
|
|
341
355
|
end
|
342
356
|
|
343
357
|
def visit_ArelExtensions_Nodes_Replace o, collector
|
344
|
-
collector <<
|
358
|
+
collector << 'REPLACE('
|
345
359
|
o.expressions.each_with_index { |arg, i|
|
346
360
|
collector << LOADED_VISITOR::COMMA if i != 0
|
347
361
|
collector = visit arg, collector
|
348
362
|
}
|
349
|
-
collector <<
|
363
|
+
collector << ')'
|
350
364
|
collector
|
351
365
|
end
|
352
366
|
|
353
367
|
def visit_ArelExtensions_Nodes_FindInSet o, collector
|
354
|
-
collector <<
|
368
|
+
collector << 'dbo.FIND_IN_SET('
|
355
369
|
o.expressions.each_with_index { |arg, i|
|
356
370
|
collector << LOADED_VISITOR::COMMA if i != 0
|
357
371
|
collector = visit arg, collector
|
358
372
|
}
|
359
|
-
collector <<
|
373
|
+
collector << ')'
|
360
374
|
collector
|
361
375
|
end
|
362
376
|
|
@@ -399,9 +413,9 @@ module ArelExtensions
|
|
399
413
|
end
|
400
414
|
|
401
415
|
def visit_ArelExtensions_Nodes_AiIMatches o, collector
|
402
|
-
collector = visit o.left.collate(true,true), collector
|
416
|
+
collector = visit o.left.collate(true, true), collector
|
403
417
|
collector << ' LIKE '
|
404
|
-
collector = visit o.right.collate(true,true), collector
|
418
|
+
collector = visit o.right.collate(true, true), collector
|
405
419
|
if o.escape
|
406
420
|
collector << ' ESCAPE '
|
407
421
|
visit o.escape, collector
|
@@ -448,7 +462,7 @@ module ArelExtensions
|
|
448
462
|
else
|
449
463
|
collector = visit o.left, collector
|
450
464
|
end
|
451
|
-
collector <<
|
465
|
+
collector << ' AS '
|
452
466
|
|
453
467
|
# sometimes these values are already quoted, if they are, don't double quote it
|
454
468
|
quote = o.right.is_a?(Arel::Nodes::SqlLiteral) && o.right[0] != '"' && o.right[-1] != '"'
|
@@ -475,108 +489,114 @@ module ArelExtensions
|
|
475
489
|
|
476
490
|
# TODO;
|
477
491
|
def visit_ArelExtensions_Nodes_GroupConcat o, collector
|
478
|
-
collector <<
|
492
|
+
collector << '(STRING_AGG('
|
479
493
|
collector = visit o.left, collector
|
480
494
|
collector << Arel::Visitors::Oracle::COMMA
|
481
495
|
collector =
|
482
496
|
if o.separator && o.separator != 'NULL'
|
483
497
|
visit o.separator, collector
|
484
498
|
else
|
485
|
-
visit Arel
|
499
|
+
visit Arel.quoted(','), collector
|
486
500
|
end
|
487
|
-
collector <<
|
501
|
+
collector << ') WITHIN GROUP (ORDER BY '
|
488
502
|
if o.order.present?
|
489
|
-
o.order.each_with_index do |order,i|
|
503
|
+
o.order.each_with_index do |order, i|
|
490
504
|
collector << Arel::Visitors::Oracle::COMMA if i != 0
|
491
505
|
collector = visit order, collector
|
492
506
|
end
|
493
507
|
else
|
494
508
|
collector = visit o.left, collector
|
495
509
|
end
|
496
|
-
collector <<
|
510
|
+
collector << '))'
|
497
511
|
collector
|
498
512
|
end
|
499
513
|
|
500
514
|
def visit_ArelExtensions_Nodes_MD5 o, collector
|
501
515
|
collector << "LOWER(CONVERT(NVARCHAR(32),HashBytes('MD5',CONVERT(VARCHAR,"
|
502
516
|
collector = visit o.left, collector
|
503
|
-
collector <<
|
517
|
+
collector << ')),2))'
|
504
518
|
collector
|
505
519
|
end
|
506
520
|
|
507
521
|
def visit_ArelExtensions_Nodes_Cast o, collector
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
522
|
+
as_attr =
|
523
|
+
case o.as_attr
|
524
|
+
when :string
|
525
|
+
'varchar'
|
526
|
+
when :time
|
527
|
+
'time'
|
528
|
+
when :date
|
529
|
+
'date'
|
530
|
+
when :datetime
|
531
|
+
'datetime'
|
532
|
+
when :number, :decimal, :float
|
533
|
+
'decimal(10,6)'
|
534
|
+
when :int
|
535
|
+
collector << 'CAST(CAST('
|
536
|
+
collector = visit o.left, collector
|
537
|
+
collector << ' AS decimal(10,0)) AS int)'
|
538
|
+
return collector
|
539
|
+
when :binary
|
540
|
+
'binary'
|
541
|
+
else
|
542
|
+
o.as_attr.to_s
|
543
|
+
end
|
544
|
+
collector << 'CAST('
|
530
545
|
collector = visit o.left, collector
|
531
|
-
collector <<
|
532
|
-
collector = visit as_attr, collector
|
533
|
-
collector <<
|
546
|
+
collector << ' AS '
|
547
|
+
collector = visit Arel::Nodes::SqlLiteral.new(as_attr), collector
|
548
|
+
collector << ')'
|
534
549
|
collector
|
535
550
|
end
|
536
551
|
|
537
552
|
def visit_ArelExtensions_Nodes_FormattedNumber o, collector
|
538
553
|
col = o.left.coalesce(0)
|
539
|
-
locale = Arel
|
540
|
-
param = Arel
|
541
|
-
sign =
|
554
|
+
locale = Arel.quoted(o.locale.tr('_', '-'))
|
555
|
+
param = Arel.quoted("N#{o.precision}")
|
556
|
+
sign = Arel.when(col < 0).
|
542
557
|
then('-').
|
543
558
|
else(o.flags.include?('+') ? '+' : (o.flags.include?(' ') ? ' ' : ''))
|
544
559
|
sign_length = o.flags.include?('+') || o.flags.include?(' ') ?
|
545
|
-
Arel
|
546
|
-
|
560
|
+
Arel.quoted(1) :
|
561
|
+
Arel.when(col < 0).then(1).else(0)
|
547
562
|
|
548
563
|
number =
|
549
564
|
if o.scientific_notation
|
550
565
|
ArelExtensions::Nodes::Concat.new([
|
551
|
-
Arel::Nodes::NamedFunction.new('FORMAT',[
|
552
|
-
col.abs/Arel
|
566
|
+
Arel::Nodes::NamedFunction.new('FORMAT', [
|
567
|
+
col.abs / Arel.quoted(10).pow(col.abs.log10.floor),
|
553
568
|
param,
|
554
569
|
locale
|
555
570
|
]),
|
556
571
|
o.type,
|
557
|
-
Arel::Nodes::NamedFunction.new('FORMAT',[
|
572
|
+
Arel::Nodes::NamedFunction.new('FORMAT', [
|
558
573
|
col.abs.log10.floor,
|
559
|
-
Arel
|
574
|
+
Arel.quoted('N0'),
|
560
575
|
locale
|
561
576
|
])
|
562
577
|
])
|
563
578
|
else
|
564
|
-
Arel::Nodes::NamedFunction.new('FORMAT',[
|
565
|
-
Arel
|
579
|
+
Arel::Nodes::NamedFunction.new('FORMAT', [
|
580
|
+
Arel.quoted(col.abs),
|
566
581
|
param,
|
567
582
|
locale
|
568
583
|
])
|
569
584
|
end
|
570
585
|
|
571
|
-
repeated_char =
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
586
|
+
repeated_char =
|
587
|
+
if o.width == 0
|
588
|
+
Arel.quoted('')
|
589
|
+
else
|
590
|
+
Arel
|
591
|
+
.when(Arel.quoted(o.width).abs - (number.length + sign_length) > 0)
|
592
|
+
.then(Arel.quoted(
|
593
|
+
o.flags.include?('-') ? ' ' : (o.flags.include?('0') ? '0' : ' ')
|
594
|
+
).repeat(Arel.quoted(o.width).abs - (number.length + sign_length))
|
595
|
+
)
|
596
|
+
.else('')
|
597
|
+
end
|
598
|
+
before = !o.flags.include?('0') && !o.flags.include?('-') ? repeated_char : ''
|
599
|
+
middle = o.flags.include?('0') && !o.flags.include?('-') ? repeated_char : ''
|
580
600
|
after = o.flags.include?('-') ? repeated_char : ''
|
581
601
|
full_number =
|
582
602
|
ArelExtensions::Nodes::Concat.new([
|
@@ -586,27 +606,27 @@ module ArelExtensions
|
|
586
606
|
number,
|
587
607
|
after
|
588
608
|
])
|
589
|
-
collector = visit ArelExtensions::Nodes::Concat.new([Arel
|
609
|
+
collector = visit ArelExtensions::Nodes::Concat.new([Arel.quoted(o.prefix), full_number, Arel.quoted(o.suffix)]), collector
|
590
610
|
collector
|
591
611
|
end
|
592
612
|
|
593
613
|
def visit_ArelExtensions_Nodes_Std o, collector
|
594
|
-
collector << (o.unbiased_estimator ?
|
614
|
+
collector << (o.unbiased_estimator ? 'STDEV(' : 'STDEVP(')
|
595
615
|
visit o.left, collector
|
596
|
-
collector <<
|
616
|
+
collector << ')'
|
597
617
|
collector
|
598
618
|
end
|
599
619
|
|
600
620
|
def visit_ArelExtensions_Nodes_Variance o, collector
|
601
|
-
collector << (o.unbiased_estimator ?
|
621
|
+
collector << (o.unbiased_estimator ? 'VAR(' : 'VARP(')
|
602
622
|
visit o.left, collector
|
603
|
-
collector <<
|
623
|
+
collector << ')'
|
604
624
|
collector
|
605
625
|
end
|
606
626
|
|
607
627
|
|
608
628
|
def visit_ArelExtensions_Nodes_LevenshteinDistance o, collector
|
609
|
-
collector <<
|
629
|
+
collector << 'dbo.LEVENSHTEIN_DISTANCE('
|
610
630
|
collector = visit o.left, collector
|
611
631
|
collector << Arel::Visitors::ToSql::COMMA
|
612
632
|
collector = visit o.right, collector
|
@@ -615,14 +635,14 @@ module ArelExtensions
|
|
615
635
|
end
|
616
636
|
|
617
637
|
|
618
|
-
def visit_ArelExtensions_Nodes_JsonGet o,collector
|
638
|
+
def visit_ArelExtensions_Nodes_JsonGet o, collector
|
619
639
|
collector << 'JSON_VALUE('
|
620
640
|
collector = visit o.dict, collector
|
621
641
|
collector << Arel::Visitors::MySQL::COMMA
|
622
642
|
if o.key.is_a?(Integer)
|
623
643
|
collector << "\"$[#{o.key}]\""
|
624
644
|
else
|
625
|
-
collector = visit Arel
|
645
|
+
collector = visit Arel.quoted('$.') + o.key, collector
|
626
646
|
end
|
627
647
|
collector << ')'
|
628
648
|
collector
|