-
Notifications
You must be signed in to change notification settings - Fork 0
/
DB.py
53 lines (46 loc) · 1.47 KB
/
DB.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
import sqlite3
def createdb():
# Creating and connecting to the Database
conn = sqlite3.connect('data.db')
# Create a cursor
c = conn.cursor()
# Create a Table Datatype text
c.execute("CREATE TABLE data (name text, username text, password text)")
# Commit our command
conn.commit()
def insertdb(name, username, password):
# Creating and connecting to the Database
conn = sqlite3.connect('data.db')
# Create a cursor
c = conn.cursor()
# Inserting Data
c.execute("INSERT INTO data (name, username, password) VALUES (?,?,?)",(name, username, password))
# Commit our command
conn.commit()
def fetchall():
# Creating and connecting to the Database
conn = sqlite3.connect('data.db')
# Create a cursor
c = conn.cursor()
# Getting formated contents
c.execute("SELECT rowid, * FROM data")
info = c.fetchall()
print("ID" +"\tUsername" +"\tPassword" +"\tName")
print("--" +"\t--------" +"\t--------"+"\t----")
for i in info:
print (str(i[0]) +"\t" + i[1]+"\t\t" + i[2]+"\t\t" + i[3])
# Commit our command
conn.commit()
def delete(id):
# Creating and connecting to the Database
conn = sqlite3.connect('data.db')
# Create a cursor
c = conn.cursor()
# Inserting Data
c.execute("DELETE from data WHERE rowid = {}".format(id))
# Commit our command
conn.commit()
def closedb():
# Close our connection
conn = sqlite3.connect('data.db')
conn.close()