-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsql.py
34 lines (21 loc) · 881 Bytes
/
sql.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
import sqlite3
conn = sqlite3.connect('mydatabase.db')
cursor = conn.cursor()
#create a table
#cursor.execute('''CREATE TABLE albums
#(title text, artist text, release_date text,
#publisher text, media_type text)
#''')
#add data to the database
cursor.execute('''INSERT INTO albums
VALUES ('The Suburbs', 'Arcade Fire', '2013',
'Independent', 'MP3')
''')
#save data to db
conn.commit()
#Insert multiple records using secure method
albums = [('Rock Spectacle', 'Barenaked Ladies','1995','Sony','MP3'),
('You Forget It In People', 'Broken Social Scene','2001','Independent','Record'),
('We Were Dead Before The Ship Even Sank', 'Modest Mouse','2007','Glacial Pace','MP3')]
cursor.executemany('INSERT INTO albums VALUES(?,?,?,?,?)', albums)
conn.commit()