Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I ' m using the sakila database. I need help with my viewCustomer function ( listed below ) . Here is a description for what

I'm using the sakila database. I need help with my viewCustomer function (listed below). Here is a description for what it needs to do: This function should run a query that gets the customer information for all customers in the database and uses that to display a menu of options containing the id - last name, first name to the user. Based on the user choice the function should print the customer's name, phone number, and address including city, email address, if they are active, and last update for the record. You should use prepared statements to run the queries. Here is the code: "void viewCustomer(sqlite3* db)
{
string query = "SELECT customer_id, last_name, first_name FROM customer";
sqlite3_stmt* stmt;
int rc = sqlite3_prepare_v2(db, query.c_str(),-1, &stmt, NULL);
if (rc != SQLITE_OK){
cerr << "Error preparing statement: "<< sqlite3_errmsg(db)<< endl;
sqlite3_close(db);
exit(1);
}
cout << "Please choose the customer you want to see:" << endl;
int pageNum =1;
int rowsPerPage =10;
int choice;
while (true){
// Execute the prepared statement
for (int i =0; i < rowsPerPage; ++i){
if (sqlite3_step(stmt)== SQLITE_ROW){
cout << pageNum * rowsPerPage + i <<".";
cout << sqlite3_column_int(stmt,0)<<"-";
cout << sqlite3_column_text(stmt,2)<<"";
cout << sqlite3_column_text(stmt,1)<< endl;
} else {
// No more rows
break;
}
}
cout << "Please choose the customer you want to see (enter 0 to go to the next page";
cout <<" or -1 to go to the previous page): ";
cin >> choice;
if (choice ==0){
pageNum++;
} else if (choice ==-1){
pageNum = max(1, pageNum -1);
} else {
// Invalid choice
cout << "Invalid choice. Please try again." << endl;
}
}
sqlite3_finalize(stmt);
}"

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essential SQLAlchemy Mapping Python To Databases

Authors: Myers, Jason Myers

2nd Edition

1491916567, 9781491916568

More Books

Students also viewed these Databases questions

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago