WebFramework v3.0.12
Web framework for C++.
Loading...
Searching...
No Matches
SQLiteDatabase.cpp
1#include "SQLiteDatabase.h"
2
3#include "Exceptions/SQLite3Exception.h"
4
5using namespace std;
6
7namespace framework
8{
9 namespace sqlite
10 {
11 sqlite3* SQLiteDatabase::operator * ()
12 {
13 return db.get();
14 }
15
16 SQLiteDatabase::SQLiteDatabase(string_view databaseName) :
17 databaseName(databaseName)
18 {
19 sqlite3* connection = nullptr;
20
21 this->databaseName += ".sqlite";
22
23 if (sqlite3_open(this->databaseName.data(), &connection) != SQLITE_OK)
24 {
25 throw exceptions::SQLite3Exception(format("Can't open {} database", this->databaseName));
26 }
27
28 db = unique_ptr<sqlite3>(connection);
29 }
30
31 const string& SQLiteDatabase::getDatabaseName() const
32 {
33 return databaseName;
34 }
35
36 void SQLiteDatabase::close()
37 {
38 db.reset();
39 }
40
41 bool SQLiteDatabase::isOpen() const
42 {
43 return static_cast<bool>(db);
44 }
45
46 const sqlite3* const SQLiteDatabase::operator * () const
47 {
48 return db.get();
49 }
50 }
51}