Skip to content

Commit

Permalink
Basic SQLite DataBase
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikpalatynski committed Feb 5, 2024
1 parent b959bba commit 7935011
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 11 deletions.
9 changes: 5 additions & 4 deletions source/DataBase/DataBaseCommon.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@

#include "DataBaseCommon.hpp"

const std::vector<std::string> DataBaseCommon::PasswordRecords{"User_Id", "Category", "Username", "Password", "Url", "Expire_Time"};
const std::vector<std::string> DataBaseCommon::UserRecord{"Username", "Password"};
const std::vector<std::string> DataBaseCommon::passwordRecords{
"User_Id", "Title", "Category", "Username", "Password", "Note", "Url", "Creation_Time", "Modify_Time", "Expiry_Time"};
const std::vector<std::string> 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"};
const std::string DataBaseCommon::users{"Users"};
const std::string DataBaseCommon::passwords{"Passwords"};
8 changes: 4 additions & 4 deletions source/DataBase/DataBaseCommon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

struct DataBaseCommon
{
static const std::vector<std::string> UserRecord;
static const std::vector<std::string> PasswordRecords;
static const std::vector<std::string> userRecords;
static const std::vector<std::string> 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;
};
6 changes: 6 additions & 0 deletions source/DataBase/DataBaseHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions source/DataBase/DataBaseHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> &columns, const std::vector<std::string> &values);
void deleteData(const std::string &tableName, const std::string &columns, const std::string &value);

void updateData(
const std::string &tableName,
Expand Down
Binary file modified source/DataBase/password-manager.db
Binary file not shown.
6 changes: 3 additions & 3 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ int main()
{
std::string password = "haslo";
PasswordManager passwordManager(password);

const std::vector<std::string> 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)
{
Expand Down

0 comments on commit 7935011

Please sign in to comment.