Python Forum
twisted: catch return from sql
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
twisted: catch return from sql
hi all,

I got this function inside twisted...

    def get_or_create_node_id(self,node_name):
            record_exists = yield self.db.runQuery("SELECT EXISTS(SELECT 1 FROM nodes WHERE name = %s)", (node_name))
        except ConnectionError:
            log.error("db interaction failed due to connection error")
        if record_exists[0] == '1':
  "creating new nodes entry {node_name}", node_name=node_name)
                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")
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

Possibly Related Threads…
Thread Author Replies Views Last Post
  Multiprocessing queue catch get timeout Pythocodras 1 729 Apr-22-2022, 06:01 PM
Last Post: Pythocodras
  how to catch schema error? maiya 0 1,142 Jul-16-2021, 08:37 AM
Last Post: maiya
  is this a good way to catch exceptions? korenron 14 3,054 Jul-05-2021, 06:20 PM
Last Post: hussaind
  pool mysql error - not catch by try\except? korenron 1 1,375 Jul-05-2021, 11:26 AM
Last Post: ibreeden
  try catch question ,get data from main code korenron 7 2,025 Nov-03-2020, 09:28 AM
Last Post: korenron
  catch input type error mcmxl22 5 2,151 Aug-11-2019, 07:33 AM
Last Post: wavic
  How to catch string between two strings SriMekala 3 2,026 May-24-2019, 03:05 AM
Last Post: heiner55
  mac os and twisted? MuntyScruntfundle 0 1,403 Sep-22-2018, 12:20 PM
Last Post: MuntyScruntfundle
  Python catch mouse click in pure text, no graphics samtal 7 5,321 Sep-10-2018, 03:02 PM
Last Post: samtal
  twisted.internet.error.ConnectionLost phob0s 0 2,991 May-23-2018, 12:57 PM
Last Post: phob0s

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020