Skip to content

Add locate support for SQLite #2392

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 6 commits into from
May 25, 2020
Merged

Conversation

bahusoid
Copy link
Member

@bahusoid bahusoid commented May 21, 2020

SQLite can support locate as instr function since Release 3.7.15 on 2012-12-12.
locate(text, value, startIndex) is emulated via combination of substr and instr

Copy link
Member

@fredericDelaporte fredericDelaporte left a comment

Choose a reason for hiding this comment

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

NHibernate.Test.TestDialects.SQLiteTestDialect.SupportsLocate override to false needs to be removed.

Edit: and also line 443 of TestCase.cs, adding it to DialectsNotSupportingStandardFunction:

{"locate", new HashSet<System.Type> {typeof (SQLiteDialect)}}

@fredericDelaporte fredericDelaporte changed the title Add locate for SQLite (supported since Release 3.7.15 On 2012-12-12) Add locate support for SQLite May 23, 2020
{
// Since v5.3
[Obsolete("Use GetReturnType method instead.")]
public IType ReturnType(IType columnType, IMapping mapping)
Copy link
Member

Choose a reason for hiding this comment

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

Nit (not required to change): it seems better to me to explicitly implement obsolete interface members. So when the member is dropped from the interface, its implementation cannot be forgotten. And it would also hide the obsolete member when manipulating a reference typed as the class.

Copy link
Member Author

@bahusoid bahusoid May 24, 2020

Choose a reason for hiding this comment

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

Ok. Noted for future... But I just copy/pasted it from some other LocateFunction for other dialect.

Copy link
Member

Choose a reason for hiding this comment

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

Which was likely already released, and so had to avoid breaking changes. This one is not released, so the nit.

{
#pragma warning disable 618
return ReturnType(argumentTypes.FirstOrDefault(), mapping);
#pragma warning restore 618
Copy link
Member

Choose a reason for hiding this comment

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

Nit continuing: this pattern is used for existing externally visible types, with an overridable obsolete member. In this case, an external derived class overriding the obsolete member would be broken without that pattern.
For a new class, there is no need for it. We could put the implementation directly here, and make the obsolete member call the non-obsolete one instead.

var text = args[1];
var value = args[0];
var startIndex = args[2];
//ifnull(
Copy link
Member

@fredericDelaporte fredericDelaporte May 24, 2020

Choose a reason for hiding this comment

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

Other nit: I tend to favor the use of functions which are in the SQL Standard, which is the case of coalesce, supported by SQLite, and which can replace ifNull without changing anything more that the function name. I do not know with certainty if ifNull is in the standard, but I think it is not.
(I have not found any reference about it being in the standard or not. It is supported by MySql, SQLite, Big Query, but not by SQL-Server (which has isNull) nor Oracle (nvl), while they all support coalesce.)

Copy link
Member

Choose a reason for hiding this comment

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

This is a dialect specific function implementation, so using non-standard function should be fine here.

@hazzik hazzik merged commit bd3fa29 into nhibernate:master May 25, 2020
@hazzik hazzik added this to the 5.3 milestone May 25, 2020
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.

3 participants