From b448ee30d30d1defb792d1fe7a5b5638ea3a8f36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20K=C3=BCnzel?= <simonk@fsmpi.rwth-aachen.de> Date: Sun, 5 May 2024 23:34:38 +0200 Subject: [PATCH] Use true/false for booleans in sql --- chapters.py | 2 +- edit.py | 2 +- jobmanagement.py | 4 ++-- jobs.py | 2 +- livestreams.py | 8 ++++---- meetings.py | 2 +- server.py | 2 +- tests/test_jobmanagement.py | 2 +- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/chapters.py b/chapters.py index 67b1ecb..bbb60ef 100644 --- a/chapters.py +++ b/chapters.py @@ -15,7 +15,7 @@ def import_xmp_chapters(jobid, jobtype, data, state, status): #pylint: disable=u if int(chapter['time']) in times: continue modify( - 'INSERT INTO chapters (lecture_id, time, text, visible, time_created, time_updated) VALUES (?, ?, ?, 0, ?, ?)', + 'INSERT INTO chapters (lecture_id, time, text, visible, time_created, time_updated) VALUES (?, ?, ?, false, ?, ?)', data['lecture_id'], int(chapter['time']), chapter['text'], datetime.now(), datetime.now() ) diff --git a/edit.py b/edit.py index 45147ac..711e8a4 100644 --- a/edit.py +++ b/edit.py @@ -182,7 +182,7 @@ def edit(prefix='', ignore=None): modify('INSERT INTO changelog \ ("table",id_value, id_key, field, value_new, value_old, "when", who, executed) \ VALUES (?,?,?,?,?, \ - (SELECT "%s" FROM %s WHERE %s = ?),?,?,1)'%( + (SELECT "%s" FROM %s WHERE %s = ?),?,?,true)'%( path['column'], path['tableinfo']['table'], path['tableinfo']['idcolumn'] diff --git a/jobmanagement.py b/jobmanagement.py index f600b43..3378ef9 100644 --- a/jobmanagement.py +++ b/jobmanagement.py @@ -54,10 +54,10 @@ def schedule_job(jobtype, data=None, priority=0, queue="default"): def cancel_job(job_id): query('UPDATE jobs SET state = \'deleted\' WHERE id = ? AND state = \'ready\'', job_id) - query('UPDATE jobs SET canceled = 1 WHERE id = ?', job_id) + query('UPDATE jobs SET canceled = true WHERE id = ?', job_id) def restart_job(job_id, canceled=False): if canceled: - query('UPDATE jobs SET state = \'ready\', canceled = 0 WHERE id = ? AND state = \'failed\'', job_id) + query('UPDATE jobs SET state = \'ready\', canceled = false WHERE id = ? AND state = \'failed\'', job_id) else: query('UPDATE jobs SET state = \'ready\' WHERE id = ? AND state = \'failed\' AND NOT canceled', job_id) diff --git a/jobs.py b/jobs.py index 52fe14f..13f64ff 100644 --- a/jobs.py +++ b/jobs.py @@ -57,7 +57,7 @@ def jobs_action(action, jobid=None): if action == 'clear_failed': query('UPDATE jobs SET state = \'deleted\' WHERE state = \'failed\' AND (id = ? OR ? IS NULL)', jobid, jobid) elif action == 'retry_failed': - query('UPDATE jobs SET state = \'ready\', canceled = 0 WHERE state = \'failed\' AND (id = ? OR ? IS NULL)', jobid, jobid) + query('UPDATE jobs SET state = \'ready\', canceled = false WHERE state = \'failed\' AND (id = ? OR ? IS NULL)', jobid, jobid) elif action == 'copy' and jobid: query("INSERT INTO jobs (type, priority, queue, state, data, time_created) \ SELECT type, priority, queue, 'ready', data, ? FROM jobs where id = ?", diff --git a/livestreams.py b/livestreams.py index 9c92b19..b7e7cc3 100644 --- a/livestreams.py +++ b/livestreams.py @@ -45,21 +45,21 @@ def streamauth_legacy(server=None): if 'lecture' in request.values: match = {'id': request.values['lecture']} try: - modify("INSERT INTO streams (handle, active, visible, lecture_id, description, poster) VALUES (?, 0, 1, -1, '', '')", request.values['name']) + modify("INSERT INTO streams (handle, active, visible, lecture_id, description, poster) VALUES (?, false, true, -1, '', '')", request.values['name']) except: pass if server: data = {'src': 'rtmp://%s/live/%s'%(server, request.values['name']), 'destbase': 'rtmp://%s/hls/%s'%(server, request.values['name'])} job_id = schedule_job('simple_live_transcode', data, priority=10) - modify("UPDATE streams SET active = 1, lecture_id = ?, job_id = ? WHERE handle = ?", + modify("UPDATE streams SET active = true, lecture_id = ?, job_id = ? WHERE handle = ?", match['id'], job_id, request.values['name']) else: - modify("UPDATE streams SET active = 1, lecture_id = ? WHERE handle = ?", + modify("UPDATE streams SET active = true, lecture_id = ? WHERE handle = ?", match['id'], request.values['name']) elif request.values['call'] == 'publish_done': job_id = query('SELECT job_id FROM streams WHERE handle = ?', request.values['name'])[0]['job_id'] - modify("UPDATE streams SET active = 0 WHERE handle = ?", request.values['name']) + modify("UPDATE streams SET active = false WHERE handle = ?", request.values['name']) if job_id: cancel_job(job_id) else: diff --git a/meetings.py b/meetings.py index 8d3a155..6ea435e 100644 --- a/meetings.py +++ b/meetings.py @@ -31,5 +31,5 @@ def update_meeting(): human_date(start), human_time(start)) modify('''REPLACE INTO announcements (extid, text, level, visible, time_publish, time_expire, time_created, time_updated, created_by) - VALUES (?, ?, 0, 1, ?, ?, ?, ?, 0)''', + VALUES (?, ?, 0, true, ?, ?, ?, ?, 0)''', 'ical:'+uid, text, start-timedelta(days=7), start+timedelta(hours=2), datetime.now(), datetime.now()) diff --git a/server.py b/server.py index 4f24ddf..ab43eb8 100644 --- a/server.py +++ b/server.py @@ -524,7 +524,7 @@ def auth(): #pylint: disable=too-many-branches if is_authorized: try: if not url_path.startswith('pub/hls/'): - modify('INSERT INTO log (id, "time", "date", video, source) VALUES (?, ?, ?, ?, 1)', + modify('INSERT INTO log (id, "time", "date", video, source) VALUES (?, ?, ?, ?, true)', cookie, datetime.now(), datetime.combine(date.today(), time()), perms[0]['vid']) elif url_path.endswith('.ts'): fmt = url_path.split('_')[-1].split('-')[0] diff --git a/tests/test_jobmanagement.py b/tests/test_jobmanagement.py index fc950c6..250c0c5 100644 --- a/tests/test_jobmanagement.py +++ b/tests/test_jobmanagement.py @@ -14,7 +14,7 @@ class JobmanagementTestCase(FlaskTestCase): return data[0]['count'] def getCanceledJobCount(self): - data = query("SELECT count(id) AS count from jobs WHERE canceled=1") + data = query("SELECT count(id) AS count from jobs WHERE canceled=true") return data[0]['count'] def generateTestJob(self): -- GitLab