#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
检查数据库结构
"""

import sqlite3

# 数据库路径
dbfile = r'\\ll\d\xtrssvjj\dpd.db'

try:
    # 连接数据库
    conn = sqlite3.connect(dbfile)
    cursor = conn.cursor()
    
    print("数据库连接成功！")
    
    # 查看所有表
    print("\n=== 数据库表列表 ===")
    cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
    tables = cursor.fetchall()
    for table in tables:
        print(f"- {table[0]}")
    
    # 查看srts表结构
    print("\n=== srts表结构 ===")
    cursor.execute("PRAGMA table_info(srts);")
    columns = cursor.fetchall()
    for col in columns:
        print(f"- {col[1]} ({col[2]})")
    
    # 查看srts表的前5条记录
    print("\n=== srts表前5条记录 ===")
    cursor.execute("SELECT * FROM srts LIMIT 5;")
    rows = cursor.fetchall()
    for row in rows:
        print(row)
    
    # 查看指定adid的记录
    print("\n=== adid=8243的记录 ===")
    cursor.execute("SELECT * FROM srts WHERE adid = 8243;")
    adid_rows = cursor.fetchall()
    if adid_rows:
        for row in adid_rows:
            print(row)
    else:
        print("没有找到adid=8243的记录")
    
    conn.close()

except Exception as e:
    print(f"错误: {e}")
