Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
46 lines
1.7 KiB
Python
46 lines
1.7 KiB
Python
import traceback
|
|
from fastapi import APIRouter, Request, Depends
|
|
from fastapi.responses import JSONResponse
|
|
from app.database import get_connection
|
|
from app.auth import get_current_user
|
|
from app.services.firebird_service import get_firebird_from_config
|
|
|
|
router = APIRouter(prefix="/debug-fb", tags=["debug"])
|
|
|
|
|
|
@router.get("/cups")
|
|
async def find_cups(request: Request, user: dict = Depends(get_current_user)):
|
|
try:
|
|
conn = get_connection()
|
|
cfg = {r["key"]: r["value"] for r in conn.execute("SELECT * FROM config").fetchall()}
|
|
conn.close()
|
|
|
|
fb, ok, msg = get_firebird_from_config(cfg)
|
|
if not ok:
|
|
return JSONResponse({"error": msg})
|
|
|
|
results = {}
|
|
|
|
# 1. Buscar todas las tablas que tengan campo con "CUP" en nombre
|
|
ok0, _, rows0 = fb.execute_query(
|
|
"SELECT TRIM(f.RDB$RELATION_NAME) AS t, TRIM(f.RDB$FIELD_NAME) AS c "
|
|
"FROM RDB$RELATION_FIELDS f WHERE f.RDB$FIELD_NAME LIKE '%CUP%' "
|
|
"AND f.RDB$SYSTEM_FLAG = 0 ORDER BY 1,2"
|
|
)
|
|
results["todos_campos_cup"] = list(rows0) if ok0 else []
|
|
|
|
# 2. Tabla PROTOCOLO - primera fila
|
|
ok1, err1, rows1 = fb.execute_query("SELECT FIRST 1 p.* FROM PROTOCOLO p")
|
|
results["protocolo_fila"] = rows1[0] if (ok1 and rows1) else f"error: {err1}"
|
|
|
|
# 3. PROTOCOLO para CH4
|
|
ok2, err2, rows2 = fb.execute_query(
|
|
"SELECT FIRST 1 p.* FROM PROTOCOLO p WHERE TRIM(p.CODIGO) = 'CH4'"
|
|
)
|
|
results["protocolo_ch4"] = rows2[0] if (ok2 and rows2) else f"error: {err2}"
|
|
|
|
fb.disconnect()
|
|
return JSONResponse(results)
|
|
except Exception:
|
|
return JSONResponse({"traceback": traceback.format_exc()})
|