From aed726c89f074e84f59637a49a0be3cab1dae5e7 Mon Sep 17 00:00:00 2001 From: Abdussamet Kocak Date: Thu, 2 Jan 2025 13:36:29 +0300 Subject: [PATCH] scan_vids: Fix syntax errors in SQL queries, handle case video is missing and update doesn't return a row --- scan_vids.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/scan_vids.py b/scan_vids.py index fd1c5f5..91379d5 100644 --- a/scan_vids.py +++ b/scan_vids.py @@ -47,6 +47,8 @@ def video_exists(con: psycopg.Connection, file_path: str) -> bool: [file_path], ) row = stmt.fetchone() + if not row: + return False return row["exists"] @@ -61,7 +63,11 @@ def save_video( ffprobe: dict, hash_partial: str, ): - sql = """INSERT INTO videos(category, file_path, ffprobe, hash_partial) VALUES (%s, %s, %s, %s) ON CONFLICT(file_path) SET last_seen_at = NOW();""" + sql = """ + INSERT INTO videos(category, file_path, ffprobe, hash_partial) + VALUES (%s, %s, %s, %s) + ON CONFLICT(file_path) DO UPDATE SET + last_seen_at = NOW();""" con.execute( sql, [