def delete_record(f_name,db_name,tb_name): """ Read CSV file which contains records to be deleted """ print ("Reading CSV file "+f_name) csvfile = Fileio(f_name) dataset = csvfile.getDataSet() """ Get database connection """ user = "******" passwd = "citoKUKU123" db = Database(db_name,user,passwd) db.getConnection() for dict in dataset: sql_string = "DELETE FROM "+tb_name+" WHERE order_id="+str(dict['Order_id']) db.updateSQL(sql_string) #print(sql_string) """ Close database """ db.closeDatabase()
print("CSV file not defined") sys.exit(0) else: f_name = opts.readf """ Get database connection """ user = "******" passwd = "citoKUKU123" db = Database(db_name, user, passwd) db.getConnection() """ Read CSV file and insert sales_record_number, shipping into item_cost table """ print("Reading CSV file " + f_name + ".csv") csvfile = Fileio(f_name + ".csv") dataset = csvfile.getDataSet() print("Inserting into item_cost table") for dict in dataset: seq = str(dict['sales_record_number']) + "," + str(dict['shipping']) sql_string = "INSERT INTO item_cost (sales_record_number,shipping) VALUES(" + seq + ")" db.insertSQL(sql_string) """ Read CSV file and update shipping column in item_cost table """ # print ("Reading CSV file "+f_name+".csv") # csvfile = Fileio(f_name+".csv") # dataset = csvfile.getDataSet() # print ("Updating shipping values in item_cost table") # for dict in dataset: # seq = str(dict['sales_record_number'])+","+str(dict['shipping']) # sql_string = "UPDATE item_cost SET shipping="+str(dict['shipping'])+" WHERE sales_record_number="+str(dict['sales_record_number']) # db.updateSQL(sql_string)