Add a Statement class to manage the sqlite3_stmt objects and avoid leaks

This commit is contained in:
louiz’
2017-06-14 00:19:15 +02:00
parent 41c23aab37
commit 9defd0ccb7
5 changed files with 61 additions and 22 deletions
+35
View File
@@ -0,0 +1,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;
};