Skip to content

Fix support for Npgsql6 provider #3064

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

Merged
merged 2 commits into from
May 12, 2022
Merged

Fix support for Npgsql6 provider #3064

merged 2 commits into from
May 12, 2022

Conversation

hazzik
Copy link
Member

@hazzik hazzik commented May 9, 2022

Fixes #2994

dbParam.DbType = DbType.Decimal;
}
else if (DriverVersionMajor < 6 || sqlType.DbType != DbType.DateTime)
Copy link
Member Author

Choose a reason for hiding this comment

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

Mr. Smarty Pants.

Choose a reason for hiding this comment

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

Hi!
I am sorry, it seems theese changes leads to an error in some cases.

Versions:

  • NHibernate 5.4.2
  • Npgsql 7.0.2

The named query:

	<sql-query name="MyQuery" cache-mode="normal" read-only="true">
	  <query-param type="DateTime" name="DateOfSearch"/>
	  <return-scalar type="Int64" column="SomeID"/>
	  <![CDATA[select ...
	        from ...
	        where ((  :DateOfSearch is null ) or (( t.DT1 <= :DateOfSearch) and ( t.DT2 >= :DateOfSearch )))
	        and ... ;]]>
	</sql-query>
	</hibernate-mapping>

Call the query:

	DateTime? dateOfSearch = null; // set null value here -- !!!!
	query.SetParameter("DateOfSearch", dateOfSearch, NHibernateUtil.DateTime);
	var result = query.List<long>();

NHibernate log:

	2023-04-21 23:01:51,433 [1] DEBUG NHibernate.Type.DateTimeType - binding null to parameter: 0
	2023-04-21 23:01:51,433 [1] DEBUG NHibernate.Type.DateTimeType - binding null to parameter: 1
	2023-04-21 23:01:51,434 [1] DEBUG NHibernate.Type.DateTimeType - binding null to parameter: 2
	2023-04-21 23:01:51,445 [1] DEBUG NHibernate.SQL - select ...
	        from ...
	        where ((  :p0 is null ) or (( mmh.DT_Mount <= :p0) and ( mmh.DT_Dismount >= :p0 ))); :p0 = NULL [Type: Object (0:0:0)]  -- !!!!
	...
	2023-04-21 23:01:51,623 [1] ERROR NHibernate.AdoNet.AbstractBatcher - Could not execute query: select ...

dbParam.DBType is empty, and Npgsql sends Prepare command to PostgreSQL with no parameter type specified, but PostgreSQL also can not guess the type from this query and value.
It works correctly, if I set non-null parameter value.

Copy link
Member

@fredericDelaporte fredericDelaporte May 25, 2023

Choose a reason for hiding this comment

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

That point has been fixed by #3299.

@hazzik
Copy link
Member Author

hazzik commented May 9, 2022

Maybe we should consider porting this to 5.3

@fredericDelaporte
Copy link
Member

Ok for targeting 5.3.x, unless we consider releasing 5.4 soon.

@hazzik hazzik added this to the 5.3.next milestone May 11, 2022
@hazzik hazzik changed the title Add support for Npgsql6 driver Fix support for Npgsql6 provider May 11, 2022
@hazzik hazzik changed the base branch from master to 5.3.x May 11, 2022 01:18
@hazzik
Copy link
Member Author

hazzik commented May 11, 2022

Ok, I've rebased to 5.3.x

@hazzik hazzik closed this May 11, 2022
@hazzik hazzik reopened this May 11, 2022
npgsql does not support .net core 2.1
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.

Npgsql 6 is not compatible
3 participants