dict cursor e pool conn

This commit is contained in:
2025-07-06 23:27:13 +02:00
parent 301aa53c72
commit 0022d0e326
6 changed files with 66 additions and 69 deletions

View File

@@ -1,27 +1,24 @@
from utils.database.connection import connetti_db
import logging
import aiomysql
logger = logging.getLogger(__name__)
def get_matlab_command(cfg: object, tool: str, unit: str) -> tuple:
async def get_matlab_command(cfg: object, tool: str, unit: str, pool) -> tuple:
with connetti_db(cfg) as conn:
cur = conn.cursor(dictionary=True)
query = f"""
SELECT m.matcall, t.ftp_send , t.unit_id, s.`desc` as statustools, t.api_send, u.inoltro_api, u.inoltro_api_url, u.inoltro_api_bearer_token, IFNULL(u.duedate, "") as duedate from matfuncs as m
INNER JOIN tools as t on t.matfunc = m.id
INNER JOIN units as u on u.id = t.unit_id
INNER JOIN statustools as s on t.statustool_id = s.id
where t.name = '{tool}' AND u.name = '{unit}';
async with pool.acquire() as conn:
async with conn.cursor(aiomysql.DictCursor) as cur:
await cur.execute(f"""
SELECT m.matcall, t.ftp_send , t.unit_id, s.`desc` as statustools, t.api_send, u.inoltro_api, u.inoltro_api_url, u.inoltro_api_bearer_token, IFNULL(u.duedate, "") as duedate from matfuncs as m
INNER JOIN tools as t on t.matfunc = m.id
INNER JOIN units as u on u.id = t.unit_id
INNER JOIN statustools as s on t.statustool_id = s.id
where t.name = '{tool}' AND u.name = '{unit}';
""")
"""
cur.execute(query)
result = cur.fetchone()
cur.close()
conn.close()
result = await cur.fetchone()
if not result:
logger.error(f"{unit} - {tool}: Matlab command not found.")
return None
else:
return result
if not result:
logger.error(f"{unit} - {tool}: Matlab command not found.")
return None
else:
return result