~singpolyma/biboumi

ref: d7427fc9ca4c06fda458e4951559f57163d90b94 biboumi/src/database/delete_query.hpp -rw-r--r-- 652 bytes
d7427fc9 — louiz’ Re-connect to postgresql when the connection is lost 5 years ago
                                                                                
577984fa louiz’
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#pragma once

#include <database/query.hpp>
#include <database/engine.hpp>

class DeleteQuery: public Query
{
public:
  DeleteQuery(const std::string& name):
      Query("DELETE")
  {
    this->body += " from " + name;
  }

  DeleteQuery& where()
  {
    this->body += " WHERE ";
    return *this;
  };

  void execute(DatabaseEngine& db)
  {
    auto statement = db.prepare(this->body);
    if (!statement)
      return;
#ifdef DEBUG_SQL_QUERIES
    const auto timer = this->log_and_time();
#endif
    statement->bind(std::move(this->params));
    if (statement->step() != StepResult::Done)
      log_error("Failed to execute DELETE command");
  }
};