activerecord 4.1.16 → 4.2.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 +4 -4
- data/CHANGELOG.md +634 -2185
- data/README.rdoc +15 -10
- data/lib/active_record.rb +2 -1
- data/lib/active_record/aggregations.rb +12 -8
- data/lib/active_record/associations.rb +58 -33
- data/lib/active_record/associations/association.rb +1 -1
- data/lib/active_record/associations/association_scope.rb +53 -21
- data/lib/active_record/associations/belongs_to_association.rb +15 -5
- data/lib/active_record/associations/builder/association.rb +16 -5
- data/lib/active_record/associations/builder/belongs_to.rb +7 -29
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +2 -11
- data/lib/active_record/associations/builder/has_one.rb +2 -2
- data/lib/active_record/associations/builder/singular_association.rb +8 -1
- data/lib/active_record/associations/collection_association.rb +32 -44
- data/lib/active_record/associations/collection_proxy.rb +1 -10
- data/lib/active_record/associations/has_many_association.rb +60 -14
- data/lib/active_record/associations/has_many_through_association.rb +34 -23
- data/lib/active_record/associations/has_one_association.rb +0 -1
- data/lib/active_record/associations/join_dependency.rb +7 -9
- data/lib/active_record/associations/join_dependency/join_association.rb +18 -14
- data/lib/active_record/associations/preloader.rb +2 -2
- data/lib/active_record/associations/preloader/association.rb +9 -5
- data/lib/active_record/associations/preloader/through_association.rb +3 -3
- data/lib/active_record/associations/singular_association.rb +16 -1
- data/lib/active_record/associations/through_association.rb +6 -22
- data/lib/active_record/attribute.rb +131 -0
- data/lib/active_record/attribute_assignment.rb +19 -11
- data/lib/active_record/attribute_decorators.rb +66 -0
- data/lib/active_record/attribute_methods.rb +53 -90
- data/lib/active_record/attribute_methods/before_type_cast.rb +2 -2
- data/lib/active_record/attribute_methods/dirty.rb +85 -42
- data/lib/active_record/attribute_methods/primary_key.rb +6 -8
- data/lib/active_record/attribute_methods/read.rb +14 -57
- data/lib/active_record/attribute_methods/serialization.rb +12 -146
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +32 -40
- data/lib/active_record/attribute_methods/write.rb +8 -23
- data/lib/active_record/attribute_set.rb +77 -0
- data/lib/active_record/attribute_set/builder.rb +32 -0
- data/lib/active_record/attributes.rb +122 -0
- data/lib/active_record/autosave_association.rb +11 -21
- data/lib/active_record/base.rb +9 -19
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +69 -45
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +22 -42
- data/lib/active_record/connection_adapters/abstract/quoting.rb +59 -60
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +37 -2
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +102 -21
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +9 -33
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +178 -55
- data/lib/active_record/connection_adapters/abstract/transaction.rb +120 -115
- data/lib/active_record/connection_adapters/abstract_adapter.rb +143 -57
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +156 -107
- data/lib/active_record/connection_adapters/column.rb +13 -244
- data/lib/active_record/connection_adapters/connection_specification.rb +6 -20
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +12 -15
- data/lib/active_record/connection_adapters/mysql_adapter.rb +55 -143
- data/lib/active_record/connection_adapters/postgresql/array_parser.rb +15 -27
- data/lib/active_record/connection_adapters/postgresql/column.rb +20 -0
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +39 -20
- data/lib/active_record/connection_adapters/postgresql/oid.rb +29 -388
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +96 -0
- data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +52 -0
- data/lib/active_record/connection_adapters/postgresql/oid/bit_varying.rb +13 -0
- data/lib/active_record/connection_adapters/postgresql/oid/bytea.rb +14 -0
- data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +46 -0
- data/lib/active_record/connection_adapters/postgresql/oid/date.rb +11 -0
- data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +27 -0
- data/lib/active_record/connection_adapters/postgresql/oid/decimal.rb +13 -0
- data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +17 -0
- data/lib/active_record/connection_adapters/postgresql/oid/float.rb +21 -0
- data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +59 -0
- data/lib/active_record/connection_adapters/postgresql/oid/inet.rb +13 -0
- data/lib/active_record/connection_adapters/postgresql/oid/infinity.rb +13 -0
- data/lib/active_record/connection_adapters/postgresql/oid/integer.rb +11 -0
- data/lib/active_record/connection_adapters/postgresql/oid/json.rb +35 -0
- data/lib/active_record/connection_adapters/postgresql/oid/jsonb.rb +23 -0
- data/lib/active_record/connection_adapters/postgresql/oid/money.rb +43 -0
- data/lib/active_record/connection_adapters/postgresql/oid/point.rb +43 -0
- data/lib/active_record/connection_adapters/postgresql/oid/range.rb +76 -0
- data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +15 -0
- data/lib/active_record/connection_adapters/postgresql/oid/time.rb +11 -0
- data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +85 -0
- data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +26 -0
- data/lib/active_record/connection_adapters/postgresql/oid/vector.rb +26 -0
- data/lib/active_record/connection_adapters/postgresql/oid/xml.rb +28 -0
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +42 -122
- data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +4 -4
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +154 -0
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +86 -34
- data/lib/active_record/connection_adapters/postgresql/utils.rb +66 -0
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +188 -452
- data/lib/active_record/connection_adapters/schema_cache.rb +14 -28
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +54 -47
- data/lib/active_record/connection_handling.rb +1 -1
- data/lib/active_record/core.rb +119 -22
- data/lib/active_record/counter_cache.rb +60 -6
- data/lib/active_record/enum.rb +9 -10
- data/lib/active_record/errors.rb +27 -26
- data/lib/active_record/explain.rb +1 -1
- data/lib/active_record/fixtures.rb +52 -45
- data/lib/active_record/gem_version.rb +3 -3
- data/lib/active_record/inheritance.rb +33 -8
- data/lib/active_record/integration.rb +4 -4
- data/lib/active_record/locking/optimistic.rb +34 -16
- data/lib/active_record/migration.rb +22 -32
- data/lib/active_record/migration/command_recorder.rb +19 -2
- data/lib/active_record/migration/join_table.rb +1 -1
- data/lib/active_record/model_schema.rb +39 -48
- data/lib/active_record/nested_attributes.rb +8 -18
- data/lib/active_record/persistence.rb +39 -22
- data/lib/active_record/query_cache.rb +3 -3
- data/lib/active_record/querying.rb +1 -8
- data/lib/active_record/railtie.rb +17 -10
- data/lib/active_record/railties/databases.rake +47 -42
- data/lib/active_record/readonly_attributes.rb +0 -1
- data/lib/active_record/reflection.rb +225 -92
- data/lib/active_record/relation.rb +35 -11
- data/lib/active_record/relation/batches.rb +0 -2
- data/lib/active_record/relation/calculations.rb +28 -32
- data/lib/active_record/relation/delegation.rb +1 -1
- data/lib/active_record/relation/finder_methods.rb +42 -20
- data/lib/active_record/relation/merger.rb +0 -1
- data/lib/active_record/relation/predicate_builder.rb +1 -22
- data/lib/active_record/relation/predicate_builder/array_handler.rb +16 -11
- data/lib/active_record/relation/predicate_builder/relation_handler.rb +0 -4
- data/lib/active_record/relation/query_methods.rb +98 -62
- data/lib/active_record/relation/spawn_methods.rb +6 -7
- data/lib/active_record/result.rb +16 -9
- data/lib/active_record/sanitization.rb +8 -1
- data/lib/active_record/schema.rb +0 -1
- data/lib/active_record/schema_dumper.rb +51 -9
- data/lib/active_record/schema_migration.rb +4 -0
- data/lib/active_record/scoping/default.rb +5 -4
- data/lib/active_record/serializers/xml_serializer.rb +3 -7
- data/lib/active_record/statement_cache.rb +79 -5
- data/lib/active_record/store.rb +5 -5
- data/lib/active_record/tasks/database_tasks.rb +37 -5
- data/lib/active_record/tasks/mysql_database_tasks.rb +10 -16
- data/lib/active_record/tasks/postgresql_database_tasks.rb +2 -2
- data/lib/active_record/timestamp.rb +9 -7
- data/lib/active_record/transactions.rb +35 -21
- data/lib/active_record/type.rb +20 -0
- data/lib/active_record/type/binary.rb +40 -0
- data/lib/active_record/type/boolean.rb +19 -0
- data/lib/active_record/type/date.rb +46 -0
- data/lib/active_record/type/date_time.rb +43 -0
- data/lib/active_record/type/decimal.rb +40 -0
- data/lib/active_record/type/decimal_without_scale.rb +11 -0
- data/lib/active_record/type/float.rb +19 -0
- data/lib/active_record/type/hash_lookup_type_map.rb +19 -0
- data/lib/active_record/type/integer.rb +23 -0
- data/lib/active_record/type/mutable.rb +16 -0
- data/lib/active_record/type/numeric.rb +36 -0
- data/lib/active_record/type/serialized.rb +51 -0
- data/lib/active_record/type/string.rb +36 -0
- data/lib/active_record/type/text.rb +11 -0
- data/lib/active_record/type/time.rb +26 -0
- data/lib/active_record/type/time_value.rb +38 -0
- data/lib/active_record/type/type_map.rb +48 -0
- data/lib/active_record/type/value.rb +101 -0
- data/lib/active_record/validations.rb +21 -16
- data/lib/active_record/validations/uniqueness.rb +9 -23
- data/lib/rails/generators/active_record/migration/migration_generator.rb +8 -4
- data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb +1 -1
- data/lib/rails/generators/active_record/model/templates/model.rb +1 -1
- metadata +71 -14
- data/lib/active_record/connection_adapters/postgresql/cast.rb +0 -168
@@ -32,7 +32,7 @@ module ActiveRecord
|
|
32
32
|
# }
|
33
33
|
def initialize(url)
|
34
34
|
raise "Database URL cannot be empty" if url.blank?
|
35
|
-
@uri =
|
35
|
+
@uri = uri_parser.parse(url)
|
36
36
|
@adapter = @uri.scheme.gsub('-', '_')
|
37
37
|
@adapter = "postgresql" if @adapter == "postgres"
|
38
38
|
|
@@ -41,7 +41,6 @@ module ActiveRecord
|
|
41
41
|
else
|
42
42
|
@query = @uri.query
|
43
43
|
end
|
44
|
-
@authority = url =~ %r{\A[^:]*://}
|
45
44
|
end
|
46
45
|
|
47
46
|
# Converts the given URL to a full connection hash.
|
@@ -63,8 +62,8 @@ module ActiveRecord
|
|
63
62
|
|
64
63
|
# Converts the query parameters of the URI into a hash.
|
65
64
|
#
|
66
|
-
# "localhost?pool=5&
|
67
|
-
# # => { "pool" => "5", "
|
65
|
+
# "localhost?pool=5&reaping_frequency=2"
|
66
|
+
# # => { "pool" => "5", "reaping_frequency" => "2" }
|
68
67
|
#
|
69
68
|
# returns empty hash if no query present.
|
70
69
|
#
|
@@ -91,21 +90,8 @@ module ActiveRecord
|
|
91
90
|
end
|
92
91
|
|
93
92
|
# Returns name of the database.
|
94
|
-
# Sqlite3's handling of a leading slash is in transition as of
|
95
|
-
# Rails 4.1.
|
96
93
|
def database_from_path
|
97
|
-
if @
|
98
|
-
# 'sqlite3:///foo' is relative, for backwards compatibility.
|
99
|
-
|
100
|
-
database_name = uri.path.sub(%r{^/}, "")
|
101
|
-
|
102
|
-
msg = "Paths in SQLite3 database URLs of the form `sqlite3:///path` will be treated as absolute in Rails 4.2. " \
|
103
|
-
"Please switch to `sqlite3:#{database_name}`."
|
104
|
-
ActiveSupport::Deprecation.warn(msg)
|
105
|
-
|
106
|
-
database_name
|
107
|
-
|
108
|
-
elsif @adapter == 'sqlite3'
|
94
|
+
if @adapter == 'sqlite3'
|
109
95
|
# 'sqlite3:/foo' is absolute, because that makes sense. The
|
110
96
|
# corresponding relative version, 'sqlite3:foo', is handled
|
111
97
|
# elsewhere, as an "opaque".
|
@@ -174,7 +160,7 @@ module ActiveRecord
|
|
174
160
|
# config = { "production" => { "host" => "localhost", "database" => "foo", "adapter" => "sqlite3" } }
|
175
161
|
# spec = Resolver.new(config).spec(:production)
|
176
162
|
# spec.adapter_method
|
177
|
-
# # => "
|
163
|
+
# # => "sqlite3_connection"
|
178
164
|
# spec.config
|
179
165
|
# # => { "host" => "localhost", "database" => "foo", "adapter" => "sqlite3" }
|
180
166
|
#
|
@@ -264,7 +250,7 @@ module ActiveRecord
|
|
264
250
|
# Connection details inside of the "url" key win any merge conflicts
|
265
251
|
def resolve_hash_connection(spec)
|
266
252
|
if spec["url"] && spec["url"] !~ /^jdbc:/
|
267
|
-
connection_hash =
|
253
|
+
connection_hash = resolve_url_connection(spec.delete("url"))
|
268
254
|
spec.merge!(connection_hash)
|
269
255
|
end
|
270
256
|
spec
|
@@ -20,27 +20,20 @@ module ActiveRecord
|
|
20
20
|
ConnectionAdapters::Mysql2Adapter.new(client, logger, options, config)
|
21
21
|
rescue Mysql2::Error => error
|
22
22
|
if error.message.include?("Unknown database")
|
23
|
-
raise ActiveRecord::NoDatabaseError.new(error.message)
|
23
|
+
raise ActiveRecord::NoDatabaseError.new(error.message, error)
|
24
24
|
else
|
25
|
-
raise
|
25
|
+
raise
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
module ConnectionAdapters
|
31
31
|
class Mysql2Adapter < AbstractMysqlAdapter
|
32
|
-
|
33
|
-
class Column < AbstractMysqlAdapter::Column # :nodoc:
|
34
|
-
def adapter
|
35
|
-
Mysql2Adapter
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
32
|
ADAPTER_NAME = 'Mysql2'
|
40
33
|
|
41
34
|
def initialize(connection, logger, connection_options, config)
|
42
35
|
super
|
43
|
-
@
|
36
|
+
@prepared_statements = false
|
44
37
|
configure_connection
|
45
38
|
end
|
46
39
|
|
@@ -69,10 +62,6 @@ module ActiveRecord
|
|
69
62
|
end
|
70
63
|
end
|
71
64
|
|
72
|
-
def new_column(field, default, type, null, collation, extra = "") # :nodoc:
|
73
|
-
Column.new(field, default, type, null, collation, strict_mode?, extra)
|
74
|
-
end
|
75
|
-
|
76
65
|
def error_number(exception)
|
77
66
|
exception.error_number if exception.respond_to?(:error_number)
|
78
67
|
end
|
@@ -83,6 +72,14 @@ module ActiveRecord
|
|
83
72
|
@connection.escape(string)
|
84
73
|
end
|
85
74
|
|
75
|
+
def quoted_date(value)
|
76
|
+
if value.acts_like?(:time) && value.respond_to?(:usec)
|
77
|
+
"#{super}.#{sprintf("%06d", value.usec)}"
|
78
|
+
else
|
79
|
+
super
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
86
83
|
# CONNECTION MANAGEMENT ====================================
|
87
84
|
|
88
85
|
def active?
|
@@ -273,7 +270,7 @@ module ActiveRecord
|
|
273
270
|
end
|
274
271
|
|
275
272
|
def full_version
|
276
|
-
@full_version ||= @connection.
|
273
|
+
@full_version ||= @connection.info[:version]
|
277
274
|
end
|
278
275
|
|
279
276
|
def set_field_encoding field_name
|
@@ -36,9 +36,9 @@ module ActiveRecord
|
|
36
36
|
ConnectionAdapters::MysqlAdapter.new(mysql, logger, options, config)
|
37
37
|
rescue Mysql::Error => error
|
38
38
|
if error.message.include?("Unknown database")
|
39
|
-
raise ActiveRecord::NoDatabaseError.new(error.message)
|
39
|
+
raise ActiveRecord::NoDatabaseError.new(error.message, error)
|
40
40
|
else
|
41
|
-
raise
|
41
|
+
raise
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
@@ -57,7 +57,7 @@ module ActiveRecord
|
|
57
57
|
# * <tt>:database</tt> - The name of the database. No default, must be provided.
|
58
58
|
# * <tt>:encoding</tt> - (Optional) Sets the client encoding by executing "SET NAMES <encoding>" after connection.
|
59
59
|
# * <tt>:reconnect</tt> - Defaults to false (See MySQL documentation: http://dev.mysql.com/doc/refman/5.0/en/auto-reconnect.html).
|
60
|
-
# * <tt>:strict</tt> - Defaults to true. Enable STRICT_ALL_TABLES. (See MySQL documentation: http://dev.mysql.com/doc/refman/5.0/en/sql-mode.html)
|
60
|
+
# * <tt>:strict</tt> - Defaults to true. Enable STRICT_ALL_TABLES. (See MySQL documentation: http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html)
|
61
61
|
# * <tt>:variables</tt> - (Optional) A hash session variables to send as `SET @@SESSION.key = value` on each database connection. Use the value `:default` to set a variable to its DEFAULT value. (See MySQL documentation: http://dev.mysql.com/doc/refman/5.0/en/set-statement.html).
|
62
62
|
# * <tt>:sslca</tt> - Necessary to use MySQL with an SSL connection.
|
63
63
|
# * <tt>:sslkey</tt> - Necessary to use MySQL with an SSL connection.
|
@@ -66,35 +66,6 @@ module ActiveRecord
|
|
66
66
|
# * <tt>:sslcipher</tt> - Necessary to use MySQL with an SSL connection.
|
67
67
|
#
|
68
68
|
class MysqlAdapter < AbstractMysqlAdapter
|
69
|
-
|
70
|
-
class Column < AbstractMysqlAdapter::Column #:nodoc:
|
71
|
-
def self.string_to_time(value)
|
72
|
-
return super unless Mysql::Time === value
|
73
|
-
new_time(
|
74
|
-
value.year,
|
75
|
-
value.month,
|
76
|
-
value.day,
|
77
|
-
value.hour,
|
78
|
-
value.minute,
|
79
|
-
value.second,
|
80
|
-
value.second_part)
|
81
|
-
end
|
82
|
-
|
83
|
-
def self.string_to_dummy_time(v)
|
84
|
-
return super unless Mysql::Time === v
|
85
|
-
new_time(2000, 01, 01, v.hour, v.minute, v.second, v.second_part)
|
86
|
-
end
|
87
|
-
|
88
|
-
def self.string_to_date(v)
|
89
|
-
return super unless Mysql::Time === v
|
90
|
-
new_date(v.year, v.month, v.day)
|
91
|
-
end
|
92
|
-
|
93
|
-
def adapter
|
94
|
-
MysqlAdapter
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
69
|
ADAPTER_NAME = 'MySQL'
|
99
70
|
|
100
71
|
class StatementPool < ConnectionAdapters::StatementPool
|
@@ -156,10 +127,6 @@ module ActiveRecord
|
|
156
127
|
end
|
157
128
|
end
|
158
129
|
|
159
|
-
def new_column(field, default, type, null, collation, extra = "") # :nodoc:
|
160
|
-
Column.new(field, default, type, null, collation, strict_mode?, extra)
|
161
|
-
end
|
162
|
-
|
163
130
|
def error_number(exception) # :nodoc:
|
164
131
|
exception.errno if exception.respond_to?(:errno)
|
165
132
|
end
|
@@ -222,6 +189,7 @@ module ActiveRecord
|
|
222
189
|
|
223
190
|
# Clears the prepared statements cache.
|
224
191
|
def clear_cache!
|
192
|
+
super
|
225
193
|
@statements.clear
|
226
194
|
end
|
227
195
|
|
@@ -294,126 +262,70 @@ module ActiveRecord
|
|
294
262
|
@connection.insert_id
|
295
263
|
end
|
296
264
|
|
297
|
-
module Fields
|
298
|
-
class Type
|
299
|
-
def
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
return if value.nil?
|
313
|
-
|
314
|
-
value.to_i rescue value ? 1 : 0
|
315
|
-
end
|
316
|
-
end
|
317
|
-
|
318
|
-
class Date < Type
|
319
|
-
def type; :date; end
|
320
|
-
|
321
|
-
def type_cast(value)
|
322
|
-
return if value.nil?
|
323
|
-
|
324
|
-
# FIXME: probably we can improve this since we know it is mysql
|
325
|
-
# specific
|
326
|
-
ConnectionAdapters::Column.value_to_date value
|
327
|
-
end
|
328
|
-
end
|
329
|
-
|
330
|
-
class DateTime < Type
|
331
|
-
def type; :datetime; end
|
332
|
-
|
333
|
-
def type_cast(value)
|
334
|
-
return if value.nil?
|
335
|
-
|
336
|
-
# FIXME: probably we can improve this since we know it is mysql
|
337
|
-
# specific
|
338
|
-
ConnectionAdapters::Column.string_to_time value
|
339
|
-
end
|
340
|
-
end
|
341
|
-
|
342
|
-
class Time < Type
|
343
|
-
def type; :time; end
|
344
|
-
|
345
|
-
def type_cast(value)
|
346
|
-
return if value.nil?
|
347
|
-
|
348
|
-
# FIXME: probably we can improve this since we know it is mysql
|
349
|
-
# specific
|
350
|
-
ConnectionAdapters::Column.string_to_dummy_time value
|
351
|
-
end
|
352
|
-
end
|
353
|
-
|
354
|
-
class Float < Type
|
355
|
-
def type; :float; end
|
356
|
-
|
357
|
-
def type_cast(value)
|
358
|
-
return if value.nil?
|
359
|
-
|
360
|
-
value.to_f
|
265
|
+
module Fields # :nodoc:
|
266
|
+
class DateTime < Type::DateTime # :nodoc:
|
267
|
+
def cast_value(value)
|
268
|
+
if Mysql::Time === value
|
269
|
+
new_time(
|
270
|
+
value.year,
|
271
|
+
value.month,
|
272
|
+
value.day,
|
273
|
+
value.hour,
|
274
|
+
value.minute,
|
275
|
+
value.second,
|
276
|
+
value.second_part)
|
277
|
+
else
|
278
|
+
super
|
279
|
+
end
|
361
280
|
end
|
362
281
|
end
|
363
282
|
|
364
|
-
class
|
365
|
-
def
|
366
|
-
|
367
|
-
|
368
|
-
|
283
|
+
class Time < Type::Time # :nodoc:
|
284
|
+
def cast_value(value)
|
285
|
+
if Mysql::Time === value
|
286
|
+
new_time(
|
287
|
+
2000,
|
288
|
+
01,
|
289
|
+
01,
|
290
|
+
value.hour,
|
291
|
+
value.minute,
|
292
|
+
value.second,
|
293
|
+
value.second_part)
|
294
|
+
else
|
295
|
+
super
|
296
|
+
end
|
369
297
|
end
|
370
298
|
end
|
371
299
|
|
372
|
-
class
|
373
|
-
|
374
|
-
return if value.nil?
|
300
|
+
class << self
|
301
|
+
TYPES = Type::HashLookupTypeMap.new # :nodoc:
|
375
302
|
|
376
|
-
|
377
|
-
end
|
378
|
-
end
|
379
|
-
|
380
|
-
TYPES = {}
|
381
|
-
|
382
|
-
# Register an MySQL +type_id+ with a typecasting object in
|
383
|
-
# +type+.
|
384
|
-
def self.register_type(type_id, type)
|
385
|
-
TYPES[type_id] = type
|
386
|
-
end
|
303
|
+
delegate :register_type, :alias_type, to: :TYPES
|
387
304
|
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
TYPES[Mysql::Field::TYPE_LONG]
|
395
|
-
else
|
396
|
-
TYPES.fetch(field.type) { Fields::Identity.new }
|
305
|
+
def find_type(field)
|
306
|
+
if field.type == Mysql::Field::TYPE_TINY && field.length > 1
|
307
|
+
TYPES.lookup(Mysql::Field::TYPE_LONG)
|
308
|
+
else
|
309
|
+
TYPES.lookup(field.type)
|
310
|
+
end
|
397
311
|
end
|
398
312
|
end
|
399
313
|
|
400
|
-
register_type Mysql::Field::TYPE_TINY,
|
401
|
-
register_type Mysql::Field::TYPE_LONG,
|
314
|
+
register_type Mysql::Field::TYPE_TINY, Type::Boolean.new
|
315
|
+
register_type Mysql::Field::TYPE_LONG, Type::Integer.new
|
402
316
|
alias_type Mysql::Field::TYPE_LONGLONG, Mysql::Field::TYPE_LONG
|
403
317
|
alias_type Mysql::Field::TYPE_NEWDECIMAL, Mysql::Field::TYPE_LONG
|
404
318
|
|
405
|
-
register_type Mysql::Field::
|
406
|
-
register_type Mysql::Field::TYPE_BLOB, Fields::Identity.new
|
407
|
-
register_type Mysql::Field::TYPE_DATE, Fields::Date.new
|
319
|
+
register_type Mysql::Field::TYPE_DATE, Type::Date.new
|
408
320
|
register_type Mysql::Field::TYPE_DATETIME, Fields::DateTime.new
|
409
321
|
register_type Mysql::Field::TYPE_TIME, Fields::Time.new
|
410
|
-
register_type Mysql::Field::TYPE_FLOAT,
|
322
|
+
register_type Mysql::Field::TYPE_FLOAT, Type::Float.new
|
323
|
+
end
|
411
324
|
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
end
|
325
|
+
def initialize_type_map(m) # :nodoc:
|
326
|
+
super
|
327
|
+
m.register_type %r(datetime)i, Fields::DateTime.new
|
328
|
+
m.register_type %r(time)i, Fields::Time.new
|
417
329
|
end
|
418
330
|
|
419
331
|
def exec_without_stmt(sql, name = 'SQL') # :nodoc:
|
@@ -431,7 +343,7 @@ module ActiveRecord
|
|
431
343
|
fields << field_name
|
432
344
|
|
433
345
|
if field.decimals > 0
|
434
|
-
types[field_name] =
|
346
|
+
types[field_name] = Type::Decimal.new
|
435
347
|
else
|
436
348
|
types[field_name] = Fields.find_type field
|
437
349
|
end
|
@@ -447,7 +359,7 @@ module ActiveRecord
|
|
447
359
|
end
|
448
360
|
end
|
449
361
|
|
450
|
-
def execute_and_free(sql, name = nil)
|
362
|
+
def execute_and_free(sql, name = nil) # :nodoc:
|
451
363
|
result = execute(sql, name)
|
452
364
|
ret = yield result
|
453
365
|
result.free
|
@@ -460,7 +372,7 @@ module ActiveRecord
|
|
460
372
|
end
|
461
373
|
alias :create :insert_sql
|
462
374
|
|
463
|
-
def exec_delete(sql, name, binds)
|
375
|
+
def exec_delete(sql, name, binds) # :nodoc:
|
464
376
|
affected_rows = 0
|
465
377
|
|
466
378
|
exec_query(sql, name, binds) do |n|
|
@@ -497,7 +409,7 @@ module ActiveRecord
|
|
497
409
|
stmt.execute(*type_casted_binds.map { |_, val| val })
|
498
410
|
rescue Mysql::Error => e
|
499
411
|
# Older versions of MySQL leave the prepared statement in a bad
|
500
|
-
# place when an error occurs. To support older
|
412
|
+
# place when an error occurs. To support older MySQL versions, we
|
501
413
|
# need to close the statement and delete the statement from the
|
502
414
|
# cache.
|
503
415
|
stmt.close
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module ActiveRecord
|
2
2
|
module ConnectionAdapters
|
3
|
-
|
4
|
-
module ArrayParser
|
3
|
+
module PostgreSQL
|
4
|
+
module ArrayParser # :nodoc:
|
5
5
|
|
6
6
|
DOUBLE_QUOTE = '"'
|
7
7
|
BACKSLASH = "\\"
|
@@ -9,35 +9,23 @@ module ActiveRecord
|
|
9
9
|
BRACKET_OPEN = '{'
|
10
10
|
BRACKET_CLOSE = '}'
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
def parse_pg_array(string)
|
22
|
-
parse_data(string)
|
12
|
+
def parse_pg_array(string) # :nodoc:
|
13
|
+
local_index = 0
|
14
|
+
array = []
|
15
|
+
while(local_index < string.length)
|
16
|
+
case string[local_index]
|
17
|
+
when BRACKET_OPEN
|
18
|
+
local_index,array = parse_array_contents(array, string, local_index + 1)
|
19
|
+
when BRACKET_CLOSE
|
20
|
+
return array
|
23
21
|
end
|
22
|
+
local_index += 1
|
24
23
|
end
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
array = []
|
29
|
-
while(local_index < string.length)
|
30
|
-
case string[local_index]
|
31
|
-
when BRACKET_OPEN
|
32
|
-
local_index,array = parse_array_contents(array, string, local_index + 1)
|
33
|
-
when BRACKET_CLOSE
|
34
|
-
return array
|
35
|
-
end
|
36
|
-
local_index += 1
|
37
|
-
end
|
25
|
+
array
|
26
|
+
end
|
38
27
|
|
39
|
-
|
40
|
-
end
|
28
|
+
private
|
41
29
|
|
42
30
|
def parse_array_contents(array, string, index)
|
43
31
|
is_escaping = false
|