SCM

[#1011018] Invalid Cast with DbType.Time Parameter

View Trackers | Bugs | Download .csv | Monitor

Date:
2011-04-23 19:58
Priority:
3
State:
Open
Submitted by:
Patrick Earl (patearl)
Assigned to:
Nobody (None)
Npgsql Version:
None
Category:
Group:
Resolution:
None
Summary:
Invalid Cast with DbType.Time Parameter

Detailed description
Parameters of type DbType.Time accept DateTimes but then break when casting from the internal type to the framework type. The existing code does not look consistent with itself.

I made the following change to avoid the cast to NpgsqlTime when the parameter value is already in DateTime format. This change allows the NHibernate time tests to pass.

new NpgsqlBackendTypeInfo(
0,
"time",
NpgsqlDbType.Time,
DbType.Time,
typeof (NpgsqlTime),
new ConvertBackendToNativeHandler(ExtendedBackendToNativeTypeConverter.ToTime),
typeof(DateTime),
*** HERE IS THE CHANGE ***
time => time is DateTime ? time : (DateTime)(NpgsqlTime)time,
*** END CHANGE ***
npgsqlTime => (npgsqlTime is TimeSpan ? (NpgsqlTime)(TimeSpan) npgsqlTime : npgsqlTime)
);

This affects 2.0.11.91 and at least some earlier versions.

Followup

Message
Date: 2011-04-25 04:02
Sender: Francisco Figueiredo jr.


Great! I'm glad to hear!

Hmmmm, I think I'm going to setup a NHibernate test case here in my dev machine so I can test on it too.

I'm looking forward your DTC bug reports! :)

Date: 2011-04-25 03:42
Sender: Patrick Earl

I checked out a fresh copy and ran all the tests. All the
date tests are passing now. Thanks for applying it. Looking
forward to a release with the fix.

On an unrelated note, there are a bunch of DTC tests failing
for Npgsql in NHibernate. I might be back to bug you again.
:)
Date: 2011-04-25 03:14
Sender: Francisco Figueiredo jr.



That's true....

I'll check how to get something done in github. It seems pretty popular nowadays. :)

While that, you can download latest source release from downloads.npgsql.org and just apply your patch, or grab the latest cvs commit from here:

http://cvs.pgfoundry.org/cgi-bin/cvsweb.cgi/npgsql/Npgsql2/src/NpgsqlTypes/NpgsqlTypesHelper.cs?rev=1.39&content-type=text/x-cvsweb-markup&sortby=rev

Sorry for this problem... :(
Date: 2011-04-25 03:07
Sender: Patrick Earl

I couldn't find an archive file for the trunk. I also had
trouble getting a CVS client... seems the technology is
getting pretty dated. :( I'll try harder, but I dare say that
it might be a good idea to migrate to a social hosting site
like github to encourage contributions.
Date: 2011-04-25 02:30
Sender: Francisco Figueiredo jr.


Thanks for the patch!

Already fixed in cvs. Please give it a try and let me know if it works for you.

Attached Files:

Changes:

No Changes Have Been Made to This Item

Powered By FusionForge