diff --git a/database.py b/database.py index 92f3ddb..d4ee09c 100644 --- a/database.py +++ b/database.py @@ -74,13 +74,13 @@ def insert_data_into_table(table_name, data): logging.error("%s", e) raise -def get_select_query_results(sql_query): +def get_select_query_results(sql_query, params=None): """Execute a query, return all rows for the query """ conn, cur = psql_connection() try: - cur.execute(sql_query) + cur.execute(sql_query, params) # For SELECT query if sql_query.upper().strip().startswith('SELECT'): result = cur.fetchall() diff --git a/rollama.py b/rollama.py index 7c24d51..fe9123d 100755 --- a/rollama.py +++ b/rollama.py @@ -293,18 +293,18 @@ def analyze_comment(comment_id): logging.info(info_message) log_message_to_db(os.environ['SRVC_NAME'], get_rollama_version()['version'], 'INFO', info_message) - sql_query = f"""SELECT + sql_query = """SELECT comment_id, comment_body FROM comments WHERE - comment_id='{comment_id}' + comment_id=%s AND comment_body NOT IN ('', '[removed]', '[deleted]'); """ - comment_data = get_select_query_results(sql_query) + comment_data = get_select_query_results(sql_query, (comment_id,)) if not comment_data: warn_message = f'Comment ID {comment_id} contains no body'