activerecord 5.0.7.2 → 5.1.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of activerecord might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/CHANGELOG.md +389 -2252
- data/MIT-LICENSE +1 -1
- data/README.rdoc +1 -1
- data/examples/performance.rb +28 -28
- data/examples/simple.rb +3 -3
- data/lib/active_record.rb +20 -20
- data/lib/active_record/aggregations.rb +244 -244
- data/lib/active_record/association_relation.rb +5 -5
- data/lib/active_record/associations.rb +1579 -1569
- data/lib/active_record/associations/alias_tracker.rb +1 -1
- data/lib/active_record/associations/association.rb +23 -15
- data/lib/active_record/associations/association_scope.rb +83 -81
- data/lib/active_record/associations/belongs_to_association.rb +0 -1
- data/lib/active_record/associations/builder/belongs_to.rb +16 -14
- data/lib/active_record/associations/builder/collection_association.rb +1 -2
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +27 -27
- data/lib/active_record/associations/collection_association.rb +74 -241
- data/lib/active_record/associations/collection_proxy.rb +144 -70
- data/lib/active_record/associations/has_many_association.rb +15 -19
- data/lib/active_record/associations/has_many_through_association.rb +12 -5
- data/lib/active_record/associations/has_one_association.rb +22 -28
- data/lib/active_record/associations/has_one_through_association.rb +5 -1
- data/lib/active_record/associations/join_dependency.rb +117 -115
- data/lib/active_record/associations/join_dependency/join_association.rb +16 -13
- data/lib/active_record/associations/join_dependency/join_base.rb +1 -1
- data/lib/active_record/associations/join_dependency/join_part.rb +1 -1
- data/lib/active_record/associations/preloader.rb +94 -94
- data/lib/active_record/associations/preloader/association.rb +87 -64
- data/lib/active_record/associations/preloader/belongs_to.rb +0 -2
- data/lib/active_record/associations/preloader/collection_association.rb +6 -6
- data/lib/active_record/associations/preloader/has_many.rb +0 -2
- data/lib/active_record/associations/preloader/singular_association.rb +6 -8
- data/lib/active_record/associations/preloader/through_association.rb +34 -41
- data/lib/active_record/associations/singular_association.rb +8 -25
- data/lib/active_record/associations/through_association.rb +3 -6
- data/lib/active_record/attribute.rb +98 -71
- data/lib/active_record/attribute/user_provided_default.rb +4 -2
- data/lib/active_record/attribute_assignment.rb +61 -61
- data/lib/active_record/attribute_decorators.rb +35 -13
- data/lib/active_record/attribute_methods.rb +56 -65
- data/lib/active_record/attribute_methods/before_type_cast.rb +7 -7
- data/lib/active_record/attribute_methods/dirty.rb +216 -34
- data/lib/active_record/attribute_methods/primary_key.rb +78 -73
- data/lib/active_record/attribute_methods/read.rb +39 -35
- data/lib/active_record/attribute_methods/serialization.rb +7 -7
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +35 -58
- data/lib/active_record/attribute_methods/write.rb +36 -30
- data/lib/active_record/attribute_mutation_tracker.rb +53 -10
- data/lib/active_record/attribute_set.rb +9 -6
- data/lib/active_record/attribute_set/builder.rb +41 -49
- data/lib/active_record/attribute_set/yaml_encoder.rb +41 -0
- data/lib/active_record/attributes.rb +21 -21
- data/lib/active_record/autosave_association.rb +13 -13
- data/lib/active_record/base.rb +24 -22
- data/lib/active_record/callbacks.rb +52 -14
- data/lib/active_record/coders/yaml_column.rb +9 -11
- data/lib/active_record/collection_cache_key.rb +6 -17
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +320 -278
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +1 -3
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +22 -34
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +31 -27
- data/lib/active_record/connection_adapters/abstract/quoting.rb +44 -57
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +9 -19
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +78 -79
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +53 -41
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +99 -93
- data/lib/active_record/connection_adapters/abstract/transaction.rb +1 -5
- data/lib/active_record/connection_adapters/abstract_adapter.rb +156 -128
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +424 -382
- data/lib/active_record/connection_adapters/column.rb +27 -5
- data/lib/active_record/connection_adapters/connection_specification.rb +128 -118
- data/lib/active_record/connection_adapters/mysql/column.rb +6 -31
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +45 -43
- data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +22 -22
- data/lib/active_record/connection_adapters/mysql/quoting.rb +6 -12
- data/lib/active_record/connection_adapters/mysql/schema_creation.rb +49 -45
- data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +16 -19
- data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +49 -31
- data/lib/active_record/connection_adapters/mysql/type_metadata.rb +5 -6
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +24 -26
- data/lib/active_record/connection_adapters/postgresql/column.rb +1 -28
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +46 -35
- data/lib/active_record/connection_adapters/postgresql/explain_pretty_printer.rb +3 -3
- data/lib/active_record/connection_adapters/postgresql/oid.rb +22 -21
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +9 -9
- data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +5 -3
- data/lib/active_record/connection_adapters/postgresql/oid/bytea.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +2 -2
- data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +3 -3
- data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +16 -16
- data/lib/active_record/connection_adapters/postgresql/oid/{rails_5_1_point.rb → legacy_point.rb} +9 -16
- data/lib/active_record/connection_adapters/postgresql/oid/money.rb +2 -2
- data/lib/active_record/connection_adapters/postgresql/oid/oid.rb +13 -0
- data/lib/active_record/connection_adapters/postgresql/oid/point.rb +28 -8
- data/lib/active_record/connection_adapters/postgresql/oid/range.rb +28 -30
- data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +2 -1
- data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +51 -51
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +38 -36
- data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +15 -0
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +37 -24
- data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +19 -23
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +161 -170
- data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +4 -4
- data/lib/active_record/connection_adapters/postgresql/utils.rb +9 -7
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +179 -152
- data/lib/active_record/connection_adapters/schema_cache.rb +16 -7
- data/lib/active_record/connection_adapters/sql_type_metadata.rb +3 -3
- data/lib/active_record/connection_adapters/sqlite3/explain_pretty_printer.rb +1 -1
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +16 -20
- data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +1 -8
- data/lib/active_record/connection_adapters/sqlite3/schema_definitions.rb +28 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_dumper.rb +17 -0
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +187 -130
- data/lib/active_record/connection_adapters/statement_pool.rb +7 -7
- data/lib/active_record/connection_handling.rb +14 -26
- data/lib/active_record/core.rb +110 -93
- data/lib/active_record/counter_cache.rb +62 -13
- data/lib/active_record/define_callbacks.rb +20 -0
- data/lib/active_record/dynamic_matchers.rb +80 -79
- data/lib/active_record/enum.rb +8 -6
- data/lib/active_record/errors.rb +58 -15
- data/lib/active_record/explain.rb +1 -2
- data/lib/active_record/explain_registry.rb +1 -1
- data/lib/active_record/explain_subscriber.rb +7 -4
- data/lib/active_record/fixture_set/file.rb +11 -8
- data/lib/active_record/fixtures.rb +66 -53
- data/lib/active_record/gem_version.rb +3 -3
- data/lib/active_record/inheritance.rb +93 -79
- data/lib/active_record/integration.rb +7 -7
- data/lib/active_record/internal_metadata.rb +3 -16
- data/lib/active_record/legacy_yaml_adapter.rb +1 -1
- data/lib/active_record/locking/optimistic.rb +64 -56
- data/lib/active_record/locking/pessimistic.rb +10 -1
- data/lib/active_record/log_subscriber.rb +29 -29
- data/lib/active_record/migration.rb +155 -172
- data/lib/active_record/migration/command_recorder.rb +94 -94
- data/lib/active_record/migration/compatibility.rb +76 -37
- data/lib/active_record/migration/join_table.rb +6 -6
- data/lib/active_record/model_schema.rb +85 -119
- data/lib/active_record/nested_attributes.rb +200 -199
- data/lib/active_record/null_relation.rb +10 -33
- data/lib/active_record/persistence.rb +45 -38
- data/lib/active_record/query_cache.rb +4 -8
- data/lib/active_record/querying.rb +2 -3
- data/lib/active_record/railtie.rb +16 -17
- data/lib/active_record/railties/controller_runtime.rb +6 -2
- data/lib/active_record/railties/databases.rake +125 -140
- data/lib/active_record/railties/jdbcmysql_error.rb +1 -1
- data/lib/active_record/readonly_attributes.rb +2 -2
- data/lib/active_record/reflection.rb +79 -96
- data/lib/active_record/relation.rb +72 -115
- data/lib/active_record/relation/batches.rb +87 -58
- data/lib/active_record/relation/batches/batch_enumerator.rb +1 -1
- data/lib/active_record/relation/calculations.rb +154 -160
- data/lib/active_record/relation/delegation.rb +30 -29
- data/lib/active_record/relation/finder_methods.rb +195 -226
- data/lib/active_record/relation/merger.rb +58 -62
- data/lib/active_record/relation/predicate_builder.rb +92 -89
- data/lib/active_record/relation/predicate_builder/array_handler.rb +7 -5
- data/lib/active_record/relation/predicate_builder/association_query_handler.rb +23 -23
- data/lib/active_record/relation/predicate_builder/base_handler.rb +3 -1
- data/lib/active_record/relation/predicate_builder/basic_object_handler.rb +0 -8
- data/lib/active_record/relation/predicate_builder/polymorphic_array_handler.rb +12 -10
- data/lib/active_record/relation/predicate_builder/range_handler.rb +0 -8
- data/lib/active_record/relation/query_attribute.rb +1 -1
- data/lib/active_record/relation/query_methods.rb +247 -295
- data/lib/active_record/relation/record_fetch_warning.rb +3 -3
- data/lib/active_record/relation/spawn_methods.rb +4 -5
- data/lib/active_record/relation/where_clause.rb +79 -65
- data/lib/active_record/relation/where_clause_factory.rb +47 -8
- data/lib/active_record/result.rb +29 -31
- data/lib/active_record/runtime_registry.rb +3 -3
- data/lib/active_record/sanitization.rb +182 -197
- data/lib/active_record/schema.rb +3 -3
- data/lib/active_record/schema_dumper.rb +14 -37
- data/lib/active_record/schema_migration.rb +3 -3
- data/lib/active_record/scoping.rb +9 -10
- data/lib/active_record/scoping/default.rb +87 -91
- data/lib/active_record/scoping/named.rb +16 -28
- data/lib/active_record/secure_token.rb +2 -2
- data/lib/active_record/statement_cache.rb +13 -15
- data/lib/active_record/store.rb +31 -32
- data/lib/active_record/suppressor.rb +2 -1
- data/lib/active_record/table_metadata.rb +9 -5
- data/lib/active_record/tasks/database_tasks.rb +72 -65
- data/lib/active_record/tasks/mysql_database_tasks.rb +75 -72
- data/lib/active_record/tasks/postgresql_database_tasks.rb +53 -48
- data/lib/active_record/tasks/sqlite_database_tasks.rb +18 -16
- data/lib/active_record/timestamp.rb +39 -25
- data/lib/active_record/touch_later.rb +1 -2
- data/lib/active_record/transactions.rb +98 -110
- data/lib/active_record/type.rb +17 -13
- data/lib/active_record/type/adapter_specific_registry.rb +46 -42
- data/lib/active_record/type/decimal_without_scale.rb +9 -0
- data/lib/active_record/type/hash_lookup_type_map.rb +3 -3
- data/lib/active_record/type/serialized.rb +8 -8
- data/lib/active_record/type/text.rb +9 -0
- data/lib/active_record/type/time.rb +0 -1
- data/lib/active_record/type/type_map.rb +11 -15
- data/lib/active_record/type/unsigned_integer.rb +15 -0
- data/lib/active_record/type_caster.rb +2 -2
- data/lib/active_record/type_caster/connection.rb +8 -6
- data/lib/active_record/type_caster/map.rb +3 -1
- data/lib/active_record/validations.rb +4 -4
- data/lib/active_record/validations/associated.rb +1 -1
- data/lib/active_record/validations/presence.rb +2 -2
- data/lib/active_record/validations/uniqueness.rb +8 -39
- data/lib/active_record/version.rb +1 -1
- data/lib/rails/generators/active_record.rb +4 -4
- data/lib/rails/generators/active_record/migration.rb +2 -2
- data/lib/rails/generators/active_record/migration/migration_generator.rb +37 -34
- data/lib/rails/generators/active_record/model/model_generator.rb +9 -9
- metadata +22 -13
- data/lib/active_record/relation/predicate_builder/class_handler.rb +0 -27
@@ -25,9 +25,9 @@ module ActiveRecord
|
|
25
25
|
value.sub!(/^\((.+)\)$/, '-\1') # (4)
|
26
26
|
case value
|
27
27
|
when /^-?\D+[\d,]+\.\d{2}$/ # (1)
|
28
|
-
value.gsub!(/[^-\d.]/,
|
28
|
+
value.gsub!(/[^-\d.]/, "")
|
29
29
|
when /^-?\D+[\d.]+,\d{2}$/ # (2)
|
30
|
-
value.gsub!(/[^-\d,]/,
|
30
|
+
value.gsub!(/[^-\d,]/, "").sub!(/,/, ".")
|
31
31
|
end
|
32
32
|
|
33
33
|
super(value)
|
@@ -1,4 +1,6 @@
|
|
1
1
|
module ActiveRecord
|
2
|
+
Point = Struct.new(:x, :y)
|
3
|
+
|
2
4
|
module ConnectionAdapters
|
3
5
|
module PostgreSQL
|
4
6
|
module OID # :nodoc:
|
@@ -12,20 +14,34 @@ module ActiveRecord
|
|
12
14
|
def cast(value)
|
13
15
|
case value
|
14
16
|
when ::String
|
15
|
-
if value
|
17
|
+
return if value.blank?
|
18
|
+
|
19
|
+
if value[0] == "(" && value[-1] == ")"
|
16
20
|
value = value[1...-1]
|
17
21
|
end
|
18
|
-
|
22
|
+
x, y = value.split(",")
|
23
|
+
build_point(x, y)
|
19
24
|
when ::Array
|
20
|
-
value
|
25
|
+
build_point(*value)
|
21
26
|
else
|
22
27
|
value
|
23
28
|
end
|
24
29
|
end
|
25
30
|
|
26
31
|
def serialize(value)
|
27
|
-
|
28
|
-
|
32
|
+
case value
|
33
|
+
when ActiveRecord::Point
|
34
|
+
"(#{number_for_point(value.x)},#{number_for_point(value.y)})"
|
35
|
+
when ::Array
|
36
|
+
serialize(build_point(*value))
|
37
|
+
else
|
38
|
+
super
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def type_cast_for_schema(value)
|
43
|
+
if ActiveRecord::Point === value
|
44
|
+
[value.x, value.y]
|
29
45
|
else
|
30
46
|
super
|
31
47
|
end
|
@@ -33,9 +49,13 @@ module ActiveRecord
|
|
33
49
|
|
34
50
|
private
|
35
51
|
|
36
|
-
|
37
|
-
|
38
|
-
|
52
|
+
def number_for_point(number)
|
53
|
+
number.to_s.gsub(/\.0$/, "")
|
54
|
+
end
|
55
|
+
|
56
|
+
def build_point(x, y)
|
57
|
+
ActiveRecord::Point.new(Float(x), Float(y))
|
58
|
+
end
|
39
59
|
end
|
40
60
|
end
|
41
61
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'active_support/core_ext/string/filters'
|
2
|
-
|
3
1
|
module ActiveRecord
|
4
2
|
module ConnectionAdapters
|
5
3
|
module PostgreSQL
|
@@ -14,11 +12,11 @@ module ActiveRecord
|
|
14
12
|
end
|
15
13
|
|
16
14
|
def type_cast_for_schema(value)
|
17
|
-
value.inspect.gsub(
|
15
|
+
value.inspect.gsub("Infinity", "::Float::INFINITY")
|
18
16
|
end
|
19
17
|
|
20
18
|
def cast_value(value)
|
21
|
-
return if value ==
|
19
|
+
return if value == "empty"
|
22
20
|
return value unless value.is_a?(::String)
|
23
21
|
|
24
22
|
extracted = extract_bounds(value)
|
@@ -55,37 +53,37 @@ module ActiveRecord
|
|
55
53
|
|
56
54
|
private
|
57
55
|
|
58
|
-
|
59
|
-
|
60
|
-
|
56
|
+
def type_cast_single(value)
|
57
|
+
infinity?(value) ? value : @subtype.deserialize(value)
|
58
|
+
end
|
61
59
|
|
62
|
-
|
63
|
-
|
64
|
-
|
60
|
+
def type_cast_single_for_database(value)
|
61
|
+
infinity?(value) ? "" : @subtype.serialize(value)
|
62
|
+
end
|
65
63
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
64
|
+
def extract_bounds(value)
|
65
|
+
from, to = value[1..-2].split(",")
|
66
|
+
{
|
67
|
+
from: (value[1] == "," || from == "-infinity") ? infinity(negative: true) : from,
|
68
|
+
to: (value[-2] == "," || to == "infinity") ? infinity : to,
|
69
|
+
exclude_start: (value[0] == "("),
|
70
|
+
exclude_end: (value[-1] == ")")
|
71
|
+
}
|
72
|
+
end
|
75
73
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
74
|
+
def infinity(negative: false)
|
75
|
+
if subtype.respond_to?(:infinity)
|
76
|
+
subtype.infinity(negative: negative)
|
77
|
+
elsif negative
|
78
|
+
-::Float::INFINITY
|
79
|
+
else
|
80
|
+
::Float::INFINITY
|
81
|
+
end
|
83
82
|
end
|
84
|
-
end
|
85
83
|
|
86
|
-
|
87
|
-
|
88
|
-
|
84
|
+
def infinity?(value)
|
85
|
+
value.respond_to?(:infinite?) && value.infinite?
|
86
|
+
end
|
89
87
|
end
|
90
88
|
end
|
91
89
|
end
|
@@ -13,13 +13,13 @@ module ActiveRecord
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def run(records)
|
16
|
-
nodes = records.reject { |row| @store.key? row[
|
17
|
-
mapped, nodes = nodes.partition { |row| @store.key? row[
|
18
|
-
ranges, nodes = nodes.partition { |row| row[
|
19
|
-
enums, nodes = nodes.partition { |row| row[
|
20
|
-
domains, nodes = nodes.partition { |row| row[
|
21
|
-
arrays, nodes = nodes.partition { |row| row[
|
22
|
-
composites, nodes = nodes.partition { |row| row[
|
16
|
+
nodes = records.reject { |row| @store.key? row["oid"].to_i }
|
17
|
+
mapped, nodes = nodes.partition { |row| @store.key? row["typname"] }
|
18
|
+
ranges, nodes = nodes.partition { |row| row["typtype"] == "r".freeze }
|
19
|
+
enums, nodes = nodes.partition { |row| row["typtype"] == "e".freeze }
|
20
|
+
domains, nodes = nodes.partition { |row| row["typtype"] == "d".freeze }
|
21
|
+
arrays, nodes = nodes.partition { |row| row["typinput"] == "array_in".freeze }
|
22
|
+
composites, nodes = nodes.partition { |row| row["typelem"].to_i != 0 }
|
23
23
|
|
24
24
|
mapped.each { |row| register_mapped_type(row) }
|
25
25
|
enums.each { |row| register_enum_type(row) }
|
@@ -42,66 +42,66 @@ module ActiveRecord
|
|
42
42
|
end
|
43
43
|
|
44
44
|
private
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
def register_mapped_type(row)
|
46
|
+
alias_type row["oid"], row["typname"]
|
47
|
+
end
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
|
49
|
+
def register_enum_type(row)
|
50
|
+
register row["oid"], OID::Enum.new
|
51
|
+
end
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
53
|
+
def register_array_type(row)
|
54
|
+
register_with_subtype(row["oid"], row["typelem"].to_i) do |subtype|
|
55
|
+
OID::Array.new(subtype, row["typdelim"])
|
56
|
+
end
|
56
57
|
end
|
57
|
-
end
|
58
58
|
|
59
|
-
|
60
|
-
|
61
|
-
|
59
|
+
def register_range_type(row)
|
60
|
+
register_with_subtype(row["oid"], row["rngsubtype"].to_i) do |subtype|
|
61
|
+
OID::Range.new(subtype, row["typname"].to_sym)
|
62
|
+
end
|
62
63
|
end
|
63
|
-
end
|
64
64
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
65
|
+
def register_domain_type(row)
|
66
|
+
if base_type = @store.lookup(row["typbasetype"].to_i)
|
67
|
+
register row["oid"], base_type
|
68
|
+
else
|
69
|
+
warn "unknown base type (OID: #{row["typbasetype"]}) for domain #{row["typname"]}."
|
70
|
+
end
|
70
71
|
end
|
71
|
-
end
|
72
72
|
|
73
|
-
|
74
|
-
|
75
|
-
|
73
|
+
def register_composite_type(row)
|
74
|
+
if subtype = @store.lookup(row["typelem"].to_i)
|
75
|
+
register row["oid"], OID::Vector.new(row["typdelim"], subtype)
|
76
|
+
end
|
76
77
|
end
|
77
|
-
end
|
78
78
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
79
|
+
def register(oid, oid_type = nil, &block)
|
80
|
+
oid = assert_valid_registration(oid, oid_type || block)
|
81
|
+
if block_given?
|
82
|
+
@store.register_type(oid, &block)
|
83
|
+
else
|
84
|
+
@store.register_type(oid, oid_type)
|
85
|
+
end
|
85
86
|
end
|
86
|
-
end
|
87
87
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
88
|
+
def alias_type(oid, target)
|
89
|
+
oid = assert_valid_registration(oid, target)
|
90
|
+
@store.alias_type(oid, target)
|
91
|
+
end
|
92
92
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
93
|
+
def register_with_subtype(oid, target_oid)
|
94
|
+
if @store.key?(target_oid)
|
95
|
+
register(oid) do |_, *args|
|
96
|
+
yield @store.lookup(target_oid, *args)
|
97
|
+
end
|
97
98
|
end
|
98
99
|
end
|
99
|
-
end
|
100
100
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
101
|
+
def assert_valid_registration(oid, oid_type)
|
102
|
+
raise ArgumentError, "can't register nil type for OID #{oid}" if oid_type.nil?
|
103
|
+
oid.to_i
|
104
|
+
end
|
105
105
|
end
|
106
106
|
end
|
107
107
|
end
|
@@ -28,12 +28,12 @@ module ActiveRecord
|
|
28
28
|
# - "schema.name".table_name
|
29
29
|
# - "schema.name"."table.name"
|
30
30
|
def quote_table_name(name) # :nodoc:
|
31
|
-
@quoted_table_names[name] ||= Utils.extract_schema_qualified_name(name.to_s).quoted
|
31
|
+
@quoted_table_names[name] ||= Utils.extract_schema_qualified_name(name.to_s).quoted.freeze
|
32
32
|
end
|
33
33
|
|
34
34
|
# Quotes schema names for use in SQL queries.
|
35
35
|
def quote_schema_name(name)
|
36
|
-
|
36
|
+
PGconn.quote_ident(name)
|
37
37
|
end
|
38
38
|
|
39
39
|
def quote_table_name_for_assignment(table, attr)
|
@@ -42,7 +42,7 @@ module ActiveRecord
|
|
42
42
|
|
43
43
|
# Quotes column names for use in SQL queries.
|
44
44
|
def quote_column_name(name) # :nodoc:
|
45
|
-
@quoted_column_names[name] ||=
|
45
|
+
@quoted_column_names[name] ||= PGconn.quote_ident(super).freeze
|
46
46
|
end
|
47
47
|
|
48
48
|
# Quote date/time values for use in SQL input.
|
@@ -55,10 +55,14 @@ module ActiveRecord
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
+
def quoted_binary(value) # :nodoc:
|
59
|
+
"'#{escape_bytea(value.to_s)}'"
|
60
|
+
end
|
61
|
+
|
58
62
|
def quote_default_expression(value, column) # :nodoc:
|
59
63
|
if value.is_a?(Proc)
|
60
64
|
value.call
|
61
|
-
elsif column.type == :uuid && value
|
65
|
+
elsif column.type == :uuid && value.include?("()")
|
62
66
|
value # Does not quote function default values for UUID columns
|
63
67
|
elsif column.respond_to?(:array?)
|
64
68
|
value = type_cast_from_column(column, value)
|
@@ -74,46 +78,44 @@ module ActiveRecord
|
|
74
78
|
|
75
79
|
private
|
76
80
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
81
|
+
def _quote(value)
|
82
|
+
case value
|
83
|
+
when OID::Xml::Data
|
84
|
+
"xml '#{quote_string(value.to_s)}'"
|
85
|
+
when OID::Bit::Data
|
86
|
+
if value.binary?
|
87
|
+
"B'#{value}'"
|
88
|
+
elsif value.hex?
|
89
|
+
"X'#{value}'"
|
90
|
+
end
|
91
|
+
when Float
|
92
|
+
if value.infinite? || value.nan?
|
93
|
+
"'#{value}'"
|
94
|
+
else
|
95
|
+
super
|
96
|
+
end
|
97
|
+
when OID::Array::Data
|
98
|
+
_quote(encode_array(value))
|
92
99
|
else
|
93
100
|
super
|
94
101
|
end
|
95
|
-
when OID::Array::Data
|
96
|
-
_quote(encode_array(value))
|
97
|
-
else
|
98
|
-
super
|
99
102
|
end
|
100
|
-
end
|
101
103
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
104
|
+
def _type_cast(value)
|
105
|
+
case value
|
106
|
+
when Type::Binary::Data
|
107
|
+
# Return a bind param hash with format as binary.
|
108
|
+
# See http://deveiate.org/code/pg/PGconn.html#method-i-exec_prepared-doc
|
109
|
+
# for more information
|
110
|
+
{ value: value.to_s, format: 1 }
|
111
|
+
when OID::Xml::Data, OID::Bit::Data
|
112
|
+
value.to_s
|
111
113
|
when OID::Array::Data
|
112
114
|
encode_array(value)
|
113
|
-
|
114
|
-
|
115
|
+
else
|
116
|
+
super
|
117
|
+
end
|
115
118
|
end
|
116
|
-
end
|
117
119
|
|
118
120
|
def encode_array(array_data)
|
119
121
|
encoder = array_data.encoder
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module ConnectionAdapters
|
3
|
+
module PostgreSQL
|
4
|
+
class SchemaCreation < AbstractAdapter::SchemaCreation # :nodoc:
|
5
|
+
private
|
6
|
+
def add_column_options!(sql, options)
|
7
|
+
if options[:collation]
|
8
|
+
sql << " COLLATE \"#{options[:collation]}\""
|
9
|
+
end
|
10
|
+
super
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|