forked from ScoDoc/ScoDoc
insertions via notesdb dans tables sans ids
This commit is contained in:
parent
e1dad774be
commit
357b6f1a7f
@ -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)
|
||||
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):
|
||||
|
Loading…
Reference in New Issue
Block a user