Изменил логику работы курсора
This commit is contained in:
parent
0b4942de7d
commit
b3656ffc05
12
endpoint.py
12
endpoint.py
@ -110,7 +110,6 @@ class Endpoint(Thread):
|
|||||||
|
|
||||||
# база данных
|
# база данных
|
||||||
self.connection = None
|
self.connection = None
|
||||||
self.cursor = None
|
|
||||||
self.db_table = config['database']['db-table']
|
self.db_table = config['database']['db-table']
|
||||||
self.db_col_names = ''
|
self.db_col_names = ''
|
||||||
for rn in self.ranges:
|
for rn in self.ranges:
|
||||||
@ -135,9 +134,10 @@ class Endpoint(Thread):
|
|||||||
return values
|
return values
|
||||||
|
|
||||||
def __read_last_db_regs(self):
|
def __read_last_db_regs(self):
|
||||||
self.cursor.execute(f"select {self.db_col_names} from `{self.db_table}`"
|
with self.connection.cursor() as cursor:
|
||||||
|
cursor.execute(f"select {self.db_col_names} from `{self.db_table}`"
|
||||||
f"order by `{self.config['database']['db-datetime-col']}` desc limit 1;")
|
f"order by `{self.config['database']['db-datetime-col']}` desc limit 1;")
|
||||||
row = self.cursor.fetchall()
|
row = cursor.fetchall()
|
||||||
if len(row) != 0:
|
if len(row) != 0:
|
||||||
return row[0]
|
return row[0]
|
||||||
else:
|
else:
|
||||||
@ -153,7 +153,8 @@ class Endpoint(Thread):
|
|||||||
|
|
||||||
query = f"insert into `{self.db_table}` ({self.db_col_names}) values ({vals_str});"
|
query = f"insert into `{self.db_table}` ({self.db_col_names}) values ({vals_str});"
|
||||||
journal.log(f"Executing query: {query}")
|
journal.log(f"Executing query: {query}")
|
||||||
self.cursor.execute(query)
|
with self.connection.cursor() as cursor:
|
||||||
|
cursor.execute(query)
|
||||||
|
|
||||||
def __endless_loop(self):
|
def __endless_loop(self):
|
||||||
# if self.log_type == 'on-change':
|
# if self.log_type == 'on-change':
|
||||||
@ -217,8 +218,7 @@ class Endpoint(Thread):
|
|||||||
database=self.config["database"]["db-name"]
|
database=self.config["database"]["db-name"]
|
||||||
) as _connection:
|
) as _connection:
|
||||||
self.connection = _connection
|
self.connection = _connection
|
||||||
with self.connection.cursor() as cursor:
|
|
||||||
self.cursor = cursor
|
|
||||||
|
|
||||||
# запуск бесконечного цикла
|
# запуск бесконечного цикла
|
||||||
self.__endless_loop()
|
self.__endless_loop()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user