-
Notifications
You must be signed in to change notification settings - Fork 21.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor microsecond precision to be database agnostic
The various databases don't actually need significantly different handling for this behavior, and they can achieve it without knowing about the type of the object. The old implementation was returning a string, which will cause problems such as breaking TZ aware attributes, and making it impossible for the adapters to supply their logic for time objects.
- Loading branch information
Showing
11 changed files
with
55 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,7 +127,12 @@ def quoted_date(value) | |
end | ||
end | ||
|
||
value.to_s(:db) | ||
result = value.to_s(:db) | ||
if value.respond_to?(:usec) && value.usec > 0 | ||
"#{result}.#{sprintf("%06d", value.usec)}" | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
sgrif
Author
Contributor
|
||
else | ||
result | ||
end | ||
end | ||
|
||
def prepare_binds_for_database(binds) # :nodoc: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
We cannot allways append microseconds. it will ignore the Time::DATE_FORMATS[:db] setting, which can be set cusomly, e.g
Time::DATE_FORMATS[:db] = "%Y-%m-%d %H:%M:%S.%3N"
See my comment to df5a38f
I see there is a precision option for dates now. Let's just stick to it and remove the #{sprintf("%06d", value.usec)}"
Rails seems to set a default for Time::DATE_FORMATS[:db] to "%Y-%m-%d %H:%M:%S"
We have to either change the default to "%Y-%m-%d %H:%M:%S.%6N" for mysql > 5.6 and other db's that support it or just stick to the default without microseconds allowing the user to reconfigure it, either by Time::DATE_FORMATS[:db] or with the precision option within a migraiton
See issue #19223