Class: SQLServerDBI::Type::SqlserverTimestamp
- Inherits:
-
Object
- Object
- SQLServerDBI::Type::SqlserverTimestamp
- Defined in:
- lib/core_ext/dbi.rb
Overview
Make sure we get DBI::Type::Timestamp returning a string NOT a time object that represents what is in the DB before type casting while letting core ActiveRecord do the reset. It is assumed that DBI is using ODBC connections and that ODBC::Timestamp is taking the native milliseconds that SQL Server stores and returning them incorrect using ODBC::Timestamp#fraction which is nanoseconds. Below shows the incorrect ODBC::Timestamp represented by DBI and the conversion we expect to have in the DB before type casting.
"1985-04-15 00:00:00 0" # => "1985-04-15 00:00:00.000"
"2008-11-08 10:24:36 300000000" # => "2008-11-08 10:24:36.003"
"2008-11-08 10:24:36 123000000" # => "2008-11-08 10:24:36.123"
Class Method Summary collapse
Class Method Details
.parse(obj) ⇒ Object
30 31 32 33 34 |
# File 'lib/core_ext/dbi.rb', line 30 def self.parse(obj) return nil if ::DBI::Type::Null.parse(obj).nil? date, time, nanoseconds = obj.split(' ') "#{date} #{time}.#{sprintf("%03d",nanoseconds.to_i/1000000)}" end |