check_schema.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import mysql.connector
  2. from decimal import Decimal
  3. import datetime
  4. DB_CONFIG = {
  5. 'user': 'root',
  6. 'password': '84853032',
  7. 'host': '47.99.60.80',
  8. 'port': 3306,
  9. 'database': '2022hs060',
  10. 'use_pure': True,
  11. 'connect_timeout': 5
  12. }
  13. def check_schema():
  14. try:
  15. conn = mysql.connector.connect(**DB_CONFIG)
  16. cursor = conn.cursor(dictionary=True)
  17. # 1. Check mp_measure_order columns
  18. print("=== mp_measure_order Columns ===")
  19. cursor.execute("DESCRIBE mp_measure_order")
  20. cols = cursor.fetchall()
  21. for col in cols:
  22. print(f"{col['Field']} - {col['Type']}")
  23. # 2. Check mp_construction_measure_others columns
  24. print("\n=== mp_construction_measure_others Columns ===")
  25. cursor.execute("DESCRIBE mp_construction_measure_others")
  26. cols = cursor.fetchall()
  27. for col in cols:
  28. print(f"{col['Field']} - {col['Type']}")
  29. # 2.1 Check mp_contract columns
  30. print("\n=== mp_contract Columns ===")
  31. cursor.execute("DESCRIBE mp_contract")
  32. cols = cursor.fetchall()
  33. for col in cols:
  34. print(f"{col['Field']} - {col['Type']}")
  35. # 3. Sample data from mp_construction_measure_others for a completed order
  36. print("\n=== Sample Data from mp_construction_measure_others (Limit 20) ===")
  37. cursor.execute("SELECT id FROM mp_measure_order WHERE status=2 LIMIT 1")
  38. order = cursor.fetchone()
  39. if order:
  40. print(f"Order ID: {order['id']}")
  41. # CORRECT COLUMN NAME: mp_construction_measure_id
  42. cursor.execute(f"SELECT name, construction_measure_amount, end_current_period_amount FROM mp_construction_measure_others WHERE mp_construction_measure_id = '{order['id']}'")
  43. rows = cursor.fetchall()
  44. for row in rows:
  45. print(row)
  46. conn.close()
  47. except Exception as e:
  48. print(e)
  49. if __name__ == "__main__":
  50. check_schema()