debug: probe possible ITEM join fields, show first row without join
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
41ee88c1b4
commit
d95e2b67ff
+30
-15
@@ -18,22 +18,37 @@ async def find_cups(request: Request, user: dict = Depends(get_current_user)):
|
|||||||
return JSONResponse({"error": msg})
|
return JSONResponse({"error": msg})
|
||||||
|
|
||||||
results = {}
|
results = {}
|
||||||
try:
|
|
||||||
ok1, err1, rows1 = fb.execute_query(
|
|
||||||
"SELECT TRIM(f.RDB$FIELD_NAME) AS campo "
|
|
||||||
"FROM RDB$RELATION_FIELDS f "
|
|
||||||
"WHERE TRIM(f.RDB$RELATION_NAME) = 'ITEM' "
|
|
||||||
"ORDER BY f.RDB$FIELD_POSITION"
|
|
||||||
)
|
|
||||||
results["columnas_item"] = [r["campo"] for r in rows1] if ok1 else err1
|
|
||||||
except Exception as e:
|
|
||||||
results["columnas_item"] = str(e)
|
|
||||||
|
|
||||||
try:
|
# Columnas de ITEM via sistema
|
||||||
ok2, err2, rows2 = fb.execute_query("SELECT FIRST 2 i.* FROM ITEM i")
|
ok1, err1, rows1 = fb.execute_query(
|
||||||
results["item_muestra"] = list(rows2) if ok2 else err2
|
"SELECT TRIM(f.RDB$FIELD_NAME) AS c FROM RDB$RELATION_FIELDS f "
|
||||||
except Exception as e:
|
"WHERE TRIM(f.RDB$RELATION_NAME)='ITEM' ORDER BY f.RDB$FIELD_POSITION"
|
||||||
results["item_muestra"] = str(e)
|
)
|
||||||
|
cols_item = [r["c"] for r in rows1] if ok1 else []
|
||||||
|
results["columnas_item"] = cols_item if cols_item else f"error: {err1}"
|
||||||
|
|
||||||
|
# Probar cada posible campo clave contra COD_EXAMEN de RELACION
|
||||||
|
candidatos = ["COD_ITEM", "CODITEM", "CODIGO", "COD", "ID", "CODARTICULO", "ARTICULO"]
|
||||||
|
joins_ok = {}
|
||||||
|
for campo in candidatos:
|
||||||
|
if campo not in cols_item:
|
||||||
|
continue
|
||||||
|
ok2, _, rows2 = fb.execute_query(
|
||||||
|
f"SELECT FIRST 3 rel.COD_EXAMEN, i.CUPS_DETALLE "
|
||||||
|
f"FROM RELACION rel "
|
||||||
|
f"LEFT JOIN ITEM i ON TRIM(i.{campo}) = TRIM(rel.COD_EXAMEN) "
|
||||||
|
f"WHERE i.CUPS_DETALLE IS NOT NULL AND TRIM(i.CUPS_DETALLE)<>'' "
|
||||||
|
)
|
||||||
|
if ok2 and rows2:
|
||||||
|
joins_ok[campo] = rows2
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
joins_ok[campo] = "sin resultados"
|
||||||
|
results["join_pruebas"] = joins_ok
|
||||||
|
|
||||||
|
# Primera fila de ITEM sin JOIN
|
||||||
|
ok3, err3, rows3 = fb.execute_query("SELECT FIRST 1 i.* FROM ITEM i")
|
||||||
|
results["item_primera_fila"] = rows3[0] if (ok3 and rows3) else f"error: {err3}"
|
||||||
|
|
||||||
fb.disconnect()
|
fb.disconnect()
|
||||||
return JSONResponse(results)
|
return JSONResponse(results)
|
||||||
|
|||||||
Reference in New Issue
Block a user