python - Using MySQL database twice in the same function returns a 1 instead of actual string -


i struggling understand why getting 1 returned after second time use database in function. need access 2 different tables information need.

class getsubdivs:     def __init__(self):         self.con = mdb.connect('localhost', 'root', 'root', 'shannon')         self.cur = self.con.cursor()      def openconnection(self):         self.con = mdb.connect('localhost', 'root', 'root', 'shannon')         self.cur = self.con.cursor()      def closeconnection(self):         self.con.commit()         self.cur.close()      def getallsubdivsfortable(self):         self.cur.execute('select * subdivs')         info = self.cur.fetchall()         print info             dict = {}  #dictionary object creates rr collection of rr resources          x in info:             littledict = {} #makes little dictionary object fill other dictionary object             id = x[0]             name = x[3]             que = ('select railroadname railroads scac = %s')             company = self.cur.execute(que, id)             print 'this company'             print company             book['name'] = name             book['company'] = company             book['link'] = none #place holder now, used later          data = json.dumps(book)         return data 

is there way can clear cursor in mysql make can information second table?

my code returns company 1 {"company": 1, "link": null, "name": "tiny truck rails"}

even though database has "railroad company" stored.

have tried using second cursor instead of reusing it?

edit, you're not calling fetchall on second query!!


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -