Initial commit
This commit is contained in:
43
check_db.py
Normal file
43
check_db.py
Normal file
@ -0,0 +1,43 @@
|
||||
import sqlite3
|
||||
import os
|
||||
|
||||
db_path = 'my_project_data.db'
|
||||
|
||||
print(f"Checking database at: {os.path.abspath(db_path)}")
|
||||
print(f"File exists: {os.path.exists(db_path)}")
|
||||
|
||||
if os.path.exists(db_path):
|
||||
try:
|
||||
conn = sqlite3.connect(db_path)
|
||||
cursor = conn.cursor()
|
||||
|
||||
# List all tables
|
||||
cursor.execute("SELECT name FROM sqlite_master WHERE type='table'")
|
||||
tables = cursor.fetchall()
|
||||
print("\nTables in database:")
|
||||
for table in tables:
|
||||
print(f"- {table[0]}")
|
||||
|
||||
# Show table structure
|
||||
cursor.execute(f"PRAGMA table_info({table[0]})")
|
||||
columns = cursor.fetchall()
|
||||
print(f" Columns: {[col[1] for col in columns]}")
|
||||
|
||||
# Show row count
|
||||
cursor.execute(f"SELECT COUNT(*) FROM {table[0]}")
|
||||
count = cursor.fetchone()[0]
|
||||
print(f" Rows: {count}")
|
||||
|
||||
# Show first few rows if any
|
||||
if count > 0:
|
||||
print(" First 3 rows:")
|
||||
cursor.execute(f"SELECT * FROM {table[0]} LIMIT 3")
|
||||
for row in cursor.fetchall():
|
||||
print(f" - {row}")
|
||||
|
||||
conn.close()
|
||||
except Exception as e:
|
||||
print(f"Error accessing database: {e}")
|
||||
else:
|
||||
print("\nDatabase file not found. Please check the path.")
|
||||
print("Current working directory:", os.getcwd())
|
||||
Reference in New Issue
Block a user