Question: ON Python, GIVEN: import sqlite3 conn = sqlite3.connect('shippers.db) # Create connection object c = conn.cursor() # Get a cursor object -- which works with tables

ON Python,

GIVEN:

import sqlite3 conn = sqlite3.connect('shippers.db) # Create connection object c = conn.cursor() # Get a cursor object -- which works with tables ## This is a long string well use to to create a table ## Note the use of triple quotes to break the string across multiple lines! tableString = """CREATE TABLE SHIPPERS ( ID INTEGER not null primary key, NAME VARCHAR(30), PHONE VARCHAR(30))""" c.execute(tableString) # Create a table ## Insert rows of data into the table c.execute("INSERT INTO SHIPPERS VALUES (1,'Speedy Express','503-555-9831')") c.execute("INSERT INTO SHIPPERS VALUES (2,'United Package','503-555-3199')") c.execute("INSERT INTO SHIPPERS VALUES (3,'Federal Shipping','503-555-9931')") c.execute("INSERT INTO SHIPPERS VALUES (4,'Hermes Parcel','503-555-2123')") conn.commit() # Save (commit) the changes ## We can also close the connection if we are done with it. ## Just be sure any changes have been committed or they will be lost. conn.close() In the lecture for this class, slide #8 has some code that creates a table named Shippers and then insert four rows/records into that table. With brutal disdain for the ordinary standards of education, copy and paste that code into a Python file and run it. Be careful! If you copy and paste code from PowerPoint to a text-based editor, single and double quotes are sometimes converted into characters that aren't quite what you're looking for. Keep an eye out for that. Once you have created the table and inserted data into it, COMMENT THAT CODE OUT. Then add code that does the following. Display the contents of the Shippers table, Delete the Federal Shipping row/record and display the table again. Then Modify the name of the "Hermes Parcel" record to "Hermes Parcel and Shipping" and once more display the table. Then add another Record for the into the table. You pick the data in the fields. Then display the table yet again. Here's something to keep in mind -- your rows/records have an integer field called ID. It is a primary key field, which means it acts as a unique identifying value for the record. If you you're trying to add a new record that has the same ID value as an existing record, your code will fail.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!