arel-compat 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +25 -0
- data/README.markdown +182 -0
- data/lib/arel.rb +13 -0
- data/lib/arel/algebra.rb +10 -0
- data/lib/arel/algebra/attributes.rb +7 -0
- data/lib/arel/algebra/attributes/attribute.rb +270 -0
- data/lib/arel/algebra/attributes/boolean.rb +21 -0
- data/lib/arel/algebra/attributes/decimal.rb +9 -0
- data/lib/arel/algebra/attributes/float.rb +9 -0
- data/lib/arel/algebra/attributes/integer.rb +10 -0
- data/lib/arel/algebra/attributes/string.rb +10 -0
- data/lib/arel/algebra/attributes/time.rb +6 -0
- data/lib/arel/algebra/core_extensions.rb +4 -0
- data/lib/arel/algebra/core_extensions/class.rb +32 -0
- data/lib/arel/algebra/core_extensions/hash.rb +11 -0
- data/lib/arel/algebra/core_extensions/object.rb +30 -0
- data/lib/arel/algebra/core_extensions/symbol.rb +9 -0
- data/lib/arel/algebra/expression.rb +43 -0
- data/lib/arel/algebra/header.rb +67 -0
- data/lib/arel/algebra/ordering.rb +23 -0
- data/lib/arel/algebra/predicates.rb +190 -0
- data/lib/arel/algebra/relations.rb +17 -0
- data/lib/arel/algebra/relations/operations/alias.rb +7 -0
- data/lib/arel/algebra/relations/operations/from.rb +6 -0
- data/lib/arel/algebra/relations/operations/group.rb +12 -0
- data/lib/arel/algebra/relations/operations/having.rb +17 -0
- data/lib/arel/algebra/relations/operations/join.rb +69 -0
- data/lib/arel/algebra/relations/operations/lock.rb +12 -0
- data/lib/arel/algebra/relations/operations/order.rb +19 -0
- data/lib/arel/algebra/relations/operations/project.rb +20 -0
- data/lib/arel/algebra/relations/operations/skip.rb +7 -0
- data/lib/arel/algebra/relations/operations/take.rb +11 -0
- data/lib/arel/algebra/relations/operations/where.rb +17 -0
- data/lib/arel/algebra/relations/relation.rb +136 -0
- data/lib/arel/algebra/relations/row.rb +26 -0
- data/lib/arel/algebra/relations/utilities/compound.rb +54 -0
- data/lib/arel/algebra/relations/utilities/externalization.rb +24 -0
- data/lib/arel/algebra/relations/utilities/nil.rb +7 -0
- data/lib/arel/algebra/relations/writes.rb +36 -0
- data/lib/arel/algebra/value.rb +14 -0
- data/lib/arel/engines.rb +2 -0
- data/lib/arel/engines/memory.rb +4 -0
- data/lib/arel/engines/memory/engine.rb +16 -0
- data/lib/arel/engines/memory/predicates.rb +99 -0
- data/lib/arel/engines/memory/primitives.rb +27 -0
- data/lib/arel/engines/memory/relations.rb +5 -0
- data/lib/arel/engines/memory/relations/array.rb +35 -0
- data/lib/arel/engines/memory/relations/compound.rb +9 -0
- data/lib/arel/engines/memory/relations/operations.rb +67 -0
- data/lib/arel/engines/memory/relations/writes.rb +7 -0
- data/lib/arel/engines/sql.rb +8 -0
- data/lib/arel/engines/sql/attributes.rb +40 -0
- data/lib/arel/engines/sql/christener.rb +14 -0
- data/lib/arel/engines/sql/compilers/ibm_db_compiler.rb +48 -0
- data/lib/arel/engines/sql/compilers/mysql_compiler.rb +11 -0
- data/lib/arel/engines/sql/compilers/oracle_compiler.rb +95 -0
- data/lib/arel/engines/sql/compilers/postgresql_compiler.rb +42 -0
- data/lib/arel/engines/sql/compilers/sqlite_compiler.rb +9 -0
- data/lib/arel/engines/sql/core_extensions.rb +4 -0
- data/lib/arel/engines/sql/core_extensions/array.rb +24 -0
- data/lib/arel/engines/sql/core_extensions/nil_class.rb +15 -0
- data/lib/arel/engines/sql/core_extensions/object.rb +19 -0
- data/lib/arel/engines/sql/core_extensions/range.rb +19 -0
- data/lib/arel/engines/sql/engine.rb +55 -0
- data/lib/arel/engines/sql/formatters.rb +122 -0
- data/lib/arel/engines/sql/predicates.rb +103 -0
- data/lib/arel/engines/sql/primitives.rb +97 -0
- data/lib/arel/engines/sql/relations.rb +10 -0
- data/lib/arel/engines/sql/relations/compiler.rb +118 -0
- data/lib/arel/engines/sql/relations/operations/alias.rb +5 -0
- data/lib/arel/engines/sql/relations/operations/join.rb +33 -0
- data/lib/arel/engines/sql/relations/relation.rb +65 -0
- data/lib/arel/engines/sql/relations/table.rb +88 -0
- data/lib/arel/engines/sql/relations/utilities/compound.rb +10 -0
- data/lib/arel/engines/sql/relations/utilities/externalization.rb +14 -0
- data/lib/arel/engines/sql/relations/utilities/nil.rb +6 -0
- data/lib/arel/engines/sql/relations/utilities/recursion.rb +13 -0
- data/lib/arel/engines/sql/relations/writes.rb +19 -0
- data/lib/arel/session.rb +51 -0
- data/lib/arel/version.rb +3 -0
- data/spec/algebra/unit/predicates/binary_spec.rb +35 -0
- data/spec/algebra/unit/predicates/equality_spec.rb +29 -0
- data/spec/algebra/unit/predicates/in_spec.rb +12 -0
- data/spec/algebra/unit/primitives/attribute_spec.rb +181 -0
- data/spec/algebra/unit/primitives/expression_spec.rb +45 -0
- data/spec/algebra/unit/primitives/value_spec.rb +15 -0
- data/spec/algebra/unit/relations/alias_spec.rb +16 -0
- data/spec/algebra/unit/relations/delete_spec.rb +9 -0
- data/spec/algebra/unit/relations/group_spec.rb +10 -0
- data/spec/algebra/unit/relations/insert_spec.rb +9 -0
- data/spec/algebra/unit/relations/join_spec.rb +25 -0
- data/spec/algebra/unit/relations/order_spec.rb +21 -0
- data/spec/algebra/unit/relations/project_spec.rb +34 -0
- data/spec/algebra/unit/relations/relation_spec.rb +187 -0
- data/spec/algebra/unit/relations/skip_spec.rb +10 -0
- data/spec/algebra/unit/relations/table_spec.rb +38 -0
- data/spec/algebra/unit/relations/take_spec.rb +10 -0
- data/spec/algebra/unit/relations/update_spec.rb +9 -0
- data/spec/algebra/unit/relations/where_spec.rb +19 -0
- data/spec/algebra/unit/session/session_spec.rb +84 -0
- data/spec/attributes/boolean_spec.rb +57 -0
- data/spec/attributes/float_spec.rb +119 -0
- data/spec/attributes/header_spec.rb +42 -0
- data/spec/attributes/integer_spec.rb +119 -0
- data/spec/attributes/string_spec.rb +43 -0
- data/spec/attributes/time_spec.rb +24 -0
- data/spec/engines/memory/integration/joins/cross_engine_spec.rb +51 -0
- data/spec/engines/memory/unit/relations/array_spec.rb +32 -0
- data/spec/engines/memory/unit/relations/insert_spec.rb +28 -0
- data/spec/engines/memory/unit/relations/join_spec.rb +31 -0
- data/spec/engines/memory/unit/relations/order_spec.rb +27 -0
- data/spec/engines/memory/unit/relations/project_spec.rb +27 -0
- data/spec/engines/memory/unit/relations/skip_spec.rb +26 -0
- data/spec/engines/memory/unit/relations/take_spec.rb +26 -0
- data/spec/engines/memory/unit/relations/where_spec.rb +39 -0
- data/spec/engines/sql/integration/joins/with_adjacency_spec.rb +258 -0
- data/spec/engines/sql/integration/joins/with_aggregations_spec.rb +221 -0
- data/spec/engines/sql/integration/joins/with_compounds_spec.rb +137 -0
- data/spec/engines/sql/unit/engine_spec.rb +45 -0
- data/spec/engines/sql/unit/predicates/binary_spec.rb +140 -0
- data/spec/engines/sql/unit/predicates/equality_spec.rb +75 -0
- data/spec/engines/sql/unit/predicates/in_spec.rb +179 -0
- data/spec/engines/sql/unit/predicates/noteq_spec.rb +75 -0
- data/spec/engines/sql/unit/predicates/predicates_spec.rb +79 -0
- data/spec/engines/sql/unit/primitives/attribute_spec.rb +36 -0
- data/spec/engines/sql/unit/primitives/expression_spec.rb +28 -0
- data/spec/engines/sql/unit/primitives/literal_spec.rb +43 -0
- data/spec/engines/sql/unit/primitives/value_spec.rb +29 -0
- data/spec/engines/sql/unit/relations/alias_spec.rb +53 -0
- data/spec/engines/sql/unit/relations/delete_spec.rb +83 -0
- data/spec/engines/sql/unit/relations/from_spec.rb +64 -0
- data/spec/engines/sql/unit/relations/group_spec.rb +72 -0
- data/spec/engines/sql/unit/relations/having_spec.rb +78 -0
- data/spec/engines/sql/unit/relations/insert_spec.rb +143 -0
- data/spec/engines/sql/unit/relations/join_spec.rb +180 -0
- data/spec/engines/sql/unit/relations/lock_spec.rb +86 -0
- data/spec/engines/sql/unit/relations/order_spec.rb +161 -0
- data/spec/engines/sql/unit/relations/project_spec.rb +143 -0
- data/spec/engines/sql/unit/relations/skip_spec.rb +41 -0
- data/spec/engines/sql/unit/relations/table_spec.rb +129 -0
- data/spec/engines/sql/unit/relations/take_spec.rb +49 -0
- data/spec/engines/sql/unit/relations/update_spec.rb +203 -0
- data/spec/engines/sql/unit/relations/where_spec.rb +72 -0
- data/spec/relations/join_spec.rb +42 -0
- data/spec/relations/relation_spec.rb +31 -0
- data/spec/shared/relation_spec.rb +255 -0
- data/spec/spec_helper.rb +36 -0
- data/spec/support/check.rb +6 -0
- data/spec/support/connections/mysql_connection.rb +14 -0
- data/spec/support/connections/oracle_connection.rb +17 -0
- data/spec/support/connections/postgresql_connection.rb +13 -0
- data/spec/support/connections/sqlite3_connection.rb +24 -0
- data/spec/support/guards.rb +28 -0
- data/spec/support/matchers.rb +4 -0
- data/spec/support/matchers/be_like.rb +24 -0
- data/spec/support/matchers/disambiguate_attributes.rb +28 -0
- data/spec/support/matchers/hash_the_same_as.rb +26 -0
- data/spec/support/matchers/have_rows.rb +18 -0
- data/spec/support/model.rb +62 -0
- data/spec/support/schemas/mysql_schema.rb +26 -0
- data/spec/support/schemas/oracle_schema.rb +20 -0
- data/spec/support/schemas/postgresql_schema.rb +26 -0
- data/spec/support/schemas/sqlite3_schema.rb +26 -0
- 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,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
|
data/lib/arel/engines.rb
ADDED
@@ -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,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,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,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
|