hardwaredb/src/main.cpp

68 lines
1.5 KiB
C++
Raw Normal View History

2025-01-28 10:06:50 -07:00
#include <iostream>
2025-01-30 22:21:42 -07:00
#include <stdio.h>
#include <sqlite/command.hpp>
#include <sqlite/result.hpp>
2025-01-28 10:06:50 -07:00
#include <string>
// #include "lists/hardware.h"
// #include "lists/cpu.h"
// #include "include/setcpu.h"
// #include "include/sethardware.h"
2025-01-30 22:21:42 -07:00
#include <sqlite3.h>
// Begin testing of SQLite3
2025-01-30 23:48:45 -07:00
static int createDB(const char* s);
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
// static int createTable(const char* s);
2025-01-28 10:06:50 -07:00
int main() {
const char* dbFile = "hardware.db";
2025-01-30 23:48:45 -07:00
sqlite3* hardwareDB;
2025-01-30 22:21:42 -07:00
createDB(dbFile);
searchTable(dbFile, "7800x3d"); // Replace this string with a variable that is the query grabbed from the user!
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;
}
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;
}