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

Fix SQL error in SQLite #193

Merged
merged 1 commit into from
Jun 9, 2023
Merged

Fix SQL error in SQLite #193

merged 1 commit into from
Jun 9, 2023

Conversation

josecelano
Copy link
Member

@josecelano josecelano commented Jun 9, 2023

The SQL query:

SELECT
  COUNT(*) as count
FROM
  (
    SELECT
      tt.torrent_id,
      tp.username AS uploader,
      tt.info_hash,
      ti.title,
      ti.description,
      tt.category_id,
      DATE_FORMAT(tt.date_uploaded, '%Y-%m-%d %H:%i:%s') AS date_uploaded,
      tt.size AS file_size,
      CAST(COALESCE(sum(ts.seeders), 0) as signed) as seeders,
      CAST(COALESCE(sum(ts.leechers), 0) as signed) as leechers
    FROM
      torrust_torrents tt
      INNER JOIN torrust_user_profiles tp ON tt.uploader_id = tp.user_id
      INNER JOIN torrust_torrent_info ti ON tt.torrent_id = ti.torrent_id
      LEFT JOIN torrust_torrent_tracker_stats ts ON tt.torrent_id = ts.torrent_id
    WHERE
      title LIKE ?
    GROUP BY
      tt.torrent_id
  ) AS count_table

should not use the DATE_FORMAT function in SQLite.

The SQL query:

```
SELECT
  COUNT(*) as count
FROM
  (
    SELECT
      tt.torrent_id,
      tp.username AS uploader,
      tt.info_hash,
      ti.title,
      ti.description,
      tt.category_id,
      DATE_FORMAT(tt.date_uploaded, '%Y-%m-%d %H:%i:%s') AS date_uploaded,
      tt.size AS file_size,
      CAST(COALESCE(sum(ts.seeders), 0) as signed) as seeders,
      CAST(COALESCE(sum(ts.leechers), 0) as signed) as leechers
    FROM
      torrust_torrents tt
      INNER JOIN torrust_user_profiles tp ON tt.uploader_id = tp.user_id
      INNER JOIN torrust_torrent_info ti ON tt.torrent_id = ti.torrent_id
      LEFT JOIN torrust_torrent_tracker_stats ts ON tt.torrent_id = ts.torrent_id
    WHERE
      title LIKE ?
    GROUP BY
      tt.torrent_id
  ) AS count_table
```

should not use the `DATE_FORMAT` function in SQLite.
@josecelano josecelano linked an issue Jun 9, 2023 that may be closed by this pull request
@josecelano josecelano added the Bug Incorrect Behavior label Jun 9, 2023
@josecelano josecelano marked this pull request as ready for review June 9, 2023 15:49
@josecelano josecelano merged commit 9f8832b into torrust:develop Jun 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Incorrect Behavior
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Fix broken tests for endpoint to get a torrent list
1 participant