From c3d7ffc1185c35d704348d4a897643fd20b04aa7 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Tue, 28 Oct 2025 10:15:26 +0800 Subject: [PATCH] bugfix --- sqlor/dbpools.py | 5 ++++- sqlor/mysqlor.py | 12 +++++++++++- sqlor/sor.py | 6 ++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/sqlor/dbpools.py b/sqlor/dbpools.py index af532bd..a4f2df6 100755 --- a/sqlor/dbpools.py +++ b/sqlor/dbpools.py @@ -70,7 +70,8 @@ class SqlorPool: yielded_sqlor = None for s in sqlors: if not s.used: - if self.test_sqlor(s): + flg = self.test_sqlor(s): + if flg: yielded_sqlor = s else: self.sqlors = [ x for x in self.sqlors if x != s ] @@ -118,7 +119,9 @@ class DBPools: sqlor = None try: async with pool.context() as sqlor: + sqlor.enter() yield sqlor + sqlor.exit() if sqlor and sqlor.dataChanged: await sqlor.commit() except Exception as e: diff --git a/sqlor/mysqlor.py b/sqlor/mysqlor.py index 4ded865..9b00c43 100755 --- a/sqlor/mysqlor.py +++ b/sqlor/mysqlor.py @@ -152,10 +152,20 @@ WHERE """ dbdesc = self.dbdesc self.conn = await aiomysql.connect(**dbdesc) - self.cur = await self.conn.cursor() self.dbname = dbdesc.get('db') async def close(self): await self.cursor.close() await self.conn.close() + async def enter(self): + self.cur = await self.conn.cursor() + + async def exit(self): + try: + await self.cur.fetchall() + self.cur.close() + except: + pass + self.cur = None + diff --git a/sqlor/sor.py b/sqlor/sor.py index 790b482..f6b817a 100755 --- a/sqlor/sor.py +++ b/sqlor/sor.py @@ -90,6 +90,12 @@ class SQLor(object): self.dataChanged = False self.metadatas={} + async def enter(self): + pass + + async def exit(self): + pass + def unpassword(self): if self.dbdesc.password: key=getConfig().password_key