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

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;   ...
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...
 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...
Design and implement a relational database application of your choice using MS Workbench on MySQL a)...
Design and implement a relational database application of your choice using MS Workbench on MySQL a) Declare two relations (tables) using the SQL DDL. To each relation name, add the last 4 digits of your Student-ID. Each relation (table) should have at least 4 attributes. Insert data to both relations (tables); (15%) b) Based on your expected use of the database, choose some of the attributes of each relation as your primary keys (indexes). To each Primary Key name, add...
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...
Create a Visual Studio console project using c++ void lowerToUpper(std::string & sentence) that iterates over all...
Create a Visual Studio console project using c++ void lowerToUpper(std::string & sentence) that iterates over all characters in the sentence argument. Any lowercase letter should be converted to uppercase. This can be done by including <cctype> and testing each character in sentence with the islower() function. If islower(sentence[i]) returns true then sentence[i] should be replaced with toupper(sentence[i]). The main() function should assign "Hello how are you doing?" to sentence, call lowerToUpper(sentence), and use an if statement to check the new...
Create a Visual Studio console project (c++) containing a main() program that declares a const int...
Create a Visual Studio console project (c++) containing a main() program that declares a const int NUM_VALUES denoting the array size. Then declare an int array with NUM_VALUES entries. Using a for loop, prompt for the values that are stored in the array as follows: "Enter NUM_VALUES integers separated by blanks:" , where NUM_VALUES is replaced with the array size. Then use another for loop to print the array entries in reverse order separated by blanks on a single line...
Write a C program The Visual Studio project itself must make its output to the Console...
Write a C program The Visual Studio project itself must make its output to the Console (i.e. the Command Prompt using printf) and it must exhibit the following features as a minimum: 3%: Looping Menu with 3 main actions: View Cars, Sell Car, View Sales Note: A Car is defined by its price and model 3%: Must contain at least three arrays to record sales figures (maximum of 10 Car models) Two for recording the price and model of one...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT