This is the code I currently have, and I am encountering errors within it.
import sys, csv, sqlite3
con = sqlite3.connect(“customers.sqlite”)
cur = con.cursor()
cur.execute(“DELETE FROM Customer IF EXISTS Customer; CREATE TABLE t (customerID INTEGER PRIMARY KEY, firstName TEXT, lastName TEXT,companyName TEXT, address TEXT, city TEXT, state TEXT,zip TEXT);”)
with open('customers.csv', 'rb') as f:
reader = csv.reader(f, delimiter=',')
for row in reader:
to_db = [str(row, “utf8”), str(row, “utf8”), str(row, “utf8”),str(row, “utf8”),str(row, “utf8”),str(row, “utf8”),str(row, “utf8”),str(row, “utf8”)]
cur.execute(“INSERT INTO Customer (firstName,lastName,companyName,address,city,state,zip) VALUES(?, ?, ?, ?, ?, ?, ?);”, to_db)
Project 17-1: Customer Data Importer Create a program that imports customer data from a CSV file into a database table. Console Customer Data Importer CSV file: customers.csv DB file: customers.sqlite Table name: Customer All old rows deleted from Customer table. 500 row(s) inserted into Customer table. Specifications • Your instructor should provide you with the CSV and database files shown above (customers.csv and customers.sqlite). The SQLite database file should contain a table named Customer. The program should begin by deleting any old data from the Customer table. Then, it should insert all data from the customers.csv file into the Customer table of the SQLite database. The CSV file should be in this format: first name, last name, company name, address, city, state, zip James,Butler, ,6649 N Blue Gum St, New Orleans, LA, 70116 Josephine, Darakjy, ,4 B Blue Ridge Blvd, Brighton, MI, 48116 Art, Venere, ,8 W Cerritos Ave #54,Bridgeport, NJ, 08014 Lenna , Paprocki,Feltz Printing, 639 Main St, Anchorage, AK, 99501 The Customer table should have the following columns and data types: customerID INTEGER PRIMARY KEY firstName TEXT lastName TEXT company Name TEXT address TEXT city TEXT state TEXT zip TEXT This program must complete within a few seconds. If it takes longer than that, you need to figure out how to improve its speed. • Use SQLite to view the data and make sure that it has been added to the database correctly. In particular, check to make sure the database automatically generates the customer IDs.