Bug 14905 - OdbcParameter does not support Timespan
Summary: OdbcParameter does not support Timespan
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Data (show other bugs)
Version: master
Hardware: PC All
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-09-21 15:01 UTC by wdehoog
Modified: 2013-09-21 15:01 UTC (History)
1 user (show)

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


Attachments

Description wdehoog 2013-09-21 15:01:22 UTC
The CopyValue method of OdbcParameter assumes the Value is a DateTime for parameters having type OdbcType.Time. However they can also be of type TimeSpan.

Something like this would do the job:

        if(Value.GetType() == typeof(DateTime)) {
          dt = (DateTime) Value;
          Marshal.WriteInt16 (_nativeBuffer, 0, (short) dt.Hour);
          Marshal.WriteInt16 (_nativeBuffer, 2, (short) dt.Minute);
          Marshal.WriteInt16 (_nativeBuffer, 4, (short) dt.Second);
        } else {
          if(Value.GetType() == typeof(TimeSpan)) {
            ts = (TimeSpan) Value;
            Marshal.WriteInt16 (_nativeBuffer, 0, (short) ts.Hours);
            Marshal.WriteInt16 (_nativeBuffer, 2, (short) ts.Minutes);
            Marshal.WriteInt16 (_nativeBuffer, 4, (short) ts.Seconds);
          } else
            throw new ArgumentException ("Unsupported Type for OdbcType.Time! "+Value.GetType());
        }

Note You need to log in before you can comment on or make changes to this bug.