mirror of
				https://github.com/librenms/librenms.git
				synced 2024-10-07 16:52:45 +00:00 
			
		
		
		
	close cursor after query
This commit is contained in:
		@@ -61,23 +61,25 @@ class DB:
 | 
				
			|||||||
                    self.conn = MySQLdb.connect(host=db_server, port=db_port, user=db_username, passwd=db_password, db=db_dbname)
 | 
					                    self.conn = MySQLdb.connect(host=db_server, port=db_port, user=db_username, passwd=db_password, db=db_dbname)
 | 
				
			||||||
                break
 | 
					                break
 | 
				
			||||||
            except (AttributeError, MySQLdb.OperationalError):
 | 
					            except (AttributeError, MySQLdb.OperationalError):
 | 
				
			||||||
                log.warning('WARNING: MySQL Error during connect, reconnecting.')
 | 
					                log.warning('WARNING: MySQL Error, reconnecting.')
 | 
				
			||||||
                time.sleep(.5)
 | 
					                time.sleep(.5)
 | 
				
			||||||
                pass
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.conn.autocommit(True)
 | 
					        self.conn.autocommit(True)
 | 
				
			||||||
        self.conn.ping(True)
 | 
					        self.conn.ping(True)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def query(self, sql):
 | 
					    def query(self, sql):
 | 
				
			||||||
        try:
 | 
					        while True:
 | 
				
			||||||
            cursor = self.conn.cursor()
 | 
					            try:
 | 
				
			||||||
            cursor.execute(sql)
 | 
					                cursor = self.conn.cursor()
 | 
				
			||||||
        except (AttributeError, MySQLdb.OperationalError):
 | 
					                cursor.execute(sql)
 | 
				
			||||||
            log.warning('WARNING: MySQL Error during query, reconnecting.')
 | 
					                ret = cursor.fetchall()
 | 
				
			||||||
            self.connect()
 | 
					                cursor.close()
 | 
				
			||||||
            cursor = self.conn.cursor()
 | 
					                return ret
 | 
				
			||||||
            cursor.execute(sql)
 | 
					            except (AttributeError, MySQLdb.OperationalError):
 | 
				
			||||||
        return cursor
 | 
					                log.warning('WARNING: MySQL Operational Error during query, reconnecting.')
 | 
				
			||||||
 | 
					                self.connect()
 | 
				
			||||||
 | 
					            except (AttributeError, MySQLdb.ProgrammingError):
 | 
				
			||||||
 | 
					                log.warning('WARNING: MySQL Programming Error during query, attempting query again.')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def get_config_data():
 | 
					def get_config_data():
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user