#!/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("SHOW CREATE VIEW con_sety_view")
print(cur.fetchone()["Create View"][:2000])
cur.execute(
    """
    SELECT s.id_sety, s.bodytype, bt.bodytype AS bt_name, s.model
    FROM con_sety s
    LEFT JOIN con_bodytypes bt ON bt.id_bodytypes=s.bodytype
    WHERE s.model=2
    GROUP BY s.bodytype
    ORDER BY bt.lp
    LIMIT 25
    """
)
print("\nDucato distinct bodytypes in use:")
for r in cur.fetchall():
    print(r)

cur.execute("SELECT COUNT(*) c FROM con_sety WHERE model=1 AND bodytype IS NOT NULL AND bodytype<>0")
print("\nTucson sets with bodytype:", cur.fetchone())
conn.close()
