-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql.py
More file actions
35 lines (25 loc) · 945 Bytes
/
sql.py
File metadata and controls
35 lines (25 loc) · 945 Bytes
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
import sqlite3
## Connectt to SQlite
connection=sqlite3.connect("oil.db")
# Create a cursor object to insert record,create table
cursor=connection.cursor()
## create the table
table_info="""
Create table OIL(NAME VARCHAR(25),TYPE VARCHAR(25),
PRICE VARCHAR(25),STOCK INT);
"""
cursor.execute(table_info)
## Insert Some more records
cursor.execute('''Insert Into OIL values('Fortune','Sunflower','1010',90)''')
cursor.execute('''Insert Into OIL values('Sunpure','Sunflower','1000',100)''')
cursor.execute('''Insert Into OIL values('Ruchi Gold','Palm','800',86)''')
cursor.execute('''Insert Into OIL values('Freedom','Sunflower','1030',50)''')
cursor.execute('''Insert Into OIL values('Gemini','Sunflower','1050',35)''')
## Disspaly ALl the records
print("The isnerted records are")
data=cursor.execute('''Select * from OIL''')
for row in data:
print(row)
## Commit your changes int he databse
connection.commit()
connection.close()