Skip to content

Commit 504d16c

Browse files
brownbeaglelifo
authored andcommitted
Add microsecond support for sqlite adapter [#1982 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
1 parent 7a99dc0 commit 504d16c

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,16 @@ def quote_column_name(name) #:nodoc:
150150
%Q("#{name}")
151151
end
152152

153+
# Quote date/time values for use in SQL input. Includes microseconds
154+
# if the value is a Time responding to usec.
155+
def quoted_date(value) #:nodoc:
156+
if value.acts_like?(:time) && value.respond_to?(:usec)
157+
"#{super}.#{sprintf("%06d", value.usec)}"
158+
else
159+
super
160+
end
161+
end
162+
153163

154164
# DATABASE STATEMENTS ======================================
155165

activerecord/test/cases/base_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ def test_preserving_time_objects
456456
)
457457

458458
# For adapters which support microsecond resolution.
459-
if current_adapter?(:PostgreSQLAdapter)
459+
if current_adapter?(:PostgreSQLAdapter) || current_adapter?(:SQLiteAdapter)
460460
assert_equal 11, Topic.find(1).written_on.sec
461461
assert_equal 223300, Topic.find(1).written_on.usec
462462
assert_equal 9900, Topic.find(2).written_on.usec

0 commit comments

Comments
 (0)