From c1d47fb32b3f5925ee2168a4c81633229eb6ce56 Mon Sep 17 00:00:00 2001 From: ganome Date: Fri, 31 Jan 2025 17:15:04 -0700 Subject: [PATCH] tacked on a third arg for searchTable() and passed it as the "key" value in the sqlite CPU table - making the function dynmaic for every element of the CPU table --- src/main.cpp | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 42fe416..4148ae9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,7 +14,7 @@ */ //Declare all the functions static int createDB(const char* s); -static int searchTable(const char* s, std::string msearch); +static int searchCPUTable(const char* s, std::string msearch, std::string searchtype); static int callback(void* NotUsed, int argc, char** argv, char** azColName); // static int createTable(const char* s); @@ -55,16 +55,31 @@ int main() { std::cout << "\t\tExample: for Intel i75820k you would enter 5820\n->"; std::cin >> msearch; msearchlower = boost::algorithm::to_lower_copy(msearch); - searchTable(dbFile, msearchlower); // Replace this string with a variable that is the query grabbed from the user! + searchCPUTable(dbFile, msearchlower, "model"); // Replace this string with a variable that is the query grabbed from the user! break; case 'r': - std::cout << "Coming Soon!!!\n"; + std::cout << "-------------------------------\n"; + std::cout << "\t\tEnter the manufacturer of the CPU.\n"; + std::cout << "\t\tExample: Intel\n->"; + std::cin >> msearch; + msearchlower = boost::algorithm::to_lower_copy(msearch); + searchCPUTable(dbFile, msearchlower, "manufacturer"); // Replace this string with a variable that is the query grabbed from the user! break; case 'y': - std::cout << "Coming Soon!!!\n"; + std::cout << "-------------------------------\n"; + std::cout << "\t\tEnter the year this CPU was launched.\n"; + std::cout << "\t\tExample: 2004\n->"; + std::cin >> msearch; + msearchlower = boost::algorithm::to_lower_copy(msearch); + searchCPUTable(dbFile, msearchlower, "releasedyear"); // Replace this string with a variable that is the query grabbed from the user! break; case 'c': - std::cout << "Coming Soon!!!\n"; + std::cout << "-------------------------------\n"; + std::cout << "\t\tEnter the Ghz portion of your main clock speed.\n"; + std::cout << "\t\tExample: 4\n->"; + std::cin >> msearch; + msearchlower = boost::algorithm::to_lower_copy(msearch); + searchCPUTable(dbFile, msearchlower, "mainclock"); // Replace this string with a variable that is the query grabbed from the user! break; default: break; @@ -92,13 +107,13 @@ static int createDB(const char* s) { return 0; } -static int searchTable(const char* s, std::string msearchlower) { +static int searchCPUTable(const char* s, std::string msearchlower, std::string searchtype) { sqlite3* hardwareDB; int exit = sqlite3_open(s, &hardwareDB); - std::string sql = "SELECT * FROM cpu WHERE model LIKE '%" + msearchlower + "%';"; + std::string sql = "SELECT * FROM cpu WHERE " + searchtype + " LIKE '%" + msearchlower + "%';"; sqlite3_exec(hardwareDB, sql.c_str(), callback, NULL, NULL);