Created
November 15, 2020 15:41
-
-
Save daniel-schroeder-dev/ef2ac2e3f1aecb6b628d7840798ed89e to your computer and use it in GitHub Desktop.
Bookshelf DB to practice SQLite
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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