File size: 1,194 Bytes
49aa9a1 1b420ad 49aa9a1 020cf0e 1b420ad 49aa9a1 1b420ad 49aa9a1 53c5d0a 49aa9a1 53c5d0a 49aa9a1 | 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 | import os
import sqlite3
ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
DB_PATH = os.path.join(ROOT_DIR, "db.sqlite")
def main() -> int:
response = input("Are you sure? [y/N]: ").strip().lower()
if response not in {"y", "yes"}:
return 0
if not os.path.exists(DB_PATH):
print("db.sqlite not found.")
return 1
conn = sqlite3.connect(DB_PATH)
try:
cur = conn.cursor()
cur.execute(
"SELECT name FROM sqlite_master WHERE type='table' AND name='pixif_cache'"
)
if cur.fetchone() is None:
print("pixif_cache table not found.")
return 1
cur.execute("SELECT COUNT(*) FROM pixif_cache WHERE url IS ''")
to_delete = cur.fetchone()[0]
if to_delete:
cur.execute("DELETE FROM pixif_cache WHERE url IS ''")
conn.commit()
cur.execute("SELECT COUNT(*) FROM pixif_cache")
remaining = cur.fetchone()[0]
finally:
conn.close()
print(f"Removed {to_delete} rows with NULL url.")
print(f"Remaining rows: {remaining}")
return 0
if __name__ == "__main__":
raise SystemExit(main())
|