Sep-08-2021, 12:38 PM
(This post was last modified: Sep-08-2021, 12:38 PM by wardancer84.)
hi all,
I got this function inside twisted...
I got this function inside twisted...
@inlineCallbacks
def get_or_create_node_id(self,node_name):
try:
record_exists = yield self.db.runQuery("SELECT EXISTS(SELECT 1 FROM nodes WHERE name = %s)", (node_name))
print(record_exists[0])
except ConnectionError:
log.error("db interaction failed due to connection error")
if record_exists[0] == '1':
log.info("creating new nodes entry {node_name}", node_name=node_name)
try:
yield self.db.runQuery("INSERT INTO nodes (name) VALUES ('%s')", (node_name))
node_id = yield self.db.runQuery("select LAST_INSERT_ID()")
except ConnectionError:
log.error("db interaction failed due to connection error")
returnValue(int(node_id))record_exists[0] returns this...2021-09-01T17:46:39+0200 [stdout#info] (1,)how can i use this in an if statement to check if the record already exists...i dont get it, not even sure if this a tuple...
if record_exists[0] == '1':Update: solved this by switching to pymysql's dict cursor...much cleaner output
