Commit 3cd64902 authored by louiz’'s avatar louiz’

Remove all the ugly database debug

parent b4b9828d
...@@ -16,10 +16,7 @@ update_autoincrement_id(std::tuple<T...>& columns, Statement& statement) ...@@ -16,10 +16,7 @@ update_autoincrement_id(std::tuple<T...>& columns, Statement& statement)
{ {
using ColumnType = typename std::decay<decltype(std::get<N>(columns))>::type; using ColumnType = typename std::decay<decltype(std::get<N>(columns))>::type;
if (std::is_same<ColumnType, Id>::value) if (std::is_same<ColumnType, Id>::value)
{ auto&& column = std::get<Id>(columns);
log_debug("EXTRACTING LAST ID");
auto&& column = std::get<Id>(columns);
}
update_autoincrement_id<N+1>(columns, statement); update_autoincrement_id<N+1>(columns, statement);
} }
......
...@@ -20,7 +20,6 @@ PostgresqlEngine::~PostgresqlEngine() ...@@ -20,7 +20,6 @@ PostgresqlEngine::~PostgresqlEngine()
std::unique_ptr<DatabaseEngine> PostgresqlEngine::open(const std::string& conninfo) std::unique_ptr<DatabaseEngine> PostgresqlEngine::open(const std::string& conninfo)
{ {
log_debug("trying to open: ", conninfo);
PGconn* con = PQconnectdb(conninfo.data()); PGconn* con = PQconnectdb(conninfo.data());
if (!con) if (!con)
...@@ -47,13 +46,11 @@ std::set<std::string> PostgresqlEngine::get_all_columns_from_table(const std::st ...@@ -47,13 +46,11 @@ std::set<std::string> PostgresqlEngine::get_all_columns_from_table(const std::st
while (statement->step() == StepResult::Row) while (statement->step() == StepResult::Row)
columns.insert(statement->get_column_text(0)); columns.insert(statement->get_column_text(0));
log_debug("found ", columns.size(), " columns.");
return columns; return columns;
} }
std::tuple<bool, std::string> PostgresqlEngine::raw_exec(const std::string& query) std::tuple<bool, std::string> PostgresqlEngine::raw_exec(const std::string& query)
{ {
log_debug("raw_exec:", query);
PGresult* res = PQexec(this->conn, query.data()); PGresult* res = PQexec(this->conn, query.data());
auto sg = utils::make_scope_guard([res](){ auto sg = utils::make_scope_guard([res](){
PQclear(res); PQclear(res);
......
...@@ -96,12 +96,7 @@ private: ...@@ -96,12 +96,7 @@ private:
params.reserve(this->params.size()); params.reserve(this->params.size());
for (const auto& param: this->params) for (const auto& param: this->params)
{ params.push_back(param.data());
log_debug("param:", param);
params.push_back(param.data());
}
log_debug("body: ", body);
const int param_size = static_cast<int>(this->params.size()); const int param_size = static_cast<int>(this->params.size());
this->result = PQexecParams(this->conn, this->body.data(), this->result = PQexecParams(this->conn, this->body.data(),
param_size, param_size,
...@@ -111,11 +106,7 @@ private: ...@@ -111,11 +106,7 @@ private:
nullptr, nullptr,
0); 0);
const auto status = PQresultStatus(this->result); const auto status = PQresultStatus(this->result);
if (status == PGRES_TUPLES_OK) if (status != PGRES_TUPLES_OK && status != PGRES_COMMAND_OK)
{
log_debug("PGRES_TUPLES_OK");
}
else if (status != PGRES_COMMAND_OK)
{ {
log_error("Failed to execute command: ", PQresultErrorMessage(this->result)); log_error("Failed to execute command: ", PQresultErrorMessage(this->result));
return false; return false;
......
...@@ -3,19 +3,16 @@ ...@@ -3,19 +3,16 @@
void actual_bind(Statement& statement, const std::string& value, int index) void actual_bind(Statement& statement, const std::string& value, int index)
{ {
log_debug("binding string:", value, " to col ", index);
statement.bind_text(index, value); statement.bind_text(index, value);
} }
void actual_bind(Statement& statement, const std::size_t value, int index) void actual_bind(Statement& statement, const std::size_t value, int index)
{ {
log_debug("binding size_t:", value);
statement.bind_int64(index, value); statement.bind_int64(index, value);
} }
void actual_bind(Statement& statement, const OptionalBool& value, int index) void actual_bind(Statement& statement, const OptionalBool& value, int index)
{ {
log_debug("binding optional_t:", value.to_string());
if (!value.is_set) if (!value.is_set)
statement.bind_int64(index, 0); statement.bind_int64(index, 0);
else if (value.value) else if (value.value)
......
...@@ -115,7 +115,6 @@ struct SelectQuery: public Query ...@@ -115,7 +115,6 @@ struct SelectQuery: public Query
while (statement->step() == StepResult::Row) while (statement->step() == StepResult::Row)
{ {
log_debug("one result.");
Row<T...> row(this->table_name); Row<T...> row(this->table_name);
extract_row_values(row, *statement); extract_row_values(row, *statement);
rows.push_back(row); rows.push_back(row);
......
...@@ -39,9 +39,6 @@ std::set<std::string> Sqlite3Engine::get_all_columns_from_table(const std::strin ...@@ -39,9 +39,6 @@ std::set<std::string> Sqlite3Engine::get_all_columns_from_table(const std::strin
sqlite3_free(errmsg); sqlite3_free(errmsg);
} }
log_debug("List of columns in table ", table_name, ":");
for (const auto& c: result)
log_debug(c);
return result; return result;
} }
...@@ -74,7 +71,6 @@ std::tuple<bool, std::string> Sqlite3Engine::raw_exec(const std::string& query) ...@@ -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) std::unique_ptr<Statement> Sqlite3Engine::prepare(const std::string& query)
{ {
sqlite3_stmt* stmt; sqlite3_stmt* stmt;
log_debug("SQLITE3: ", query);
auto res = sqlite3_prepare(db, query.data(), static_cast<int>(query.size()) + 1, auto res = sqlite3_prepare(db, query.data(), static_cast<int>(query.size()) + 1,
&stmt, nullptr); &stmt, nullptr);
if (res != SQLITE_OK) if (res != SQLITE_OK)
...@@ -88,7 +84,6 @@ std::unique_ptr<Statement> Sqlite3Engine::prepare(const std::string& query) ...@@ -88,7 +84,6 @@ std::unique_ptr<Statement> Sqlite3Engine::prepare(const std::string& query)
void Sqlite3Engine::extract_last_insert_rowid(Statement&) void Sqlite3Engine::extract_last_insert_rowid(Statement&)
{ {
this->last_inserted_rowid = sqlite3_last_insert_rowid(this->db); 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() std::string Sqlite3Engine::id_column_type()
......
...@@ -19,7 +19,6 @@ class Sqlite3Statement: public Statement ...@@ -19,7 +19,6 @@ class Sqlite3Statement: public Statement
StepResult step() override final StepResult step() override final
{ {
auto res = sqlite3_step(this->get()); auto res = sqlite3_step(this->get());
log_debug("step: ", res);
if (res == SQLITE_ROW) if (res == SQLITE_ROW)
return StepResult::Row; return StepResult::Row;
else if (res == SQLITE_DONE) else if (res == SQLITE_DONE)
......
...@@ -65,11 +65,10 @@ class Table ...@@ -65,11 +65,10 @@ class Table
{ {
std::string query{"CREATE TABLE IF NOT EXISTS "}; std::string query{"CREATE TABLE IF NOT EXISTS "};
query += this->name; query += this->name;
query += " (\n"; query += " (";
this->add_column_create(db, query); this->add_column_create(db, query);
query += ")"; query += ")";
log_debug("create:" , query);
auto result = db.raw_exec(query); auto result = db.raw_exec(query);
if (std::get<0>(result) == false) if (std::get<0>(result) == false)
log_error("Error executing query: ", std::get<1>(result)); log_error("Error executing query: ", std::get<1>(result));
...@@ -112,21 +111,11 @@ class Table ...@@ -112,21 +111,11 @@ class Table
add_column_create(DatabaseEngine& db, std::string& str) add_column_create(DatabaseEngine& db, std::string& str)
{ {
using ColumnType = typename std::remove_reference<decltype(std::get<N>(std::declval<ColumnTypes>()))>::type; using ColumnType = typename std::remove_reference<decltype(std::get<N>(std::declval<ColumnTypes>()))>::type;
// using RealType = typename ColumnType::real_type;
str += ColumnType::name; str += ColumnType::name;
str += " "; str += " ";
// if (std::is_same<ColumnType, Id>::value) str += ToSQLType<ColumnType>(db);
// {
// str += "INTEGER PRIMARY KEY AUTOINCREMENT";
// }
// else
// {
str += ToSQLType<ColumnType>(db);
// append_option<ColumnType>(str);
// }
if (N != sizeof...(T) - 1) if (N != sizeof...(T) - 1)
str += ","; str += ",";
str += "\n";
add_column_create<N+1>(db, str); add_column_create<N+1>(db, str);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment