Skip to content

Commit

Permalink
Merge torrust#193: Fix SQL error in SQLite
Browse files Browse the repository at this point in the history
6023b96 fix: [torrust#190] SQL error in SQLite (Jose Celano)

Pull request description:

  The SQL query:

  ```sql
  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.

Top commit has no ACKs.

Tree-SHA512: 44de35f013c0209bd51ce241fbf53bbf4745ecf37883c1af73bd2a80ae484074a93d8e5ea9d480da8ee8699828bf232dfdc2cd1cfe1649b49c8e0ab8667d5563
  • Loading branch information
josecelano committed Jun 9, 2023
2 parents 8737e92 + 6023b96 commit 9f8832b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/databases/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ impl Database for Sqlite {
};

let mut query_string = format!(
"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,
"SELECT tt.torrent_id, tp.username AS uploader, tt.info_hash, ti.title, ti.description, tt.category_id, tt.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
Expand Down

0 comments on commit 9f8832b

Please sign in to comment.