arel 4.0.0 → 4.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,8 +3,8 @@ module Arel
3
3
  class OrderClauses < Arel::Visitors::ToSql
4
4
  private
5
5
 
6
- def visit_Arel_Nodes_SelectStatement o
7
- o.orders.map { |x| visit x }
6
+ def visit_Arel_Nodes_SelectStatement o, a
7
+ o.orders.map { |x| visit x, a }
8
8
  end
9
9
  end
10
10
  end
@@ -3,16 +3,16 @@ module Arel
3
3
  class PostgreSQL < Arel::Visitors::ToSql
4
4
  private
5
5
 
6
- def visit_Arel_Nodes_Matches o
7
- "#{visit o.left} ILIKE #{visit o.right}"
6
+ def visit_Arel_Nodes_Matches o, a
7
+ "#{visit o.left, a} ILIKE #{visit o.right, a}"
8
8
  end
9
9
 
10
- def visit_Arel_Nodes_DoesNotMatch o
11
- "#{visit o.left} NOT ILIKE #{visit o.right}"
10
+ def visit_Arel_Nodes_DoesNotMatch o, a
11
+ "#{visit o.left, a} NOT ILIKE #{visit o.right, a}"
12
12
  end
13
13
 
14
- def visit_Arel_Nodes_DistinctOn o
15
- "DISTINCT ON ( #{visit o.expr} )"
14
+ def visit_Arel_Nodes_DistinctOn o, a
15
+ "DISTINCT ON ( #{visit o.expr, a} )"
16
16
  end
17
17
  end
18
18
  end
@@ -4,10 +4,10 @@ module Arel
4
4
  private
5
5
 
6
6
  # Locks are not supported in SQLite
7
- def visit_Arel_Nodes_Lock o
7
+ def visit_Arel_Nodes_Lock o, a
8
8
  end
9
9
 
10
- def visit_Arel_Nodes_SelectStatement o
10
+ def visit_Arel_Nodes_SelectStatement o, a
11
11
  o.limit = Arel::Nodes::Limit.new(-1) if o.offset && !o.limit
12
12
  super
13
13
  end
@@ -53,23 +53,16 @@ module Arel
53
53
 
54
54
  DISTINCT = 'DISTINCT' # :nodoc:
55
55
 
56
- attr_accessor :last_column
57
-
58
56
  def initialize connection
59
57
  @connection = connection
60
58
  @schema_cache = connection.schema_cache
61
59
  @quoted_tables = {}
62
60
  @quoted_columns = {}
63
- @last_column = nil
64
- end
65
-
66
- def accept object
67
- self.last_column = nil
68
- super
69
61
  end
70
62
 
71
63
  private
72
- def visit_Arel_Nodes_DeleteStatement o
64
+
65
+ def visit_Arel_Nodes_DeleteStatement o, a
73
66
  [
74
67
  "DELETE FROM #{visit o.relation}",
75
68
  ("WHERE #{o.wheres.map { |x| visit x }.join AND}" unless o.wheres.empty?)
@@ -88,7 +81,7 @@ module Arel
88
81
  stmt
89
82
  end
90
83
 
91
- def visit_Arel_Nodes_UpdateStatement o
84
+ def visit_Arel_Nodes_UpdateStatement o, a
92
85
  if o.orders.empty? && o.limit.nil?
93
86
  wheres = o.wheres
94
87
  else
@@ -97,7 +90,7 @@ module Arel
97
90
  warn(<<-eowarn) if $VERBOSE
98
91
  (#{caller.first}) Using UpdateManager without setting UpdateManager#key is
99
92
  deprecated and support will be removed in Arel 4.0.0. Please set the primary
100
- key on UpdateManager using UpdateManager#key=
93
+ key on UpdateManager using UpdateManager#key= '#{key.inspect}'
101
94
  eowarn
102
95
  key = o.relation.primary_key
103
96
  end
@@ -106,34 +99,34 @@ key on UpdateManager using UpdateManager#key=
106
99
  end
107
100
 
108
101
  [
109
- "UPDATE #{visit o.relation}",
110
- ("SET #{o.values.map { |value| visit value }.join ', '}" unless o.values.empty?),
111
- ("WHERE #{wheres.map { |x| visit x }.join ' AND '}" unless wheres.empty?),
102
+ "UPDATE #{visit o.relation, a}",
103
+ ("SET #{o.values.map { |value| visit value, a }.join ', '}" unless o.values.empty?),
104
+ ("WHERE #{wheres.map { |x| visit x, a }.join ' AND '}" unless wheres.empty?),
112
105
  ].compact.join ' '
113
106
  end
114
107
 
115
- def visit_Arel_Nodes_InsertStatement o
108
+ def visit_Arel_Nodes_InsertStatement o, a
116
109
  [
117
- "INSERT INTO #{visit o.relation}",
110
+ "INSERT INTO #{visit o.relation, a}",
118
111
 
119
112
  ("(#{o.columns.map { |x|
120
113
  quote_column_name x.name
121
114
  }.join ', '})" unless o.columns.empty?),
122
115
 
123
- (visit o.values if o.values),
116
+ (visit o.values, a if o.values),
124
117
  ].compact.join ' '
125
118
  end
126
119
 
127
- def visit_Arel_Nodes_Exists o
128
- "EXISTS (#{visit o.expressions})#{
129
- o.alias ? " AS #{visit o.alias}" : ''}"
120
+ def visit_Arel_Nodes_Exists o, a
121
+ "EXISTS (#{visit o.expressions, a})#{
122
+ o.alias ? " AS #{visit o.alias, a}" : ''}"
130
123
  end
131
124
 
132
- def visit_Arel_Nodes_True o
125
+ def visit_Arel_Nodes_True o, a
133
126
  "TRUE"
134
127
  end
135
128
 
136
- def visit_Arel_Nodes_False o
129
+ def visit_Arel_Nodes_False o, a
137
130
  "FALSE"
138
131
  end
139
132
 
@@ -142,6 +135,7 @@ key on UpdateManager using UpdateManager#key=
142
135
  end
143
136
 
144
137
  def column_for attr
138
+ return unless attr
145
139
  name = attr.name.to_s
146
140
  table = attr.relation.table_name
147
141
 
@@ -154,66 +148,66 @@ key on UpdateManager using UpdateManager#key=
154
148
  @schema_cache.columns_hash(table)
155
149
  end
156
150
 
157
- def visit_Arel_Nodes_Values o
151
+ def visit_Arel_Nodes_Values o, a
158
152
  "VALUES (#{o.expressions.zip(o.columns).map { |value, attr|
159
153
  if Nodes::SqlLiteral === value
160
- visit value
154
+ visit value, a
161
155
  else
162
156
  quote(value, attr && column_for(attr))
163
157
  end
164
158
  }.join ', '})"
165
159
  end
166
160
 
167
- def visit_Arel_Nodes_SelectStatement o
161
+ def visit_Arel_Nodes_SelectStatement o, a
168
162
  str = ''
169
163
 
170
164
  if o.with
171
- str << visit(o.with)
165
+ str << visit(o.with, a)
172
166
  str << SPACE
173
167
  end
174
168
 
175
- o.cores.each { |x| str << visit_Arel_Nodes_SelectCore(x) }
169
+ o.cores.each { |x| str << visit_Arel_Nodes_SelectCore(x, a) }
176
170
 
177
171
  unless o.orders.empty?
178
172
  str << SPACE
179
173
  str << ORDER_BY
180
174
  len = o.orders.length - 1
181
175
  o.orders.each_with_index { |x, i|
182
- str << visit(x)
176
+ str << visit(x, a)
183
177
  str << COMMA unless len == i
184
178
  }
185
179
  end
186
180
 
187
- str << " #{visit(o.limit)}" if o.limit
188
- str << " #{visit(o.offset)}" if o.offset
189
- str << " #{visit(o.lock)}" if o.lock
181
+ str << " #{visit(o.limit, a)}" if o.limit
182
+ str << " #{visit(o.offset, a)}" if o.offset
183
+ str << " #{visit(o.lock, a)}" if o.lock
190
184
 
191
185
  str.strip!
192
186
  str
193
187
  end
194
188
 
195
- def visit_Arel_Nodes_SelectCore o
189
+ def visit_Arel_Nodes_SelectCore o, a
196
190
  str = "SELECT"
197
191
 
198
- str << " #{visit(o.top)}" if o.top
199
- str << " #{visit(o.set_quantifier)}" if o.set_quantifier
192
+ str << " #{visit(o.top, a)}" if o.top
193
+ str << " #{visit(o.set_quantifier, a)}" if o.set_quantifier
200
194
 
201
195
  unless o.projections.empty?
202
196
  str << SPACE
203
197
  len = o.projections.length - 1
204
198
  o.projections.each_with_index do |x, i|
205
- str << visit(x)
199
+ str << visit(x, a)
206
200
  str << COMMA unless len == i
207
201
  end
208
202
  end
209
203
 
210
- str << " FROM #{visit(o.source)}" if o.source && !o.source.empty?
204
+ str << " FROM #{visit(o.source, a)}" if o.source && !o.source.empty?
211
205
 
212
206
  unless o.wheres.empty?
213
207
  str << WHERE
214
208
  len = o.wheres.length - 1
215
209
  o.wheres.each_with_index do |x, i|
216
- str << visit(x)
210
+ str << visit(x, a)
217
211
  str << AND unless len == i
218
212
  end
219
213
  end
@@ -222,18 +216,18 @@ key on UpdateManager using UpdateManager#key=
222
216
  str << GROUP_BY
223
217
  len = o.groups.length - 1
224
218
  o.groups.each_with_index do |x, i|
225
- str << visit(x)
219
+ str << visit(x, a)
226
220
  str << COMMA unless len == i
227
221
  end
228
222
  end
229
223
 
230
- str << " #{visit(o.having)}" if o.having
224
+ str << " #{visit(o.having, a)}" if o.having
231
225
 
232
226
  unless o.windows.empty?
233
227
  str << WINDOW
234
228
  len = o.windows.length - 1
235
229
  o.windows.each_with_index do |x, i|
236
- str << visit(x)
230
+ str << visit(x, a)
237
231
  str << COMMA unless len == i
238
232
  end
239
233
  end
@@ -241,237 +235,244 @@ key on UpdateManager using UpdateManager#key=
241
235
  str
242
236
  end
243
237
 
244
- def visit_Arel_Nodes_Bin o
245
- visit o.expr
238
+ def visit_Arel_Nodes_Bin o, a
239
+ visit o.expr, a
246
240
  end
247
241
 
248
- def visit_Arel_Nodes_Distinct o
242
+ def visit_Arel_Nodes_Distinct o, a
249
243
  DISTINCT
250
244
  end
251
245
 
252
- def visit_Arel_Nodes_DistinctOn o
246
+ def visit_Arel_Nodes_DistinctOn o, a
253
247
  raise NotImplementedError, 'DISTINCT ON not implemented for this db'
254
248
  end
255
249
 
256
- def visit_Arel_Nodes_With o
257
- "WITH #{o.children.map { |x| visit x }.join(', ')}"
250
+ def visit_Arel_Nodes_With o, a
251
+ "WITH #{o.children.map { |x| visit x, a }.join(', ')}"
258
252
  end
259
253
 
260
- def visit_Arel_Nodes_WithRecursive o
261
- "WITH RECURSIVE #{o.children.map { |x| visit x }.join(', ')}"
254
+ def visit_Arel_Nodes_WithRecursive o, a
255
+ "WITH RECURSIVE #{o.children.map { |x| visit x, a }.join(', ')}"
262
256
  end
263
257
 
264
- def visit_Arel_Nodes_Union o
265
- "( #{visit o.left} UNION #{visit o.right} )"
258
+ def visit_Arel_Nodes_Union o, a
259
+ "( #{visit o.left, a} UNION #{visit o.right, a} )"
266
260
  end
267
261
 
268
- def visit_Arel_Nodes_UnionAll o
269
- "( #{visit o.left} UNION ALL #{visit o.right} )"
262
+ def visit_Arel_Nodes_UnionAll o, a
263
+ "( #{visit o.left, a} UNION ALL #{visit o.right, a} )"
270
264
  end
271
265
 
272
- def visit_Arel_Nodes_Intersect o
273
- "( #{visit o.left} INTERSECT #{visit o.right} )"
266
+ def visit_Arel_Nodes_Intersect o, a
267
+ "( #{visit o.left, a} INTERSECT #{visit o.right, a} )"
274
268
  end
275
269
 
276
- def visit_Arel_Nodes_Except o
277
- "( #{visit o.left} EXCEPT #{visit o.right} )"
270
+ def visit_Arel_Nodes_Except o, a
271
+ "( #{visit o.left, a} EXCEPT #{visit o.right, a} )"
278
272
  end
279
273
 
280
- def visit_Arel_Nodes_NamedWindow o
281
- "#{quote_column_name o.name} AS #{visit_Arel_Nodes_Window o}"
274
+ def visit_Arel_Nodes_NamedWindow o, a
275
+ "#{quote_column_name o.name} AS #{visit_Arel_Nodes_Window o, a}"
282
276
  end
283
277
 
284
- def visit_Arel_Nodes_Window o
278
+ def visit_Arel_Nodes_Window o, a
285
279
  s = [
286
- ("ORDER BY #{o.orders.map { |x| visit(x) }.join(', ')}" unless o.orders.empty?),
287
- (visit o.framing if o.framing)
280
+ ("ORDER BY #{o.orders.map { |x| visit(x, a) }.join(', ')}" unless o.orders.empty?),
281
+ (visit o.framing, a if o.framing)
288
282
  ].compact.join ' '
289
283
  "(#{s})"
290
284
  end
291
285
 
292
- def visit_Arel_Nodes_Rows o
286
+ def visit_Arel_Nodes_Rows o, a
293
287
  if o.expr
294
- "ROWS #{visit o.expr}"
288
+ "ROWS #{visit o.expr, a}"
295
289
  else
296
290
  "ROWS"
297
291
  end
298
292
  end
299
293
 
300
- def visit_Arel_Nodes_Range o
294
+ def visit_Arel_Nodes_Range o, a
301
295
  if o.expr
302
- "RANGE #{visit o.expr}"
296
+ "RANGE #{visit o.expr, a}"
303
297
  else
304
298
  "RANGE"
305
299
  end
306
300
  end
307
301
 
308
- def visit_Arel_Nodes_Preceding o
309
- "#{o.expr ? visit(o.expr) : 'UNBOUNDED'} PRECEDING"
302
+ def visit_Arel_Nodes_Preceding o, a
303
+ "#{o.expr ? visit(o.expr, a) : 'UNBOUNDED'} PRECEDING"
310
304
  end
311
305
 
312
- def visit_Arel_Nodes_Following o
313
- "#{o.expr ? visit(o.expr) : 'UNBOUNDED'} FOLLOWING"
306
+ def visit_Arel_Nodes_Following o, a
307
+ "#{o.expr ? visit(o.expr, a) : 'UNBOUNDED'} FOLLOWING"
314
308
  end
315
309
 
316
- def visit_Arel_Nodes_CurrentRow o
310
+ def visit_Arel_Nodes_CurrentRow o, a
317
311
  "CURRENT ROW"
318
312
  end
319
313
 
320
- def visit_Arel_Nodes_Over o
314
+ def visit_Arel_Nodes_Over o, a
321
315
  case o.right
322
316
  when nil
323
- "#{visit o.left} OVER ()"
317
+ "#{visit o.left, a} OVER ()"
324
318
  when Arel::Nodes::SqlLiteral
325
- "#{visit o.left} OVER #{visit o.right}"
319
+ "#{visit o.left, a} OVER #{visit o.right, a}"
326
320
  when String, Symbol
327
- "#{visit o.left} OVER #{quote_column_name o.right.to_s}"
321
+ "#{visit o.left, a} OVER #{quote_column_name o.right.to_s}"
328
322
  else
329
- "#{visit o.left} OVER #{visit o.right}"
323
+ "#{visit o.left, a} OVER #{visit o.right, a}"
330
324
  end
331
325
  end
332
326
 
333
- def visit_Arel_Nodes_Having o
334
- "HAVING #{visit o.expr}"
327
+ def visit_Arel_Nodes_Having o, a
328
+ "HAVING #{visit o.expr, a}"
335
329
  end
336
330
 
337
- def visit_Arel_Nodes_Offset o
338
- "OFFSET #{visit o.expr}"
331
+ def visit_Arel_Nodes_Offset o, a
332
+ "OFFSET #{visit o.expr, a}"
339
333
  end
340
334
 
341
- def visit_Arel_Nodes_Limit o
342
- "LIMIT #{visit o.expr}"
335
+ def visit_Arel_Nodes_Limit o, a
336
+ "LIMIT #{visit o.expr, a}"
343
337
  end
344
338
 
345
339
  # FIXME: this does nothing on most databases, but does on MSSQL
346
- def visit_Arel_Nodes_Top o
340
+ def visit_Arel_Nodes_Top o, a
347
341
  ""
348
342
  end
349
343
 
350
- def visit_Arel_Nodes_Lock o
351
- visit o.expr
344
+ def visit_Arel_Nodes_Lock o, a
345
+ visit o.expr, a
352
346
  end
353
347
 
354
- def visit_Arel_Nodes_Grouping o
355
- "(#{visit o.expr})"
348
+ def visit_Arel_Nodes_Grouping o, a
349
+ "(#{visit o.expr, a})"
356
350
  end
357
351
 
358
- def visit_Arel_SelectManager o
352
+ def visit_Arel_SelectManager o, a
359
353
  "(#{o.to_sql.rstrip})"
360
354
  end
361
355
 
362
- def visit_Arel_Nodes_Ascending o
363
- "#{visit o.expr} ASC"
356
+ def visit_Arel_Nodes_Ascending o, a
357
+ "#{visit o.expr, a} ASC"
364
358
  end
365
359
 
366
- def visit_Arel_Nodes_Descending o
367
- "#{visit o.expr} DESC"
360
+ def visit_Arel_Nodes_Descending o, a
361
+ "#{visit o.expr, a} DESC"
368
362
  end
369
363
 
370
- def visit_Arel_Nodes_Group o
371
- visit o.expr
364
+ def visit_Arel_Nodes_Group o, a
365
+ visit o.expr, a
372
366
  end
373
367
 
374
- def visit_Arel_Nodes_NamedFunction o
368
+ def visit_Arel_Nodes_NamedFunction o, a
375
369
  "#{o.name}(#{o.distinct ? 'DISTINCT ' : ''}#{o.expressions.map { |x|
376
- visit x
377
- }.join(', ')})#{o.alias ? " AS #{visit o.alias}" : ''}"
370
+ visit x, a
371
+ }.join(', ')})#{o.alias ? " AS #{visit o.alias, a}" : ''}"
378
372
  end
379
373
 
380
- def visit_Arel_Nodes_Extract o
381
- "EXTRACT(#{o.field.to_s.upcase} FROM #{visit o.expr})#{o.alias ? " AS #{visit o.alias}" : ''}"
374
+ def visit_Arel_Nodes_Extract o, a
375
+ "EXTRACT(#{o.field.to_s.upcase} FROM #{visit o.expr, a})#{o.alias ? " AS #{visit o.alias, a}" : ''}"
382
376
  end
383
377
 
384
- def visit_Arel_Nodes_Count o
378
+ def visit_Arel_Nodes_Count o, a
385
379
  "COUNT(#{o.distinct ? 'DISTINCT ' : ''}#{o.expressions.map { |x|
386
- visit x
387
- }.join(', ')})#{o.alias ? " AS #{visit o.alias}" : ''}"
380
+ visit x, a
381
+ }.join(', ')})#{o.alias ? " AS #{visit o.alias, a}" : ''}"
388
382
  end
389
383
 
390
- def visit_Arel_Nodes_Sum o
384
+ def visit_Arel_Nodes_Sum o, a
391
385
  "SUM(#{o.distinct ? 'DISTINCT ' : ''}#{o.expressions.map { |x|
392
- visit x }.join(', ')})#{o.alias ? " AS #{visit o.alias}" : ''}"
386
+ visit x, a }.join(', ')})#{o.alias ? " AS #{visit o.alias, a}" : ''}"
393
387
  end
394
388
 
395
- def visit_Arel_Nodes_Max o
389
+ def visit_Arel_Nodes_Max o, a
396
390
  "MAX(#{o.distinct ? 'DISTINCT ' : ''}#{o.expressions.map { |x|
397
- visit x }.join(', ')})#{o.alias ? " AS #{visit o.alias}" : ''}"
391
+ visit x, a }.join(', ')})#{o.alias ? " AS #{visit o.alias, a}" : ''}"
398
392
  end
399
393
 
400
- def visit_Arel_Nodes_Min o
394
+ def visit_Arel_Nodes_Min o, a
401
395
  "MIN(#{o.distinct ? 'DISTINCT ' : ''}#{o.expressions.map { |x|
402
- visit x }.join(', ')})#{o.alias ? " AS #{visit o.alias}" : ''}"
396
+ visit x, a }.join(', ')})#{o.alias ? " AS #{visit o.alias, a}" : ''}"
403
397
  end
404
398
 
405
- def visit_Arel_Nodes_Avg o
399
+ def visit_Arel_Nodes_Avg o, a
406
400
  "AVG(#{o.distinct ? 'DISTINCT ' : ''}#{o.expressions.map { |x|
407
- visit x }.join(', ')})#{o.alias ? " AS #{visit o.alias}" : ''}"
401
+ visit x, a }.join(', ')})#{o.alias ? " AS #{visit o.alias, a}" : ''}"
408
402
  end
409
403
 
410
- def visit_Arel_Nodes_TableAlias o
411
- "#{visit o.relation} #{quote_table_name o.name}"
404
+ def visit_Arel_Nodes_TableAlias o, a
405
+ "#{visit o.relation, a} #{quote_table_name o.name}"
412
406
  end
413
407
 
414
- def visit_Arel_Nodes_Between o
415
- "#{visit o.left} BETWEEN #{visit o.right}"
408
+ def visit_Arel_Nodes_Between o, a
409
+ a = o.left if Arel::Attributes::Attribute === o.left
410
+ "#{visit o.left, a} BETWEEN #{visit o.right, a}"
416
411
  end
417
412
 
418
- def visit_Arel_Nodes_GreaterThanOrEqual o
419
- "#{visit o.left} >= #{visit o.right}"
413
+ def visit_Arel_Nodes_GreaterThanOrEqual o, a
414
+ a = o.left if Arel::Attributes::Attribute === o.left
415
+ "#{visit o.left, a} >= #{visit o.right, a}"
420
416
  end
421
417
 
422
- def visit_Arel_Nodes_GreaterThan o
423
- "#{visit o.left} > #{visit o.right}"
418
+ def visit_Arel_Nodes_GreaterThan o, a
419
+ a = o.left if Arel::Attributes::Attribute === o.left
420
+ "#{visit o.left, a} > #{visit o.right, a}"
424
421
  end
425
422
 
426
- def visit_Arel_Nodes_LessThanOrEqual o
427
- "#{visit o.left} <= #{visit o.right}"
423
+ def visit_Arel_Nodes_LessThanOrEqual o, a
424
+ a = o.left if Arel::Attributes::Attribute === o.left
425
+ "#{visit o.left, a} <= #{visit o.right, a}"
428
426
  end
429
427
 
430
- def visit_Arel_Nodes_LessThan o
431
- "#{visit o.left} < #{visit o.right}"
428
+ def visit_Arel_Nodes_LessThan o, a
429
+ a = o.left if Arel::Attributes::Attribute === o.left
430
+ "#{visit o.left, a} < #{visit o.right, a}"
432
431
  end
433
432
 
434
- def visit_Arel_Nodes_Matches o
435
- "#{visit o.left} LIKE #{visit o.right}"
433
+ def visit_Arel_Nodes_Matches o, a
434
+ a = o.left if Arel::Attributes::Attribute === o.left
435
+ "#{visit o.left, a} LIKE #{visit o.right, a}"
436
436
  end
437
437
 
438
- def visit_Arel_Nodes_DoesNotMatch o
439
- "#{visit o.left} NOT LIKE #{visit o.right}"
438
+ def visit_Arel_Nodes_DoesNotMatch o, a
439
+ a = o.left if Arel::Attributes::Attribute === o.left
440
+ "#{visit o.left, a} NOT LIKE #{visit o.right, a}"
440
441
  end
441
442
 
442
- def visit_Arel_Nodes_JoinSource o
443
+ def visit_Arel_Nodes_JoinSource o, a
443
444
  [
444
- (visit(o.left) if o.left),
445
- o.right.map { |j| visit j }.join(' ')
445
+ (visit(o.left, a) if o.left),
446
+ o.right.map { |j| visit j, a }.join(' ')
446
447
  ].compact.join ' '
447
448
  end
448
449
 
449
- def visit_Arel_Nodes_StringJoin o
450
- visit o.left
450
+ def visit_Arel_Nodes_StringJoin o, a
451
+ visit o.left, a
451
452
  end
452
453
 
453
- def visit_Arel_Nodes_OuterJoin o
454
- "LEFT OUTER JOIN #{visit o.left} #{visit o.right}"
454
+ def visit_Arel_Nodes_OuterJoin o, a
455
+ "LEFT OUTER JOIN #{visit o.left, a} #{visit o.right, a}"
455
456
  end
456
457
 
457
- def visit_Arel_Nodes_InnerJoin o
458
- s = "INNER JOIN #{visit o.left}"
458
+ def visit_Arel_Nodes_InnerJoin o, a
459
+ s = "INNER JOIN #{visit o.left, a}"
459
460
  if o.right
460
461
  s << SPACE
461
- s << visit(o.right)
462
+ s << visit(o.right, a)
462
463
  end
463
464
  s
464
465
  end
465
466
 
466
- def visit_Arel_Nodes_On o
467
- "ON #{visit o.expr}"
467
+ def visit_Arel_Nodes_On o, a
468
+ "ON #{visit o.expr, a}"
468
469
  end
469
470
 
470
- def visit_Arel_Nodes_Not o
471
- "NOT (#{visit o.expr})"
471
+ def visit_Arel_Nodes_Not o, a
472
+ "NOT (#{visit o.expr, a})"
472
473
  end
473
474
 
474
- def visit_Arel_Table o
475
+ def visit_Arel_Table o, a
475
476
  if o.table_alias
476
477
  "#{quote_table_name o.name} #{quote_table_name o.table_alias}"
477
478
  else
@@ -479,65 +480,68 @@ key on UpdateManager using UpdateManager#key=
479
480
  end
480
481
  end
481
482
 
482
- def visit_Arel_Nodes_In o
483
+ def visit_Arel_Nodes_In o, a
483
484
  if Array === o.right && o.right.empty?
484
485
  '1=0'
485
486
  else
486
- "#{visit o.left} IN (#{visit o.right})"
487
+ a = o.left if Arel::Attributes::Attribute === o.left
488
+ "#{visit o.left, a} IN (#{visit o.right, a})"
487
489
  end
488
490
  end
489
491
 
490
- def visit_Arel_Nodes_NotIn o
492
+ def visit_Arel_Nodes_NotIn o, a
491
493
  if Array === o.right && o.right.empty?
492
494
  '1=1'
493
495
  else
494
- "#{visit o.left} NOT IN (#{visit o.right})"
496
+ a = o.left if Arel::Attributes::Attribute === o.left
497
+ "#{visit o.left, a} NOT IN (#{visit o.right, a})"
495
498
  end
496
499
  end
497
500
 
498
- def visit_Arel_Nodes_And o
499
- o.children.map { |x| visit x }.join ' AND '
501
+ def visit_Arel_Nodes_And o, a
502
+ o.children.map { |x| visit x, a }.join ' AND '
500
503
  end
501
504
 
502
- def visit_Arel_Nodes_Or o
503
- "#{visit o.left} OR #{visit o.right}"
505
+ def visit_Arel_Nodes_Or o, a
506
+ "#{visit o.left, a} OR #{visit o.right, a}"
504
507
  end
505
508
 
506
- def visit_Arel_Nodes_Assignment o
509
+ def visit_Arel_Nodes_Assignment o, a
507
510
  right = quote(o.right, column_for(o.left))
508
- "#{visit o.left} = #{right}"
511
+ "#{visit o.left, a} = #{right}"
509
512
  end
510
513
 
511
- def visit_Arel_Nodes_Equality o
514
+ def visit_Arel_Nodes_Equality o, a
512
515
  right = o.right
513
516
 
517
+ a = o.left if Arel::Attributes::Attribute === o.left
514
518
  if right.nil?
515
- "#{visit o.left} IS NULL"
519
+ "#{visit o.left, a} IS NULL"
516
520
  else
517
- "#{visit o.left} = #{visit right}"
521
+ "#{visit o.left, a} = #{visit right, a}"
518
522
  end
519
523
  end
520
524
 
521
- def visit_Arel_Nodes_NotEqual o
525
+ def visit_Arel_Nodes_NotEqual o, a
522
526
  right = o.right
523
527
 
528
+ a = o.left if Arel::Attributes::Attribute === o.left
524
529
  if right.nil?
525
- "#{visit o.left} IS NOT NULL"
530
+ "#{visit o.left, a} IS NOT NULL"
526
531
  else
527
- "#{visit o.left} != #{visit right}"
532
+ "#{visit o.left, a} != #{visit right, a}"
528
533
  end
529
534
  end
530
535
 
531
- def visit_Arel_Nodes_As o
532
- "#{visit o.left} AS #{visit o.right}"
536
+ def visit_Arel_Nodes_As o, a
537
+ "#{visit o.left, a} AS #{visit o.right, a}"
533
538
  end
534
539
 
535
- def visit_Arel_Nodes_UnqualifiedColumn o
540
+ def visit_Arel_Nodes_UnqualifiedColumn o, a
536
541
  "#{quote_column_name o.name}"
537
542
  end
538
543
 
539
- def visit_Arel_Attributes_Attribute o
540
- self.last_column = column_for o
544
+ def visit_Arel_Attributes_Attribute o, a
541
545
  join_name = o.relation.table_alias || o.relation.name
542
546
  "#{quote_table_name join_name}.#{quote_column_name o.name}"
543
547
  end
@@ -548,7 +552,7 @@ key on UpdateManager using UpdateManager#key=
548
552
  alias :visit_Arel_Attributes_Time :visit_Arel_Attributes_Attribute
549
553
  alias :visit_Arel_Attributes_Boolean :visit_Arel_Attributes_Attribute
550
554
 
551
- def literal o; o end
555
+ def literal o, a; o end
552
556
 
553
557
  alias :visit_Arel_Nodes_BindParam :literal
554
558
  alias :visit_Arel_Nodes_SqlLiteral :literal
@@ -556,8 +560,8 @@ key on UpdateManager using UpdateManager#key=
556
560
  alias :visit_Bignum :literal
557
561
  alias :visit_Fixnum :literal
558
562
 
559
- def quoted o
560
- quote(o, last_column)
563
+ def quoted o, a
564
+ quote(o, column_for(a))
561
565
  end
562
566
 
563
567
  alias :visit_ActiveSupport_Multibyte_Chars :quoted
@@ -575,8 +579,8 @@ key on UpdateManager using UpdateManager#key=
575
579
  alias :visit_Time :quoted
576
580
  alias :visit_TrueClass :quoted
577
581
 
578
- def visit_Arel_Nodes_InfixOperation o
579
- "#{visit o.left} #{o.operator} #{visit o.right}"
582
+ def visit_Arel_Nodes_InfixOperation o, a
583
+ "#{visit o.left, a} #{o.operator} #{visit o.right, a}"
580
584
  end
581
585
 
582
586
  alias :visit_Arel_Nodes_Addition :visit_Arel_Nodes_InfixOperation
@@ -584,8 +588,8 @@ key on UpdateManager using UpdateManager#key=
584
588
  alias :visit_Arel_Nodes_Multiplication :visit_Arel_Nodes_InfixOperation
585
589
  alias :visit_Arel_Nodes_Division :visit_Arel_Nodes_InfixOperation
586
590
 
587
- def visit_Array o
588
- o.map { |x| visit x }.join(', ')
591
+ def visit_Array o, a
592
+ o.map { |x| visit x, a }.join(', ')
589
593
  end
590
594
 
591
595
  def quote value, column = nil