lenguyenthanh / fide

Experimental FIDE Api
https://fide.lichess.dev/docs/index.html
GNU Affero General Public License v3.0
7 stars 2 forks source link

Fix query syntax when isActive = true #118

Closed lenguyenthanh closed 4 months ago

lenguyenthanh commented 4 months ago

ServerInternalError was thrown for this

curl -X 'GET' \
  'http://localhost:9669/api/players?sort_by=standard&order_by=desc&is_active=true&name=magnus%20carlsen&page=1&page_size=30' \
  -H 'accept: application/json'

with stacktrace:

[info] πŸ”₯
[info] πŸ”₯  Postgres ERROR 42601 raised in scanner_yyerror (scan.l:1241)
[info] πŸ”₯
[info] πŸ”₯    Problem: Syntax error at or near "AND".
[info] πŸ”₯
[info] πŸ”₯  The statement under consideration was defined
[info] πŸ”₯    at /Users/tle/git/lichess/fide/modules/db/src/main/scala/Db.scala:262
[info] πŸ”₯
[info] πŸ”₯      SELECT p.id, p.name, p.title, p.women_title, p.other_titles, p.standard, p.rapid, p.blitz, p.sex, p.birth_year, p.active, p.updated_at, p.created_at, f.id, f.name
[info] πŸ”₯      FROM players AS p LEFT JOIN federations AS f ON p.federation_id = f.id
[info] πŸ”₯    WHERE
[info] πŸ”₯      AND p.active = $1
[info] πŸ”₯      └─── Syntax error at or near "AND".
[info] πŸ”₯      ORDER BY p.birth_year ASC NULLS LAST
[info] πŸ”₯      LIMIT $2 OFFSET $3
[info] πŸ”₯
[info] πŸ”₯  If this is an error you wish to trap and handle in your application, you can do
[info] πŸ”₯  so with a SqlState extractor. For example:
[info] πŸ”₯
[info] πŸ”₯    doSomething.recoverWith { case SqlState.SyntaxError(ex) =>  ...}
[info] πŸ”₯
[info] skunk.exception.PostgresErrorException: Syntax error at or near "AND".