tmp: debug script exploración muestras pendientes Firebird
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
"""
|
||||
Explora tablas de toma de muestras pendientes en Firebird.
|
||||
Uso: python debug_muestras.py
|
||||
"""
|
||||
from app.database import get_connection
|
||||
from app.services.firebird_service import get_firebird_from_config
|
||||
|
||||
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:
|
||||
print("Error Firebird:", msg)
|
||||
exit(1)
|
||||
|
||||
# 1. Buscar tablas que suenen a muestras/toma
|
||||
print("=== Tablas con nombres relacionados a muestras ===")
|
||||
_, _, tablas = fb.execute_query("""
|
||||
SELECT TRIM(rdb$relation_name) AS tabla
|
||||
FROM rdb$relations
|
||||
WHERE rdb$system_flag = 0
|
||||
AND (UPPER(rdb$relation_name) LIKE '%MUESTRA%'
|
||||
OR UPPER(rdb$relation_name) LIKE '%TOMA%'
|
||||
OR UPPER(rdb$relation_name) LIKE '%PENDIENTE%'
|
||||
OR UPPER(rdb$relation_name) LIKE '%EXAMEN%'
|
||||
OR UPPER(rdb$relation_name) LIKE '%RESULTADO%'
|
||||
OR UPPER(rdb$relation_name) LIKE '%RELACION%'
|
||||
OR UPPER(rdb$relation_name) LIKE '%ORDEN%')
|
||||
ORDER BY 1
|
||||
""", None)
|
||||
for t in (tablas or []):
|
||||
print(" ", t["TABLA"])
|
||||
|
||||
# 2. Ver columnas de RELACION (exámenes por recepción)
|
||||
print("\n=== Columnas de RELACION ===")
|
||||
_, _, cols = fb.execute_query("""
|
||||
SELECT TRIM(rdb$field_name) AS campo
|
||||
FROM rdb$relation_fields
|
||||
WHERE rdb$relation_name = 'RELACION'
|
||||
ORDER BY rdb$field_position
|
||||
""", None)
|
||||
for c in (cols or []):
|
||||
print(" ", c["CAMPO"])
|
||||
|
||||
# 3. Ver si hay campo de estado/pendiente en RELACION
|
||||
print("\n=== Muestra de RELACION (primeras 3 filas) ===")
|
||||
_, _, sample = fb.execute_query("SELECT FIRST 3 * FROM RELACION", None)
|
||||
for r in (sample or []):
|
||||
print(" ", dict(r))
|
||||
|
||||
# 4. Si existe TOMA_MUESTRA o similar, ver su estructura
|
||||
for tabla in ["TOMA_MUESTRA", "MUESTRAS", "TOMA", "MUESTRA"]:
|
||||
ok_t, _, _ = fb.execute_query(f"SELECT FIRST 1 * FROM {tabla}", None)
|
||||
if ok_t:
|
||||
print(f"\n=== Tabla {tabla} existe — columnas ===")
|
||||
_, _, tcols = fb.execute_query(f"""
|
||||
SELECT TRIM(rdb$field_name) AS campo
|
||||
FROM rdb$relation_fields
|
||||
WHERE rdb$relation_name = '{tabla}'
|
||||
ORDER BY rdb$field_position
|
||||
""", None)
|
||||
for c in (tcols or []):
|
||||
print(" ", c["CAMPO"])
|
||||
_, _, trows = fb.execute_query(f"SELECT FIRST 3 * FROM {tabla}", None)
|
||||
for r in (trows or []):
|
||||
print(" ", dict(r))
|
||||
|
||||
fb.disconnect()
|
||||
print("\nFin.")
|
||||
Reference in New Issue
Block a user