· 6 years ago · Apr 01, 2019, 11:08 PM
1import sqlite3
2
3with sqlite3.connect('blog.db') as conn:
4
5 conn.execute(
6 "CREATE TABLE IF NOT EXISTS posts"
7 "(title TEXT, post TEXT)"
8 )
9
10
11 # insert dummy data into the table
12 number_of_posts = conn.execute("SELECT count(title) FROM posts").fetchone()
13
14 if not number_of_posts[0] > 0:
15 conn.execute('INSERT INTO posts VALUES("Good", "I\'m good.")')
16 conn.execute('INSERT INTO posts VALUES("Well", "I\'m well.")')
17 conn.execute('INSERT INTO posts VALUES("Excellent", "I\'m excellent.")')
18 conn.execute('INSERT INTO posts VALUES("Okay", "I\'m okay.")')