sync util scripts
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
|
||||
import sqlite3
|
||||
|
||||
db = "paintingzz.db"
|
||||
|
||||
conn = sqlite3.connect(db)
|
||||
cur = conn.cursor()
|
||||
|
||||
table = "inspections"
|
||||
|
||||
# Find completely NULL columns
|
||||
cur.execute(f"PRAGMA table_info({table})")
|
||||
columns = [row[1] for row in cur.fetchall()]
|
||||
|
||||
empty_columns = []
|
||||
|
||||
for col in columns:
|
||||
print('cucurucu')
|
||||
cur.execute(
|
||||
f'SELECT COUNT(*) FROM "{table}" WHERE "{col}" IS NOT NULL'
|
||||
)
|
||||
count = cur.fetchone()[0]
|
||||
|
||||
if count <100 :
|
||||
print('list b growing')
|
||||
empty_columns.append(col)
|
||||
print(empty_columns)
|
||||
|
||||
print("Removing:", empty_columns)
|
||||
|
||||
# SQLite >= 3.35 supports DROP COLUMN
|
||||
for col in empty_columns:
|
||||
cur.execute(
|
||||
f'ALTER TABLE "{table}" DROP COLUMN "{col}"'
|
||||
)
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
Reference in New Issue
Block a user