File size: 1,043 Bytes
acf6310 | 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 | import sqlite3
from pathlib import Path
def ensure_database(base_dir):
db_dir = Path(base_dir) / 'db'
db_dir.mkdir(parents=True, exist_ok=True)
db_path = db_dir / 'database.db'
conn = sqlite3.connect(db_path)
try:
cursor = conn.cursor()
cursor.execute(
'''
CREATE TABLE IF NOT EXISTS user_info (
id INTEGER PRIMARY KEY AUTOINCREMENT,
type INTEGER NOT NULL,
filePath TEXT NOT NULL,
userName TEXT NOT NULL,
status INTEGER DEFAULT 0
)
'''
)
cursor.execute(
'''
CREATE TABLE IF NOT EXISTS file_records (
id INTEGER PRIMARY KEY AUTOINCREMENT,
filename TEXT NOT NULL,
filesize REAL,
upload_time DATETIME DEFAULT CURRENT_TIMESTAMP,
file_path TEXT
)
'''
)
conn.commit()
finally:
conn.close()
return db_path
|