I am trying to sanitise data from different sources programatically. The following function is part of my effort:
def artikel(datum,ti,wod_id,publ_id,di): titel = ti.strip().upper() if db(db.artikel.titel == titel).count() < 1: # Is titel already in database? artikel_id = db.artikel.insert(titel = titel, publikasie_id = publ_id, wos_id = wos_id, datum = datum, id_nr = di.strip().upper()) # insert if not. else: # get the id if it is already there artikel_id = db(db.artikel.titel == titel).select()[0].id return(artikel_id) It tries to determine whether there is already such a value for 'titel'. If it is not already there, insert the record, else get the id. But this function fails at the line after "else:" with: Traceback (most recent call last): File "<console>", line 1, in <module> File "/home/js/web2py/gluon/sql.py", line 2987, in select return self.parse(db,rows,self.colnames) File "/home/js/web2py/gluon/sql.py", line 3034, in parse str(value)[:10].strip().split('-')] ValueError: need more than 1 value to unpack What is the best way of doing this? Should I create a unique index on field "titel" and then insert with a "try ... except" ? Regards Johann
-- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.