QNLP  v1.0
db_helper.cpp
Go to the documentation of this file.
1 
9 #include "db_helper.hpp"
10 
11 using namespace QNLP;
12 
13 DBHelper::DBHelper() : db_ptr(nullptr){};
14 
15 DBHelper::DBHelper(const std::string filename) : db_ptr(nullptr), db_filename(filename){
16  SQL_RETURN_CHECK ( DBHelper::openDB(filename), SQLITE_OK );
17 }
18 
21 }
22 
24  if(this->db_ptr != nullptr ){
25  // std::cout << "CLOSING " << db_filename << std::endl;
26  SQL_RETURN_CHECK ( sqlite3_close(this->db_ptr), SQLITE_OK );
27  }
28  db_filename.clear();
29  db_ptr = nullptr;
30 }
31 
32 int DBHelper::openDB(std::string filename){
33  if(this->db_ptr == nullptr){
34  this->db_filename = filename;
35  // std::cout << "OPENING " << filename << std::endl;
36  int rc = sqlite3_open_v2( (const char *) filename.c_str(), &this->db_ptr, SQLITE_OPEN_READWRITE, NULL);
37  if (rc != SQLITE_OK){
39  }
40  return rc;
41 
42  } else {
43  return 0;
44  }
45 }
46 
47 sqlite3* DBHelper::getDBRef(){
48  return this->db_ptr;
49 }
50 
51 std::string DBHelper::getFilename(){
52  return this->db_filename;
53 }
Database access and manipulation functions.
std::string db_filename
Definition: db_helper.hpp:72
void closeDB()
Closes the database if the DB pointer is open.
Definition: db_helper.cpp:23
#define SQL_RETURN_CHECK(x, y)
Definition: db_helper.hpp:19
sqlite3 * getDBRef()
Returns a pointer to the DB object.
Definition: db_helper.cpp:47
int openDB(const std::string filename)
Opens the requested database, and gives the return code of the operation. If the DB pointer has alrea...
Definition: db_helper.cpp:32
std::string getFilename()
Get the name of the opened database.
Definition: db_helper.cpp:51
sqlite3 * db_ptr
Definition: db_helper.hpp:71