#include #include #include using namespace std; int listArtists(mysqlpp::Result &res, mysqlpp::Query &query) { mysqlpp::Row row; query.clear(); query << "select * from Artists;"; res = query.store(); if(res) { cout << left; cout << setw(15) << "Artist ID" << setw(20) << "First Name" << "Last Name" << endl; for (mysqlpp::Row::size_type i = 0; i < res.rows(); ++i) { row = res.at(i); cout << left << setw(15) << string(row["ID"]) << setw(20) << string(row["First Name"]) << string(row["Last Name"]) << endl; } } else { cerr << "Failed to get Artists table: " << query.error() << endl; return EXIT_FAILURE; } return EXIT_SUCCESS; } int listSongs(mysqlpp::Result &res, mysqlpp::Query &query) { mysqlpp::Row row; query.clear(); query << "select * from Songs;"; res = query.store(); if(res) { cout << left; cout << setw(20) << "ISSN" << setw(30) << "Title" << setw(10) << "Cost" << "ID" << endl; for (mysqlpp::Row::size_type i = 0; i < res.rows(); ++i) { row = res.at(i); cout << left << setw(20) << string(row["ISSN"]) << setw(30) << string(row["Title"]) << setw(10) << string(row["Cost"]) << string(row["ID"]) << endl; } } else { cerr << "Failed to get Songs table: " << query.error() << endl; return EXIT_FAILURE; } return EXIT_SUCCESS; } int main() { mysqlpp::Connection con; mysqlpp::Result res; int optionChoice = 3; try { con.connect("mysql_cpp_data","localhost", "root", "olathe"); } catch(const mysqlpp::ConnectionFailed& er) { cerr << "Connection failed: " << er.what() << endl; return EXIT_FAILURE; } mysqlpp::Query query = con.query(); query << "use Music_Inventory;"; query.store(); while(optionChoice != 2) { char temp; optionChoice = 3; cout << "Please enter the number of an action to execute:\n" << "0 - List All Artists\n" << "1 - List All Songs\n" << "2 - Exit\n"; while(optionChoice < 0 || optionChoice > 2) { cout << "? "; cin >> optionChoice; } cout << endl; if(optionChoice == 0) { listArtists(res, query); } else if(optionChoice == 1) { listSongs(res, query); } if(optionChoice != 2) { cin >> temp; cout << "\n\n"; } } return EXIT_SUCCESS; }