arel-compat 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. data/History.txt +25 -0
  2. data/README.markdown +182 -0
  3. data/lib/arel.rb +13 -0
  4. data/lib/arel/algebra.rb +10 -0
  5. data/lib/arel/algebra/attributes.rb +7 -0
  6. data/lib/arel/algebra/attributes/attribute.rb +270 -0
  7. data/lib/arel/algebra/attributes/boolean.rb +21 -0
  8. data/lib/arel/algebra/attributes/decimal.rb +9 -0
  9. data/lib/arel/algebra/attributes/float.rb +9 -0
  10. data/lib/arel/algebra/attributes/integer.rb +10 -0
  11. data/lib/arel/algebra/attributes/string.rb +10 -0
  12. data/lib/arel/algebra/attributes/time.rb +6 -0
  13. data/lib/arel/algebra/core_extensions.rb +4 -0
  14. data/lib/arel/algebra/core_extensions/class.rb +32 -0
  15. data/lib/arel/algebra/core_extensions/hash.rb +11 -0
  16. data/lib/arel/algebra/core_extensions/object.rb +30 -0
  17. data/lib/arel/algebra/core_extensions/symbol.rb +9 -0
  18. data/lib/arel/algebra/expression.rb +43 -0
  19. data/lib/arel/algebra/header.rb +67 -0
  20. data/lib/arel/algebra/ordering.rb +23 -0
  21. data/lib/arel/algebra/predicates.rb +190 -0
  22. data/lib/arel/algebra/relations.rb +17 -0
  23. data/lib/arel/algebra/relations/operations/alias.rb +7 -0
  24. data/lib/arel/algebra/relations/operations/from.rb +6 -0
  25. data/lib/arel/algebra/relations/operations/group.rb +12 -0
  26. data/lib/arel/algebra/relations/operations/having.rb +17 -0
  27. data/lib/arel/algebra/relations/operations/join.rb +69 -0
  28. data/lib/arel/algebra/relations/operations/lock.rb +12 -0
  29. data/lib/arel/algebra/relations/operations/order.rb +19 -0
  30. data/lib/arel/algebra/relations/operations/project.rb +20 -0
  31. data/lib/arel/algebra/relations/operations/skip.rb +7 -0
  32. data/lib/arel/algebra/relations/operations/take.rb +11 -0
  33. data/lib/arel/algebra/relations/operations/where.rb +17 -0
  34. data/lib/arel/algebra/relations/relation.rb +136 -0
  35. data/lib/arel/algebra/relations/row.rb +26 -0
  36. data/lib/arel/algebra/relations/utilities/compound.rb +54 -0
  37. data/lib/arel/algebra/relations/utilities/externalization.rb +24 -0
  38. data/lib/arel/algebra/relations/utilities/nil.rb +7 -0
  39. data/lib/arel/algebra/relations/writes.rb +36 -0
  40. data/lib/arel/algebra/value.rb +14 -0
  41. data/lib/arel/engines.rb +2 -0
  42. data/lib/arel/engines/memory.rb +4 -0
  43. data/lib/arel/engines/memory/engine.rb +16 -0
  44. data/lib/arel/engines/memory/predicates.rb +99 -0
  45. data/lib/arel/engines/memory/primitives.rb +27 -0
  46. data/lib/arel/engines/memory/relations.rb +5 -0
  47. data/lib/arel/engines/memory/relations/array.rb +35 -0
  48. data/lib/arel/engines/memory/relations/compound.rb +9 -0
  49. data/lib/arel/engines/memory/relations/operations.rb +67 -0
  50. data/lib/arel/engines/memory/relations/writes.rb +7 -0
  51. data/lib/arel/engines/sql.rb +8 -0
  52. data/lib/arel/engines/sql/attributes.rb +40 -0
  53. data/lib/arel/engines/sql/christener.rb +14 -0
  54. data/lib/arel/engines/sql/compilers/ibm_db_compiler.rb +48 -0
  55. data/lib/arel/engines/sql/compilers/mysql_compiler.rb +11 -0
  56. data/lib/arel/engines/sql/compilers/oracle_compiler.rb +95 -0
  57. data/lib/arel/engines/sql/compilers/postgresql_compiler.rb +42 -0
  58. data/lib/arel/engines/sql/compilers/sqlite_compiler.rb +9 -0
  59. data/lib/arel/engines/sql/core_extensions.rb +4 -0
  60. data/lib/arel/engines/sql/core_extensions/array.rb +24 -0
  61. data/lib/arel/engines/sql/core_extensions/nil_class.rb +15 -0
  62. data/lib/arel/engines/sql/core_extensions/object.rb +19 -0
  63. data/lib/arel/engines/sql/core_extensions/range.rb +19 -0
  64. data/lib/arel/engines/sql/engine.rb +55 -0
  65. data/lib/arel/engines/sql/formatters.rb +122 -0
  66. data/lib/arel/engines/sql/predicates.rb +103 -0
  67. data/lib/arel/engines/sql/primitives.rb +97 -0
  68. data/lib/arel/engines/sql/relations.rb +10 -0
  69. data/lib/arel/engines/sql/relations/compiler.rb +118 -0
  70. data/lib/arel/engines/sql/relations/operations/alias.rb +5 -0
  71. data/lib/arel/engines/sql/relations/operations/join.rb +33 -0
  72. data/lib/arel/engines/sql/relations/relation.rb +65 -0
  73. data/lib/arel/engines/sql/relations/table.rb +88 -0
  74. data/lib/arel/engines/sql/relations/utilities/compound.rb +10 -0
  75. data/lib/arel/engines/sql/relations/utilities/externalization.rb +14 -0
  76. data/lib/arel/engines/sql/relations/utilities/nil.rb +6 -0
  77. data/lib/arel/engines/sql/relations/utilities/recursion.rb +13 -0
  78. data/lib/arel/engines/sql/relations/writes.rb +19 -0
  79. data/lib/arel/session.rb +51 -0
  80. data/lib/arel/version.rb +3 -0
  81. data/spec/algebra/unit/predicates/binary_spec.rb +35 -0
  82. data/spec/algebra/unit/predicates/equality_spec.rb +29 -0
  83. data/spec/algebra/unit/predicates/in_spec.rb +12 -0
  84. data/spec/algebra/unit/primitives/attribute_spec.rb +181 -0
  85. data/spec/algebra/unit/primitives/expression_spec.rb +45 -0
  86. data/spec/algebra/unit/primitives/value_spec.rb +15 -0
  87. data/spec/algebra/unit/relations/alias_spec.rb +16 -0
  88. data/spec/algebra/unit/relations/delete_spec.rb +9 -0
  89. data/spec/algebra/unit/relations/group_spec.rb +10 -0
  90. data/spec/algebra/unit/relations/insert_spec.rb +9 -0
  91. data/spec/algebra/unit/relations/join_spec.rb +25 -0
  92. data/spec/algebra/unit/relations/order_spec.rb +21 -0
  93. data/spec/algebra/unit/relations/project_spec.rb +34 -0
  94. data/spec/algebra/unit/relations/relation_spec.rb +187 -0
  95. data/spec/algebra/unit/relations/skip_spec.rb +10 -0
  96. data/spec/algebra/unit/relations/table_spec.rb +38 -0
  97. data/spec/algebra/unit/relations/take_spec.rb +10 -0
  98. data/spec/algebra/unit/relations/update_spec.rb +9 -0
  99. data/spec/algebra/unit/relations/where_spec.rb +19 -0
  100. data/spec/algebra/unit/session/session_spec.rb +84 -0
  101. data/spec/attributes/boolean_spec.rb +57 -0
  102. data/spec/attributes/float_spec.rb +119 -0
  103. data/spec/attributes/header_spec.rb +42 -0
  104. data/spec/attributes/integer_spec.rb +119 -0
  105. data/spec/attributes/string_spec.rb +43 -0
  106. data/spec/attributes/time_spec.rb +24 -0
  107. data/spec/engines/memory/integration/joins/cross_engine_spec.rb +51 -0
  108. data/spec/engines/memory/unit/relations/array_spec.rb +32 -0
  109. data/spec/engines/memory/unit/relations/insert_spec.rb +28 -0
  110. data/spec/engines/memory/unit/relations/join_spec.rb +31 -0
  111. data/spec/engines/memory/unit/relations/order_spec.rb +27 -0
  112. data/spec/engines/memory/unit/relations/project_spec.rb +27 -0
  113. data/spec/engines/memory/unit/relations/skip_spec.rb +26 -0
  114. data/spec/engines/memory/unit/relations/take_spec.rb +26 -0
  115. data/spec/engines/memory/unit/relations/where_spec.rb +39 -0
  116. data/spec/engines/sql/integration/joins/with_adjacency_spec.rb +258 -0
  117. data/spec/engines/sql/integration/joins/with_aggregations_spec.rb +221 -0
  118. data/spec/engines/sql/integration/joins/with_compounds_spec.rb +137 -0
  119. data/spec/engines/sql/unit/engine_spec.rb +45 -0
  120. data/spec/engines/sql/unit/predicates/binary_spec.rb +140 -0
  121. data/spec/engines/sql/unit/predicates/equality_spec.rb +75 -0
  122. data/spec/engines/sql/unit/predicates/in_spec.rb +179 -0
  123. data/spec/engines/sql/unit/predicates/noteq_spec.rb +75 -0
  124. data/spec/engines/sql/unit/predicates/predicates_spec.rb +79 -0
  125. data/spec/engines/sql/unit/primitives/attribute_spec.rb +36 -0
  126. data/spec/engines/sql/unit/primitives/expression_spec.rb +28 -0
  127. data/spec/engines/sql/unit/primitives/literal_spec.rb +43 -0
  128. data/spec/engines/sql/unit/primitives/value_spec.rb +29 -0
  129. data/spec/engines/sql/unit/relations/alias_spec.rb +53 -0
  130. data/spec/engines/sql/unit/relations/delete_spec.rb +83 -0
  131. data/spec/engines/sql/unit/relations/from_spec.rb +64 -0
  132. data/spec/engines/sql/unit/relations/group_spec.rb +72 -0
  133. data/spec/engines/sql/unit/relations/having_spec.rb +78 -0
  134. data/spec/engines/sql/unit/relations/insert_spec.rb +143 -0
  135. data/spec/engines/sql/unit/relations/join_spec.rb +180 -0
  136. data/spec/engines/sql/unit/relations/lock_spec.rb +86 -0
  137. data/spec/engines/sql/unit/relations/order_spec.rb +161 -0
  138. data/spec/engines/sql/unit/relations/project_spec.rb +143 -0
  139. data/spec/engines/sql/unit/relations/skip_spec.rb +41 -0
  140. data/spec/engines/sql/unit/relations/table_spec.rb +129 -0
  141. data/spec/engines/sql/unit/relations/take_spec.rb +49 -0
  142. data/spec/engines/sql/unit/relations/update_spec.rb +203 -0
  143. data/spec/engines/sql/unit/relations/where_spec.rb +72 -0
  144. data/spec/relations/join_spec.rb +42 -0
  145. data/spec/relations/relation_spec.rb +31 -0
  146. data/spec/shared/relation_spec.rb +255 -0
  147. data/spec/spec_helper.rb +36 -0
  148. data/spec/support/check.rb +6 -0
  149. data/spec/support/connections/mysql_connection.rb +14 -0
  150. data/spec/support/connections/oracle_connection.rb +17 -0
  151. data/spec/support/connections/postgresql_connection.rb +13 -0
  152. data/spec/support/connections/sqlite3_connection.rb +24 -0
  153. data/spec/support/guards.rb +28 -0
  154. data/spec/support/matchers.rb +4 -0
  155. data/spec/support/matchers/be_like.rb +24 -0
  156. data/spec/support/matchers/disambiguate_attributes.rb +28 -0
  157. data/spec/support/matchers/hash_the_same_as.rb +26 -0
  158. data/spec/support/matchers/have_rows.rb +18 -0
  159. data/spec/support/model.rb +62 -0
  160. data/spec/support/schemas/mysql_schema.rb +26 -0
  161. data/spec/support/schemas/oracle_schema.rb +20 -0
  162. data/spec/support/schemas/postgresql_schema.rb +26 -0
  163. data/spec/support/schemas/sqlite3_schema.rb +26 -0
  164. metadata +258 -0
@@ -0,0 +1,24 @@
1
+ module Arel
2
+ class Externalization < Compound
3
+ attributes :relation
4
+ deriving :initialize, :==
5
+
6
+ def wheres
7
+ []
8
+ end
9
+
10
+ def attributes
11
+ @attributes ||= Header.new(relation.attributes.map { |a| a.to_attribute(self) })
12
+ end
13
+ end
14
+
15
+ module Relation
16
+ def externalize
17
+ @externalized ||= externalizable?? Externalization.new(self) : self
18
+ end
19
+
20
+ def externalizable?
21
+ false
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,7 @@
1
+ require 'singleton'
2
+
3
+ module Arel
4
+ class Nil
5
+ include Relation, Singleton
6
+ end
7
+ end
@@ -0,0 +1,36 @@
1
+ module Arel
2
+ class Deletion < Compound
3
+ attributes :relation
4
+ deriving :initialize, :==
5
+
6
+ def call
7
+ engine.delete(self)
8
+ end
9
+ end
10
+
11
+ class Insert < Compound
12
+ attributes :relation, :record
13
+ deriving :==
14
+
15
+ def initialize(relation, record)
16
+ @relation, @record = relation, record.bind(relation)
17
+ end
18
+
19
+ def call
20
+ engine.create(self)
21
+ end
22
+ end
23
+
24
+ class Update < Compound
25
+ attributes :relation, :assignments
26
+ deriving :==
27
+
28
+ def initialize(relation, assignments)
29
+ @relation, @assignments = relation, assignments.bind(relation)
30
+ end
31
+
32
+ def call
33
+ engine.update(self)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,14 @@
1
+ module Arel
2
+ class Value
3
+ attributes :value, :relation
4
+ deriving :initialize, :==
5
+
6
+ def bind(relation)
7
+ Value.new(value, relation)
8
+ end
9
+
10
+ def to_ordering
11
+ self
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,2 @@
1
+ require 'arel/engines/sql'
2
+ require 'arel/engines/memory'
@@ -0,0 +1,4 @@
1
+ require 'arel/engines/memory/relations'
2
+ require 'arel/engines/memory/primitives'
3
+ require 'arel/engines/memory/engine'
4
+ require 'arel/engines/memory/predicates'
@@ -0,0 +1,16 @@
1
+ module Arel
2
+ module Memory
3
+ class Engine
4
+ module CRUD
5
+ def read(relation)
6
+ relation.eval
7
+ end
8
+
9
+ def create(relation)
10
+ relation.eval
11
+ end
12
+ end
13
+ include CRUD
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,99 @@
1
+ module Arel
2
+ module Predicates
3
+ class Binary < Predicate
4
+ def eval(row)
5
+ operand1.eval(row).send(operator, operand2.eval(row))
6
+ end
7
+ end
8
+
9
+ class Unary < Predicate
10
+ def eval(row)
11
+ operand.eval(row).send(operator)
12
+ end
13
+ end
14
+
15
+ class Not < Unary
16
+ def eval(row)
17
+ !operand.eval(row)
18
+ end
19
+ end
20
+
21
+ class Polyadic < Predicate
22
+ def eval(row)
23
+ predicates.send(compounder) do |operation|
24
+ operation.eval(row)
25
+ end
26
+ end
27
+ end
28
+
29
+ class Any < Polyadic
30
+ def compounder; :any? end
31
+ end
32
+
33
+ class All < Polyadic
34
+ def compounder; :all? end
35
+ end
36
+
37
+ class CompoundPredicate < Binary
38
+ def eval(row)
39
+ eval "operand1.eval(row) #{operator} operand2.eval(row)"
40
+ end
41
+ end
42
+
43
+ class Or < CompoundPredicate
44
+ def operator; :or end
45
+ end
46
+
47
+ class And < CompoundPredicate
48
+ def operator; :and end
49
+ end
50
+
51
+ class Equality < Binary
52
+ def operator; :== end
53
+ end
54
+
55
+ class Inequality < Binary
56
+ def eval(row)
57
+ operand1.eval(row) != operand2.eval(row)
58
+ end
59
+ end
60
+
61
+ class GreaterThanOrEqualTo < Binary
62
+ def operator; :>= end
63
+ end
64
+
65
+ class GreaterThan < Binary
66
+ def operator; :> end
67
+ end
68
+
69
+ class LessThanOrEqualTo < Binary
70
+ def operator; :<= end
71
+ end
72
+
73
+ class LessThan < Binary
74
+ def operator; :< end
75
+ end
76
+
77
+ class Match < Binary
78
+ def operator; :=~ end
79
+ end
80
+
81
+ class NotMatch < Binary
82
+ def eval(row)
83
+ operand1.eval(row) !~ operand2.eval(row)
84
+ end
85
+ end
86
+
87
+ class In < Binary
88
+ def eval(row)
89
+ operand2.eval(row).include?(operand1.eval(row))
90
+ end
91
+ end
92
+
93
+ class NotIn < Binary
94
+ def eval(row)
95
+ !(operand2.eval(row).include?(operand1.eval(row)))
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,27 @@
1
+ module Arel
2
+ class Attribute
3
+ def eval(row)
4
+ row[self]
5
+ end
6
+ end
7
+
8
+ class Value
9
+ def eval(row)
10
+ value
11
+ end
12
+ end
13
+
14
+ class Ordering
15
+ def eval(row1, row2)
16
+ (attribute.eval(row1) <=> attribute.eval(row2)) * direction
17
+ end
18
+ end
19
+
20
+ class Descending < Ordering
21
+ def direction; -1 end
22
+ end
23
+
24
+ class Ascending < Ordering
25
+ def direction; 1 end
26
+ end
27
+ end
@@ -0,0 +1,5 @@
1
+ require 'arel/engines/memory/relations/array'
2
+ require 'arel/engines/memory/relations/operations'
3
+ require 'arel/engines/memory/relations/writes'
4
+ require 'arel/engines/memory/relations/compound'
5
+
@@ -0,0 +1,35 @@
1
+ module Arel
2
+ class Array
3
+ include Relation
4
+
5
+ attributes :array, :attribute_names_and_types
6
+ include Recursion::BaseCase
7
+ deriving :==, :initialize
8
+
9
+ def initialize(array, attribute_names_and_types)
10
+ @array, @attribute_names_and_types = array, attribute_names_and_types
11
+ end
12
+
13
+ def engine
14
+ @engine ||= Memory::Engine.new
15
+ end
16
+
17
+ def attributes
18
+ @attributes ||= begin
19
+ attrs = @attribute_names_and_types.collect do |attribute, type|
20
+ attribute = type.new(self, attribute) if Symbol === attribute
21
+ attribute
22
+ end
23
+ Header.new(attrs)
24
+ end
25
+ end
26
+
27
+ def format(attribute, value)
28
+ value
29
+ end
30
+
31
+ def eval
32
+ @array.collect { |r| Row.new(self, r) }
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,9 @@
1
+ module Arel
2
+ class Compound
3
+ delegate :array, :to => :relation
4
+
5
+ def unoperated_rows
6
+ relation.call.collect { |row| row.bind(self) }
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,67 @@
1
+ module Arel
2
+ class Where < Compound
3
+ def eval
4
+ unoperated_rows.select { |row| predicates.all? { |p| p.eval(row) } }
5
+ end
6
+ end
7
+
8
+ class Order < Compound
9
+ def eval
10
+ unoperated_rows.sort do |row1, row2|
11
+ ordering = orders.detect { |o| o.eval(row1, row2) != 0 } || orders.last
12
+ ordering.eval(row1, row2)
13
+ end
14
+ end
15
+ end
16
+
17
+ class Project < Compound
18
+ def eval
19
+ unoperated_rows.collect { |r| r.slice(*projections) }
20
+ end
21
+ end
22
+
23
+ class Take < Compound
24
+ def eval
25
+ unoperated_rows[0, taken]
26
+ end
27
+ end
28
+
29
+ class Skip < Compound
30
+ def eval
31
+ unoperated_rows[skipped..-1]
32
+ end
33
+ end
34
+
35
+ class From < Compound
36
+ def eval
37
+ unoperated_rows[sources..-1]
38
+ end
39
+ end
40
+
41
+ class Group < Compound
42
+ def eval
43
+ raise NotImplementedError
44
+ end
45
+ end
46
+
47
+ class Alias < Compound
48
+ def eval
49
+ unoperated_rows
50
+ end
51
+ end
52
+
53
+ class Join
54
+ def eval
55
+ result = []
56
+ relation1.call.each do |row1|
57
+ relation2.call.each do |row2|
58
+ combined_row = row1.combine(row2, self)
59
+ if predicates.all? { |p| p.eval(combined_row) }
60
+ result << combined_row
61
+ end
62
+ end
63
+ end
64
+ result
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,7 @@
1
+ module Arel
2
+ class Insert < Compound
3
+ def eval
4
+ unoperated_rows + [Row.new(self, record.values.collect(&:value))]
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ require 'arel/engines/sql/attributes'
2
+ require 'arel/engines/sql/engine'
3
+ require 'arel/engines/sql/relations'
4
+ require 'arel/engines/sql/primitives'
5
+ require 'arel/engines/sql/predicates'
6
+ require 'arel/engines/sql/formatters'
7
+ require 'arel/engines/sql/core_extensions'
8
+ require 'arel/engines/sql/christener'
@@ -0,0 +1,40 @@
1
+ module Arel
2
+ module Sql
3
+ module Attributes
4
+ def self.for(column)
5
+ case column.type
6
+ when :string then String
7
+ when :text then String
8
+ when :integer then Integer
9
+ when :float then Float
10
+ when :decimal then Decimal
11
+ when :date then Time
12
+ when :datetime then Time
13
+ when :timestamp then Time
14
+ when :time then Time
15
+ when :binary then String
16
+ when :boolean then Boolean
17
+ else
18
+ raise NotImplementedError, "Column type `#{column.type}` is not currently handled"
19
+ end
20
+ end
21
+
22
+ def initialize(column, *args)
23
+ @column = column
24
+ super(*args)
25
+ end
26
+
27
+ def type_cast(value)
28
+ @column.type_cast(value)
29
+ end
30
+
31
+ %w(Boolean Decimal Float Integer String Time).each do |klass|
32
+ class_eval <<-R
33
+ class #{klass} < Arel::Attributes::#{klass}
34
+ include Attributes
35
+ end
36
+ R
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,14 @@
1
+ module Arel
2
+ module Sql
3
+ class Christener
4
+ def name_for(relation)
5
+ @used_names ||= Hash.new(0)
6
+ (@relation_names ||= Hash.new do |hash, relation|
7
+ name = relation.table_alias ? relation.table_alias : relation.name
8
+ @used_names[name] += 1
9
+ hash[relation] = name + (@used_names[name] > 1 ? "_#{@used_names[name]}" : '')
10
+ end)[relation.table]
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,48 @@
1
+ # +-----------------------------------------------------------------------+
2
+ # | |
3
+ # | Copyright (c) 2010 IBM Corporation |
4
+ # | |
5
+ # | Permission is hereby granted, free of charge, to any person obtaining |
6
+ # | a copy of this software and associated documentation files (the |
7
+ # | "Software"), to deal in the Software without restriction, including |
8
+ # | without limitation the rights to use, copy, modify, merge, publish, |
9
+ # | distribute, sublicense, and/or sell copies of the Software, and to |
10
+ # | permit persons to whom the Software is furnished to do so, subject to |
11
+ # | the following conditions: |
12
+ # | |
13
+ # | The above copyright notice and this permission notice shall be |
14
+ # | included in all copies or substantial portions of the Software. |
15
+ # | |
16
+ # | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
17
+ # | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
18
+ # | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.|
19
+ # | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR |
20
+ # | ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
21
+ # | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
22
+ # | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
23
+ # | |
24
+ # +-----------------------------------------------------------------------+
25
+
26
+ #
27
+ # Author: Praveen Devarao <praveendrl@in.ibm.com>
28
+ #
29
+
30
+ module Arel
31
+ module SqlCompiler
32
+ class IBM_DBCompiler < GenericCompiler
33
+
34
+ def limited_update_conditions(conditions, taken)
35
+ quoted_primary_key = engine.quote_table_name(primary_key)
36
+ update_conditions = "WHERE #{quoted_primary_key} IN (SELECT #{quoted_primary_key} FROM #{engine.connection.quote_table_name table.name} #{conditions} " #Note: - ')' not added, limit segment is to be appended
37
+ engine.add_limit_offset!(update_conditions,{:limit=>taken,:offset=>nil})
38
+ update_conditions << ")" # Close the sql segment
39
+ update_conditions
40
+ end
41
+
42
+ def add_limit_on_delete(taken)
43
+ raise "IBM_DB does not support limit on deletion" # Limiting the number of rows to be deleted is not supported by IBM_DB
44
+ end
45
+
46
+ end
47
+ end
48
+ end