From ca054d5cd627c410758c6da52a3cac261ac2278b Mon Sep 17 00:00:00 2001 From: Simon Date: Fri, 22 Jan 2021 13:09:28 +0000 Subject: [PATCH] Add ability to specify table to SQL config --- FreeDMR-SAMPLE.cfg | 1 + bridge_master.py | 2 +- config.py | 3 ++- mysql_config.py | 5 +++-- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/FreeDMR-SAMPLE.cfg b/FreeDMR-SAMPLE.cfg index a8a7ffe..73a2054 100755 --- a/FreeDMR-SAMPLE.cfg +++ b/FreeDMR-SAMPLE.cfg @@ -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 diff --git a/bridge_master.py b/bridge_master.py index ddfbfb1..0500179 100755 --- a/bridge_master.py +++ b/bridge_master.py @@ -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') diff --git a/config.py b/config.py index 4a3c79a..4ee710a 100755 --- a/config.py +++ b/config.py @@ -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') }) diff --git a/mysql_config.py b/mysql_config.py index 5ff9394..a6e6eb4 100644 --- a/mysql_config.py +++ b/mysql_config.py @@ -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')