forked from realpython/discover-flask
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql.py
More file actions
19 lines (13 loc) · 669 Bytes
/
sql.py
File metadata and controls
19 lines (13 loc) · 669 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# sql.py - Create a SQLite3 table and populate it with data
import sqlite3
# create a new database if the database doesn't already exist
with sqlite3.connect('sample.db') as connection:
# get a cursor object used to execute SQL commands
c = connection.cursor()
# create the table
c.execute('CREATE TABLE posts(title TEXT, description TEXT)')
# insert dummy data into the 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.")')