Add ability to specify table to SQL config

This commit is contained in:
Simon 2021-01-22 13:09:28 +00:00
parent 279185b0a2
commit ca054d5cd6
4 changed files with 7 additions and 4 deletions

View File

@ -114,6 +114,7 @@ PASS: mypassword
DB: hblink
SERVER: 127.0.0.1
PORT: 3306
TABLE: repeaters
# OPENBRIDGE INSTANCES - DUPLICATE SECTION FOR MULTIPLE CONNECTIONS
# OpenBridge is a protocol originall created by DMR+ for connection between an

View File

@ -1771,7 +1771,7 @@ if __name__ == '__main__':
if CONFIG['MYSQL']['USE_MYSQL'] == True:
logger.debug('(MYSQL) MySQL config enabled')
SQLCONFIG = {}
sql = useMYSQL(CONFIG['MYSQL']['SERVER'], CONFIG['MYSQL']['USER'], CONFIG['MYSQL']['PASS'], CONFIG['MYSQL']['DB'],logger)
sql = useMYSQL(CONFIG['MYSQL']['SERVER'], CONFIG['MYSQL']['USER'], CONFIG['MYSQL']['PASS'], CONFIG['MYSQL']['DB'],CONFIG['MYSQL']['TABLE'],logger)
#Run it once immediately
if sql.con():
logger.debug('(MYSQL) reading config from database')

View File

@ -162,7 +162,8 @@ def build_config(_config_file):
'PASS': config.get(section, 'PASS'),
'DB': config.get(section, 'DB'),
'SERVER': config.get(section, 'SERVER'),
'PORT': config.getint(section,'PORT')
'PORT': config.getint(section,'PORT'),
'TABLE': config.get(section, 'TABLE')
})

View File

@ -4,11 +4,12 @@ from mysql.connector import errorcode
class useMYSQL:
#Init new object
def __init__(self, server,user,password,database,logger):
def __init__(self, server,user,password,database,table,logger):
self.server = server
self.user = user
self.password = password
self.database = database
self.table = table
self.logger = logger
#Connect
@ -49,7 +50,7 @@ class useMYSQL:
_cursor = self.db.cursor()
try:
_cursor.execute("select * from repeaters where MODE='MASTER'")
_cursor.execute("select * from {} where MODE='MASTER'".format(self.table))
except mysql.connector.Error as err:
_cursor.close()
logger.info('(MYSQL) error, problem with cursor execute')