~singpolyma/biboumi

3cd649023680bd49f9865fd62474d4db6a9d7c68 — louiz’ 4 years ago b4b9828
Remove all the ugly database debug
M src/database/insert_query.hpp => src/database/insert_query.hpp +1 -4
@@ 16,10 16,7 @@ update_autoincrement_id(std::tuple<T...>& columns, Statement& statement)
{
  using ColumnType = typename std::decay<decltype(std::get<N>(columns))>::type;
  if (std::is_same<ColumnType, Id>::value)
    {
      log_debug("EXTRACTING LAST ID");
      auto&& column = std::get<Id>(columns);
    }
    auto&& column = std::get<Id>(columns);
  update_autoincrement_id<N+1>(columns, statement);
}


M src/database/postgresql_engine.cpp => src/database/postgresql_engine.cpp +0 -3
@@ 20,7 20,6 @@ PostgresqlEngine::~PostgresqlEngine()

std::unique_ptr<DatabaseEngine> PostgresqlEngine::open(const std::string& conninfo)
{
  log_debug("trying to open: ", conninfo);
  PGconn* con = PQconnectdb(conninfo.data());

  if (!con)


@@ 47,13 46,11 @@ std::set<std::string> PostgresqlEngine::get_all_columns_from_table(const std::st
  while (statement->step() == StepResult::Row)
    columns.insert(statement->get_column_text(0));

  log_debug("found ", columns.size(), " columns.");
  return columns;
}

std::tuple<bool, std::string> PostgresqlEngine::raw_exec(const std::string& query)
{
  log_debug("raw_exec:", query);
  PGresult* res = PQexec(this->conn, query.data());
  auto sg = utils::make_scope_guard([res](){
      PQclear(res);

M src/database/postgresql_statement.hpp => src/database/postgresql_statement.hpp +2 -11
@@ 96,12 96,7 @@ private:
    params.reserve(this->params.size());

    for (const auto& param: this->params)
      {
        log_debug("param:", param);
        params.push_back(param.data());
      }

    log_debug("body: ", body);
      params.push_back(param.data());
    const int param_size = static_cast<int>(this->params.size());
    this->result = PQexecParams(this->conn, this->body.data(),
                                param_size,


@@ 111,11 106,7 @@ private:
                                nullptr,
                                0);
    const auto status = PQresultStatus(this->result);
    if (status == PGRES_TUPLES_OK)
      {
        log_debug("PGRES_TUPLES_OK");
      }
    else if (status != PGRES_COMMAND_OK)
    if (status != PGRES_TUPLES_OK && status != PGRES_COMMAND_OK)
      {
        log_error("Failed to execute command: ", PQresultErrorMessage(this->result));
        return false;

M src/database/query.cpp => src/database/query.cpp +0 -3
@@ 3,19 3,16 @@

void actual_bind(Statement& statement, const std::string& value, int index)
{
  log_debug("binding string:", value, " to col ", index);
  statement.bind_text(index, value);
}

void actual_bind(Statement& statement, const std::size_t value, int index)
{
  log_debug("binding size_t:", value);
  statement.bind_int64(index, value);
}

void actual_bind(Statement& statement, const OptionalBool& value, int index)
{
  log_debug("binding optional_t:", value.to_string());
  if (!value.is_set)
    statement.bind_int64(index, 0);
  else if (value.value)

M src/database/select_query.hpp => src/database/select_query.hpp +0 -1
@@ 115,7 115,6 @@ struct SelectQuery: public Query

      while (statement->step() == StepResult::Row)
        {
          log_debug("one result.");
          Row<T...> row(this->table_name);
          extract_row_values(row, *statement);
          rows.push_back(row);

M src/database/sqlite3_engine.cpp => src/database/sqlite3_engine.cpp +0 -5
@@ 39,9 39,6 @@ std::set<std::string> Sqlite3Engine::get_all_columns_from_table(const std::strin
      sqlite3_free(errmsg);
    }

  log_debug("List of columns in table ", table_name, ":");
  for (const auto& c: result)
    log_debug(c);
  return result;
}



@@ 74,7 71,6 @@ std::tuple<bool, std::string> Sqlite3Engine::raw_exec(const std::string& query)
std::unique_ptr<Statement> Sqlite3Engine::prepare(const std::string& query)
{
  sqlite3_stmt* stmt;
  log_debug("SQLITE3: ", query);
  auto res = sqlite3_prepare(db, query.data(), static_cast<int>(query.size()) + 1,
                             &stmt, nullptr);
  if (res != SQLITE_OK)


@@ 88,7 84,6 @@ std::unique_ptr<Statement> Sqlite3Engine::prepare(const std::string& query)
void Sqlite3Engine::extract_last_insert_rowid(Statement&)
{
  this->last_inserted_rowid = sqlite3_last_insert_rowid(this->db);
  log_debug("extracted inserted ID: ", this->last_inserted_rowid);
}

std::string Sqlite3Engine::id_column_type()

M src/database/sqlite3_statement.hpp => src/database/sqlite3_statement.hpp +0 -1
@@ 19,7 19,6 @@ class Sqlite3Statement: public Statement
  StepResult step() override final
  {
    auto res = sqlite3_step(this->get());
    log_debug("step: ", res);
    if (res == SQLITE_ROW)
      return StepResult::Row;
    else if (res == SQLITE_DONE)

M src/database/table.hpp => src/database/table.hpp +2 -13
@@ 65,11 65,10 @@ class Table
  {
    std::string query{"CREATE TABLE IF NOT EXISTS "};
    query += this->name;
    query += " (\n";
    query += " (";
    this->add_column_create(db, query);
    query += ")";

    log_debug("create:" , query);
    auto result = db.raw_exec(query);
    if (std::get<0>(result) == false)
      log_error("Error executing query: ", std::get<1>(result));


@@ 112,21 111,11 @@ class Table
  add_column_create(DatabaseEngine& db, std::string& str)
  {
    using ColumnType = typename std::remove_reference<decltype(std::get<N>(std::declval<ColumnTypes>()))>::type;
//    using RealType = typename ColumnType::real_type;
    str += ColumnType::name;
    str += " ";
//    if (std::is_same<ColumnType, Id>::value)
//      {
//        str += "INTEGER PRIMARY KEY AUTOINCREMENT";
//      }
//    else
//      {
        str += ToSQLType<ColumnType>(db);
//        append_option<ColumnType>(str);
//      }
    str += ToSQLType<ColumnType>(db);
    if (N != sizeof...(T) - 1)
      str += ",";
    str += "\n";

    add_column_create<N+1>(db, str);
  }