Files

76 lines
3.6 KiB
Python
Raw Permalink Normal View History

2026-06-27 02:21:09 +00:00
import sqlite3
import os
db_files = [
r'./qple_quiz.db',
r'./qple_quiz_corrupted.db.bak',
r'./qple_quiz_0621.db'
]
for db in db_files:
if not os.path.exists(db):
print(f"File not found: {db}")
continue
print(f"\nDB: {db} (Size: {os.path.getsize(db)} bytes)")
try:
conn = sqlite3.connect(db)
cursor = conn.cursor()
# list tables
cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
tables = [row[0] for row in cursor.fetchall()]
print(" Tables:", tables)
for t in ['QuizQuestions', 'QuizExplain', 'Bookmark', 'DescriptiveGrading']:
if t in tables:
cursor.execute(f"SELECT COUNT(*) FROM {t};")
cnt = cursor.fetchone()[0]
print(f" {t}: {cnt} rows")
# if QuizQuestions, list source counts
if t == 'QuizQuestions':
cursor.execute("PRAGMA table_info(QuizQuestions);")
cols = [c[1] for c in cursor.fetchall()]
print(f" Columns: {cols}")
cursor.execute("SELECT source, COUNT(*), MIN(id), MAX(id) FROM QuizQuestions GROUP BY source;")
src_cnt = cursor.fetchall()
print(f" QuizQuestions breakdown: {src_cnt}")
elif t == 'QuizExplain':
# check if source column exists
cursor.execute("PRAGMA table_info(QuizExplain);")
cols = [c[1] for c in cursor.fetchall()]
print(f" Columns: {cols}")
if 'source' in cols:
cursor.execute("SELECT source, COUNT(*), MIN(id), MAX(id) FROM QuizExplain GROUP BY source;")
print(f" QuizExplain breakdown: {cursor.fetchall()}")
else:
cursor.execute("SELECT COUNT(*), MIN(id), MAX(id) FROM QuizExplain;")
print(f" QuizExplain (no source): {cursor.fetchall()}")
elif t == 'Bookmark':
cursor.execute("PRAGMA table_info(Bookmark);")
cols = [c[1] for c in cursor.fetchall()]
print(f" Columns: {cols}")
if 'source' in cols:
cursor.execute("SELECT source, COUNT(*), MIN(question_id), MAX(question_id) FROM Bookmark GROUP BY source;")
print(f" Bookmark breakdown: {cursor.fetchall()}")
else:
cursor.execute("SELECT COUNT(*), MIN(question_id), MAX(question_id) FROM Bookmark;")
print(f" Bookmark (no source): {cursor.fetchall()}")
elif t == 'DescriptiveGrading':
cursor.execute("PRAGMA table_info(DescriptiveGrading);")
cols = [c[1] for c in cursor.fetchall()]
print(f" Columns: {cols}")
if 'source' in cols:
cursor.execute("SELECT source, COUNT(*) FROM DescriptiveGrading GROUP BY source;")
print(f" DescriptiveGrading breakdown: {cursor.fetchall()}")
else:
cursor.execute("SELECT COUNT(*) FROM DescriptiveGrading;")
print(f" DescriptiveGrading (no source): {cursor.fetchall()}")
conn.close()
except Exception as e:
print(f" Error inspecting: {e}")