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

Rule S2077: support for additional database libraries: PetaPoco #6192

Closed
wants to merge 5 commits into from

Conversation

martin-strecker-sonarsource
Copy link
Contributor

Part of #3905

@sonarcloud
Copy link

sonarcloud bot commented Oct 12, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@sonarcloud
Copy link

sonarcloud bot commented Oct 12, 2022

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell B 2 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

Comment on lines +26 to +37
database.Query<Entity>(query, param + otherParam); // Noncompliant FP. The second argument is params object[] args and is safe.
database.Query<Entity>(new[] { typeof(Entity) }, null, query + param); // FN. This overload is not supported (sql string in the third parameter).
database.Query<Entity, Entity>(query + param); // Noncompliant
database.Query<Entity, Entity, Entity>(query + param); // Noncompliant
database.Query<Entity, Entity, Entity, Entity>(query + param); // Noncompliant
database.Query<Entity, Entity, Entity, Entity, Entity>(query + param); // Noncompliant

database.Fetch<Entity>(query); // Compliant
database.Fetch<Entity>(query + param); // Noncompliant
database.Fetch<Entity>(query + param); // Noncompliant
database.Fetch<Entity>(2, 10, query + param); // FN. This overload is not supported (sql string in the third parameter).
database.Fetch<Entity>(param + otherParam, 10, query); // Noncompliant FP. The first argument is not a string.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pavel-mikula-sonarsource I stopped here, for now, to get some feedback from you. This library has more than 20 overloads for each of Query, Fetch, QueryAsync, and FetchAsync. The SQL string parameter can appear on positions 1, 2, 3, and 4. Our current logic does only support 2 locations and increasing the count, even more, leads to more FPs because we would detect more violations in the params object[] args arguments.
I'm not sure how to proceed with this library but the current approach seems to be a dead end to me with too many FPs and FNs. A viable solution would use the argument-to-parameter mapping logic and use the parameter's name for detection (We could also improve detection for the other libraries, because these only support positional arguments but not named arguments at the moment).

Here is the overload where SQL is in the fourth position:
await database.FetchAsync<Entity>(CancellationToken.None, page: 1, itemsPerPage: 10, "Sql");

Copy link
Contributor

@pavel-mikula-sonarsource pavel-mikula-sonarsource left a comment

Choose a reason for hiding this comment

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

Let's cut the branch, remove PetaPoco from this issue and create new one with the captured knowledge for the future.

@pavel-mikula-sonarsource pavel-mikula-sonarsource moved this from Review in progress to In progress in Best Kanban Oct 13, 2022
Best Kanban automation moved this from In progress to Done Oct 13, 2022
@costin-zaharia-sonarsource costin-zaharia-sonarsource deleted the Martin/S2077_PetaPoco branch March 7, 2023 10:27
martin-strecker-sonarsource added a commit that referenced this pull request Jul 7, 2023
martin-strecker-sonarsource added a commit that referenced this pull request Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Best Kanban
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants