From b3656ffc05c81942f0e11ba65db5ba2c25f6b287 Mon Sep 17 00:00:00 2001 From: Vladislav Date: Fri, 27 Oct 2023 12:41:19 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D1=83=20=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D1=8B=20=D0=BA=D1=83=D1=80=D1=81=D0=BE=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- endpoint.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/endpoint.py b/endpoint.py index a60f8f0..ccceab2 100644 --- a/endpoint.py +++ b/endpoint.py @@ -110,7 +110,6 @@ class Endpoint(Thread): # база данных self.connection = None - self.cursor = None self.db_table = config['database']['db-table'] self.db_col_names = '' for rn in self.ranges: @@ -135,13 +134,14 @@ class Endpoint(Thread): return values def __read_last_db_regs(self): - self.cursor.execute(f"select {self.db_col_names} from `{self.db_table}`" - f"order by `{self.config['database']['db-datetime-col']}` desc limit 1;") - row = self.cursor.fetchall() - if len(row) != 0: - return row[0] - else: - return None + 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;") + row = cursor.fetchall() + if len(row) != 0: + return row[0] + else: + return None def __insert_db_row(self, values): vals_str = "" @@ -153,7 +153,8 @@ class Endpoint(Thread): query = f"insert into `{self.db_table}` ({self.db_col_names}) values ({vals_str});" journal.log(f"Executing query: {query}") - self.cursor.execute(query) + with self.connection.cursor() as cursor: + cursor.execute(query) def __endless_loop(self): # if self.log_type == 'on-change': @@ -217,8 +218,7 @@ class Endpoint(Thread): database=self.config["database"]["db-name"] ) as _connection: self.connection = _connection - with self.connection.cursor() as cursor: - self.cursor = cursor - # запуск бесконечного цикла - self.__endless_loop() + # запуск бесконечного цикла + self.__endless_loop() +