-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsql_work.py
44 lines (29 loc) · 929 Bytes
/
sql_work.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
import sqlite3
#connect to database
conn=sqlite3.connect("DataBase")
curser=conn.cursor()
#fill a list of list with database tabel content
def get_from_database():
tabel_list=[]
curser.execute('SELECT name,job,internal,direct,fax,IpPhone FROM phonebook')
rows=curser.fetchall()
for row in rows:
tabel_list.append(row)
tabel_list.pop(0)
return tabel_list
#fill database with a list of list : <tabel_list>
def fill_database(tabel_list):
for i in tabel_list:
curser.execute('INSERT INTO phonebook (name,job,internal,direct,fax,IpPhone) VALUES (?,?,?,?,?,?)'
,(i)
)
conn.commit()
#clear database before updating
def clear_tabel():
conn=sqlite3.connect("DataBase")
curser=conn.cursor()
curser.execute('DELETE FROM phonebook;')
conn.commit()
print('tabel clear')
def update_tabel():
print('tabel_updated')