activerecord 4.1.15 → 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 -2176
- data/README.rdoc +15 -10
- data/lib/active_record/aggregations.rb +12 -8
- 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/join_association.rb +18 -14
- data/lib/active_record/associations/join_dependency.rb +7 -9
- 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/preloader.rb +2 -2
- data/lib/active_record/associations/singular_association.rb +16 -1
- data/lib/active_record/associations/through_association.rb +6 -22
- data/lib/active_record/associations.rb +58 -33
- 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/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_methods.rb +53 -90
- data/lib/active_record/attribute_set/builder.rb +32 -0
- data/lib/active_record/attribute_set.rb +77 -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/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/oid.rb +29 -388
- 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/command_recorder.rb +19 -2
- data/lib/active_record/migration/join_table.rb +1 -1
- data/lib/active_record/migration.rb +22 -32
- 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/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/array_handler.rb +16 -11
- data/lib/active_record/relation/predicate_builder/relation_handler.rb +0 -4
- data/lib/active_record/relation/predicate_builder.rb +1 -22
- data/lib/active_record/relation/query_methods.rb +98 -62
- data/lib/active_record/relation/spawn_methods.rb +6 -7
- data/lib/active_record/relation.rb +35 -11
- 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 +1 -1
- 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/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/type.rb +20 -0
- data/lib/active_record/validations/uniqueness.rb +9 -23
- data/lib/active_record/validations.rb +21 -16
- data/lib/active_record.rb +2 -1
- 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
@@ -13,101 +13,36 @@ module ActiveRecord
|
|
13
13
|
ISO_DATETIME = /\A(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)(\.\d+)?\z/
|
14
14
|
end
|
15
15
|
|
16
|
-
attr_reader :name, :
|
17
|
-
attr_accessor :primary, :coder
|
16
|
+
attr_reader :name, :cast_type, :null, :sql_type, :default, :default_function
|
18
17
|
|
19
|
-
|
18
|
+
delegate :type, :precision, :scale, :limit, :klass, :accessor,
|
19
|
+
:number?, :binary?, :changed?,
|
20
|
+
:type_cast_from_user, :type_cast_from_database, :type_cast_for_database,
|
21
|
+
:type_cast_for_schema,
|
22
|
+
to: :cast_type
|
20
23
|
|
21
24
|
# Instantiates a new column in the table.
|
22
25
|
#
|
23
26
|
# +name+ is the column's name, such as <tt>supplier_id</tt> in <tt>supplier_id int(11)</tt>.
|
24
27
|
# +default+ is the type-casted default value, such as +new+ in <tt>sales_stage varchar(20) default 'new'</tt>.
|
28
|
+
# +cast_type+ is the object used for type casting and type information.
|
25
29
|
# +sql_type+ is used to extract the column's length, if necessary. For example +60+ in
|
26
30
|
# <tt>company_name varchar(60)</tt>.
|
27
31
|
# It will be mapped to one of the standard Rails SQL types in the <tt>type</tt> attribute.
|
28
32
|
# +null+ determines if this column allows +NULL+ values.
|
29
|
-
def initialize(name, default, sql_type = nil, null = true)
|
33
|
+
def initialize(name, default, cast_type, sql_type = nil, null = true)
|
30
34
|
@name = name
|
35
|
+
@cast_type = cast_type
|
31
36
|
@sql_type = sql_type
|
32
37
|
@null = null
|
33
|
-
@
|
34
|
-
@precision = extract_precision(sql_type)
|
35
|
-
@scale = extract_scale(sql_type)
|
36
|
-
@type = simplified_type(sql_type)
|
37
|
-
@default = extract_default(default)
|
38
|
+
@default = default
|
38
39
|
@default_function = nil
|
39
|
-
@primary = nil
|
40
|
-
@coder = nil
|
41
|
-
end
|
42
|
-
|
43
|
-
# Returns +true+ if the column is either of type string or text.
|
44
|
-
def text?
|
45
|
-
type == :string || type == :text
|
46
|
-
end
|
47
|
-
|
48
|
-
# Returns +true+ if the column is either of type integer, float or decimal.
|
49
|
-
def number?
|
50
|
-
type == :integer || type == :float || type == :decimal
|
51
40
|
end
|
52
41
|
|
53
42
|
def has_default?
|
54
43
|
!default.nil?
|
55
44
|
end
|
56
45
|
|
57
|
-
# Returns the Ruby class that corresponds to the abstract data type.
|
58
|
-
def klass
|
59
|
-
case type
|
60
|
-
when :integer then Fixnum
|
61
|
-
when :float then Float
|
62
|
-
when :decimal then BigDecimal
|
63
|
-
when :datetime, :timestamp, :time then Time
|
64
|
-
when :date then Date
|
65
|
-
when :text, :string, :binary then String
|
66
|
-
when :boolean then Object
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def binary?
|
71
|
-
type == :binary
|
72
|
-
end
|
73
|
-
|
74
|
-
# Casts a Ruby value to something appropriate for writing to the database.
|
75
|
-
def type_cast_for_write(value)
|
76
|
-
return value unless number?
|
77
|
-
|
78
|
-
case value
|
79
|
-
when FalseClass
|
80
|
-
0
|
81
|
-
when TrueClass
|
82
|
-
1
|
83
|
-
when String
|
84
|
-
value.presence
|
85
|
-
else
|
86
|
-
value
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
# Casts value (which is a String) to an appropriate instance.
|
91
|
-
def type_cast(value)
|
92
|
-
return nil if value.nil?
|
93
|
-
return coder.load(value) if encoded?
|
94
|
-
|
95
|
-
klass = self.class
|
96
|
-
|
97
|
-
case type
|
98
|
-
when :string, :text then value
|
99
|
-
when :integer then klass.value_to_integer(value)
|
100
|
-
when :float then value.to_f
|
101
|
-
when :decimal then klass.value_to_decimal(value)
|
102
|
-
when :datetime, :timestamp then klass.string_to_time(value)
|
103
|
-
when :time then klass.string_to_dummy_time(value)
|
104
|
-
when :date then klass.value_to_date(value)
|
105
|
-
when :binary then klass.binary_to_string(value)
|
106
|
-
when :boolean then klass.value_to_boolean(value)
|
107
|
-
else value
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
46
|
# Returns the human name of the column name.
|
112
47
|
#
|
113
48
|
# ===== Examples
|
@@ -116,177 +51,11 @@ module ActiveRecord
|
|
116
51
|
Base.human_attribute_name(@name)
|
117
52
|
end
|
118
53
|
|
119
|
-
def
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
class << self
|
124
|
-
# Used to convert from BLOBs to Strings
|
125
|
-
def binary_to_string(value)
|
126
|
-
value
|
54
|
+
def with_type(type)
|
55
|
+
dup.tap do |clone|
|
56
|
+
clone.instance_variable_set('@cast_type', type)
|
127
57
|
end
|
128
|
-
|
129
|
-
def value_to_date(value)
|
130
|
-
if value.is_a?(String)
|
131
|
-
return nil if value.empty?
|
132
|
-
fast_string_to_date(value) || fallback_string_to_date(value)
|
133
|
-
elsif value.respond_to?(:to_date)
|
134
|
-
value.to_date
|
135
|
-
else
|
136
|
-
value
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
def string_to_time(string)
|
141
|
-
return string unless string.is_a?(String)
|
142
|
-
return nil if string.empty?
|
143
|
-
|
144
|
-
fast_string_to_time(string) || fallback_string_to_time(string)
|
145
|
-
end
|
146
|
-
|
147
|
-
def string_to_dummy_time(string)
|
148
|
-
return string unless string.is_a?(String)
|
149
|
-
return nil if string.empty?
|
150
|
-
|
151
|
-
dummy_time_string = "2000-01-01 #{string}"
|
152
|
-
|
153
|
-
fast_string_to_time(dummy_time_string) || begin
|
154
|
-
time_hash = Date._parse(dummy_time_string)
|
155
|
-
return nil if time_hash[:hour].nil?
|
156
|
-
new_time(*time_hash.values_at(:year, :mon, :mday, :hour, :min, :sec, :sec_fraction))
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
# convert something to a boolean
|
161
|
-
def value_to_boolean(value)
|
162
|
-
if value.is_a?(String) && value.empty?
|
163
|
-
nil
|
164
|
-
else
|
165
|
-
TRUE_VALUES.include?(value)
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
# Used to convert values to integer.
|
170
|
-
# handle the case when an integer column is used to store boolean values
|
171
|
-
def value_to_integer(value)
|
172
|
-
case value
|
173
|
-
when TrueClass, FalseClass
|
174
|
-
value ? 1 : 0
|
175
|
-
else
|
176
|
-
value.to_i rescue nil
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
# convert something to a BigDecimal
|
181
|
-
def value_to_decimal(value)
|
182
|
-
# Using .class is faster than .is_a? and
|
183
|
-
# subclasses of BigDecimal will be handled
|
184
|
-
# in the else clause
|
185
|
-
if value.class == BigDecimal
|
186
|
-
value
|
187
|
-
elsif value.respond_to?(:to_d)
|
188
|
-
value.to_d
|
189
|
-
else
|
190
|
-
value.to_s.to_d
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
protected
|
195
|
-
# '0.123456' -> 123456
|
196
|
-
# '1.123456' -> 123456
|
197
|
-
def microseconds(time)
|
198
|
-
time[:sec_fraction] ? (time[:sec_fraction] * 1_000_000).to_i : 0
|
199
|
-
end
|
200
|
-
|
201
|
-
def new_date(year, mon, mday)
|
202
|
-
if year && year != 0
|
203
|
-
Date.new(year, mon, mday) rescue nil
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
def new_time(year, mon, mday, hour, min, sec, microsec, offset = nil)
|
208
|
-
# Treat 0000-00-00 00:00:00 as nil.
|
209
|
-
return nil if year.nil? || (year == 0 && mon == 0 && mday == 0)
|
210
|
-
|
211
|
-
if offset
|
212
|
-
time = Time.utc(year, mon, mday, hour, min, sec, microsec) rescue nil
|
213
|
-
return nil unless time
|
214
|
-
|
215
|
-
time -= offset
|
216
|
-
Base.default_timezone == :utc ? time : time.getlocal
|
217
|
-
else
|
218
|
-
Time.public_send(Base.default_timezone, year, mon, mday, hour, min, sec, microsec) rescue nil
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
def fast_string_to_date(string)
|
223
|
-
if string =~ Format::ISO_DATE
|
224
|
-
new_date $1.to_i, $2.to_i, $3.to_i
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
|
-
# Doesn't handle time zones.
|
229
|
-
def fast_string_to_time(string)
|
230
|
-
if string =~ Format::ISO_DATETIME
|
231
|
-
microsec = ($7.to_r * 1_000_000).to_i
|
232
|
-
new_time $1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i, $6.to_i, microsec
|
233
|
-
end
|
234
|
-
end
|
235
|
-
|
236
|
-
def fallback_string_to_date(string)
|
237
|
-
new_date(*::Date._parse(string, false).values_at(:year, :mon, :mday))
|
238
|
-
end
|
239
|
-
|
240
|
-
def fallback_string_to_time(string)
|
241
|
-
time_hash = Date._parse(string)
|
242
|
-
time_hash[:sec_fraction] = microseconds(time_hash)
|
243
|
-
|
244
|
-
new_time(*time_hash.values_at(:year, :mon, :mday, :hour, :min, :sec, :sec_fraction, :offset))
|
245
|
-
end
|
246
58
|
end
|
247
|
-
|
248
|
-
private
|
249
|
-
def extract_limit(sql_type)
|
250
|
-
$1.to_i if sql_type =~ /\((.*)\)/
|
251
|
-
end
|
252
|
-
|
253
|
-
def extract_precision(sql_type)
|
254
|
-
$2.to_i if sql_type =~ /^(numeric|decimal|number)\((\d+)(,\d+)?\)/i
|
255
|
-
end
|
256
|
-
|
257
|
-
def extract_scale(sql_type)
|
258
|
-
case sql_type
|
259
|
-
when /^(numeric|decimal|number)\((\d+)\)/i then 0
|
260
|
-
when /^(numeric|decimal|number)\((\d+)(,(\d+))\)/i then $4.to_i
|
261
|
-
end
|
262
|
-
end
|
263
|
-
|
264
|
-
def simplified_type(field_type)
|
265
|
-
case field_type
|
266
|
-
when /int/i
|
267
|
-
:integer
|
268
|
-
when /float|double/i
|
269
|
-
:float
|
270
|
-
when /decimal|numeric|number/i
|
271
|
-
extract_scale(field_type) == 0 ? :integer : :decimal
|
272
|
-
when /datetime/i
|
273
|
-
:datetime
|
274
|
-
when /timestamp/i
|
275
|
-
:timestamp
|
276
|
-
when /time/i
|
277
|
-
:time
|
278
|
-
when /date/i
|
279
|
-
:date
|
280
|
-
when /clob/i, /text/i
|
281
|
-
:text
|
282
|
-
when /blob/i, /binary/i
|
283
|
-
:binary
|
284
|
-
when /char/i
|
285
|
-
:string
|
286
|
-
when /boolean/i
|
287
|
-
:boolean
|
288
|
-
end
|
289
|
-
end
|
290
59
|
end
|
291
60
|
end
|
292
61
|
# :startdoc:
|
@@ -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
|