arel 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +7 -0
- data/lib/arel.rb +1 -1
- data/lib/arel/nodes/infix_operation.rb +1 -0
- data/lib/arel/visitors/to_sql.rb +14 -6
- data/test/nodes/test_infix_operation.rb +30 -0
- data/test/test_select_manager.rb +1 -1
- data/test/visitors/test_to_sql.rb +18 -0
- metadata +53 -57
data/History.txt
CHANGED
data/lib/arel.rb
CHANGED
data/lib/arel/visitors/to_sql.rb
CHANGED
@@ -8,14 +8,13 @@ module Arel
|
|
8
8
|
@engine = engine
|
9
9
|
@connection = nil
|
10
10
|
@pool = nil
|
11
|
-
@last_column = nil
|
12
11
|
@quoted_tables = {}
|
13
12
|
@quoted_columns = {}
|
14
13
|
end
|
15
14
|
|
16
15
|
def accept object
|
17
|
-
|
18
|
-
@pool
|
16
|
+
self.last_column = nil
|
17
|
+
@pool = @engine.connection_pool
|
19
18
|
@pool.with_connection do |conn|
|
20
19
|
@connection = conn
|
21
20
|
super
|
@@ -23,6 +22,14 @@ module Arel
|
|
23
22
|
end
|
24
23
|
|
25
24
|
private
|
25
|
+
def last_column= col
|
26
|
+
Thread.current[:arel_visitors_to_sql_last_column] = col
|
27
|
+
end
|
28
|
+
|
29
|
+
def last_column
|
30
|
+
Thread.current[:arel_visitors_to_sql_last_column]
|
31
|
+
end
|
32
|
+
|
26
33
|
def visit_Arel_Nodes_DeleteStatement o
|
27
34
|
[
|
28
35
|
"DELETE FROM #{visit o.relation}",
|
@@ -356,7 +363,7 @@ key on UpdateManager using UpdateManager#key=
|
|
356
363
|
end
|
357
364
|
|
358
365
|
def visit_Arel_Attributes_Attribute o
|
359
|
-
|
366
|
+
self.last_column = column_for o
|
360
367
|
join_name = o.relation.table_alias || o.relation.name
|
361
368
|
"#{quote_table_name join_name}.#{quote_column_name o.name}"
|
362
369
|
end
|
@@ -374,7 +381,7 @@ key on UpdateManager using UpdateManager#key=
|
|
374
381
|
alias :visit_Bignum :literal
|
375
382
|
alias :visit_Fixnum :literal
|
376
383
|
|
377
|
-
def quoted o; quote(o,
|
384
|
+
def quoted o; quote(o, last_column) end
|
378
385
|
|
379
386
|
alias :visit_ActiveSupport_Multibyte_Chars :quoted
|
380
387
|
alias :visit_ActiveSupport_StringInquirer :quoted
|
@@ -409,7 +416,8 @@ key on UpdateManager using UpdateManager#key=
|
|
409
416
|
end
|
410
417
|
|
411
418
|
def quote_table_name name
|
412
|
-
|
419
|
+
return name if Arel::Nodes::SqlLiteral === name
|
420
|
+
@quoted_tables[name] ||= @connection.quote_table_name(name)
|
413
421
|
end
|
414
422
|
|
415
423
|
def quote_column_name name
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module Arel
|
4
|
+
module Nodes
|
5
|
+
class TestInfixOperation < MiniTest::Unit::TestCase
|
6
|
+
def test_construct
|
7
|
+
operation = InfixOperation.new :+, 1, 2
|
8
|
+
assert_equal :+, operation.operator
|
9
|
+
assert_equal 1, operation.left
|
10
|
+
assert_equal 2, operation.right
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_operation_alias
|
14
|
+
operation = InfixOperation.new :+, 1, 2
|
15
|
+
aliaz = operation.as('zomg')
|
16
|
+
assert_kind_of As, aliaz
|
17
|
+
assert_equal operation, aliaz.left
|
18
|
+
assert_equal 'zomg', aliaz.right
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_opertaion_ordering
|
22
|
+
operation = InfixOperation.new :+, 1, 2
|
23
|
+
ordering = operation.desc
|
24
|
+
assert_kind_of Ordering, ordering
|
25
|
+
assert_equal operation, ordering.expr
|
26
|
+
assert_equal :desc, ordering.direction
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/test/test_select_manager.rb
CHANGED
@@ -216,7 +216,7 @@ module Arel
|
|
216
216
|
table = Table.new :users, :engine => Table.engine, :as => 'foo'
|
217
217
|
mgr = table.from table
|
218
218
|
mgr.skip 10
|
219
|
-
mgr.to_sql.must_be_like %{ SELECT FROM "users" foo OFFSET 10 }
|
219
|
+
mgr.to_sql.must_be_like %{ SELECT FROM "users" "foo" OFFSET 10 }
|
220
220
|
end
|
221
221
|
end
|
222
222
|
|
@@ -1,5 +1,9 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
+
class Arel::Visitors::ToSql
|
4
|
+
def last_column; Thread.current[:arel_visitors_to_sql_last_column]; end
|
5
|
+
end
|
6
|
+
|
3
7
|
module Arel
|
4
8
|
module Visitors
|
5
9
|
describe 'the to_sql visitor' do
|
@@ -9,6 +13,20 @@ module Arel
|
|
9
13
|
@attr = @table[:id]
|
10
14
|
end
|
11
15
|
|
16
|
+
it "should be thread safe around usage of last_column" do
|
17
|
+
visit_integer_column = Thread.new do
|
18
|
+
Thread.stop
|
19
|
+
@visitor.send(:visit_Arel_Attributes_Attribute, @attr)
|
20
|
+
end
|
21
|
+
|
22
|
+
sleep 0.2
|
23
|
+
@visitor.accept(@table[:name])
|
24
|
+
assert_equal(:string, @visitor.last_column.type)
|
25
|
+
visit_integer_column.run
|
26
|
+
visit_integer_column.join
|
27
|
+
assert_equal(:string, @visitor.last_column.type)
|
28
|
+
end
|
29
|
+
|
12
30
|
it 'should not quote sql literals' do
|
13
31
|
node = @table[Arel.star]
|
14
32
|
sql = @visitor.accept node
|
metadata
CHANGED
@@ -1,15 +1,10 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: arel
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.1.1
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 2
|
8
|
-
- 1
|
9
|
-
- 0
|
10
|
-
version: 2.1.0
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Aaron Patterson
|
14
9
|
- Bryan Halmkamp
|
15
10
|
- Emilio Tagua
|
@@ -17,49 +12,56 @@ authors:
|
|
17
12
|
autorequire:
|
18
13
|
bindir: bin
|
19
14
|
cert_chain: []
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
15
|
+
date: 2011-05-17 00:00:00.000000000 Z
|
16
|
+
dependencies:
|
17
|
+
- !ruby/object:Gem::Dependency
|
18
|
+
name: minitest
|
19
|
+
requirement: &2156937040 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ! '>='
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 2.0.2
|
25
|
+
type: :development
|
25
26
|
prerelease: false
|
26
|
-
|
27
|
+
version_requirements: *2156937040
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: hoe
|
30
|
+
requirement: &2156936540 !ruby/object:Gem::Requirement
|
27
31
|
none: false
|
28
|
-
requirements:
|
29
|
-
- -
|
30
|
-
- !ruby/object:Gem::Version
|
31
|
-
|
32
|
-
segments:
|
33
|
-
- 2
|
34
|
-
- 9
|
35
|
-
- 4
|
36
|
-
version: 2.9.4
|
32
|
+
requirements:
|
33
|
+
- - ! '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 2.9.1
|
37
36
|
type: :development
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: *2156936540
|
39
|
+
description: ! 'Arel is a SQL AST manager for Ruby. It
|
40
|
+
|
41
|
+
|
42
42
|
1. Simplifies the generation complex of SQL queries
|
43
|
+
|
43
44
|
2. Adapts to various RDBMS systems
|
44
|
-
|
45
|
+
|
46
|
+
|
45
47
|
It is intended to be a framework framework; that is, you can build your own ORM
|
48
|
+
|
46
49
|
with it, focusing on innovative object and collection modeling as opposed to
|
47
|
-
|
48
|
-
|
50
|
+
|
51
|
+
database compatibility and query generation.'
|
52
|
+
email:
|
49
53
|
- aaron@tenderlovemaking.com
|
50
54
|
- bryan@brynary.com
|
51
55
|
- miloops@gmail.com
|
52
56
|
- nick@example.org
|
53
57
|
executables: []
|
54
|
-
|
55
58
|
extensions: []
|
56
|
-
|
57
|
-
extra_rdoc_files:
|
59
|
+
extra_rdoc_files:
|
58
60
|
- History.txt
|
59
61
|
- MIT-LICENSE.txt
|
60
62
|
- Manifest.txt
|
61
63
|
- README.markdown
|
62
|
-
files:
|
64
|
+
files:
|
63
65
|
- .autotest
|
64
66
|
- .gemtest
|
65
67
|
- History.txt
|
@@ -168,47 +170,41 @@ files:
|
|
168
170
|
- test/visitors/test_postgres.rb
|
169
171
|
- test/visitors/test_sqlite.rb
|
170
172
|
- test/visitors/test_to_sql.rb
|
173
|
+
- test/nodes/test_infix_operation.rb
|
171
174
|
homepage: http://github.com/rails/arel
|
172
175
|
licenses: []
|
173
|
-
|
174
176
|
post_install_message:
|
175
|
-
rdoc_options:
|
177
|
+
rdoc_options:
|
176
178
|
- --main
|
177
179
|
- README.markdown
|
178
|
-
require_paths:
|
180
|
+
require_paths:
|
179
181
|
- lib
|
180
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
182
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
181
183
|
none: false
|
182
|
-
requirements:
|
183
|
-
- -
|
184
|
-
- !ruby/object:Gem::Version
|
185
|
-
|
186
|
-
|
187
|
-
- 0
|
188
|
-
version: "0"
|
189
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ! '>='
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
190
189
|
none: false
|
191
|
-
requirements:
|
192
|
-
- -
|
193
|
-
- !ruby/object:Gem::Version
|
194
|
-
|
195
|
-
segments:
|
196
|
-
- 0
|
197
|
-
version: "0"
|
190
|
+
requirements:
|
191
|
+
- - ! '>='
|
192
|
+
- !ruby/object:Gem::Version
|
193
|
+
version: '0'
|
198
194
|
requirements: []
|
199
|
-
|
200
195
|
rubyforge_project: arel
|
201
|
-
rubygems_version: 1.
|
196
|
+
rubygems_version: 1.8.2
|
202
197
|
signing_key:
|
203
198
|
specification_version: 3
|
204
199
|
summary: Arel is a SQL AST manager for Ruby
|
205
|
-
test_files:
|
200
|
+
test_files:
|
206
201
|
- test/attributes/test_attribute.rb
|
207
202
|
- test/nodes/test_as.rb
|
208
203
|
- test/nodes/test_bin.rb
|
209
204
|
- test/nodes/test_count.rb
|
210
205
|
- test/nodes/test_delete_statement.rb
|
211
206
|
- test/nodes/test_equality.rb
|
207
|
+
- test/nodes/test_infix_operation.rb
|
212
208
|
- test/nodes/test_insert_statement.rb
|
213
209
|
- test/nodes/test_named_function.rb
|
214
210
|
- test/nodes/test_node.rb
|