# -*- coding: utf-8 -*-
r"""B52: in bảng nha_may (id|ten) + danh sách 40 dòng su_co_kph đang có (để chống trùng khi ghi)."""
import sqlite3

B = r'C:\c\deepseek-harness\claw2-db\btchem.db'
c = sqlite3.connect('file:%s?mode=ro' % B.replace('\\', '/'), uri=True)

print('=== nha_may (%d dòng) ===' % c.execute('select count(*) from nha_may').fetchone()[0])
for r in c.execute('select id, ten, ifnull(khu_vuc,"") from nha_may order by id'):
    print('  %-4s %-46s %s' % (r[0], str(r[1])[:46], str(r[2])[:16]))

print()
print('=== su_co_kph đang có (%d dòng) — để chống ghi trùng ===' % c.execute('select count(*) from su_co_kph').fetchone()[0])
for r in c.execute('''select s.id, ifnull(s.ngay_tao,''), ifnull(n.ten,'(khong ro)'), ifnull(s.ten_vu_viec,''), ifnull(s.trang_thai,'')
                      from su_co_kph s left join nha_may n on n.id = s.nha_may_id order by s.id'''):
    print('  id=%-3s %-11s %-28s %-96s %s' % (r[0], r[1], str(r[2])[:28], str(r[3])[:96], r[4]))
print()
print('=== alias nhà máy (nha_may_alias) — để khớp tên trong sổ ===')
for r in c.execute('''select n.id, n.ten, a.alias from nha_may_alias a join nha_may n on n.id=a.nha_may_id order by n.id'''):
    print('  %-4s %-40s | %s' % (r[0], str(r[1])[:40], r[2]))
c.close()
