~singpolyma/biboumi

ref: 9defd0ccb75b1905c308ed0437e5ccd479e3a7b8 biboumi/src/database/statement.hpp -rw-r--r-- 566 bytes
9defd0cc — louiz’ Add a Statement class to manage the sqlite3_stmt objects and avoid leaks 5 years ago
                                                                                
9defd0cc 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
34
35
#pragma once

#include <sqlite3.h>

class Statement
{
 public:
  Statement(sqlite3_stmt* stmt):
      stmt(stmt) {}
  ~Statement()
  {
    sqlite3_finalize(this->stmt);
  }

  Statement(const Statement&) = delete;
  Statement& operator=(const Statement&) = delete;
  Statement(Statement&& other):
      stmt(other.stmt)
  {
    other.stmt = nullptr;
  }
  Statement& operator=(Statement&& other)
  {
    this->stmt = other.stmt;
    other.stmt = nullptr;
    return *this;
  }
  sqlite3_stmt* get()
  {
    return this->stmt;
  }

 private:
  sqlite3_stmt* stmt;
};