2025-01-31 16:19:21 -07:00
|
|
|
#include <boost/algorithm/string/case_conv.hpp>
|
|
|
|
|
#include <cctype>
|
2025-01-28 10:06:50 -07:00
|
|
|
#include <iostream>
|
2025-01-30 22:21:42 -07:00
|
|
|
#include <stdio.h>
|
2025-01-31 10:26:06 -07:00
|
|
|
#include <string>
|
2025-01-31 16:19:21 -07:00
|
|
|
#include <cctype>
|
2025-01-30 22:21:42 -07:00
|
|
|
#include <sqlite/command.hpp>
|
|
|
|
|
#include <sqlite/result.hpp>
|
|
|
|
|
#include <sqlite3.h>
|
2025-01-31 16:19:21 -07:00
|
|
|
#include <boost/algorithm/string.hpp>
|
2025-01-31 10:26:06 -07:00
|
|
|
/*
|
|
|
|
|
* Implementing SQLite3 on suggestion from MD.rpm - Thanks MD!
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
//Declare all the functions
|
2025-01-30 23:48:45 -07:00
|
|
|
static int createDB(const char* s);
|
2025-01-31 10:03:51 -07:00
|
|
|
static int searchTable(const char* s, std::string msearch);
|
|
|
|
|
static int callback(void* NotUsed, int argc, char** argv, char** azColName);
|
2025-01-30 22:21:42 -07:00
|
|
|
|
2025-01-31 10:03:51 -07:00
|
|
|
// static int createTable(const char* s);
|
2025-01-28 10:06:50 -07:00
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
|
2025-01-31 10:03:51 -07:00
|
|
|
const char* dbFile = "hardware.db";
|
2025-01-30 23:48:45 -07:00
|
|
|
sqlite3* hardwareDB;
|
2025-01-30 22:21:42 -07:00
|
|
|
|
2025-01-31 16:19:21 -07:00
|
|
|
std::string msearch;
|
|
|
|
|
std::string msearchlower;
|
|
|
|
|
|
2025-01-31 10:03:51 -07:00
|
|
|
createDB(dbFile);
|
2025-01-29 10:18:17 -07:00
|
|
|
|
2025-01-31 16:19:21 -07:00
|
|
|
char quit = '&';
|
|
|
|
|
|
|
|
|
|
while(tolower(quit) != 'q') {
|
|
|
|
|
std::cout << "========================\n";
|
|
|
|
|
std::cout << "Welcome to the Universal Hardware database!\n";
|
|
|
|
|
std::cout << "(S)earch for a part by model name\n";
|
|
|
|
|
std::cout << "(Q)uit hardware database\n";
|
|
|
|
|
std::cin >> quit;
|
|
|
|
|
switch(tolower(quit)) {
|
|
|
|
|
case 's':
|
|
|
|
|
std::cout << "Enter search string: ";
|
|
|
|
|
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!
|
|
|
|
|
break;
|
|
|
|
|
case 'q':
|
|
|
|
|
break;
|
|
|
|
|
// default:
|
|
|
|
|
// break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-01-29 10:18:17 -07:00
|
|
|
|
2025-01-31 16:19:21 -07:00
|
|
|
// system("sleep 1s");
|
2025-01-28 10:06:50 -07:00
|
|
|
return 0;
|
|
|
|
|
}
|
2025-01-30 23:48:45 -07:00
|
|
|
|
|
|
|
|
static int createDB(const char* s) {
|
|
|
|
|
|
|
|
|
|
sqlite3* hardwareDB;
|
|
|
|
|
int exit = 0;
|
|
|
|
|
exit = sqlite3_open(s, &hardwareDB);
|
|
|
|
|
|
|
|
|
|
sqlite3_close(hardwareDB);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-31 16:19:21 -07:00
|
|
|
static int searchTable(const char* s, std::string msearchlower) {
|
2025-01-31 10:03:51 -07:00
|
|
|
|
|
|
|
|
sqlite3* hardwareDB;
|
|
|
|
|
|
|
|
|
|
int exit = sqlite3_open(s, &hardwareDB);
|
|
|
|
|
|
2025-01-31 16:19:21 -07:00
|
|
|
std::string sql = "SELECT * FROM cpu WHERE model LIKE '%" + msearchlower + "%';";
|
2025-01-31 10:03:51 -07:00
|
|
|
|
|
|
|
|
sqlite3_exec(hardwareDB, sql.c_str(), callback, NULL, NULL);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int callback(void* NotUsed, int argc, char** argv, char** azColName) {
|
|
|
|
|
// Wrap out ouput so it's easier to read for multiple results
|
|
|
|
|
std::cout << "=====================" << std::endl;
|
|
|
|
|
|
|
|
|
|
for (int i=0; i < argc; i++) {
|
|
|
|
|
//column name and value
|
|
|
|
|
std::cout << azColName[i] << ": " << argv[i] << std::endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::cout << std::endl;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|