-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_db.py
More file actions
59 lines (48 loc) · 1.81 KB
/
Copy pathcheck_db.py
File metadata and controls
59 lines (48 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import sqlite3
import os
def check_db():
if not os.path.exists("reports.db"):
print("Файл reports.db не найден!")
return
print(f"Размер файла: {os.path.getsize('reports.db')} байт")
con = sqlite3.connect("reports.db")
c = con.cursor()
# Список всех таблиц
print("\n=== Все таблицы в базе ===")
c.execute("SELECT name FROM sqlite_master WHERE type='table'")
tables = c.fetchall()
for table in tables:
print(f" {table[0]}")
if not tables:
print(" Таблиц не найдено!")
con.close()
return
# Проверяем каждую таблицу
for table_name in [t[0] for t in tables]:
print(f"\n=== Таблица: {table_name} ===")
# Структура
c.execute(f"PRAGMA table_info({table_name})")
columns = c.fetchall()
if columns:
print(" Структура:")
for col in columns:
print(f" {col[1]} ({col[2]})")
else:
print(" Структура не найдена")
# Количество записей
try:
c.execute(f"SELECT COUNT(*) FROM {table_name}")
count = c.fetchone()[0]
print(f" Записей: {count}")
if count > 0:
# Первые записи
c.execute(f"SELECT * FROM {table_name} LIMIT 3")
rows = c.fetchall()
print(" Первые записи:")
for row in rows:
print(f" {row}")
except Exception as e:
print(f" Ошибка при чтении: {e}")
con.close()
if __name__ == "__main__":
check_db()