Skip to content

Instantly share code, notes, and snippets.

@daniel-schroeder-dev
Created November 15, 2020 15:41
Show Gist options
  • Select an option

  • Save daniel-schroeder-dev/ef2ac2e3f1aecb6b628d7840798ed89e to your computer and use it in GitHub Desktop.

Select an option

Save daniel-schroeder-dev/ef2ac2e3f1aecb6b628d7840798ed89e to your computer and use it in GitHub Desktop.
Bookshelf DB to practice SQLite
#!/usr/bin/python3
import cgitb
cgitb.enable
from helper import showData
import sqlite3
con = sqlite3.connect('database/bookshelf.db')
sql = con.cursor()
query = """
CREATE TABLE IF NOT EXISTS programming_books(
title TEXT,
author TEXT,
num_pages INTEGER,
price REAL
)
"""
sql.execute(query)
programming_books = [
[
'Effective Java',
'Joshua Bloch',
392,
54.99,
],
[
'Problem Solving With Algorithms And Data Structures Using Python',
'Bradley Miller',
425,
35.99,
],
[
'Flask Web Development',
'Miguel Grinberg',
291,
44.99,
],
]
for programming_book in programming_books:
query = "INSERT INTO programming_books VALUES(?, ?, ?, ?)"
sql.execute(query, programming_book)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment