Skip to content

NH-4017 - Handle Time parameter conversion for newer Npgsql #631

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

fredericDelaporte
Copy link
Member

@fredericDelaporte fredericDelaporte commented May 25, 2017

NH-4017 - Handle Time parameter conversion for newer Npgsql

The change appears to be supported by older version of Npgsql, so I am coding it for all instead of checking the Npgsql version and doing it only for v3 and above.

…onverting only if Npgsql v3 or higher is loaded.
@fredericDelaporte fredericDelaporte requested a review from hazzik May 28, 2017 18:02
hazzik
hazzik previously approved these changes May 30, 2017
Copy link
Member

@hazzik hazzik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hazzik
Copy link
Member

hazzik commented May 30, 2017

It all looks good, however, I think we need more robust solution to be introduced.

@fredericDelaporte
Copy link
Member Author

More robust about the version check or about the conversion? If the version check does not suit you much, I may still split that into two drivers, choose the most up to date as default and then let the user configure the older one if he needs it.

@hazzik
Copy link
Member

hazzik commented May 30, 2017

More robust about the version check or about the conversion?

More robust about setting these parameters. I think we need to move the parameter setup earlier in the pipeline (not sure where as I did not check the code).

@fredericDelaporte
Copy link
Member Author

Maybe not easy to do. In the case of failing tests for Npgsql 3 without that changes, earliest in the pipeline would be in the type classes, such as TimeAsTimeSpanType. Those types classes have currently no knowledge of target database and driver. They do not have any references to the session factory, and adding one would be a major change, causing those classes to no more be usable as singleton, as they are currently used.

So we will have to check if that could make sens to that at some intermediate stage between types and driver.

But in the Npgsql case, having it quite late in the pipeline does not look to me bad: Npgsql does no more accept DateTime as time value and fails with them, while other databases may still want DateTime. Converting it that late allows to catch all cases, even user own supplied parameters, allowing user to stay database agnostic. Otherwise he would have to adapt his parameter values according to the target db.

The other case is SQL Server 2008 and above: I do not know if this case still accepts DateTime as time or does throw. If it is the former, doing it that late is then less legit.

@hazzik
Copy link
Member

hazzik commented May 30, 2017

I'm just thinking out loud, feel free to ignore:)


MySQL, Sql Server ODBC, and Sybase Advantage Database fail with the same results: they want TimeSpan instead of DateTime for DbType.Time

@fredericDelaporte
Copy link
Member Author

fredericDelaporte commented May 30, 2017

No trouble, having concern about how to do thing reasonably better is always welcome. ("Reasonably" because we say in french "better is enemy of good", meaning wanting to do better while already having something good may lead to bad indeed.) So if we agree it is good enough as is currently, well, I will merge. And maybe do you want to add some task in Jira for redesigning this.

@hazzik
Copy link
Member

hazzik commented May 30, 2017

Can you quick try the solution proposed in NH-3078?

@fredericDelaporte
Copy link
Member Author

I have seen it. I expect it to cause other databases to fail. This solution remove the TimeSpan conversion to a DateTime done by all time types by default. I think this conversion has been coded because most other db likely require a DateTime instead of a TimeSpan.

And that will "fix" the Sybase issue only for parameters set by NHibernate from its type classes, not for others.

@hazzik
Copy link
Member

hazzik commented May 30, 2017

I've checked the solution from NH-3078 with following drivers, and it works:

  • Sql2008ClientDriver
  • SqlClientDriver
  • SqlServerCeDriver
  • OdbcDriver
  • [EDIT] FirebirdClientDriver

I believe, that it will work for MySql and PostgresSql as well (Maybe it will work for everything).

[EDIT]Does not work

  • SQLite20Driver

PS: It seems that there are no way to set the parameters not through XxxType

@hazzik
Copy link
Member

hazzik commented May 30, 2017

It should also work for OracleManagedDataClientDriver.
[EDIT] - it does not.

@hazzik hazzik dismissed their stale review May 30, 2017 22:00

Please provide the test case demonstrating the failure outside of TimeType and TimeAsTimeSpanType

Copy link
Member

@hazzik hazzik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide a test case demonstrating the failure outside of TimeType and TimeAsTimeSpanType

@fredericDelaporte
Copy link
Member Author

Please provide a test case demonstrating the failure outside of TimeType and TimeAsTimeSpanType

Ok, not doable unless diving deep in internals thanks to GetSessionImplementation(), so that would be a bit nitpicking.

@hazzik
Copy link
Member

hazzik commented Jun 1, 2017

Closing in favor of #637. Feel free to reopen if needed.

@hazzik hazzik closed this Jun 1, 2017
@fredericDelaporte fredericDelaporte deleted the NH-4017 branch June 2, 2017 12:32
@hazzik hazzik removed this from the 5.0 milestone Aug 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants