From 793501179e338c61c61892121fbae903238d74ba Mon Sep 17 00:00:00 2001 From: dominikpalatynski Date: Mon, 5 Feb 2024 21:09:01 +0100 Subject: [PATCH] Basic SQLite DataBase --- source/DataBase/DataBaseCommon.cpp | 9 +++++---- source/DataBase/DataBaseCommon.hpp | 8 ++++---- source/DataBase/DataBaseHandler.cpp | 6 ++++++ source/DataBase/DataBaseHandler.hpp | 1 + source/DataBase/password-manager.db | Bin 24576 -> 24576 bytes source/main.cpp | 6 +++--- 6 files changed, 19 insertions(+), 11 deletions(-) diff --git a/source/DataBase/DataBaseCommon.cpp b/source/DataBase/DataBaseCommon.cpp index ba64c4d..6370077 100644 --- a/source/DataBase/DataBaseCommon.cpp +++ b/source/DataBase/DataBaseCommon.cpp @@ -1,9 +1,10 @@ #include "DataBaseCommon.hpp" -const std::vector DataBaseCommon::PasswordRecords{"User_Id", "Category", "Username", "Password", "Url", "Expire_Time"}; -const std::vector DataBaseCommon::UserRecord{"Username", "Password"}; +const std::vector DataBaseCommon::passwordRecords{ + "User_Id", "Title", "Category", "Username", "Password", "Note", "Url", "Creation_Time", "Modify_Time", "Expiry_Time"}; +const std::vector DataBaseCommon::userRecords{"Username", "Password"}; const std::string DataBaseCommon::dataBasePath{"../../../source/DataBase/password-manager.db"}; -const std::string DataBaseCommon::Users{"Users"}; -const std::string DataBaseCommon::Passwords{"Passwords"}; \ No newline at end of file +const std::string DataBaseCommon::users{"Users"}; +const std::string DataBaseCommon::passwords{"Passwords"}; \ No newline at end of file diff --git a/source/DataBase/DataBaseCommon.hpp b/source/DataBase/DataBaseCommon.hpp index 4e0b1d9..0e9f5d0 100644 --- a/source/DataBase/DataBaseCommon.hpp +++ b/source/DataBase/DataBaseCommon.hpp @@ -5,10 +5,10 @@ struct DataBaseCommon { - static const std::vector UserRecord; - static const std::vector PasswordRecords; + static const std::vector userRecords; + static const std::vector passwordRecords; static const std::string dataBasePath; - static const std::string Users; - static const std::string Passwords; + static const std::string users; + static const std::string passwords; }; diff --git a/source/DataBase/DataBaseHandler.cpp b/source/DataBase/DataBaseHandler.cpp index 450a44a..9801dc7 100644 --- a/source/DataBase/DataBaseHandler.cpp +++ b/source/DataBase/DataBaseHandler.cpp @@ -70,6 +70,12 @@ void DataBaseHandler::insertData(const std::string &tableName, const std::vector executeQuery(query); } +void DataBaseHandler::deleteData(const std::string &tableName, const std::string &columns, const std::string &value) +{ + std::string query = "DELETE FROM " + tableName + " WHERE " + columns + " = '" + value + "';"; + executeQuery(query); +} + void DataBaseHandler::updateData( const std::string &tableName, const std::string &setRecord, diff --git a/source/DataBase/DataBaseHandler.hpp b/source/DataBase/DataBaseHandler.hpp index ef0d3af..2a5c697 100644 --- a/source/DataBase/DataBaseHandler.hpp +++ b/source/DataBase/DataBaseHandler.hpp @@ -15,6 +15,7 @@ class DataBaseHandler void createTable(const std::string &tableName, const std::string &columns); void insertData(const std::string &tableName, const std::vector &columns, const std::vector &values); + void deleteData(const std::string &tableName, const std::string &columns, const std::string &value); void updateData( const std::string &tableName, diff --git a/source/DataBase/password-manager.db b/source/DataBase/password-manager.db index 32ddc6430515a6121241ba749bb1d463c62c0955..ec89acd55a77991d0c3db8e29e23d7bae07a2a09 100644 GIT binary patch delta 99 zcmZoTz}Rqrae_3X#6%fqRtW~Zvd)buOXQjO4{R0`*v9W*$H>FLDGC9~$|b4ACAhF} YeoAIqWqe3xZmMfVL1qzzxyZl(0P^4=Hvj+t delta 36 scmZoTz}Rqrae_3X*hCp;Rxt)W|JscyOXN3mIQ-zB7{I=n-QcG_0NB9{9smFU diff --git a/source/main.cpp b/source/main.cpp index 9070fcb..cbfe74c 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -8,12 +8,12 @@ int main() { std::string password = "haslo"; PasswordManager passwordManager(password); - + const std::vector passwordValues{ + "1", "test", "test", "test", "test", "test", "test", "test", "Modify_Time", "Expiry_Time"}; try { DataBaseHandler dataBaseHandler(DataBaseCommon::dataBasePath); - - std::cout << "Db is working" << std::endl; + std::cout << "dataBase is working" << std::endl; } catch (const std::exception &e) {