comparison sat/memory/sqlite.py @ 2918:21cf8395616c

memory (sqlite): fixed fileUpdate when original value is not set (NULL)
author Goffi <goffi@goffi.org>
date Fri, 26 Apr 2019 11:57:26 +0200
parents 1a23547f95fd
children e4715a609d75
comparison
equal deleted inserted replaced
2917:adf6e33a3e50 2918:21cf8395616c
903 cursor.execute(query, [file_id]) 903 cursor.execute(query, [file_id])
904 try: 904 try:
905 older_value_raw = cursor.fetchone()[0] 905 older_value_raw = cursor.fetchone()[0]
906 except TypeError: 906 except TypeError:
907 raise exceptions.NotFound 907 raise exceptions.NotFound
908 value = json.loads(older_value_raw) 908 if older_value_raw is None:
909 value = {}
910 else:
911 value = json.loads(older_value_raw)
909 update_cb(value) 912 update_cb(value)
910 value_raw = json.dumps(value) 913 value_raw = json.dumps(value)
911 update_query = 'UPDATE files SET {column}=? WHERE id=? AND {column}=?'.format(column=column) 914 if older_value_raw is None:
912 update_args = (value_raw, file_id, older_value_raw) 915 update_query = 'UPDATE files SET {column}=? WHERE id=? AND {column} is NULL'.format(column=column)
916 update_args = (value_raw, file_id)
917 else:
918 update_query = 'UPDATE files SET {column}=? WHERE id=? AND {column}=?'.format(column=column)
919 update_args = (value_raw, file_id, older_value_raw)
913 try: 920 try:
914 cursor.execute(update_query, update_args) 921 cursor.execute(update_query, update_args)
915 except sqlite3.Error: 922 except sqlite3.Error:
916 pass 923 pass
917 else: 924 else: