From 357b6f1a7fb925fa87bf68b6b1ccddd58918a967 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sun, 15 Aug 2021 22:51:04 +0200 Subject: [PATCH] insertions via notesdb dans tables sans ids --- app/scodoc/notesdb.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/app/scodoc/notesdb.py b/app/scodoc/notesdb.py index 4342d128b..796f6edf2 100644 --- a/app/scodoc/notesdb.py +++ b/app/scodoc/notesdb.py @@ -82,7 +82,7 @@ def SimpleDictFetch(query, args, cursor=None): return cursor.dictfetchall() -def DBInsertDict(cnx, table, vals, commit=0, convert_empty_to_nulls=1): +def DBInsertDict(cnx, table, vals, commit=0, convert_empty_to_nulls=1, return_id=True): """insert into table values in dict 'vals' Return: id de l'object créé """ @@ -104,8 +104,11 @@ def DBInsertDict(cnx, table, vals, commit=0, convert_empty_to_nulls=1): ) else: cursor.execute("insert into %s default values" % table) - cursor.execute(f"SELECT CURRVAL('{table}_id_seq')") # id créé - oid = cursor.fetchone()[0] + if return_id: + cursor.execute(f"SELECT CURRVAL('{table}_id_seq')") # id créé + oid = cursor.fetchone()[0] + else: + oid = None except: log("DBInsertDict: EXCEPTION !") log("DBInsertDict: table=%s, vals=%s" % (str(table), str(vals))) @@ -305,7 +308,13 @@ class EditableTable(object): if title in self.input_formators: vals[title] = self.input_formators[title](vals[title]) # insert - new_id = DBInsertDict(cnx, self.table_name, vals, commit=True) + new_id = DBInsertDict( + cnx, + self.table_name, + vals, + commit=True, + return_id=(self.id_name is not None), + ) return new_id def delete(self, cnx, oid, commit=True):