#!/usr/bin/env python3
import pymysql

conn = pymysql.connect(
    host="192.168.200.4",
    port=3307,
    user="developer",
    password="DEVEL!now1",
    database="astara_pdb_demo_hy",
    charset="utf8mb4",
)
cur = conn.cursor(pymysql.cursors.DictCursor)
cur.execute("DESCRIBE con_sety")
print("con_sety:", cur.fetchall())
cur.execute("SELECT * FROM con_bodytypes ORDER BY lp, id_bodytypes")
print("bodytypes:", cur.fetchall())
cur.execute(
    """
    SELECT s.id_sety, s.bodytype, w.wersja, s.cena
    FROM con_sety s
    JOIN con_wersje w ON w.id_wersje=s.wersja
    WHERE s.model=2
    ORDER BY s.id_sety
    LIMIT 15
    """
)
try:
    print("ducato sety sample:", cur.fetchall())
except Exception as e:
    print("bodytype col error:", e)
    cur.execute(
        "SELECT s.id_sety, w.wersja FROM con_sety s JOIN con_wersje w ON w.id_wersje=s.wersja WHERE s.model=2 ORDER BY s.id_sety LIMIT 10"
    )
    print(cur.fetchall())
conn.close()
