-
Notifications
You must be signed in to change notification settings - Fork 0
/
sqlite.py
79 lines (53 loc) · 1.43 KB
/
sqlite.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import sqlite3
import xlrd
address="list.xls"
#address=input('Enter file path :')
line_count=0
l=list()
d=dict()
l2=list()
excel_reader=xlrd.open_workbook(address)
sheet = excel_reader.sheet_by_index(0)
sheet.cell_value(0,0)
for i in range(2,sheet.nrows):
row=sheet.row_values(i)
d[row[2]]=[row[3],row[5]]
conn=sqlite3.connect("personel")
curser=conn.cursor()
curser.execute('''CREATE TABLE IF NOT EXISTS main (
id integer PRIMARY KEY,
name TEXT NULL ,
full_name TEXT NOT NULL,
birth_date TEXT NOT NULL,
code TEXT NULL,
city TEXT NULL,
job TEXT NULL,
contract_type TEXT NULL,
FOREIGN KEY (job) REFERENCES jobs (id)
FOREIGN KEY (city) REFERENCES cities (id)
FOREIGN KEY (contract_type) REFERENCES contracts (id)
)''')
curser.execute('''CREATE TABLE IF NOT EXISTS jobs (
id integer PRIMARY KEY,
name TEXT NOT NULL
)''')
curser.execute('''CREATE TABLE IF NOT EXISTS cities (
id integer PRIMARY KEY,
name TEXT NOT NULL
)''')
curser.execute('''CREATE TABLE IF NOT EXISTS contracts (
id integer PRIMARY KEY,
name TEXT NOT NULL
)''')
# curser.execute('''INSERT INTO jobs (id,name)
# VALUES
# (1,\'نگهبان\'),
# (2,\'کارمند\')
# '''
# )
for i in d:
name=i
curser.execute('INSERT INTO main (full_name,birth_date,job) VALUES (?,?,?)'
,(name,d[name][0],d[name][1])
)
conn.commit()