#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sqlite3

db_path = r'\\ll\D\xtrssvjj\db\dpd.db'

try:
    conn = sqlite3.connect(db_path)
    
    # 使用两个游标避免状态混乱
    cursor1 = conn.cursor()
    cursor2 = conn.cursor()
    
    print(f"连接数据库成功: {db_path}")
    
    # 搜索包含"长恨歌"的adname
    cursor1.execute("""
        SELECT DISTINCT adid, adname FROM srts 
        WHERE adname LIKE ? 
        ORDER BY adid
    """, ("%长恨歌%",))
    
    results = cursor1.fetchall()
    
    if results:
        print(f"找到 {len(results)} 个匹配结果:")
        for adid, adname in results:
            print(f"adid: {adid}, adname: {adname}")
            
            # 查找对应的author - 使用title列
            cursor2.execute("""
                SELECT author FROM ads 
                WHERE title LIKE ? 
                LIMIT 1
            """, (f"%{adname}%",))
            author_result = cursor2.fetchone()
            if author_result:
                print(f"  author: {author_result[0]}")
            else:
                print("  author: 未找到")
                
            # 检查字幕数量
            cursor2.execute("""
                SELECT COUNT(*) FROM srts 
                WHERE adid = ?
            """, (adid,))
            subtitle_count = cursor2.fetchone()[0]
            print(f"  字幕数量: {subtitle_count}")
    else:
        print("未找到匹配结果")
        
finally:
    conn.close()
    print("\n数据库连接已关闭")