Aug-18-2021, 10:17 AM
(Aug-17-2021, 06:24 PM)deanhystad Wrote: This code makes no sense to me. What do you expect it to do?
def get_or_create_node_id(self,node_name,c,cur,nodes): if node_name in nodes: print ("%s found in dict, has id %s" % ( node_name, nodes[node_name] )) return int(nodes[node_name]) else: print("creating new node entry ..") sql = "INSERT INTO nodes VALUES (DEFAULT, '%s')" % (node_name) cur.execute(sql) c.commit() return self.get_or_create_node_id(node_name)
it looks in the database of the "node" is already there, if yes it returns the id of the node (db id), if no it creates the node in the db.