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
This commit is contained in:
ganome 2025-01-31 17:15:04 -07:00
parent bbb08cbbf8
commit c1d47fb32b
Signed by untrusted user who does not match committer: Ganome
GPG Key ID: 944DE53336D81B83

View File

@ -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);