Question

In: Computer Science

Develop a C++/Python program using visual studio connected to mysql workbench to show all vendor's name...

Develop a C++/Python program using visual studio connected to mysql workbench to show all vendor's name and phone (vendor_name and vendor_phone) in the state "CA" and the city "Los Angeles".

here is the database tables

CREATE TABLE general_ledger_accounts
(
account_number INT PRIMARY KEY,
account_description VARCHAR(50) UNIQUE
);

CREATE TABLE terms
(
terms_id INT PRIMARY KEY AUTO_INCREMENT,
terms_description VARCHAR(50) NOT NULL,
terms_due_days INT NOT NULL
);

CREATE TABLE vendors
(
vendor_id INT PRIMARY KEY AUTO_INCREMENT,
vendor_name VARCHAR(50) NOT NULL UNIQUE,
vendor_address1 VARCHAR(50),
vendor_address2 VARCHAR(50),
vendor_city VARCHAR(50) NOT NULL,
vendor_state CHAR(2) NOT NULL,
vendor_zip_code VARCHAR(20) NOT NULL,
vendor_phone VARCHAR(50),
vendor_contact_last_name VARCHAR(50),
vendor_contact_first_name VARCHAR(50),
default_terms_id INT NOT NULL,
default_account_number INT NOT NULL,
CONSTRAINT vendors_fk_terms
FOREIGN KEY (default_terms_id)
REFERENCES terms (terms_id),
CONSTRAINT vendors_fk_accounts
FOREIGN KEY (default_account_number)
REFERENCES general_ledger_accounts (account_number)
);

CREATE TABLE invoices
(
invoice_id INT PRIMARY KEY AUTO_INCREMENT,
vendor_id INT NOT NULL,
invoice_number VARCHAR(50) NOT NULL,
invoice_date DATE NOT NULL,
invoice_total DECIMAL(9,2) NOT NULL,
payment_total DECIMAL(9,2) NOT NULL DEFAULT 0,
credit_total DECIMAL(9,2) NOT NULL DEFAULT 0,
terms_id INT NOT NULL,
invoice_due_date DATE NOT NULL,
payment_date DATE,
CONSTRAINT invoices_fk_vendors
FOREIGN KEY (vendor_id)
REFERENCES vendors (vendor_id),
CONSTRAINT invoices_fk_terms
FOREIGN KEY (terms_id)
REFERENCES terms (terms_id)
);

CREATE TABLE invoice_line_items
(
invoice_id INT NOT NULL,
invoice_sequence INT NOT NULL,
account_number INT NOT NULL,
line_item_amount DECIMAL(9,2) NOT NULL,
line_item_description VARCHAR(100) NOT NULL,
CONSTRAINT line_items_pk
PRIMARY KEY (invoice_id, invoice_sequence),
CONSTRAINT line_items_fk_invoices
FOREIGN KEY (invoice_id)
REFERENCES invoices (invoice_id),
CONSTRAINT line_items_fk_acounts
FOREIGN KEY (account_number)
REFERENCES general_ledger_accounts (account_number)
);

-- create the indexes
CREATE INDEX invoices_invoice_date_ix
ON invoices (invoice_date DESC);

-- create some test tables that aren't explicitly
-- related to the previous five tables
CREATE TABLE vendor_contacts
(
vendor_id INT PRIMARY KEY,
last_name VARCHAR(50) NOT NULL,
first_name VARCHAR(50) NOT NULL
);

CREATE TABLE invoice_archive
(
invoice_id INT NOT NULL,
vendor_id INT NOT NULL,
invoice_number VARCHAR(50) NOT NULL,
invoice_date DATE NOT NULL,
invoice_total DECIMAL(9,2) NOT NULL,
payment_total DECIMAL(9,2) NOT NULL,
credit_total DECIMAL(9,2) NOT NULL,
terms_id INT NOT NULL,
invoice_due_date DATE NOT NULL,
payment_date DATE
);

Solutions

Expert Solution

Hii, I'm unaware of the password, username, database name, and of course host name so, I'm nor able to show you the output but the below program is quite correct and you can run in your machine. Just replace the database name, username, password, and host name with yours and that's pretty much it, you are good to go. Enjoy!

Source Code in Python, refer to screenshot for indentation

import mysql.connector


db = mysql.connector.connect(
host="localhost",
user="yourusername",
password="yourpassword",
database="mydatabase"
)

cursor = db.cursor()


#creating tables for this program
cursor.execute("CREATE TABLE general_ledger_accounts(account_number INT PRIMARY KEY,account_description VARCHAR(50) UNIQUE)");

cursor.execute("CREATE TABLE terms(terms_id INT PRIMARY KEY AUTO_INCREMENT,terms_description VARCHAR(50) NOT NULL,terms_due_days INT NOT NULL)");

cursor.execute("CREATE TABLE vendors(vendor_id INT PRIMARY KEY AUTO_INCREMENT,vendor_name VARCHAR(50) NOT NULL UNIQUE,vendor_address1 VARCHAR(50),vendor_address2 VARCHAR(50),vendor_city VARCHAR(50) NOT NULL,vendor_state CHAR(2) NOT NULL,vendor_zip_code VARCHAR(20) NOT NULL,vendor_phone VARCHAR(50),vendor_contact_last_name VARCHAR(50),vendor_contact_first_name VARCHAR(50),default_terms_id INT NOT NULL,default_account_number INT NOT NULL,CONSTRAINT vendors_fk_termsFOREIGN KEY (default_terms_id) REFERENCES terms (terms_id),CONSTRAINT vendors_fk_accounts FOREIGN KEY (default_account_number) REFERENCES general_ledger_accounts (account_number))");

cursor.execute("CREATE TABLE invoices(invoice_id INT PRIMARY KEY AUTO_INCREMENT,vendor_id INT NOT NULL,invoice_number VARCHAR(50) NOT NULL,invoice_date DATE NOT NULL,invoice_total DECIMAL(9,2) NOT NULL,payment_total DECIMAL(9,2) NOT NULL DEFAULT 0,credit_total DECIMAL(9,2) NOT NULL DEFAULT 0,terms_id INT NOT NULL,invoice_due_date DATE NOT NULL,payment_date DATE,CONSTRAINT invoices_fk_vendors FOREIGN KEY (vendor_id) REFERENCES vendors (vendor_id),CONSTRAINT invoices_fk_termsF OREIGN KEY (terms_id) REFERENCES terms (terms_id))");

cursor.execute("CREATE TABLE invoice_line_items(invoice_id INT NOT NULL,invoice_sequence INT NOT NULL,account_number INT NOT NULL,line_item_amount DECIMAL(9,2) NOT NULL,line_item_description VARCHAR(100) NOT NULL,CONSTRAINT line_items_pk PRIMARY KEY (invoice_id, invoice_sequence),CONSTRAINT line_items_fk_invoices FOREIGN KEY (invoice_id) REFERENCES invoices (invoice_id),CONSTRAINT line_items_fk_acounts FOREIGN KEY (account_number) REFERENCES general_ledger_accounts (account_number))");

# creating indexes for the table
cursor.execute("CREATE INDEX invoices_invoice_date_ix ON invoices (invoice_date DESC)");

# creating table that arn't related to the above tables
cursor.execute("CREATE TABLE vendor_contacts(vendor_id INT PRIMARY KEY,last_name VARCHAR(50) NOT NULL,first_name VARCHAR(50) NOT NULL)")

cursor.execute("CREATE TABLE invoice_archive(invoice_id INT NOT NULL,vendor_id INT NOT NULL,invoice_number VARCHAR(50) NOT NULL,invoice_date DATE NOT NULL,invoice_total DECIMAL(9,2) NOT NULL,payment_total DECIMAL(9,2) NOT NULL,credit_total DECIMAL(9,2) NOT NULL,terms_id INT NOT NULL,invoice_due_date DATE NOT NULL,payment_date DATE)");

# quering out desired output through SELECT and WHERE clause
cursor.execute("SELECT vendor_name, vendor_phone from vendors WHERE vendor_state='CA' and vendor_city='Los Angeles'")

result = cursor.fetchall()

for row in result:
print(row)
  
  
Source Code indentation


Related Solutions

USING VISUAL STUDIO 2017, LANGUAGE VISUAL C# I have struggled on this program for quite some...
USING VISUAL STUDIO 2017, LANGUAGE VISUAL C# I have struggled on this program for quite some time and still can't quite figure it out. I'm creating an app that has 2 textboxes, 1 for inputting customer name, and the second for entering the number of tickets the customer wants to purchase. There are 3 listboxes, the first with the days of the week, the second with 4 different theaters, and the third listbox is to display the customer name, number...
This is in MySQL Part one: Using the MySQL Workbench Data Modeler, construct a diagram that...
This is in MySQL Part one: Using the MySQL Workbench Data Modeler, construct a diagram that shows the table in 3rd Normal Form. Part two: Provide a summary of the steps you took to achieve 3rd Normal form. Include your rationale for new table creation, key selection and grouping of attributes. Table Details: The Anita Wooten Art Gallery wishes to maintain data on their customers, artists and paintings. They may have several paintings by each artist in the gallery at...
write a c++ program using micro soft visual studio 2010 to write a program and store...
write a c++ program using micro soft visual studio 2010 to write a program and store 36 in variable x and 8 in variable y. add them and store the result in the variable sum. then display the sum on screen with descriptive text. calculate the square root of integer 36 in x. store the result in a variable. calculate the cube root of integer 8 in y. store result in a variable. display the results of square root and...
In MySql, using Application MYSQL Workbench and the Chinook database, please answer the following: -- 12....
In MySql, using Application MYSQL Workbench and the Chinook database, please answer the following: -- 12. SELECT the trackid, name and filesize (as shown in the bytes column) for all tracks that have a file size less than 2000000 and a GenreId of 1 or a file size less than 2000000 and a Genreid of 2 -- 13. Add a sort to the query from number 12 to sort by GenreID; -- 14. List all columns from the customer table...
C++ PROGRAM Using the attached C++ code (Visual Studio project), 1) implement a CoffeeMakerFactory class that...
C++ PROGRAM Using the attached C++ code (Visual Studio project), 1) implement a CoffeeMakerFactory class that prompts the user to select a type of coffee she likes and 2) returns the object of what she selected to the console. #include "stdafx.h" #include <iostream> using namespace std; // Product from which the concrete products will inherit from class Coffee { protected:    char _type[15]; public:    Coffee()    {    }    char *getType()    {        return _type;   ...
In visual Studio C++ Create a program that uses a for loop to input the high...
In visual Studio C++ Create a program that uses a for loop to input the high temperature, and low temperature for each day of the week. The high and low will be placed into two elements of the array. For each loop the high and low will be placed into the next set of elements of the array. After the temps for all seven days have been entered into the array, a for loop will be used to pull out...
String Manipulator Write a program to manipulate strings. (Visual Studio C++) In this program take a...
String Manipulator Write a program to manipulate strings. (Visual Studio C++) In this program take a whole paragraph with punctuations (up to 500 letters) either input from user, initialize or read from file and provide following functionalities within a class: a)   Declare class Paragraph_Analysis b)   Member Function: SearchWord (to search for a particular word) c)   Member Function: SearchLetter (to search for a particular letter) d)   Member Function: WordCount (to count total words) e)   Member Function: LetterCount (ONLY to count all...
Using MySQL Workbench to write and run the following steps, and take a screenshot for me!...
Using MySQL Workbench to write and run the following steps, and take a screenshot for me! Create a species table and a specimen table. In the species table, include attributes that reflect the name of the species, a general description of the species, and any other attributes you feel relevant. In the specimens table, include an ID for the specimen, a reference to the species which it is, the date which it was observed, and any relevant details like height,...
 VISUAL STUDIO (File Creation and Submissions)  FLOWCHART  Writing program in C++ ( cout,...
 VISUAL STUDIO (File Creation and Submissions)  FLOWCHART  Writing program in C++ ( cout, \n, \t, solving expressions )  Correcting errors Q1: Draw flow Chart of the following problems: a) Display “Hello World” on screen. b) Display Your Name, date of birth and mobile number on screen. c) Compute and display the perimeter and area of a rectangle with a height of 7 inches and width of 5 inches. d) Compute and display the perimeter and area...
DEVELOP IN VISUAL STUDIOS C++ PLEASE 1. Develop a main program that does the following a)...
DEVELOP IN VISUAL STUDIOS C++ PLEASE 1. Develop a main program that does the following a) Create six nodes of integers such as n0, n1, n2, n3, n4, n5 (n0 is the head) b) Assign data to each nodes such as n1->data = 2; n2->data = 5, n3->data = 3, n4->data = 10, n5->data = 1. c) Make n0 ->next to point to n1, and n0->prev to point to NULL 2.) Print out the content of list you have created...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT