from read_log_times import connect import json with connect() as c: with c.cursor() as q: queries = [ "SHOW COLUMNS FROM crm_customer LIKE 'auto_pool_enabled'", "SELECT COUNT(*) total, SUM(owner_user_id IS NULL) no_owner, SUM(owner_user_id=0) zero_owner, SUM(auto_pool_enabled=1) enabled, SUM(auto_pool_enabled=0) disabled, SUM(auto_pool_enabled IS NULL) unset FROM crm_customer WHERE deleted=0", "SELECT owner_user_id IS NULL no_owner, auto_pool_enabled+0 enabled, COUNT(*) count FROM crm_customer WHERE deleted=0 GROUP BY owner_user_id IS NULL, auto_pool_enabled", "SELECT id,code,status FROM system_role WHERE code IN ('super_admin','crm_admin') AND deleted=0", ] for sql in queries: q.execute(sql) print(json.dumps({'sql': sql, 'rows': q.fetchall()}, ensure_ascii=False, default=str))