Bug 14443 - Reading Time or DateTime with ODBC is not working on Linux 64 bit
Summary: Reading Time or DateTime with ODBC is not working on Linux 64 bit
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Data (show other bugs)
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-09-04 15:33 UTC by wdehoog
Modified: 2013-09-06 04:54 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
the test file I use (1.12 KB, text/x-csharp)
2013-09-05 12:53 UTC, wdehoog
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 14443 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
NEW

Description wdehoog 2013-09-04 15:33:42 UTC
When trying this code on Ubuntu 64 bits:

string sql = "SELECT '23:45:01'::time, '12:34:56'::time ";
dbcmd.CommandText = sql;
IDataReader reader = dbcmd.ExecuteReader();
reader.Read();
Console.WriteLine("0: " + reader.GetDataTypeName(0));
Console.WriteLine("1: " + reader.GetDataTypeName(1));
string str =  reader[0].ToString();
Console.WriteLine(str);
str =  reader[1].ToString();
Console.WriteLine(str);

it outputs:
0: time
1: time
00:00:01
00:00:56

On Ubuntu 32 bits:
0: time
1: time
23:45:01
12:34:56

When reading a DateTime value (postgres type ::date or ::timestamp) the DateTime constructor throws an exception (unrepresentable date time) on 64bit platform. On 32bits it works normally.

On 64 bits Libreoffice using the same odbc driver (postgresql) does show the correct time or date values so it is probably not an odbc or postgres problem.

I suspect something is wrong with the way libodbc is used on 64bit platform. (Is struct OdbcTimestamp ok?)
Comment 1 wdehoog 2013-09-05 12:52:07 UTC
I played around in OdbcDataReader.cs and noticed some very weird behaviour:

this original source crashes:
  DateTime dtv = new DateTime(ts_data.year, ts_data.month,
                              ts_data.day, ts_data.hour, ts_data.minute,
                              ts_data.second);

this actually works:
  DateTime dtv = new DateTime(ts_data.year,ts_data.month,ts_data.day);
  TimeSpan time = new TimeSpan (ts_data.hour, ts_data.minute, ts_data.second);
  dtv = dtv.Add(time);
  DataValue = dtv;

It should not be different according to the source of DateTime.

Another weird thing is that when I print the output of libodbc using 
Console.WriteLine(String.Format("libodbc: {0}-{1}-{2} {3}:{4}:{5}:{6}", ts_data.year, ts_data.month, ts_data.day, ts_data.hour, ts_data.minute, ts_data.second, ts_data.fraction));

using sql: SELECT '2013-12-03 12:34:56'::timestamp, '2013-12-03'::date, '12:34:56'::time 

with the original version
  0: timestamp without time zone
  1: date
  2: time
  libodbc: 0-0-3 12:34:56:0
  <exeption>

with the working version
  0: timestamp without time zone
  1: date
  2: time
  libodbc: 2013-12-3 12:34:56:0
  12/3/2013 12:34:56 PM
  libodbc: 2013-12-3 0:0:0:0
  12/3/2013 12:00:00 AM
  12:34:56

Note that the Console.WriteLine statement is _before_ the DateTime construction. 


Last weird thing is when I add this extra code:
  DateTime dtv2 = new DateTime(1,1,1,0,0,0);
it crashes. When adding
  DateTime dtv2 = new DateTime(1,1,1);
it works.

How can a constructor cause data to be corrupted?
Comment 2 wdehoog 2013-09-05 12:53:33 UTC
Created attachment 4789 [details]
the test file I use
Comment 3 wdehoog 2013-09-05 13:33:36 UTC
Forgot to add:

mono -- version
Mono JIT compiler version 2.10.8.1 (Debian 2.10.8.1-5ubuntu1)
Copyright (C) 2002-2011 Novell, Inc, Xamarin, Inc and Contributors. www.mono-project.com
	TLS:           __thread
	SIGSEGV:       altstack
	Notifications: epoll
	Architecture:  amd64
	Disabled:      none
	Misc:          softdebug 
	LLVM:          supported, not enabled.
	GC:            Included Boehm (with typed GC and Parallel Mark)

lsb_release -a
Description:	Ubuntu 13.04
Release:	13.04
Codename:	raring

uname -a
Linux xtreamer-ultra-2 3.8.0-26-generic #38-Ubuntu SMP Mon Jun 17 21:43:33 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
Comment 4 wdehoog 2013-09-06 04:54:12 UTC
Tried current mono from git and the problem is here as well and the work around solves it here too.

Mono JIT compiler version 3.2.3 (master/e682ece do sep  5 22:01:49 CEST 2013)
Copyright (C) 2002-2012 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
        TLS:           __thread
        SIGSEGV:       altstack
        Notifications: epoll
        Architecture:  amd64
        Disabled:      none
        Misc:          softdebug 
        LLVM:          supported, not enabled.
        GC:            sgen