Subject: libdbi-ruby1.8: DBI::StatementHandle::fetch or fetch_all convert SQL
DATE type into DateTime but should be Date
Package: libdbi-ruby1.8
Version: 0.4.3-2
Severity: important
*** Please type your report below this line ***
When a result set, obtained by DBI::StatementHandle::fetch or fetch_all
contains a column of SQL type DATE, it is converted by the DBI to a
DateTime object with zeroes in all time fields. Its dbi_type is
DBI::Type::Timestamp. In other words, the DBI does not distinguish
between the SQL types TIMESTAMP and DATE. Example:
irb> db.execute('select thedate from mytable').fetch[0]
=> #<DateTime: 2455755.5,0,2299161>
irb> db.execute('select thedate from mytable').fetch[0].to_s
=> "2011-07-13T00:00:00+00:00"
irb> db.execute('select thedate from mytable').fetch_array[0].to_s
=> "2011-07-13"
irb> db.execute('select thedate from mytable').column_info
=> [{:type=>"date", :scale=>nil, :array_of_type=>nil,
:dbi_type=>DBI::Type::Timestamp, :precision=>nil,
:name=>"thedate", :type_name=>"date"}]
where db is a DBI connection handle and mytable.thedate is a column of
SQL type DATE. As you can see fetch_array, which does no type
convertion, produces the date correctly just as it was returned by the
RDBMS (PostgreSQL in this case).
This is a DBI problem, not a PostgreSQL or dbd-pg problem. This can be
verified by looking at /usr/lib/ruby/1.8/dbi/types.rb:
163 def self.parse(obj)
164 case obj
165 when ::DateTime
166 return obj
167 when ::Date
168 return create(obj.year, obj.month, obj.day, 0, 0, 0)
The date 2011-08-13 is not the same as the date and time
2011-08-13t00:00:00+00:00 and therefore the two should not be conflated.
Furthermore, Ruby has a perfectly reasonable class, Date, that matches
with the SQL type DATE.
-- System Information:
Debian Release: 6.0.2
APT prefers stable-updates
APT policy: (500, 'stable-updates'), (500, 'stable')
Architecture: i386 (x86_64)
Kernel: Linux 2.6.32-5-amd64 (SMP w/2 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Versions of packages libdbi-ruby1.8 depends on:
ii libdeprecated-ruby1. 2.0.1-2 Library for handling deprecated co
ii libruby1.8 1.8.7.302-2squeeze1 Libraries necessary to run Ruby 1.
libdbi-ruby1.8 recommends no packages.
Versions of packages libdbi-ruby1.8 suggests:
pn libdbi-ruby <none> (no description available)
-- debconf-show failed
--
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]