@kaiserb1/

SQLite

Python

No description

fork
loading
Files
  • main.py
  • database.db
main.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
import sqlite3

conn = sqlite3.connect("database.db")
c = conn.cursor()


'''
# Create the table, read the article below if you
# are unsure of what they mean
# https://www.w3schools.com/sql/sql_datatypes.asp
SQL_STATEMENT = """CREATE TABLE emp (
	staff_number INTEGER PRIMARY KEY,
	fname VARCHAR(20),
	lname VARCHAR(30),
	gender CHAR(1),
	joining DATE
);"""
c.execute(SQL_STATEMENT)

# Insert some users into our database
c.execute("""INSERT INTO emp VALUES (23, "Rishabh", "Bansal", "M", "2014-03-28");""")
c.execute("""INSERT INTO emp VALUES (1, "Bill", "Gates", "M", "1980-10-28");""")
'''

# Fetch the data 
c.execute("SELECT * FROM emp  where fname = 'Bill'")

# Store + print the fetched data
result = c.fetchall()
for i in result:
	print(i)

""" Printed:
(1, 'Bill', 'Gates', 'M', '1980-10-28')
(23, 'Rishabh', 'Bansal', 'M', '2014-03-28')
"""

# Remember to save + close
conn.commit()
conn.close()