Changeset 7780
- Timestamp:
- 10/07/07 22:01:59 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r7778 r7780 3 3 * Raise ProtectedAttributeAssignmentError in development and test environments when mass-assigning to an attr_protected attribute. #9802 [Henrik N] 4 4 5 * MySQL: speedup date/time parsing. [Jeremy Kemper]5 * Speedup database date/time parsing. [Jeremy Kemper, Tarmo TÀnav] 6 6 7 7 * Fix calling .clear on a has_many :dependent=>:delete_all association. [tarmo] trunk/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
r7771 r7780 7 7 # An abstract definition of a column in a table. 8 8 class Column 9 module Format 10 ISO_DATE = /\A(\d{4})-(\d\d)-(\d\d)\z/ 11 ISO_DATETIME = /\A(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)(\.\d+)?\z/ 12 end 13 9 14 attr_reader :name, :default, :type, :limit, :null, :sql_type, :precision, :scale 10 15 attr_accessor :primary … … 110 115 def string_to_date(string) 111 116 return string unless string.is_a?(String) 112 113 new_date *ParseDate.parsedate(string)[0..2] 117 return nil if string.empty? 118 119 fast_string_to_date(string) || fallback_string_to_date(string) 114 120 end 115 121 … … 118 124 return nil if string.empty? 119 125 120 time_hash = Date._parse(string) 121 time_hash[:sec_fraction] = microseconds(time_hash) 122 123 new_time *time_hash.values_at(:year, :mon, :mday, :hour, :min, :sec, :sec_fraction) 126 fast_string_to_time(string) || fallback_string_to_time(string) 124 127 end 125 128 … … 174 177 # Append zero calendar reform start to account for dates skipped by calendar reform 175 178 DateTime.new(year, mon, mday, hour, min, sec, zone_offset, 0) rescue nil 179 end 180 181 def fast_string_to_date(string) 182 if string =~ Format::ISO_DATE 183 new_date $1.to_i, $2.to_i, $3.to_i 184 end 185 end 186 187 # Doesn't handle time zones. 188 def fast_string_to_time(string) 189 if string =~ Format::ISO_DATETIME 190 microsec = ($7.to_f * 10e6).to_i 191 new_time $1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i, $6.to_i, microsec 192 end 193 end 194 195 def fallback_string_to_date(string) 196 new_date *ParseDate.parsedate(string)[0..2] 197 end 198 199 def fallback_string_to_time(string) 200 time_hash = Date._parse(string) 201 time_hash[:sec_fraction] = microseconds(time_hash) 202 203 new_time *time_hash.values_at(:year, :mon, :mday, :hour, :min, :sec, :sec_fraction) 176 204 end 177 205 end trunk/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
r7771 r7780 92 92 module ConnectionAdapters 93 93 class MysqlColumn < Column #:nodoc: 94 module Format95 DATE = /\A(\d{4})-(\d\d)-(\d\d)\z/96 DATETIME = /\A(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)(?:\.(\d{6}))?\z/97 end98 99 94 def extract_default(default) 100 95 if type == :binary || type == :text … … 108 103 else 109 104 super 110 end111 end112 113 class << self114 def string_to_date(string)115 return string unless string.is_a?(String)116 return nil if string.empty?117 118 if string =~ Format::DATE119 new_date $1.to_i, $2.to_i, $3.to_i120 else121 super122 end123 end124 125 def string_to_time(string)126 return string unless string.is_a?(String)127 return nil if string.empty?128 129 if string =~ Format::DATETIME130 new_time $1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i, $6.to_i, $7.to_i131 else132 super133 end134 105 end 135 106 end