Skip to content
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

Bug in Sql.Function Left? #2605

Closed
yarecky1 opened this issue Nov 6, 2020 · 7 comments · Fixed by #2606
Closed

Bug in Sql.Function Left? #2605

yarecky1 opened this issue Nov 6, 2020 · 7 comments · Fixed by #2606
Assignees
Labels
status: has-pr There is active PR for issue type: bug
Milestone

Comments

@yarecky1
Copy link
Contributor

yarecky1 commented Nov 6, 2020

Hi,

Just reading the code and found this:

[Sql.Function(                      PreferServerSide = true)]
[Sql.Function(PN.SQLite, "LeftStr", PreferServerSide = true)]
public static string? Left(string? str, int? length)
{
    return length == null || str == null || str.Length < length? null: str.Substring(1, length.Value);
}

Why startIndex = 1 in str.Substring(1, length.Value)?
Shouldn't be there startIndex = 0?
(startIndex = The zero-based starting character position of a substring in this instance.)

@MaceWindu
Copy link
Contributor

Yep, looks like a bug.

@MaceWindu MaceWindu added this to the 3.2.0 milestone Nov 7, 2020
@yarecky1
Copy link
Contributor Author

yarecky1 commented Nov 7, 2020

I'll make PR.

@MaceWindu
Copy link
Contributor

Thanks. Please check if we have test coverage for this function (looks like at least client-side part is missing) and add missing test case.

@yarecky1
Copy link
Contributor Author

yarecky1 commented Nov 7, 2020

@MaceWindu Where is the best place to insert the tests for functions? I've searched the folders and nothing fits.
I'm asking because I see next bug here (index will be less than 0 and will raise exception):

public static string? Substring(string? str, int? startIndex, int? length)
{
    return str == null || startIndex == null || length == null ? null : str.Substring(startIndex.Value - 1, length.Value);
}

@MaceWindu
Copy link
Contributor

Tests for those functions are there https://github.com/linq2db/linq2db/blob/master/Tests/Linq/Linq/StringFunctionTests.cs
and I don't see them testing non-db execution :-/

@yarecky1
Copy link
Contributor Author

yarecky1 commented Nov 7, 2020

Ok, already started and decided to add tests to all non-db string functions.

@yarecky1
Copy link
Contributor Author

yarecky1 commented Nov 8, 2020

Finished.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: has-pr There is active PR for issue type: bug
Development

Successfully merging a pull request may close this issue.

2 participants