
Concept explainers
Need some help understanding this Python program that creates a new
The function named create_table will create a table in the DSUCollege.db database called students that has five fields: student_id, first_name, last_name, major, and gpa. The first_name, last_name, and major columns should be TEXT data types, the student_id column should be an INTEGER datatype and gpa should be a REAL datatype (link to SQLite Data typesLinks to an external site.). Before creating the table, add code to drop the table. After the table has been created, display a message that the table has been created successfully.
The function named populate_table populates the students table with the following values:
student_id | first_name | last_name | major | gpa |
1111 | Dave | Grohl | Music | 4.0 |
2222 | Belinda | Carlisle | Accounting | 3.5 |
3333 | Joe | Elliot | Computer Science | 2.8 |
4444 | Angus | Young | Accounting | 2.1 |
5555 | Susanna | Hoffs | Music | 3.1 |
6666 | Debbie | Harry | Computer Science | 3.4 |
7777 | Saul | Hudson | Music | 2.7 |
8888 | Paul | Hewson | Computer Science | 1.8 |
After the seven rows have been added, display a message that the table has been populated.
After the table has been populated a function named update_table should be called that creates and runs SQL statements to do the following:
- Dave Grohl (id 1111) has graduated, delete him from the table and display a message that the delete was successful. Use the id field to locate the correct record to delete.
- Paul Hewson (id 8888) has changed majors to Music, update his major to reflect the change and display a message that the update has been successful. Use the id field to locate the correct record to update.
- Debbie Harry's (id 6666) gpa has increased to 4.0, update her gpa to 4.0 and display a message that the update was successful. Use the id field to locate the correct record to update.
After the updates have been completed, a function named query_table should be called that creates and runs the following queries:
- Create a query to display all information about all students in alphabetical order (a to z) by last_name.
- Create a query to display the first_name and last_name of all students who major in Music.
- Create a query to display the first_name, last_name, major and gpa with gpa >= 3.0, order the query results by gpa in descending order.

Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images

- class Database:def __init__(self, db_name):self.db = sqlite3.connect(db_name)self.cursor = self.db.cursor()def create_table(self, table_schema):self.cursor.execute(table_schema)self.db.commit()def insert_data(self, table_name, data):for i in range(len(data)):keys = ", ".join(data.columns)values = ", ".join([f"'{value}'" if pd.isna(value) else str(value) for value in data.iloc[i]])self.cursor.execute(f"INSERT INTO {table_name} ({keys}) VALUES ({values})")self.db.commit()def search_data(self, table_name, year):self.cursor.execute(f"SELECT * FROM {table_name} WHERE year={year}")result = self.cursor.fetchone()if result is not None:return resultelse:return Nonedef delete_data(self, table_name, year):self.cursor.execute(f"DELETE FROM {table_name} WHERE year={year}")self.db.commit()return self.cursor.rowcount > 0 Please rewrite (or convert) the code above with format: def QueryBuilder( Data_Base, Query_Type, Query_Tuple):'''''' Build Query_String'''''' return Query_Stringarrow_forwardBelow is “Book Order,” the only table in library management system’s database. The design of “Book Order” as you may tell is in the zero normal formal form, you as the database designer want to convert the design into the third normal form. Order ID Special order date Customer ID Customer last name Customer First name Customer birth date Book ISBN1 Book Title 1 Book Author 1 Book publication year 1 Book ISBN2 Book Title 2 Book Author 2 Book publication year 2 Store ID Store name Store location Special order status Book Order(Order ID, Special order date, Customer ID, Customer last name, Customer First name, Customer birth date, Book ISBN1, Book Title 1, Book Author 1, Book publication year 1, Book ISBN2, Book Title 2, Book Author 2, Book publication year 2, Store ID, Store name, Store location, Special order status)arrow_forwardQUESTION 21 Code a chain of MongoDB methods that retrieves documents from MondoDB collection named WEB322 the only documents that are selected are the ones with value 211 in the semester field the only fields of the selected documents that are retrieved are firstName and lastName make sure the _id field is NOT retrieved sort the selected documents by lastName in ascending sequence store the result to an array named result assume the connection between the program and database had already been established and the name of the database object is dbarrow_forward
- When the Search button is pressed in the screen depicted, the getSales() function from the PosDAO.java class is called, the parameters of this function are the from date and to date.The getSales () function should return a list of Pos objects that matches the criteria specified, Note this function has to perform two INNER JOINs in to combine all three tables in order to get all the needed data to fill the Pos object. The database schema is also depicted. The PosDAO, Product, SalesDetails and Pos classes are shown BELOW Write the getSales() function public class PosDAO { private Connection conn; PreparedStatement stmt = null; public boolean openConnection(){ try { // db parameters String url = "jdbc:mysql://localhost:4306/swen2005"; String user = "root"; String password = ""; // create a connection to the database conn = DriverManager.getConnection(url, user, password); if (conn!= null){ return true;…arrow_forwardPopulation Database Compile and run CreateCityDB.java which will create a Java DB database named CityDB. The CityDB database will have a table named City, with the following columns: CityName & Population. Their Data Types: CHAR(50) Primary Key & DOUBLE. The CityName column stores the name of a city, and the Population column stores the population of that city. After you run the CreateCityDB.java program, the City table will contain 20 rows with various cities and their populations. Next, create an application that connects to the CityDB database and allows the user to select any of the following operations: Sort the list of cities by population, in ascending order. Sort the list of cities by population, in descending order. Sort the list of cities by name. Get the total population of all the cities. Get the average population of all the cities. Get the highest population. Get the lowest population. CreateCityDB.java import java.sql.*; /** This program creates the CityDB…arrow_forwardABC department store keeps information on departments, products, and employees. For each department, the department ID, name and office phone extension are stored. For each employee, the employee ID, and name are stored. A department can have many employees and each employee can be assigned to multiple departments. Each department is managed by one employee. Each department sells many products and each product is sold by only one department. Products can be shoes, clothes, or other miscellaneous. The product ID and price are stored for each product. No additional data is stored for the miscellaneous products. For all shoes, shoe type, shoe color and shoe size are also stored. For all clothes, the season (one of: winter, spring, summer, year-round) is stored. Clothes can be shirts, pants or dresses. For shirts, collar size, sleeve size and type are stored. For pants, waist size, length and type are stored. For dresses, size, and type are stored. Draw the Crow’s foot ERD (including all…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





