dotnetcore / dotnetcore/FreeSql

复杂条件下 使用EndWith函数 映射SQL错误

Open
#2,212 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
4.4k
Forks
910
PR merge metrics
No merged PRs in 30d

Description

https://github.com/dotnetcore/FreeSql/blob/4673be865e2ec07ddeb1d6e35be2c4aba6eff29b/Providers/FreeSql.Provider.PostgreSQL/PostgreSQLExpression.cs#L455

```c#
x.EndsWith("_abcd")
```

在【x】长度恰好等于目标字符串【"_abcd"】长度-1时 会恒返回【true】
| strpos({left}, {args0Value}) | char_length({left}) | char_length({args0Value})) |
|---------|---------|---------|
| 0 | 4| 5 |

0 = 4 - 5 +1

应改为先判断长度 再计算大小
`if (exp.Method.Name == "EndsWith") return $"(char_length ({left})>=char_length ({args0Value}) and strpos({left}, {args0Value}) = char_length({left})-char_length({args0Value})+1)";`

鉴于本地只有【PostgreSQL 16.2】环境 无法测试其他环境 从源码看 推测其他环境具有相同的问题

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at Providers/FreeSql.Provider.PostgreSQL/PostgreSQLExpression.cs around line 455 and inspect the EndsWith SQL translation. Reproduce the reported case on PostgreSQL 16.2, then verify that strings shorter than the suffix no longer match while valid suffixes still do. If possible, compare behavior across the other provider implementations mentioned by the repository.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, postgresql
Domain
backend, databases
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.