Created a running loop to accept user input for searching/quit
functionality. More search features coming soon!
This commit is contained in:
parent
77ef0710c2
commit
dc11fd691f
35
src/main.cpp
35
src/main.cpp
@ -1,9 +1,13 @@
|
|||||||
|
#include <boost/algorithm/string/case_conv.hpp>
|
||||||
|
#include <cctype>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <cctype>
|
||||||
#include <sqlite/command.hpp>
|
#include <sqlite/command.hpp>
|
||||||
#include <sqlite/result.hpp>
|
#include <sqlite/result.hpp>
|
||||||
#include <sqlite3.h>
|
#include <sqlite3.h>
|
||||||
|
#include <boost/algorithm/string.hpp>
|
||||||
/*
|
/*
|
||||||
* Implementing SQLite3 on suggestion from MD.rpm - Thanks MD!
|
* Implementing SQLite3 on suggestion from MD.rpm - Thanks MD!
|
||||||
*
|
*
|
||||||
@ -20,11 +24,34 @@ int main() {
|
|||||||
const char* dbFile = "hardware.db";
|
const char* dbFile = "hardware.db";
|
||||||
sqlite3* hardwareDB;
|
sqlite3* hardwareDB;
|
||||||
|
|
||||||
|
std::string msearch;
|
||||||
|
std::string msearchlower;
|
||||||
|
|
||||||
createDB(dbFile);
|
createDB(dbFile);
|
||||||
searchTable(dbFile, "7800x3d"); // Replace this string with a variable that is the query grabbed from the user!
|
|
||||||
|
|
||||||
|
char quit = '&';
|
||||||
|
|
||||||
system("sleep 1s");
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// system("sleep 1s");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,13 +66,13 @@ static int createDB(const char* s) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int searchTable(const char* s, std::string msearch) {
|
static int searchTable(const char* s, std::string msearchlower) {
|
||||||
|
|
||||||
sqlite3* hardwareDB;
|
sqlite3* hardwareDB;
|
||||||
|
|
||||||
int exit = sqlite3_open(s, &hardwareDB);
|
int exit = sqlite3_open(s, &hardwareDB);
|
||||||
|
|
||||||
std::string sql = "SELECT * FROM cpu WHERE model='" + msearch + "';";
|
std::string sql = "SELECT * FROM cpu WHERE model LIKE '%" + msearchlower + "%';";
|
||||||
|
|
||||||
sqlite3_exec(hardwareDB, sql.c_str(), callback, NULL, NULL);
|
sqlite3_exec(hardwareDB, sql.c_str(), callback, NULL, NULL);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user