arel_extensions 1.4.0 → 2.0.0.rc3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +2 -1
- data/.gitignore +6 -7
- data/.rubocop.yml +3 -67
- data/.travis/oracle/download.js +152 -0
- data/.travis/oracle/download.sh +30 -0
- data/.travis/oracle/download_ojdbc.js +116 -0
- data/.travis/oracle/install.sh +34 -0
- data/.travis/setup_accounts.sh +9 -0
- data/.travis/sqlite3/extension-functions.sh +6 -0
- data/.travis.yml +223 -0
- data/Gemfile +28 -2
- data/README.md +90 -239
- data/Rakefile +30 -48
- data/TODO +1 -0
- data/appveyor.yml +22 -60
- data/arel_extensions.gemspec +14 -13
- data/functions.html +3 -3
- data/gemfiles/rails3.gemfile +10 -10
- data/gemfiles/rails4.gemfile +29 -0
- data/gemfiles/rails5_0.gemfile +29 -0
- data/gemfiles/rails5_1_4.gemfile +14 -14
- data/gemfiles/rails5_2.gemfile +14 -16
- data/init/mssql.sql +4 -4
- data/init/mysql.sql +38 -38
- data/init/oracle.sql +0 -0
- data/init/postgresql.sql +21 -21
- data/init/sqlite.sql +0 -0
- data/lib/arel_extensions/attributes.rb +3 -15
- data/lib/arel_extensions/boolean_functions.rb +14 -53
- data/lib/arel_extensions/common_sql_functions.rb +17 -16
- data/lib/arel_extensions/comparators.rb +28 -27
- data/lib/arel_extensions/date_duration.rb +13 -17
- data/lib/arel_extensions/insert_manager.rb +15 -18
- data/lib/arel_extensions/math.rb +53 -55
- data/lib/arel_extensions/math_functions.rb +39 -46
- data/lib/arel_extensions/nodes/abs.rb +1 -0
- data/lib/arel_extensions/nodes/blank.rb +2 -1
- data/lib/arel_extensions/nodes/case.rb +19 -20
- data/lib/arel_extensions/nodes/cast.rb +8 -10
- data/lib/arel_extensions/nodes/ceil.rb +1 -1
- data/lib/arel_extensions/nodes/coalesce.rb +4 -3
- data/lib/arel_extensions/nodes/collate.rb +10 -9
- data/lib/arel_extensions/nodes/concat.rb +18 -9
- data/lib/arel_extensions/nodes/date_diff.rb +26 -42
- data/lib/arel_extensions/nodes/duration.rb +3 -0
- data/lib/arel_extensions/nodes/find_in_set.rb +1 -0
- data/lib/arel_extensions/nodes/floor.rb +1 -1
- data/lib/arel_extensions/nodes/format.rb +8 -35
- data/lib/arel_extensions/nodes/formatted_number.rb +23 -22
- data/lib/arel_extensions/nodes/function.rb +37 -42
- data/lib/arel_extensions/nodes/is_null.rb +0 -0
- data/lib/arel_extensions/nodes/json.rb +39 -52
- data/lib/arel_extensions/nodes/length.rb +0 -5
- data/lib/arel_extensions/nodes/levenshtein_distance.rb +1 -1
- data/lib/arel_extensions/nodes/locate.rb +2 -1
- data/lib/arel_extensions/nodes/log10.rb +2 -1
- data/lib/arel_extensions/nodes/matches.rb +7 -5
- data/lib/arel_extensions/nodes/md5.rb +1 -0
- data/lib/arel_extensions/nodes/power.rb +5 -5
- data/lib/arel_extensions/nodes/rand.rb +1 -0
- data/lib/arel_extensions/nodes/repeat.rb +5 -3
- data/lib/arel_extensions/nodes/replace.rb +8 -16
- data/lib/arel_extensions/nodes/round.rb +6 -5
- data/lib/arel_extensions/nodes/soundex.rb +15 -15
- data/lib/arel_extensions/nodes/std.rb +21 -18
- data/lib/arel_extensions/nodes/substring.rb +16 -8
- data/lib/arel_extensions/nodes/then.rb +1 -1
- data/lib/arel_extensions/nodes/trim.rb +6 -4
- data/lib/arel_extensions/nodes/union.rb +8 -5
- data/lib/arel_extensions/nodes/union_all.rb +7 -4
- data/lib/arel_extensions/nodes/wday.rb +4 -0
- data/lib/arel_extensions/nodes.rb +1 -1
- data/lib/arel_extensions/null_functions.rb +5 -19
- data/lib/arel_extensions/predications.rb +43 -44
- data/lib/arel_extensions/railtie.rb +5 -5
- data/lib/arel_extensions/set_functions.rb +7 -5
- data/lib/arel_extensions/string_functions.rb +29 -59
- data/lib/arel_extensions/tasks.rb +6 -6
- data/lib/arel_extensions/version.rb +1 -1
- data/lib/arel_extensions/visitors/ibm_db.rb +31 -24
- data/lib/arel_extensions/visitors/mssql.rb +191 -422
- data/lib/arel_extensions/visitors/mysql.rb +212 -350
- data/lib/arel_extensions/visitors/oracle.rb +178 -220
- data/lib/arel_extensions/visitors/oracle12.rb +31 -18
- data/lib/arel_extensions/visitors/postgresql.rb +173 -256
- data/lib/arel_extensions/visitors/sqlite.rb +126 -140
- data/lib/arel_extensions/visitors/to_sql.rb +237 -298
- data/lib/arel_extensions/visitors.rb +62 -83
- data/lib/arel_extensions.rb +31 -224
- data/test/database.yml +7 -15
- data/test/helper.rb +18 -0
- data/test/real_db_test.rb +117 -120
- data/test/support/fake_record.rb +3 -9
- data/test/test_comparators.rb +17 -14
- data/test/visitors/test_bulk_insert_oracle.rb +11 -11
- data/test/visitors/test_bulk_insert_sqlite.rb +13 -12
- data/test/visitors/test_bulk_insert_to_sql.rb +13 -11
- data/test/visitors/test_oracle.rb +55 -55
- data/test/visitors/test_to_sql.rb +226 -419
- data/test/with_ar/all_agnostic_test.rb +366 -709
- data/test/with_ar/insert_agnostic_test.rb +21 -27
- data/test/with_ar/test_bulk_sqlite.rb +16 -17
- data/test/with_ar/test_math_sqlite.rb +26 -26
- data/test/with_ar/test_string_mysql.rb +33 -31
- data/test/with_ar/test_string_sqlite.rb +34 -30
- metadata +34 -43
- data/.github/workflows/publish.yml +0 -29
- data/.github/workflows/release.yml +0 -30
- data/.github/workflows/ruby.yml +0 -399
- data/CONTRIBUTING.md +0 -102
- data/NEWS.md +0 -78
- data/bin/build +0 -15
- data/bin/compose +0 -6
- data/bin/publish +0 -8
- data/dev/arelx.dockerfile +0 -44
- data/dev/compose.yaml +0 -71
- data/dev/postgres.dockerfile +0 -5
- data/dev/rbenv +0 -189
- data/gemfiles/rails4_2.gemfile +0 -38
- data/gemfiles/rails5.gemfile +0 -29
- data/gemfiles/rails6.gemfile +0 -33
- data/gemfiles/rails6_1.gemfile +0 -33
- data/gemfiles/rails7.gemfile +0 -33
- data/gemfiles/rails7_1.gemfile +0 -33
- data/gemfiles/rails7_2.gemfile +0 -33
- data/gemspecs/arel_extensions-v1.gemspec +0 -27
- data/gemspecs/arel_extensions-v2.gemspec +0 -27
- data/generate_gems.sh +0 -15
- data/lib/arel_extensions/aliases.rb +0 -14
- data/lib/arel_extensions/helpers.rb +0 -62
- data/lib/arel_extensions/nodes/aggregate_function.rb +0 -13
- data/lib/arel_extensions/nodes/formatted_date.rb +0 -42
- data/lib/arel_extensions/nodes/rollup.rb +0 -36
- data/lib/arel_extensions/nodes/select.rb +0 -10
- data/lib/arel_extensions/nodes/sum.rb +0 -7
- data/lib/arel_extensions/visitors/convert_format.rb +0 -37
- data/test/arelx_test_helper.rb +0 -74
- data/version_v1.rb +0 -3
- data/version_v2.rb +0 -3
@@ -1,23 +1,16 @@
|
|
1
1
|
module ArelExtensions
|
2
2
|
module Visitors
|
3
|
-
|
4
|
-
DATE_MAPPING = {
|
5
|
-
|
6
|
-
'h' => '%H', 'mn' => '%M', 's' => '%S'
|
7
|
-
}.freeze
|
8
|
-
|
9
|
-
DATE_FORMAT_DIRECTIVES = { # ISO C / POSIX
|
3
|
+
Arel::Visitors::SQLite.class_eval do
|
4
|
+
Arel::Visitors::SQLite::DATE_MAPPING = {'d' => '%d', 'm' => '%m', 'w' => '%W', 'y' => '%Y', 'wd' => '%w', 'M' => '%M', 'h' => '%H', 'mn' => '%M', 's' => '%S'}
|
5
|
+
Arel::Visitors::SQLite::DATE_FORMAT_DIRECTIVES = { # ISO C / POSIX
|
10
6
|
'%Y' => '%Y', '%C' => '', '%y' => '%y', '%m' => '%m', '%B' => '%M', '%b' => '%b', '%^b' => '%b', # year, month
|
11
7
|
'%d' => '%d', '%e' => '%e', '%j' => '%j', '%w' => '%w', '%A' => '%W', # day, weekday
|
12
8
|
'%H' => '%H', '%k' => '%k', '%I' => '%I', '%l' => '%l', '%P' => '%p', '%p' => '%p', # hours
|
13
9
|
'%M' => '%M', '%S' => '%S', '%L' => '', '%N' => '%f', '%z' => '' # seconds, subseconds
|
14
|
-
}
|
15
|
-
|
16
|
-
NUMBER_COMMA_MAPPING = {
|
17
|
-
'fr_FR' => {',' => ' ', '.' => ','}
|
18
|
-
}.freeze
|
10
|
+
}
|
11
|
+
Arel::Visitors::SQLite::NUMBER_COMMA_MAPPING = { 'fr_FR' => {',' => ' ','.' =>','} }
|
19
12
|
|
20
|
-
#
|
13
|
+
#String functions
|
21
14
|
def visit_ArelExtensions_Nodes_IMatches o, collector # insensitive on ASCII
|
22
15
|
collector = visit o.left.ci_collate, collector
|
23
16
|
collector << ' LIKE '
|
@@ -31,27 +24,27 @@ module ArelExtensions
|
|
31
24
|
end
|
32
25
|
|
33
26
|
def visit_ArelExtensions_Nodes_AiMatches o, collector
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
27
|
+
collector = visit o.left.ai_collate, collector
|
28
|
+
collector << ' LIKE '
|
29
|
+
collector = visit o.right.ai_collate, collector
|
30
|
+
if o.escape
|
31
|
+
collector << ' ESCAPE '
|
32
|
+
visit o.escape, collector
|
33
|
+
else
|
34
|
+
collector
|
35
|
+
end
|
43
36
|
end
|
44
37
|
|
45
38
|
def visit_ArelExtensions_Nodes_AiIMatches o, collector
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
39
|
+
collector = visit o.left.collate(true,true), collector
|
40
|
+
collector << ' LIKE '
|
41
|
+
collector = visit o.right.collate(true,true), collector
|
42
|
+
if o.escape
|
43
|
+
collector << ' ESCAPE '
|
44
|
+
visit o.escape, collector
|
45
|
+
else
|
46
|
+
collector
|
47
|
+
end
|
55
48
|
end
|
56
49
|
|
57
50
|
def visit_ArelExtensions_Nodes_SMatches o, collector
|
@@ -80,6 +73,7 @@ module ArelExtensions
|
|
80
73
|
collector
|
81
74
|
end
|
82
75
|
|
76
|
+
|
83
77
|
def visit_ArelExtensions_Nodes_IDoesNotMatch o, collector
|
84
78
|
collector = visit o.left.lower, collector
|
85
79
|
collector << ' NOT LIKE '
|
@@ -94,44 +88,44 @@ module ArelExtensions
|
|
94
88
|
|
95
89
|
# Date operations
|
96
90
|
def visit_ArelExtensions_Nodes_DateAdd o, collector
|
97
|
-
collector <<
|
91
|
+
collector << "date("
|
98
92
|
collector = visit o.expressions.first, collector
|
99
|
-
collector << COMMA
|
93
|
+
collector << Arel::Visitors::SQLite::COMMA
|
100
94
|
collector = visit o.sqlite_value, collector
|
101
|
-
collector <<
|
95
|
+
collector << ")"
|
102
96
|
collector
|
103
97
|
end
|
104
98
|
|
105
99
|
def visit_ArelExtensions_Nodes_DateDiff o, collector
|
106
|
-
|
107
|
-
when :ruby_time, :datetime, :time
|
100
|
+
if o.left_node_type == :ruby_time || o.left_node_type == :datetime || o.left_node_type == :time
|
108
101
|
collector << "strftime('%s', "
|
109
102
|
collector = visit o.left, collector
|
110
103
|
collector << ") - strftime('%s', "
|
111
104
|
collector = visit o.right, collector
|
112
105
|
else
|
113
|
-
collector <<
|
106
|
+
collector << "julianday("
|
114
107
|
collector = visit o.left, collector
|
115
|
-
collector <<
|
108
|
+
collector << ") - julianday("
|
116
109
|
collector = visit o.right, collector
|
117
110
|
end
|
118
|
-
collector <<
|
111
|
+
collector << ")"
|
119
112
|
collector
|
120
113
|
end
|
121
114
|
|
122
115
|
def visit_ArelExtensions_Nodes_Duration o, collector
|
123
|
-
collector << "strftime('#{DATE_MAPPING[o.left]}'#{COMMA}"
|
116
|
+
collector << "strftime('#{Arel::Visitors::SQLite::DATE_MAPPING[o.left]}'#{Arel::Visitors::SQLite::COMMA}"
|
124
117
|
collector = visit o.right, collector
|
125
|
-
collector <<
|
118
|
+
collector << ")"
|
126
119
|
collector
|
127
120
|
end
|
128
121
|
|
122
|
+
|
129
123
|
def visit_ArelExtensions_Nodes_Locate o, collector
|
130
|
-
collector <<
|
124
|
+
collector << "instr("
|
131
125
|
collector = visit o.expr, collector
|
132
|
-
collector << COMMA
|
126
|
+
collector << Arel::Visitors::SQLite::COMMA
|
133
127
|
collector = visit o.right, collector
|
134
|
-
collector <<
|
128
|
+
collector << ")"
|
135
129
|
collector
|
136
130
|
end
|
137
131
|
|
@@ -141,17 +135,17 @@ module ArelExtensions
|
|
141
135
|
collector = visit arg, collector
|
142
136
|
collector << ' || ' unless i == o.expressions.length - 1
|
143
137
|
}
|
144
|
-
collector <<
|
138
|
+
collector << ")"
|
145
139
|
collector
|
146
140
|
end
|
147
141
|
|
148
142
|
def visit_ArelExtensions_Nodes_Substring o, collector
|
149
|
-
collector <<
|
143
|
+
collector << "SUBSTR("
|
150
144
|
o.expressions.each_with_index { |arg, i|
|
151
|
-
collector << COMMA
|
145
|
+
collector << Arel::Visitors::SQLite::COMMA unless i == 0
|
152
146
|
collector = visit arg, collector
|
153
147
|
}
|
154
|
-
collector <<
|
148
|
+
collector << ")"
|
155
149
|
collector
|
156
150
|
end
|
157
151
|
|
@@ -162,32 +156,32 @@ module ArelExtensions
|
|
162
156
|
end
|
163
157
|
|
164
158
|
def visit_ArelExtensions_Nodes_IsNotNull o, collector
|
165
|
-
|
159
|
+
collector = visit o.expr, collector
|
166
160
|
collector << ' IS NOT NULL'
|
167
161
|
collector
|
168
162
|
end
|
169
163
|
|
170
164
|
def visit_ArelExtensions_Nodes_Rand o, collector
|
171
|
-
collector <<
|
165
|
+
collector << "RANDOM("
|
172
166
|
if o.left != nil && o.right != nil
|
173
167
|
collector = visit o.left, collector
|
174
|
-
collector << COMMA
|
168
|
+
collector << Arel::Visitors::SQLite::COMMA
|
175
169
|
collector = visit o.right, collector
|
176
170
|
end
|
177
|
-
collector <<
|
171
|
+
collector << ")"
|
178
172
|
collector
|
179
173
|
end
|
180
174
|
|
181
175
|
def visit_Arel_Nodes_Regexp o, collector
|
182
176
|
collector = visit o.left, collector
|
183
|
-
collector <<
|
177
|
+
collector << " REGEXP"
|
184
178
|
collector = visit o.right, collector
|
185
179
|
collector
|
186
180
|
end
|
187
181
|
|
188
182
|
def visit_Arel_Nodes_NotRegexp o, collector
|
189
183
|
collector = visit o.left, collector
|
190
|
-
collector <<
|
184
|
+
collector << " NOT REGEXP "
|
191
185
|
collector = visit o.right, collector
|
192
186
|
collector
|
193
187
|
end
|
@@ -195,45 +189,35 @@ module ArelExtensions
|
|
195
189
|
def visit_ArelExtensions_Nodes_Wday o, collector
|
196
190
|
collector << "STRFTIME('%w',"
|
197
191
|
collector = visit o.date, collector
|
198
|
-
collector <<
|
192
|
+
collector << ")"
|
199
193
|
collector
|
200
194
|
end
|
201
195
|
|
202
|
-
#
|
203
|
-
#
|
204
|
-
# WHEN 3.42 >= 0 THEN CAST(3.42 AS INT)
|
205
|
-
# WHEN CAST(3.42 AS INT) = 3.42 THEN CAST(3.42 AS INT)
|
206
|
-
# ELSE CAST((3.42 - 1.0) AS INT)
|
207
|
-
# END
|
208
|
-
# AS FLOAT
|
209
|
-
# )
|
196
|
+
# CASE WHEN ROUND(3.42,1) > round(3.42) THEN round(3.42) ELSE round(3.42)-1 END
|
197
|
+
# OR CAST(3.14 AS INTEGER)
|
210
198
|
def visit_ArelExtensions_Nodes_Floor o, collector
|
211
|
-
collector <<
|
212
|
-
collector = visit o.left, collector
|
213
|
-
collector << ' >= 0 THEN CAST('
|
199
|
+
collector << "CASE WHEN ROUND("
|
214
200
|
collector = visit o.left, collector
|
215
|
-
collector <<
|
201
|
+
collector << ", 1) > ROUND("
|
216
202
|
collector = visit o.left, collector
|
217
|
-
collector <<
|
203
|
+
collector << ") THEN ROUND("
|
218
204
|
collector = visit o.left, collector
|
219
|
-
collector <<
|
205
|
+
collector << ") ELSE ROUND("
|
220
206
|
collector = visit o.left, collector
|
221
|
-
collector <<
|
222
|
-
collector = visit o.left, collector
|
223
|
-
collector << ' - 1.0) AS INT) END AS FLOAT)'
|
207
|
+
collector << ") - 1 END"
|
224
208
|
collector
|
225
209
|
end
|
226
210
|
|
227
211
|
def visit_ArelExtensions_Nodes_Ceil o, collector
|
228
|
-
collector <<
|
212
|
+
collector << "CASE WHEN ROUND("
|
229
213
|
collector = visit o.left, collector
|
230
|
-
collector <<
|
214
|
+
collector << ", 1) > ROUND("
|
231
215
|
collector = visit o.left, collector
|
232
|
-
collector <<
|
216
|
+
collector << ") THEN ROUND("
|
233
217
|
collector = visit o.left, collector
|
234
|
-
collector <<
|
218
|
+
collector << ") + 1 ELSE ROUND("
|
235
219
|
collector = visit o.left, collector
|
236
|
-
collector <<
|
220
|
+
collector << ") END"
|
237
221
|
collector
|
238
222
|
end
|
239
223
|
|
@@ -241,19 +225,20 @@ module ArelExtensions
|
|
241
225
|
def visit_ArelExtensions_InsertManager_BulkValues o, collector
|
242
226
|
o.left.each_with_index do |row, idx|
|
243
227
|
collector << 'SELECT '
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
228
|
+
v = Arel::Nodes::Values.new(row, o.cols)
|
229
|
+
len = v.expressions.length - 1
|
230
|
+
v.expressions.zip(v.columns).each_with_index { |(value, attr), i|
|
231
|
+
case value
|
232
|
+
when Arel::Nodes::SqlLiteral, Arel::Nodes::BindParam
|
233
|
+
collector = visit value.as(attr.name), collector
|
234
|
+
else
|
235
|
+
collector << quote(value, attr && column_for(attr)).to_s
|
236
|
+
if idx == 0
|
237
|
+
collector << " AS "
|
238
|
+
collector << quote(attr.name)
|
239
|
+
end
|
254
240
|
end
|
255
|
-
|
256
|
-
collector << COMMA unless i == len
|
241
|
+
collector << Arel::Visitors::SQLite::COMMA unless i == len
|
257
242
|
}
|
258
243
|
collector << ' UNION ALL ' unless idx == o.left.length - 1
|
259
244
|
end
|
@@ -264,24 +249,19 @@ module ArelExtensions
|
|
264
249
|
o.left.each_with_index do |row, idx|
|
265
250
|
collector << 'SELECT '
|
266
251
|
len = row.length - 1
|
267
|
-
row.
|
252
|
+
row.each_with_index { |value, i|
|
253
|
+
attr = o.cols[i]
|
268
254
|
case value
|
269
255
|
when Arel::Nodes::SqlLiteral, Arel::Nodes::BindParam
|
270
256
|
collector = visit value.as(attr.name), collector
|
271
|
-
when Integer
|
272
|
-
collector << value.to_s
|
273
|
-
if idx == 0
|
274
|
-
collector << ' AS '
|
275
|
-
collector << quote(attr.name)
|
276
|
-
end
|
277
257
|
else
|
278
258
|
collector << (attr && attr.able_to_type_cast? ? quote(attr.type_cast_for_database(value)) : quote(value).to_s)
|
279
259
|
if idx == 0
|
280
|
-
collector <<
|
260
|
+
collector << " AS "
|
281
261
|
collector << quote(attr.name)
|
282
262
|
end
|
283
263
|
end
|
284
|
-
|
264
|
+
collector << Arel::Visitors::SQLite::COMMA unless i == len
|
285
265
|
}
|
286
266
|
collector << ' UNION ALL ' unless idx == o.left.length - 1
|
287
267
|
end
|
@@ -290,58 +270,54 @@ module ArelExtensions
|
|
290
270
|
end
|
291
271
|
|
292
272
|
def visit_ArelExtensions_Nodes_Union o, collector
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
visit o.right, collector
|
305
|
-
end
|
273
|
+
if o.left.is_a?(Arel::SelectManager)
|
274
|
+
collector = visit o.left.ast, collector
|
275
|
+
else
|
276
|
+
collector = visit o.left, collector
|
277
|
+
end
|
278
|
+
collector << " UNION "
|
279
|
+
if o.right.is_a?(Arel::SelectManager)
|
280
|
+
collector = visit o.right.ast, collector
|
281
|
+
else
|
282
|
+
collector = visit o.right, collector
|
283
|
+
end
|
306
284
|
collector
|
307
285
|
end
|
308
286
|
|
309
287
|
def visit_ArelExtensions_Nodes_UnionAll o, collector
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
visit o.right, collector
|
322
|
-
end
|
288
|
+
if o.left.is_a?(Arel::SelectManager)
|
289
|
+
collector = visit o.left.ast, collector
|
290
|
+
else
|
291
|
+
collector = visit o.left, collector
|
292
|
+
end
|
293
|
+
collector << " UNION ALL "
|
294
|
+
if o.right.is_a?(Arel::SelectManager)
|
295
|
+
collector = visit o.right.ast, collector
|
296
|
+
else
|
297
|
+
collector = visit o.right, collector
|
298
|
+
end
|
323
299
|
collector
|
324
300
|
end
|
325
301
|
|
326
302
|
def get_time_converted element
|
327
303
|
if element.is_a?(Time)
|
328
|
-
Arel::Nodes::NamedFunction.new('STRFTIME',
|
304
|
+
return Arel::Nodes::NamedFunction.new('STRFTIME',[element, '%H:%M:%S'])
|
329
305
|
elsif element.is_a?(Arel::Attributes::Attribute)
|
330
|
-
col = Arel.
|
306
|
+
col = Arel::Table.engine.connection.schema_cache.columns_hash(element.relation.table_name)[element.name.to_s]
|
331
307
|
if col && (col.type == :time)
|
332
|
-
Arel::Nodes::NamedFunction.new('STRFTIME',
|
308
|
+
return Arel::Nodes::NamedFunction.new('STRFTIME',[element, '%H:%M:%S'])
|
333
309
|
else
|
334
|
-
element
|
310
|
+
return element
|
335
311
|
end
|
336
312
|
else
|
337
|
-
element
|
313
|
+
return element
|
338
314
|
end
|
339
315
|
end
|
340
316
|
|
341
317
|
remove_method(:visit_Arel_Nodes_GreaterThanOrEqual) rescue nil
|
342
318
|
def visit_Arel_Nodes_GreaterThanOrEqual o, collector
|
343
319
|
collector = visit get_time_converted(o.left), collector
|
344
|
-
collector <<
|
320
|
+
collector << " >= "
|
345
321
|
collector = visit get_time_converted(o.right), collector
|
346
322
|
collector
|
347
323
|
end
|
@@ -349,7 +325,7 @@ module ArelExtensions
|
|
349
325
|
remove_method(:visit_Arel_Nodes_GreaterThan) rescue nil
|
350
326
|
def visit_Arel_Nodes_GreaterThan o, collector
|
351
327
|
collector = visit get_time_converted(o.left), collector
|
352
|
-
collector <<
|
328
|
+
collector << " > "
|
353
329
|
collector = visit get_time_converted(o.right), collector
|
354
330
|
collector
|
355
331
|
end
|
@@ -357,7 +333,7 @@ module ArelExtensions
|
|
357
333
|
remove_method(:visit_Arel_Nodes_LessThanOrEqual) rescue nil
|
358
334
|
def visit_Arel_Nodes_LessThanOrEqual o, collector
|
359
335
|
collector = visit get_time_converted(o.left), collector
|
360
|
-
collector <<
|
336
|
+
collector << " <= "
|
361
337
|
collector = visit get_time_converted(o.right), collector
|
362
338
|
collector
|
363
339
|
end
|
@@ -365,12 +341,22 @@ module ArelExtensions
|
|
365
341
|
remove_method(:visit_Arel_Nodes_LessThan) rescue nil
|
366
342
|
def visit_Arel_Nodes_LessThan o, collector
|
367
343
|
collector = visit get_time_converted(o.left), collector
|
368
|
-
collector <<
|
344
|
+
collector << " < "
|
369
345
|
collector = visit get_time_converted(o.right), collector
|
370
346
|
collector
|
371
347
|
end
|
372
348
|
|
373
|
-
|
349
|
+
|
350
|
+
alias_method :old_visit_Arel_Nodes_SelectStatement, :visit_Arel_Nodes_SelectStatement
|
351
|
+
def visit_Arel_Nodes_SelectStatement o, collector
|
352
|
+
if !collector.value.blank? && o.limit.blank?
|
353
|
+
o = o.dup
|
354
|
+
o.orders = []
|
355
|
+
end
|
356
|
+
old_visit_Arel_Nodes_SelectStatement(o,collector)
|
357
|
+
end
|
358
|
+
|
359
|
+
alias_method :old_visit_Arel_Nodes_As, :visit_Arel_Nodes_As
|
374
360
|
def visit_Arel_Nodes_As o, collector
|
375
361
|
if o.left.is_a?(Arel::Nodes::Binary)
|
376
362
|
collector << '('
|
@@ -379,22 +365,22 @@ module ArelExtensions
|
|
379
365
|
else
|
380
366
|
collector = visit o.left, collector
|
381
367
|
end
|
382
|
-
|
383
|
-
collector << " AS #{sep}"
|
368
|
+
collector << " AS \""
|
384
369
|
collector = visit o.right, collector
|
385
|
-
collector << "
|
370
|
+
collector << "\""
|
386
371
|
collector
|
387
372
|
end
|
388
373
|
|
389
374
|
def visit_ArelExtensions_Nodes_FormattedNumber o, collector
|
390
|
-
format = Arel::Nodes::NamedFunction.new('printf',
|
391
|
-
locale_map = NUMBER_COMMA_MAPPING[o.locale]
|
375
|
+
format = Arel::Nodes::NamedFunction.new('printf',[Arel::Nodes.build_quoted(o.original_string),o.left])
|
376
|
+
locale_map = Arel::Visitors::SQLite::NUMBER_COMMA_MAPPING[o.locale]
|
392
377
|
if locale_map
|
393
|
-
format = format.replace(',',
|
378
|
+
format = format.replace(',',locale_map[',']).replace('.',locale_map['.'])
|
394
379
|
end
|
395
380
|
visit format, collector
|
396
381
|
collector
|
397
382
|
end
|
383
|
+
|
398
384
|
end
|
399
385
|
end
|
400
386
|
end
|