Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Python using sqlite3 These are the contents of the .db file: import sqlite3 # sqlite3.connect creates a file named 'lab7.db' on the system. connection

In Python using sqlite3

These are the contents of the .db file:

import sqlite3 # sqlite3.connect creates a file named 'lab7.db' on the system. connection = sqlite3.connect('lab7.db') # The cursor is the control structure that traverses records in the database. cursor = connection.cursor() cursor.execute("INSERT INTO products values(null, ?, ?, ?, ?)", ('Hurricane Jelly Beans','jelly beans','abc123', '1.00')) cursor.execute("INSERT INTO products values(null, ?, ?, ?, ?)", ('Typhoon Model Boat','plastic model boat', 'abc456', '12.00')) cursor.execute("INSERT INTO products values(null, ?, ?, ?, ?)", ('Supermarine Spitfire', 'plastic model airplane', 'bcd123', '3.00')) cursor.execute("INSERT INTO products values(null, ?, ?, ?, ?)", ('ENIAC', 'model of first computer', 'bcd456', '21.00')) cursor.execute("INSERT INTO products values(null, ?, ?, ?, ?)", ('Toyota', 'Corrolla', 'gas2013', '1.00')) cursor.execute("INSERT INTO products values(null, ?, ?, ?, ?)", ('Ford', 'Escape', 'hybrid2008', '2.00')) cursor.execute("INSERT INTO products values(null, ?, ?, ?, ?)", ('Ford', 'Fusion', 'hybrid2017', '2.00')) cursor.execute("INSERT INTO products values(null, ?, ?, ?, ?)", ('Kia', 'forte', 'gas2014', '2.00')) cursor.execute("INSERT INTO products values(null, ?, ?, ?, ?)", ('Cadillac', 'Escalade', 'gas2014', '3.00')) cursor.execute("INSERT INTO products values(null, ?, ?, ?, ?)", ('Honda', 'accord', 'gas2014', '7.00')) cursor.execute("INSERT INTO products values(null, ?, ?, ?, ?)", ('Honda', 'civic', 'hybrid2017', '2.00')) cursor.execute("INSERT INTO products values(null, ?, ?, ?, ?)", ('Ford', 'explorer', 'gas2016', '3.00')) cursor.execute("INSERT INTO products values(null, ?, ?, ?, ?)", ('Hyundai', 'sonata', 'gas2014', '2.00')) cursor.execute("INSERT INTO products values(null, ?, ?, ?, ?)", ('Rolls Royce', 'phantom', 'gas2018', '4.00')) # Commit the changes connection.commit()

Create and run the following script to display all of the records in your lab7.db. Complete all of the TODOs.

# TODO import sqlite3 import sqlite3 # TODO Create a sqlite3 connection to the lab7.db database file that # was created in Section 4 conn = sqlite3.connect('lab7.db')

# TODO Using the connection you created in the previous step, create a cursor cur = conn.cursor() # TODO Using the cursor, execute an SQL statement that selects # all of the records from the products table with this SQL: SELECT * FROM products all = cur.execute('SELECT * FROM products')

# TODO Display all of the records in columns. You MUST use the str.format() # method to print the data in columns for row in all: ##################################### ########## YOUR CODE ############### ########## GOES HERE ############### #####################################

stuck on the last part to display the columns using str.format()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Carlos Coronel, Steven Morris

14th Edition

978-0357673034

More Books

Students also viewed these Databases questions

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago