-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql.py
More file actions
28 lines (20 loc) · 770 Bytes
/
sql.py
File metadata and controls
28 lines (20 loc) · 770 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
import sqlite3
conn = sqlite3.connect('test.db')
crsr = conn.cursor()
sql_command = '''CREATE TABLE IF NOT EXISTS pokemon(
national_dex VARCHAR(4),
regional_dex VARCHAR(4),
name VARCHAR(20),
primary_type VARCHAR(30),
secondary_type VARCHAR(30));'''
crsr.execute(sql_command)
def insert_pokemon(pokemon_list):
conn = sqlite3.connect('test.db')
c = conn.cursor()
sql = ''' INSERT INTO pokemon(national_dex,regional_dex,
name,primary_type,secondary_type)
VALUES(?,?,?,?,?) '''
for pokemon in pokemon_list:
c.execute(sql, (pokemon['NationalDex'], pokemon['RegionalDex'],
pokemon['Name'], pokemon['Primary Type'], pokemon['Secondary Type']))
conn.commit()