-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql.py
More file actions
22 lines (14 loc) · 710 Bytes
/
sql.py
File metadata and controls
22 lines (14 loc) · 710 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# sql.py- Script to create db and populate with data
import sqlite3
#creates a new db if it doesn't already exist
with sqlite3.connect("blog.db") as connection:
#get a cursor obj used to execute SQL commands
c = connection.cursor()
#create the table
c.execute("""CREATE TABLE posts (title TEXT, post TEXT)""")
#insert some dummies into TABLE
c.execute('INSERT INTO posts VALUES("Good", "I\'m good.")')
c.execute('INSERT INTO posts VALUES("Well", "I\'m well.")')
c.execute('INSERT INTO posts VALUES("Excellent", "I\'m excellent.")')
c.execute('INSERT INTO posts VALUES("Okay", "I\'m okay.")')
c.execute('INSERT INTO posts VALUES("Awesome", "I\'m awesome.")')