Files
pricing_review/release/testdata/probe_db.py

38 lines
1.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""最小探针:定位哪个库、哪种打开方式能读。只读 SELECT。
2026-10-11:路径改走 gen_testdata.find_data_dir()(旧 glob 指向改名前的目录必 IndexError)。"""
import os
import sqlite3
import sys
sys.stdout.reconfigure(errors="replace")
HERE = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, HERE)
import gen_testdata as G
dd = G.find_data_dir()
if not dd:
print("!! 找不到数据目录(history.db)。请先在控制台里指定,或放到母体旁。")
sys.exit(1)
rh, th, rs, ts = G.db_paths(dd)
targets = {
"history.db(真实)": rh,
"history-test.db": th,
"session.db(真实)": rs,
"session-test.db": ts,
}
for name, p in targets.items():
if not os.path.exists(p):
print("%-18s 缺文件" % name)
continue
for mode, uri in (("普通", False), ("ro", True)):
try:
con = sqlite3.connect(p if not uri else "file:" + p.replace("\\", "/") + "?mode=ro",
uri=uri, timeout=5)
n = con.execute("SELECT COUNT(*) FROM sqlite_master").fetchone()[0]
con.close()
print("%-18s %-4s OK, sqlite_master=%d" % (name, mode, n))
break
except Exception as e:
print("%-18s %-4s FAIL: %s" % (name, mode, e))