arel 2.1.4 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'hoe', '>= 2.1.0'
4
+ gem 'minitest'
@@ -1,3 +1,11 @@
1
+ == 2.2.0 / 2011-08-09
2
+
3
+ * Bug Fixes
4
+
5
+ * The database connection caches visitors for generating SQL.
6
+ * FALSE and TRUE nodes can be constructed.
7
+ * Fixed ORDER BY / LIMIT clauses for UPDATE statements in Oracle.
8
+
1
9
  == 2.1.4 / 2011-07-25
2
10
 
3
11
  * Bug Fixes
@@ -1,5 +1,6 @@
1
1
  .autotest
2
2
  .gemtest
3
+ Gemfile
3
4
  History.txt
4
5
  MIT-LICENSE.txt
5
6
  Manifest.txt
@@ -27,6 +28,7 @@ lib/arel/nodes/count.rb
27
28
  lib/arel/nodes/delete_statement.rb
28
29
  lib/arel/nodes/descending.rb
29
30
  lib/arel/nodes/equality.rb
31
+ lib/arel/nodes/false.rb
30
32
  lib/arel/nodes/function.rb
31
33
  lib/arel/nodes/in.rb
32
34
  lib/arel/nodes/infix_operation.rb
@@ -43,6 +45,7 @@ lib/arel/nodes/sql_literal.rb
43
45
  lib/arel/nodes/string_join.rb
44
46
  lib/arel/nodes/table_alias.rb
45
47
  lib/arel/nodes/terminal.rb
48
+ lib/arel/nodes/true.rb
46
49
  lib/arel/nodes/unary.rb
47
50
  lib/arel/nodes/unqualified_column.rb
48
51
  lib/arel/nodes/update_statement.rb
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{arel}
5
- s.version = "2.1.4.20110725155854"
5
+ s.version = "2.2.0.20110809140134"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Aaron Patterson", "Bryan Halmkamp", "Emilio Tagua", "Nick Kallen"]
9
- s.date = %q{2011-07-25}
8
+ s.authors = [%q{Aaron Patterson}, %q{Bryan Halmkamp}, %q{Emilio Tagua}, %q{Nick Kallen}]
9
+ s.date = %q{2011-08-09}
10
10
  s.description = %q{Arel is a SQL AST manager for Ruby. It
11
11
 
12
12
  1. Simplifies the generation complex of SQL queries
@@ -15,30 +15,26 @@ Gem::Specification.new do |s|
15
15
  It is intended to be a framework framework; that is, you can build your own ORM
16
16
  with it, focusing on innovative object and collection modeling as opposed to
17
17
  database compatibility and query generation.}
18
- s.email = ["aaron@tenderlovemaking.com", "bryan@brynary.com", "miloops@gmail.com", "nick@example.org"]
19
- s.extra_rdoc_files = ["History.txt", "MIT-LICENSE.txt", "Manifest.txt", "README.markdown"]
20
- s.files = [".autotest", ".gemtest", "History.txt", "MIT-LICENSE.txt", "Manifest.txt", "README.markdown", "Rakefile", "arel.gemspec", "lib/arel.rb", "lib/arel/alias_predication.rb", "lib/arel/attributes.rb", "lib/arel/attributes/attribute.rb", "lib/arel/compatibility/wheres.rb", "lib/arel/crud.rb", "lib/arel/delete_manager.rb", "lib/arel/deprecated.rb", "lib/arel/expression.rb", "lib/arel/expressions.rb", "lib/arel/factory_methods.rb", "lib/arel/insert_manager.rb", "lib/arel/math.rb", "lib/arel/nodes.rb", "lib/arel/nodes/and.rb", "lib/arel/nodes/ascending.rb", "lib/arel/nodes/binary.rb", "lib/arel/nodes/count.rb", "lib/arel/nodes/delete_statement.rb", "lib/arel/nodes/descending.rb", "lib/arel/nodes/equality.rb", "lib/arel/nodes/function.rb", "lib/arel/nodes/in.rb", "lib/arel/nodes/infix_operation.rb", "lib/arel/nodes/inner_join.rb", "lib/arel/nodes/insert_statement.rb", "lib/arel/nodes/join_source.rb", "lib/arel/nodes/named_function.rb", "lib/arel/nodes/node.rb", "lib/arel/nodes/ordering.rb", "lib/arel/nodes/outer_join.rb", "lib/arel/nodes/select_core.rb", "lib/arel/nodes/select_statement.rb", "lib/arel/nodes/sql_literal.rb", "lib/arel/nodes/string_join.rb", "lib/arel/nodes/table_alias.rb", "lib/arel/nodes/terminal.rb", "lib/arel/nodes/unary.rb", "lib/arel/nodes/unqualified_column.rb", "lib/arel/nodes/update_statement.rb", "lib/arel/nodes/values.rb", "lib/arel/nodes/with.rb", "lib/arel/order_predications.rb", "lib/arel/predications.rb", "lib/arel/relation.rb", "lib/arel/select_manager.rb", "lib/arel/sql/engine.rb", "lib/arel/sql_literal.rb", "lib/arel/table.rb", "lib/arel/tree_manager.rb", "lib/arel/update_manager.rb", "lib/arel/visitors.rb", "lib/arel/visitors/depth_first.rb", "lib/arel/visitors/dot.rb", "lib/arel/visitors/ibm_db.rb", "lib/arel/visitors/informix.rb", "lib/arel/visitors/join_sql.rb", "lib/arel/visitors/mssql.rb", "lib/arel/visitors/mysql.rb", "lib/arel/visitors/oracle.rb", "lib/arel/visitors/order_clauses.rb", "lib/arel/visitors/postgresql.rb", "lib/arel/visitors/sqlite.rb", "lib/arel/visitors/to_sql.rb", "lib/arel/visitors/visitor.rb", "lib/arel/visitors/where_sql.rb", "test/attributes/test_attribute.rb", "test/helper.rb", "test/nodes/test_as.rb", "test/nodes/test_ascending.rb", "test/nodes/test_bin.rb", "test/nodes/test_count.rb", "test/nodes/test_delete_statement.rb", "test/nodes/test_descending.rb", "test/nodes/test_equality.rb", "test/nodes/test_infix_operation.rb", "test/nodes/test_insert_statement.rb", "test/nodes/test_named_function.rb", "test/nodes/test_node.rb", "test/nodes/test_not.rb", "test/nodes/test_or.rb", "test/nodes/test_select_core.rb", "test/nodes/test_select_statement.rb", "test/nodes/test_sql_literal.rb", "test/nodes/test_sum.rb", "test/nodes/test_update_statement.rb", "test/support/fake_record.rb", "test/test_activerecord_compat.rb", "test/test_attributes.rb", "test/test_crud.rb", "test/test_delete_manager.rb", "test/test_factory_methods.rb", "test/test_insert_manager.rb", "test/test_select_manager.rb", "test/test_table.rb", "test/test_update_manager.rb", "test/visitors/test_depth_first.rb", "test/visitors/test_dot.rb", "test/visitors/test_ibm_db.rb", "test/visitors/test_informix.rb", "test/visitors/test_join_sql.rb", "test/visitors/test_mssql.rb", "test/visitors/test_mysql.rb", "test/visitors/test_oracle.rb", "test/visitors/test_postgres.rb", "test/visitors/test_sqlite.rb", "test/visitors/test_to_sql.rb"]
18
+ s.email = [%q{aaron@tenderlovemaking.com}, %q{bryan@brynary.com}, %q{miloops@gmail.com}, %q{nick@example.org}]
19
+ s.extra_rdoc_files = [%q{History.txt}, %q{MIT-LICENSE.txt}, %q{Manifest.txt}, %q{README.markdown}]
20
+ s.files = [%q{.autotest}, %q{.gemtest}, %q{Gemfile}, %q{History.txt}, %q{MIT-LICENSE.txt}, %q{Manifest.txt}, %q{README.markdown}, %q{Rakefile}, %q{arel.gemspec}, %q{lib/arel.rb}, %q{lib/arel/alias_predication.rb}, %q{lib/arel/attributes.rb}, %q{lib/arel/attributes/attribute.rb}, %q{lib/arel/compatibility/wheres.rb}, %q{lib/arel/crud.rb}, %q{lib/arel/delete_manager.rb}, %q{lib/arel/deprecated.rb}, %q{lib/arel/expression.rb}, %q{lib/arel/expressions.rb}, %q{lib/arel/factory_methods.rb}, %q{lib/arel/insert_manager.rb}, %q{lib/arel/math.rb}, %q{lib/arel/nodes.rb}, %q{lib/arel/nodes/and.rb}, %q{lib/arel/nodes/ascending.rb}, %q{lib/arel/nodes/binary.rb}, %q{lib/arel/nodes/count.rb}, %q{lib/arel/nodes/delete_statement.rb}, %q{lib/arel/nodes/descending.rb}, %q{lib/arel/nodes/equality.rb}, %q{lib/arel/nodes/false.rb}, %q{lib/arel/nodes/function.rb}, %q{lib/arel/nodes/in.rb}, %q{lib/arel/nodes/infix_operation.rb}, %q{lib/arel/nodes/inner_join.rb}, %q{lib/arel/nodes/insert_statement.rb}, %q{lib/arel/nodes/join_source.rb}, %q{lib/arel/nodes/named_function.rb}, %q{lib/arel/nodes/node.rb}, %q{lib/arel/nodes/ordering.rb}, %q{lib/arel/nodes/outer_join.rb}, %q{lib/arel/nodes/select_core.rb}, %q{lib/arel/nodes/select_statement.rb}, %q{lib/arel/nodes/sql_literal.rb}, %q{lib/arel/nodes/string_join.rb}, %q{lib/arel/nodes/table_alias.rb}, %q{lib/arel/nodes/terminal.rb}, %q{lib/arel/nodes/true.rb}, %q{lib/arel/nodes/unary.rb}, %q{lib/arel/nodes/unqualified_column.rb}, %q{lib/arel/nodes/update_statement.rb}, %q{lib/arel/nodes/values.rb}, %q{lib/arel/nodes/with.rb}, %q{lib/arel/order_predications.rb}, %q{lib/arel/predications.rb}, %q{lib/arel/relation.rb}, %q{lib/arel/select_manager.rb}, %q{lib/arel/sql/engine.rb}, %q{lib/arel/sql_literal.rb}, %q{lib/arel/table.rb}, %q{lib/arel/tree_manager.rb}, %q{lib/arel/update_manager.rb}, %q{lib/arel/visitors.rb}, %q{lib/arel/visitors/depth_first.rb}, %q{lib/arel/visitors/dot.rb}, %q{lib/arel/visitors/ibm_db.rb}, %q{lib/arel/visitors/informix.rb}, %q{lib/arel/visitors/join_sql.rb}, %q{lib/arel/visitors/mssql.rb}, %q{lib/arel/visitors/mysql.rb}, %q{lib/arel/visitors/oracle.rb}, %q{lib/arel/visitors/order_clauses.rb}, %q{lib/arel/visitors/postgresql.rb}, %q{lib/arel/visitors/sqlite.rb}, %q{lib/arel/visitors/to_sql.rb}, %q{lib/arel/visitors/visitor.rb}, %q{lib/arel/visitors/where_sql.rb}, %q{test/attributes/test_attribute.rb}, %q{test/helper.rb}, %q{test/nodes/test_as.rb}, %q{test/nodes/test_ascending.rb}, %q{test/nodes/test_bin.rb}, %q{test/nodes/test_count.rb}, %q{test/nodes/test_delete_statement.rb}, %q{test/nodes/test_descending.rb}, %q{test/nodes/test_equality.rb}, %q{test/nodes/test_infix_operation.rb}, %q{test/nodes/test_insert_statement.rb}, %q{test/nodes/test_named_function.rb}, %q{test/nodes/test_node.rb}, %q{test/nodes/test_not.rb}, %q{test/nodes/test_or.rb}, %q{test/nodes/test_select_core.rb}, %q{test/nodes/test_select_statement.rb}, %q{test/nodes/test_sql_literal.rb}, %q{test/nodes/test_sum.rb}, %q{test/nodes/test_update_statement.rb}, %q{test/support/fake_record.rb}, %q{test/test_activerecord_compat.rb}, %q{test/test_attributes.rb}, %q{test/test_crud.rb}, %q{test/test_delete_manager.rb}, %q{test/test_factory_methods.rb}, %q{test/test_insert_manager.rb}, %q{test/test_select_manager.rb}, %q{test/test_table.rb}, %q{test/test_update_manager.rb}, %q{test/visitors/test_depth_first.rb}, %q{test/visitors/test_dot.rb}, %q{test/visitors/test_ibm_db.rb}, %q{test/visitors/test_informix.rb}, %q{test/visitors/test_join_sql.rb}, %q{test/visitors/test_mssql.rb}, %q{test/visitors/test_mysql.rb}, %q{test/visitors/test_oracle.rb}, %q{test/visitors/test_postgres.rb}, %q{test/visitors/test_sqlite.rb}, %q{test/visitors/test_to_sql.rb}]
21
21
  s.homepage = %q{http://github.com/rails/arel}
22
- s.rdoc_options = ["--main", "README.markdown"]
23
- s.require_paths = ["lib"]
22
+ s.rdoc_options = [%q{--main}, %q{README.markdown}]
23
+ s.require_paths = [%q{lib}]
24
24
  s.rubyforge_project = %q{arel}
25
- s.rubygems_version = %q{1.3.6}
25
+ s.rubygems_version = %q{1.8.6.1}
26
26
  s.summary = %q{Arel is a SQL AST manager for Ruby}
27
- s.test_files = ["test/attributes/test_attribute.rb", "test/nodes/test_as.rb", "test/nodes/test_ascending.rb", "test/nodes/test_bin.rb", "test/nodes/test_count.rb", "test/nodes/test_delete_statement.rb", "test/nodes/test_descending.rb", "test/nodes/test_equality.rb", "test/nodes/test_infix_operation.rb", "test/nodes/test_insert_statement.rb", "test/nodes/test_named_function.rb", "test/nodes/test_node.rb", "test/nodes/test_not.rb", "test/nodes/test_or.rb", "test/nodes/test_select_core.rb", "test/nodes/test_select_statement.rb", "test/nodes/test_sql_literal.rb", "test/nodes/test_sum.rb", "test/nodes/test_update_statement.rb", "test/test_activerecord_compat.rb", "test/test_attributes.rb", "test/test_crud.rb", "test/test_delete_manager.rb", "test/test_factory_methods.rb", "test/test_insert_manager.rb", "test/test_select_manager.rb", "test/test_table.rb", "test/test_update_manager.rb", "test/visitors/test_depth_first.rb", "test/visitors/test_dot.rb", "test/visitors/test_ibm_db.rb", "test/visitors/test_informix.rb", "test/visitors/test_join_sql.rb", "test/visitors/test_mssql.rb", "test/visitors/test_mysql.rb", "test/visitors/test_oracle.rb", "test/visitors/test_postgres.rb", "test/visitors/test_sqlite.rb", "test/visitors/test_to_sql.rb"]
27
+ s.test_files = [%q{test/attributes/test_attribute.rb}, %q{test/nodes/test_as.rb}, %q{test/nodes/test_ascending.rb}, %q{test/nodes/test_bin.rb}, %q{test/nodes/test_count.rb}, %q{test/nodes/test_delete_statement.rb}, %q{test/nodes/test_descending.rb}, %q{test/nodes/test_equality.rb}, %q{test/nodes/test_infix_operation.rb}, %q{test/nodes/test_insert_statement.rb}, %q{test/nodes/test_named_function.rb}, %q{test/nodes/test_node.rb}, %q{test/nodes/test_not.rb}, %q{test/nodes/test_or.rb}, %q{test/nodes/test_select_core.rb}, %q{test/nodes/test_select_statement.rb}, %q{test/nodes/test_sql_literal.rb}, %q{test/nodes/test_sum.rb}, %q{test/nodes/test_update_statement.rb}, %q{test/test_activerecord_compat.rb}, %q{test/test_attributes.rb}, %q{test/test_crud.rb}, %q{test/test_delete_manager.rb}, %q{test/test_factory_methods.rb}, %q{test/test_insert_manager.rb}, %q{test/test_select_manager.rb}, %q{test/test_table.rb}, %q{test/test_update_manager.rb}, %q{test/visitors/test_depth_first.rb}, %q{test/visitors/test_dot.rb}, %q{test/visitors/test_ibm_db.rb}, %q{test/visitors/test_informix.rb}, %q{test/visitors/test_join_sql.rb}, %q{test/visitors/test_mssql.rb}, %q{test/visitors/test_mysql.rb}, %q{test/visitors/test_oracle.rb}, %q{test/visitors/test_postgres.rb}, %q{test/visitors/test_sqlite.rb}, %q{test/visitors/test_to_sql.rb}]
28
28
 
29
29
  if s.respond_to? :specification_version then
30
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
31
30
  s.specification_version = 3
32
31
 
33
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
34
- s.add_development_dependency(%q<minitest>, ["~> 2.3"])
35
- s.add_development_dependency(%q<hoe>, ["~> 2.9"])
32
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
33
+ s.add_development_dependency(%q<hoe>, ["~> 2.10"])
36
34
  else
37
- s.add_dependency(%q<minitest>, ["~> 2.3"])
38
- s.add_dependency(%q<hoe>, ["~> 2.9"])
35
+ s.add_dependency(%q<hoe>, ["~> 2.10"])
39
36
  end
40
37
  else
41
- s.add_dependency(%q<minitest>, ["~> 2.3"])
42
- s.add_dependency(%q<hoe>, ["~> 2.9"])
38
+ s.add_dependency(%q<hoe>, ["~> 2.10"])
43
39
  end
44
40
  end
@@ -33,7 +33,7 @@ require 'arel/sql_literal'
33
33
  ####
34
34
 
35
35
  module Arel
36
- VERSION = '2.1.4'
36
+ VERSION = '2.2.0'
37
37
 
38
38
  def self.sql raw_sql
39
39
  Arel::Nodes::SqlLiteral.new raw_sql
@@ -2,6 +2,14 @@ module Arel
2
2
  ###
3
3
  # Methods for creating various nodes
4
4
  module FactoryMethods
5
+ def create_true
6
+ Arel::Nodes::True.new
7
+ end
8
+
9
+ def create_false
10
+ Arel::Nodes::False.new
11
+ end
12
+
5
13
  def create_table_alias relation, name
6
14
  Nodes::TableAlias.new(relation, name)
7
15
  end
@@ -8,6 +8,8 @@ require 'arel/nodes/update_statement'
8
8
  # terminal
9
9
 
10
10
  require 'arel/nodes/terminal'
11
+ require 'arel/nodes/true'
12
+ require 'arel/nodes/false'
11
13
 
12
14
  # unary
13
15
  require 'arel/nodes/unary'
@@ -0,0 +1,6 @@
1
+ module Arel
2
+ module Nodes
3
+ class False < Arel::Nodes::Node
4
+ end
5
+ end
6
+ end
@@ -9,6 +9,10 @@ module Arel
9
9
  def initialize single_source, joinop = []
10
10
  super
11
11
  end
12
+
13
+ def empty?
14
+ !left && right.empty?
15
+ end
12
16
  end
13
17
  end
14
18
  end
@@ -32,8 +32,7 @@ module Arel
32
32
  #
33
33
  # Maybe we should just use `Table.engine`? :'(
34
34
  def to_sql engine = Table.engine
35
- viz = Visitors.for engine
36
- viz.accept self
35
+ engine.connection.visitor.accept self
37
36
  end
38
37
 
39
38
  # Iterate through AST, nodes will be yielded depth-first
@@ -0,0 +1,6 @@
1
+ module Arel
2
+ module Nodes
3
+ class True < Arel::Nodes::Node
4
+ end
5
+ end
6
+ end
@@ -1,6 +1,5 @@
1
1
  module Arel
2
2
  module Predications
3
-
4
3
  def not_eq other
5
4
  Nodes::NotEqual.new self, other
6
5
  end
@@ -149,13 +149,13 @@ module Arel
149
149
 
150
150
  def wheres
151
151
  warn "#{caller[0]}: SelectManager#wheres is deprecated and will be removed in ARel 3.0.0 with no replacement"
152
- Compatibility::Wheres.new @engine, @ctx.wheres
152
+ Compatibility::Wheres.new @engine.connection_pool, @ctx.wheres
153
153
  end
154
154
 
155
155
  def where_sql
156
156
  return if @ctx.wheres.empty?
157
157
 
158
- viz = Visitors::WhereSql.new @engine
158
+ viz = Visitors::WhereSql.new @engine.connection_pool
159
159
  Nodes::SqlLiteral.new viz.accept @ctx
160
160
  end
161
161
 
@@ -205,12 +205,13 @@ module Arel
205
205
  def join_sql
206
206
  return nil if @ctx.source.right.empty?
207
207
 
208
- sql = @visitor.dup.extend(Visitors::JoinSql).accept @ctx
208
+ sql = visitor.dup.extend(Visitors::JoinSql).accept @ctx
209
209
  Nodes::SqlLiteral.new sql
210
210
  end
211
211
 
212
212
  def order_clauses
213
- Visitors::OrderClauses.new(@engine).accept(@ast).map { |x|
213
+ visitor = Visitors::OrderClauses.new(@engine.connection_pool)
214
+ visitor.accept(@ast).map { |x|
214
215
  Nodes::SqlLiteral.new x
215
216
  }
216
217
  end
@@ -4,21 +4,23 @@ module Arel
4
4
  include Arel::Relation
5
5
  include Arel::FactoryMethods
6
6
 
7
- attr_accessor :visitor
8
7
  attr_reader :ast, :engine
9
8
 
10
9
  def initialize engine
11
- @engine = engine
12
- @visitor = Visitors.visitor_for @engine
13
- @ctx = nil
10
+ @engine = engine
11
+ @ctx = nil
14
12
  end
15
13
 
16
14
  def to_dot
17
15
  Visitors::Dot.new.accept @ast
18
16
  end
19
17
 
18
+ def visitor
19
+ engine.connection.visitor
20
+ end
21
+
20
22
  def to_sql
21
- @visitor.accept @ast
23
+ visitor.accept @ast
22
24
  end
23
25
 
24
26
  def initialize_copy other
@@ -65,6 +65,18 @@ module Arel
65
65
  "( #{visit o.left} MINUS #{visit o.right} )"
66
66
  end
67
67
 
68
+ def visit_Arel_Nodes_UpdateStatement o
69
+ # Oracle does not allow ORDER BY/LIMIT in UPDATEs.
70
+ if o.orders.any? && o.limit.nil?
71
+ # However, there is no harm in silently eating the ORDER BY clause if no LIMIT has been provided,
72
+ # otherwise let the user deal with the error
73
+ o = o.dup
74
+ o.orders = []
75
+ end
76
+
77
+ super
78
+ end
79
+
68
80
  ###
69
81
  # Hacks for the order clauses specific to Oracle
70
82
  def order_hacks o
@@ -4,17 +4,15 @@ require 'date'
4
4
  module Arel
5
5
  module Visitors
6
6
  class ToSql < Arel::Visitors::Visitor
7
- def initialize engine
8
- @engine = engine
7
+ def initialize pool
8
+ @pool = pool
9
9
  @connection = nil
10
- @pool = nil
11
10
  @quoted_tables = {}
12
11
  @quoted_columns = {}
13
12
  end
14
13
 
15
14
  def accept object
16
15
  self.last_column = nil
17
- @pool = @engine.connection_pool
18
16
  @pool.with_connection do |conn|
19
17
  @connection = conn
20
18
  super
@@ -90,6 +88,14 @@ key on UpdateManager using UpdateManager#key=
90
88
  o.alias ? " AS #{visit o.alias}" : ''}"
91
89
  end
92
90
 
91
+ def visit_Arel_Nodes_True o
92
+ "TRUE"
93
+ end
94
+
95
+ def visit_Arel_Nodes_False o
96
+ "FALSE"
97
+ end
98
+
93
99
  def table_exists? name
94
100
  @pool.table_exists? name
95
101
  end
@@ -134,7 +140,7 @@ key on UpdateManager using UpdateManager#key=
134
140
  (visit(o.top) if o.top),
135
141
  (visit(o.set_quantifier) if o.set_quantifier),
136
142
  ("#{o.projections.map { |x| visit x }.join ', '}" unless o.projections.empty?),
137
- (visit(o.source) if o.source),
143
+ ("FROM #{visit(o.source)}" if o.source && !o.source.empty?),
138
144
  ("WHERE #{o.wheres.map { |x| visit x }.join ' AND ' }" unless o.wheres.empty?),
139
145
  ("GROUP BY #{o.groups.map { |x| visit x }.join ', ' }" unless o.groups.empty?),
140
146
  (visit(o.having) if o.having),
@@ -280,10 +286,7 @@ key on UpdateManager using UpdateManager#key=
280
286
  end
281
287
 
282
288
  def visit_Arel_Nodes_JoinSource o
283
- return unless o.left || !o.right.empty?
284
-
285
289
  [
286
- "FROM",
287
290
  (visit(o.left) if o.left),
288
291
  o.right.map { |j| visit j }.join(' ')
289
292
  ].compact.join ' '
@@ -8,13 +8,13 @@ module Arel
8
8
  end
9
9
 
10
10
  def test_default_to_sql
11
- viz = Arel::Visitors::ToSql.new Table.engine
11
+ viz = Arel::Visitors::ToSql.new Table.engine.connection_pool
12
12
  node = Arel::Nodes::Bin.new(Arel.sql('zomg'))
13
13
  assert_equal 'zomg', viz.accept(node)
14
14
  end
15
15
 
16
16
  def test_mysql_to_sql
17
- viz = Arel::Visitors::MySQL.new Table.engine
17
+ viz = Arel::Visitors::MySQL.new Table.engine.connection_pool
18
18
  node = Arel::Nodes::Bin.new(Arel.sql('zomg'))
19
19
  assert_equal 'BINARY zomg', viz.accept(node)
20
20
  end
@@ -23,7 +23,7 @@ module Arel
23
23
  def test_set_quantifier
24
24
  core = Arel::Nodes::SelectCore.new
25
25
  core.set_quantifier = Arel::Nodes::Distinct.new
26
- viz = Arel::Visitors::ToSql.new Table.engine
26
+ viz = Arel::Visitors::ToSql.new Table.engine.connection_pool
27
27
  assert_match 'DISTINCT', viz.accept(core)
28
28
  end
29
29
  end
@@ -3,6 +3,10 @@ require 'helper'
3
3
  module Arel
4
4
  module Nodes
5
5
  describe 'sql literal' do
6
+ before do
7
+ @visitor = Visitors::ToSql.new Table.engine.connection_pool
8
+ end
9
+
6
10
  describe 'sql' do
7
11
  it 'makes a sql literal node' do
8
12
  sql = Arel.sql 'foo'
@@ -13,38 +17,33 @@ module Arel
13
17
  describe 'count' do
14
18
  it 'makes a count node' do
15
19
  node = SqlLiteral.new('*').count
16
- viz = Visitors::ToSql.new Table.engine
17
- viz.accept(node).must_be_like %{ COUNT(*) }
20
+ @visitor.accept(node).must_be_like %{ COUNT(*) }
18
21
  end
19
22
 
20
23
  it 'makes a distinct node' do
21
24
  node = SqlLiteral.new('*').count true
22
- viz = Visitors::ToSql.new Table.engine
23
- viz.accept(node).must_be_like %{ COUNT(DISTINCT *) }
25
+ @visitor.accept(node).must_be_like %{ COUNT(DISTINCT *) }
24
26
  end
25
27
  end
26
28
 
27
29
  describe 'equality' do
28
30
  it 'makes an equality node' do
29
31
  node = SqlLiteral.new('foo').eq(1)
30
- viz = Visitors::ToSql.new Table.engine
31
- viz.accept(node).must_be_like %{ foo = 1 }
32
+ @visitor.accept(node).must_be_like %{ foo = 1 }
32
33
  end
33
34
  end
34
35
 
35
36
  describe 'grouped "or" equality' do
36
37
  it 'makes a grouping node with an or node' do
37
38
  node = SqlLiteral.new('foo').eq_any([1,2])
38
- viz = Visitors::ToSql.new Table.engine
39
- viz.accept(node).must_be_like %{ (foo = 1 OR foo = 2) }
39
+ @visitor.accept(node).must_be_like %{ (foo = 1 OR foo = 2) }
40
40
  end
41
41
  end
42
42
 
43
43
  describe 'grouped "and" equality' do
44
44
  it 'makes a grouping node with an or node' do
45
45
  node = SqlLiteral.new('foo').eq_all([1,2])
46
- viz = Visitors::ToSql.new Table.engine
47
- viz.accept(node).must_be_like %{ (foo = 1 AND foo = 2) }
46
+ @visitor.accept(node).must_be_like %{ (foo = 1 AND foo = 2) }
48
47
  end
49
48
  end
50
49
  end
@@ -3,9 +3,9 @@ module FakeRecord
3
3
  end
4
4
 
5
5
  class Connection
6
- attr_reader :tables, :columns_hash
6
+ attr_reader :tables, :columns_hash, :visitor
7
7
 
8
- def initialize
8
+ def initialize(visitor)
9
9
  @tables = %w{ users photos developers products}
10
10
  @columns = {
11
11
  'users' => [
@@ -27,6 +27,7 @@ module FakeRecord
27
27
  'users' => 'id',
28
28
  'products' => 'id'
29
29
  }
30
+ @visitor = visitor
30
31
  end
31
32
 
32
33
  def primary_key name
@@ -78,7 +79,7 @@ module FakeRecord
78
79
 
79
80
  def initialize
80
81
  @spec = Spec.new(:adapter => 'america')
81
- @connection = Connection.new
82
+ @connection = Connection.new(Arel::Visitors::ToSql.new(self))
82
83
  end
83
84
 
84
85
  def with_connection
@@ -23,6 +23,16 @@ module Arel
23
23
  assert_equal :one, on.expr
24
24
  end
25
25
 
26
+ def test_create_true
27
+ true_node = @factory.create_true
28
+ assert_instance_of Nodes::True, true_node
29
+ end
30
+
31
+ def test_create_false
32
+ false_node = @factory.create_false
33
+ assert_instance_of Nodes::False, false_node
34
+ end
35
+
26
36
  def test_lower
27
37
  lower = @factory.lower :one
28
38
  assert_instance_of Nodes::NamedFunction, lower
@@ -42,6 +42,10 @@ module Arel
42
42
  @engine.connection.tables
43
43
  end
44
44
 
45
+ def visitor
46
+ @engine.connection.visitor
47
+ end
48
+
45
49
  def execute sql, name = nil, *args
46
50
  @executed << sql
47
51
  end
@@ -62,6 +62,19 @@ module Arel
62
62
  um = Arel::UpdateManager.new Table.engine
63
63
  um.table(Table.new(:users)).must_equal um
64
64
  end
65
+
66
+ it 'generates an update statement with joins' do
67
+ um = Arel::UpdateManager.new Table.engine
68
+
69
+ table = Table.new(:users)
70
+ join_source = Arel::Nodes::JoinSource.new(
71
+ table,
72
+ [table.create_join(Table.new(:posts))]
73
+ )
74
+
75
+ um.table join_source
76
+ um.to_sql.must_be_like %{ UPDATE "users" INNER JOIN "posts" }
77
+ end
65
78
  end
66
79
 
67
80
  describe 'where' do
@@ -4,7 +4,7 @@ module Arel
4
4
  module Visitors
5
5
  describe 'the ibm_db visitor' do
6
6
  before do
7
- @visitor = IBM_DB.new Table.engine
7
+ @visitor = IBM_DB.new Table.engine.connection_pool
8
8
  end
9
9
 
10
10
  it 'uses FETCH FIRST n ROWS to limit results' do
@@ -4,7 +4,7 @@ module Arel
4
4
  module Visitors
5
5
  describe 'the informix visitor' do
6
6
  before do
7
- @visitor = Informix.new Table.engine
7
+ @visitor = Informix.new Table.engine.connection_pool
8
8
  end
9
9
 
10
10
  it 'uses LIMIT n to limit results' do
@@ -4,7 +4,7 @@ module Arel
4
4
  module Visitors
5
5
  describe 'the join_sql visitor' do
6
6
  before do
7
- @visitor = ToSql.new Table.engine
7
+ @visitor = ToSql.new Table.engine.connection_pool
8
8
  @visitor.extend(JoinSql)
9
9
  end
10
10
 
@@ -4,7 +4,7 @@ module Arel
4
4
  module Visitors
5
5
  describe 'the mssql visitor' do
6
6
  before do
7
- @visitor = MSSQL.new Table.engine
7
+ @visitor = MSSQL.new Table.engine.connection_pool
8
8
  @table = Arel::Table.new "users"
9
9
  end
10
10
 
@@ -4,7 +4,7 @@ module Arel
4
4
  module Visitors
5
5
  describe 'the mysql visitor' do
6
6
  before do
7
- @visitor = MySQL.new Table.engine
7
+ @visitor = MySQL.new Table.engine.connection_pool
8
8
  end
9
9
 
10
10
  it 'squashes parenthesis on multiple unions' do
@@ -4,7 +4,7 @@ module Arel
4
4
  module Visitors
5
5
  describe 'the oracle visitor' do
6
6
  before do
7
- @visitor = Oracle.new Table.engine
7
+ @visitor = Oracle.new Table.engine.connection_pool
8
8
  end
9
9
 
10
10
  it 'modifies order when there is distinct and first value' do
@@ -4,7 +4,7 @@ module Arel
4
4
  module Visitors
5
5
  describe 'the postgres visitor' do
6
6
  before do
7
- @visitor = PostgreSQL.new Table.engine
7
+ @visitor = PostgreSQL.new Table.engine.connection_pool
8
8
  end
9
9
 
10
10
  describe 'locking' do
@@ -4,7 +4,7 @@ module Arel
4
4
  module Visitors
5
5
  describe 'the sqlite visitor' do
6
6
  before do
7
- @visitor = SQLite.new Table.engine
7
+ @visitor = SQLite.new Table.engine.connection_pool
8
8
  end
9
9
 
10
10
  it 'defaults limit to -1' do
@@ -8,7 +8,7 @@ module Arel
8
8
  module Visitors
9
9
  describe 'the to_sql visitor' do
10
10
  before do
11
- @visitor = ToSql.new Table.engine
11
+ @visitor = ToSql.new Table.engine.connection_pool
12
12
  @table = Table.new(:users)
13
13
  @attr = @table[:id]
14
14
  end
@@ -220,7 +220,7 @@ module Arel
220
220
  end
221
221
  end
222
222
  in_node = Nodes::In.new @attr, %w{ a b c }
223
- visitor = visitor.new(Table.engine)
223
+ visitor = visitor.new(Table.engine.connection_pool)
224
224
  visitor.expected = Table.engine.connection.columns(:users).find { |x|
225
225
  x.name == 'name'
226
226
  }
@@ -308,7 +308,7 @@ module Arel
308
308
  end
309
309
  end
310
310
  in_node = Nodes::NotIn.new @attr, %w{ a b c }
311
- visitor = visitor.new(Table.engine)
311
+ visitor = visitor.new(Table.engine.connection_pool)
312
312
  visitor.expected = Table.engine.connection.columns(:users).find { |x|
313
313
  x.name == 'name'
314
314
  }
@@ -325,6 +325,22 @@ module Arel
325
325
  end
326
326
  end
327
327
 
328
+ describe 'Constants' do
329
+ it "should handle true" do
330
+ test = Table.new(:users).create_true
331
+ @visitor.accept(test).must_be_like %{
332
+ TRUE
333
+ }
334
+ end
335
+
336
+ it "should handle false" do
337
+ test = Table.new(:users).create_false
338
+ @visitor.accept(test).must_be_like %{
339
+ FALSE
340
+ }
341
+ end
342
+ end
343
+
328
344
  describe 'TableAlias' do
329
345
  it "should use the underlying table for checking columns" do
330
346
  test = Table.new(:users).alias('zomgusers')[:id].eq '3'
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 2
7
- - 1
8
- - 4
9
- version: 2.1.4
7
+ - 2
8
+ - 0
9
+ version: 2.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Aaron Patterson
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2011-07-25 00:00:00 -07:00
20
+ date: 2011-08-09 00:00:00 -07:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
@@ -72,6 +72,7 @@ extra_rdoc_files:
72
72
  files:
73
73
  - .autotest
74
74
  - .gemtest
75
+ - Gemfile
75
76
  - History.txt
76
77
  - MIT-LICENSE.txt
77
78
  - Manifest.txt
@@ -99,6 +100,7 @@ files:
99
100
  - lib/arel/nodes/delete_statement.rb
100
101
  - lib/arel/nodes/descending.rb
101
102
  - lib/arel/nodes/equality.rb
103
+ - lib/arel/nodes/false.rb
102
104
  - lib/arel/nodes/function.rb
103
105
  - lib/arel/nodes/in.rb
104
106
  - lib/arel/nodes/infix_operation.rb
@@ -115,6 +117,7 @@ files:
115
117
  - lib/arel/nodes/string_join.rb
116
118
  - lib/arel/nodes/table_alias.rb
117
119
  - lib/arel/nodes/terminal.rb
120
+ - lib/arel/nodes/true.rb
118
121
  - lib/arel/nodes/unary.rb
119
122
  - lib/arel/nodes/unqualified_column.rb
120
123
  - lib/arel/nodes/update_statement.rb