Skip to content

Commit

Permalink
refactor: use member naming convention
Browse files Browse the repository at this point in the history
  • Loading branch information
csirianni committed Oct 24, 2023
1 parent 07beb40 commit 0aeb3df
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
24 changes: 12 additions & 12 deletions backend/src/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,56 +18,56 @@ namespace

namespace database
{
Database::Database(const std::string &file_path) : is_closed(false)
Database::Database(const std::string &file_path) : is_closed_(false)
{
if (std::filesystem::exists(file_path))
{
std::remove(file_path.c_str());
}

int result = sqlite3_open_v2(file_path.c_str(), &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
int result = sqlite3_open_v2(file_path.c_str(), &db_, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
if (result != SQLITE_OK)
{
const char *error_msg = sqlite3_errmsg(db);
const char *error_msg = sqlite3_errmsg(db_);
fprintf(stderr, "SQLite error: %s\n", error_msg);
}
}

void Database::execute(const std::string &command)
{
int result = sqlite3_exec(db, command.c_str(), NULL, NULL, NULL);
int result = sqlite3_exec(db_, command.c_str(), NULL, NULL, NULL);
if (result != SQLITE_OK)
{
const char *error_msg = sqlite3_errmsg(db);
const char *error_msg = sqlite3_errmsg(db_);
fprintf(stderr, "SQLite error: %s\n", error_msg);
}
}

void Database::printTable(const std::string &table)
{
const std::string query = "SELECT * FROM " + table + ";";
int result = sqlite3_exec(db, query.c_str(), printRow, NULL, NULL);
int result = sqlite3_exec(db_, query.c_str(), printRow, NULL, NULL);
if (result != SQLITE_OK)
{
const char *error_msg = sqlite3_errmsg(db);
const char *error_msg = sqlite3_errmsg(db_);
fprintf(stderr, "SQLite error: %s\n", error_msg);
}
}

void Database::close()
{
sqlite3_close(db);
is_closed = true;
sqlite3_close(db_);
is_closed_ = true;
}

Database::~Database()
{
if (!is_closed)
if (!is_closed_)
{
int result = sqlite3_close(db);
int result = sqlite3_close(db_);
if (result != SQLITE_OK)
{
const char *error_msg = sqlite3_errmsg(db);
const char *error_msg = sqlite3_errmsg(db_);
fprintf(stderr, "SQLite error: %s\n", error_msg);
}
std::abort();
Expand Down
4 changes: 2 additions & 2 deletions backend/src/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ namespace database
~Database();

private:
sqlite3 *db;
bool is_closed;
sqlite3 *db_;
bool is_closed_;
};
}
#endif // DATABASE_H

0 comments on commit 0aeb3df

Please sign in to comment.