-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_QC_service_table.py
55 lines (37 loc) · 1.39 KB
/
create_QC_service_table.py
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
import sqlite3
import pandas as pd
def list_tables(sql_cursor):
sqlQ = "SELECT name FROM sqlite_master WHERE type='table'"
sql_cursor.execute(sqlQ)
tableList = [ t for l in cur.fetchall() for t in l ]
return tableList
def create_service_table(sql_cursor):
if 'service' in list_tables(sql_cursor):
sql_cursor.execute("DROP TABLE service")
sqlQ = (''' CREATE TABLE service
( procedure_id INTEGER PRIMARY KEY,
date TEXT NOT NULL,
type TEXT,
is_pm TEXT,
comment TEXT
)''')
sql_cursor.execute(sqlQ)
return True
def write_service(sql_cursor, df):
sqlQ = ("INSERT INTO service VALUES (?, ?, ?, ?, ?)")
for r in df.itertuples():
print(list(r))
r = [None,] + list(r)[1:]
sql_cursor.execute(sqlQ, r)
return True
if __name__ == '__main__':
db_file = 'qc_qehf_st191107.db'
conn = sqlite3.connect(db_file)
conn.execute("PRAGMA foreign_keys = ON")
cur = conn.cursor()
create_service_table(cur)
conn.commit()
## df = pd.read_csv('Lumos_Cleaning.csv')
## write_service(cur, df)
## conn.commit()
conn.close()