-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetDetails.py
More file actions
46 lines (34 loc) Β· 1.2 KB
/
GetDetails.py
File metadata and controls
46 lines (34 loc) Β· 1.2 KB
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
import sqlite3
def MyApp():
my_name = input("Name : ")
my_email = input("Email : ")
my_phone_number = input("Phone Number : ")
my_age = input("age : ")
my_date_of_birth = input("Date of birth : ")
conn = None
try:
print("connecting... π°π°π° ")
conn = sqlite3.connect('xyz.db')
print(" :) connected π ")
except Error as e:
print(" :( βπ "+ e)
cur = conn.cursor()
cur.execute(''' SELECT count(name) FROM sqlite_master WHERE type='table' AND name='MyData' ''')
#if the count is 1, then table exists
if cur.fetchone()[0]==1:
print('Table exists.')
else:
cur.execute("CREATE TABLE MyData (course_title TEXT, author TEXT, course_rating FLOAT, course_price FLOAT)")
print(":)... Table is created")
sql = '''INSERT INTO MyData (name, email, phone_number, age, date_of_birth)
VALUES(?, ?, ?, ?, ?)'''
val = (my_name, my_email, my_phone_number, my_age, my_date_of_birth)
cur.execute(sql,val)
print('Detail Inserted π ')
sql1= "SELECT * FROM MyData"
cur.execute(sql1)
rows = cur.fetchall()
for row in rows:
print(row)
conn.commit()
MyApp()