import fdb, sys

conn = fdb.connect(
    dsn=r"localhost:c:\medicus 3\data\medicus.fdb",
    user="SYSDBA", password="masterkey", charset="win1250"
)
cur = conn.cursor()

# Try CSSZ_ODB
try:
    cur.execute("SELECT FIRST 30 * FROM CSSZ_ODB")
    cols = [d[0] for d in cur.description]
    print("CSSZ_ODB cols:", cols)
    for r in cur.fetchall():
        print(r)
except Exception as e:
    print("CSSZ_ODB:", e)

# Try ODB table
try:
    cur.execute("SELECT FIRST 30 * FROM ODB")
    cols = [d[0] for d in cur.description]
    print("ODB cols:", cols)
    for r in cur.fetchall():
        print(r)
except Exception as e:
    print("ODB:", e)

# List all tables with ODB in name
try:
    cur.execute("SELECT RDB$RELATION_NAME FROM RDB$RELATIONS WHERE RDB$RELATION_NAME LIKE '%ODB%' AND RDB$SYSTEM_FLAG = 0")
    for r in cur.fetchall():
        print("Table:", r[0].strip())
except Exception as e:
    print("table list:", e)

conn.close()
print("DONE")
