Querying database works with static string - just need to ask the user
what they're searching for now
This commit is contained in:
parent
bde8026eca
commit
aee543a7b4
@ -1,4 +1,13 @@
|
|||||||
|
# Hardware Database
|
||||||
Learning C++ while building a universal hardware database that can be referenced for any machine that
|
Learning C++ while building a universal hardware database that can be referenced for any machine that
|
||||||
has already been added.
|
has already been added.
|
||||||
|
|
||||||
See your machine specs? If not - Add Them with a Pull Request!
|
See your machine specs? If not - Add Them with a Pull Request!
|
||||||
|
|
||||||
|
Building from source:
|
||||||
|
|
||||||
|
Create a new build directory and enter it with `mkdir build && cd build`.
|
||||||
|
Then run the commands `cmake .. && make`.
|
||||||
|
The new binary is called hardwareDB.
|
||||||
|
make sure to copy the hardware.db from the parent directory, or move the new binary into the parent directory.
|
||||||
|
`mv ../hardware.db .` OR `mv hardwareDB ../` .
|
||||||
|
|||||||
60
src/main.cpp
60
src/main.cpp
@ -11,40 +11,18 @@
|
|||||||
|
|
||||||
// Begin testing of SQLite3
|
// Begin testing of SQLite3
|
||||||
static int createDB(const char* s);
|
static int createDB(const char* s);
|
||||||
static int createTable(const char* s);
|
static int searchTable(const char* s, std::string msearch);
|
||||||
|
static int callback(void* NotUsed, int argc, char** argv, char** azColName);
|
||||||
|
|
||||||
|
// static int createTable(const char* s);
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
|
||||||
const char* dir = "hardware.db";
|
const char* dbFile = "hardware.db";
|
||||||
sqlite3* hardwareDB;
|
sqlite3* hardwareDB;
|
||||||
|
|
||||||
createDB(dir);
|
createDB(dbFile);
|
||||||
// createTable(dir);
|
searchTable(dbFile, "7800x3d"); // Replace this string with a variable that is the query grabbed from the user!
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* //Create the CPU classes from the cpulist file
|
|
||||||
int counter= 0;
|
|
||||||
auto cpus = genCPUclasses();
|
|
||||||
for (CPU& cpu: cpus) {
|
|
||||||
// cpus[counter].HardwareSpecs["model"] = "value";
|
|
||||||
std::cout << cpu.HardwareSpecs["model"] << " loaded at index: " << counter << std::endl;
|
|
||||||
counter++;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
//Testing the new dictionaries
|
|
||||||
// cout << "Lets try the setCPU function!\n";
|
|
||||||
// std::cout << "A7800x3d main clock speed is: " << A7800x3d->HardwareSpecs["mainclock"] << std::endl;
|
|
||||||
// setHardwaremanufacturer(A7800x3d, "AMD");
|
|
||||||
// setCPUcores(A7800x3d, "cores", 8);
|
|
||||||
// setCPUthreads(A7800x3d, "threads", 16);
|
|
||||||
// setCPUmainclock(A7800x3d, "mainclock", "4.8 Ghz");
|
|
||||||
// setCPUboostclock(A7800x3d, "boostclock", "5.2 ghz");
|
|
||||||
// cout << "\n\nA7800x3d new main/boost speed is: " << A7800x3d->HardwareSpecs["mainclock"] << "/" << A7800x3d->HardwareSpecs["boostclock"] << endl;
|
|
||||||
// cout << "A7800x3d manufacturer is: " << A7800x3d->HardwareSpecs["manufacturer"] << "\n\n\n";
|
|
||||||
|
|
||||||
|
|
||||||
system("sleep 1s");
|
system("sleep 1s");
|
||||||
@ -55,7 +33,6 @@ static int createDB(const char* s) {
|
|||||||
|
|
||||||
sqlite3* hardwareDB;
|
sqlite3* hardwareDB;
|
||||||
int exit = 0;
|
int exit = 0;
|
||||||
|
|
||||||
exit = sqlite3_open(s, &hardwareDB);
|
exit = sqlite3_open(s, &hardwareDB);
|
||||||
|
|
||||||
sqlite3_close(hardwareDB);
|
sqlite3_close(hardwareDB);
|
||||||
@ -63,3 +40,28 @@ static int createDB(const char* s) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int searchTable(const char* s, std::string msearch) {
|
||||||
|
|
||||||
|
sqlite3* hardwareDB;
|
||||||
|
|
||||||
|
int exit = sqlite3_open(s, &hardwareDB);
|
||||||
|
|
||||||
|
std::string sql = "SELECT * FROM cpu WHERE model='" + msearch + "';";
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user