how to create a database in python using sql lite 3 by by stuart hall
Author:by stuart hall [hall, by stuart]
Language: eng
Format: azw3
Published: 2015-04-04T04:00:00+00:00
Please select an option: 1 - Add a new film. 2 - Delete a film. 3 - Show all films. 4 - Sort films by year. 5 - Find films by year. 6 - Find films by genre. q - Exit. Your choice:
Part 5 –the first function def getNum
The first function we are defining validates the integer (or input the user is going to make)
Notice that the end user must type in a whole number as specified
While loop is used so that if the end user enters wrong data the loop will take them back to start
So if a whole number is not entered a ValueError will be generated- it will loop to start and not allow the end user to go any further
Part 6- the second function- def makeFilmTable
This is the sql element the cursor is essential to navigate around the database
The function creates a structure of a database which the information will be stored in
Db.commit() saves the data to the database that is entered in our program by our end user
The sql needs to be put this inside a cursor.execute() statement for it to be carried out by Python
Part 7- define functions to find year to find genre
Notice that the function for Find is created after these two functions that refer to it .This function deals with creating a capacity for end user to enter a number that relates to a selection in the dictionary previously created .getNum is the validation while loop function we put in at start
Again refers to Find function we are going to create in a minute , this time it enables an end user to enter a genre for the film data that they wish to store
Part 8-define the find function
The find function is a helper function for the find functions
Notice that it uses db.commit() to save data to our database we created earlier, and that it has features discussed previously such as cursor =db.cursor()
Db.commit saves all changes made
The ? Is used to indicate that this is data we do not know yet
Cursor.execute -This is used to pass all sql statements to the database
with connect("films.db") as db: forms the connection with the database
Cursor =db.cursor() identifies the cursor for the database ,which tells Python where in the database you are looking at the time
Part 8-define the formatting of the print
The first line sets up the headers for the table.
The next puts in 45 equals signs to go below the header.
Then we use join() to go through each record in results and format it with the same spacing's we used for the headers.
This deals with setting the amount of characters that can be entered within each field type of the database
Ie id- would have a max of 3 characters-title –would be less than 15
Part 9-define delete film function
Db.commit saves all changes made
The ? Is used to indicate that this is data we do not know yet Cursor.execute -This is used to pass all sql statements to the database
with connect("films.db") as db: forms the connection with the database
Cursor =db.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
The Mikado Method by Ola Ellnestam Daniel Brolund(20604)
Hello! Python by Anthony Briggs(19899)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(18208)
Dependency Injection in .NET by Mark Seemann(18109)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(17576)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(17422)
Kotlin in Action by Dmitry Jemerov(17185)
Adobe Camera Raw For Digital Photographers Only by Rob Sheppard(16934)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(16236)
Grails in Action by Glen Smith Peter Ledbrook(15390)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(13266)
Secrets of the JavaScript Ninja by John Resig & Bear Bibeault(11382)
A Developer's Guide to Building Resilient Cloud Applications with Azure by Hamida Rebai Trabelsi(10580)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(10393)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(9389)
Hit Refresh by Satya Nadella(9085)
The Kubernetes Operator Framework Book by Michael Dame(8522)
Exploring Deepfakes by Bryan Lyon and Matt Tora(8348)
Robo-Advisor with Python by Aki Ranin(8294)