I wrote a python daemon that continuously examines the mysql database. It works great when I constantly connect and connect to the database between queries as follows:
def connect(self): self.connection = MySQLdb.connect(...) self.cursor = self.connection.cursor() return self.cursor def disconnect(self): ... self.cursor.close() self.connection.close() def getData(); .... sqlcmd = """SELECT ....""" self.cursor.execute (sqlcmd % (params)) result = self.cursor.fetchall() return result if __name__ == "__main__": db = prepaid_db.Database() while 1: dbConnection = db.connect() data = db.getData() ... do stuff db.disconnect
But when I try to open a database connection (as shown below), I get an empty request, although although it works, I can request db manually, give it the same request and get the expected result.
if __name__ == "__main__": db = prepaid_db.Database() dbConnection = db.connect() while 1: data = db.getData() ... do stuff db.disconnect
I tried everything to understand why he would do this:
- disabled the query cache and added random x = x to the query if mysql cache was confused by similar queries
- mysql query logging enabled: the query arrives but returns an empty set
- moved cursor.connect to database.connect and back to getData (), no difference
I would like to know what I do not understand.
source share