QNLP  v1.0
QNLP::DBHelper Class Reference

#include <db_helper.hpp>

Collaboration diagram for QNLP::DBHelper:
Collaboration graph

Public Member Functions

 DBHelper ()
 
 DBHelper (const std::string filename)
 
 ~DBHelper ()
 
int openDB (const std::string filename)
 Opens the requested database, and gives the return code of the operation. If the DB pointer has already been associated with data, then the return code is 0, and no operation is performed. More...
 
void closeDB ()
 Closes the database if the DB pointer is open. More...
 
sqlite3 * getDBRef ()
 Returns a pointer to the DB object. More...
 
std::string getFilename ()
 Get the name of the opened database. More...
 

Private Attributes

sqlite3 * db_ptr
 
std::string db_filename
 

Detailed Description

Definition at line 35 of file db_helper.hpp.

Constructor & Destructor Documentation

◆ DBHelper() [1/2]

DBHelper::DBHelper ( )

Definition at line 13 of file db_helper.cpp.

13 : db_ptr(nullptr){};
sqlite3 * db_ptr
Definition: db_helper.hpp:71

◆ DBHelper() [2/2]

DBHelper::DBHelper ( const std::string  filename)

Definition at line 15 of file db_helper.cpp.

15  : db_ptr(nullptr), db_filename(filename){
16  SQL_RETURN_CHECK ( DBHelper::openDB(filename), SQLITE_OK );
17 }
std::string db_filename
Definition: db_helper.hpp:72
#define SQL_RETURN_CHECK(x, y)
Definition: db_helper.hpp:19
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
sqlite3 * db_ptr
Definition: db_helper.hpp:71

References openDB(), and SQL_RETURN_CHECK.

Here is the call graph for this function:

◆ ~DBHelper()

DBHelper::~DBHelper ( )

Definition at line 19 of file db_helper.cpp.

19  {
21 }
void closeDB()
Closes the database if the DB pointer is open.
Definition: db_helper.cpp:23

References closeDB().

Here is the call graph for this function:

Member Function Documentation

◆ closeDB()

void DBHelper::closeDB ( )

Closes the database if the DB pointer is open.

Definition at line 23 of file db_helper.cpp.

23  {
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 }
std::string db_filename
Definition: db_helper.hpp:72
#define SQL_RETURN_CHECK(x, y)
Definition: db_helper.hpp:19
sqlite3 * db_ptr
Definition: db_helper.hpp:71

References db_filename, db_ptr, and SQL_RETURN_CHECK.

Referenced by openDB(), TEST_CASE(), and ~DBHelper().

Here is the caller graph for this function:

◆ getDBRef()

sqlite3 * DBHelper::getDBRef ( )

Returns a pointer to the DB object.

Returns
sqlite3*

Definition at line 47 of file db_helper.cpp.

47  {
48  return this->db_ptr;
49 }
sqlite3 * db_ptr
Definition: db_helper.hpp:71

References db_ptr.

Referenced by TEST_CASE().

Here is the caller graph for this function:

◆ getFilename()

std::string DBHelper::getFilename ( )

Get the name of the opened database.

Returns
std::string

Definition at line 51 of file db_helper.cpp.

51  {
52  return this->db_filename;
53 }
std::string db_filename
Definition: db_helper.hpp:72

References db_filename.

Referenced by TEST_CASE().

Here is the caller graph for this function:

◆ openDB()

int DBHelper::openDB ( const std::string  filename)

Opens the requested database, and gives the return code of the operation. If the DB pointer has already been associated with data, then the return code is 0, and no operation is performed.

Parameters
stringPath to database on filesystem.
Returns
int Return code of the DB access.

Definition at line 32 of file db_helper.cpp.

32  {
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 }
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
sqlite3 * db_ptr
Definition: db_helper.hpp:71

References closeDB(), db_filename, and db_ptr.

Referenced by DBHelper(), QNLP::CorpusUtils::loadData(), and TEST_CASE().

Here is the call graph for this function:
Here is the caller graph for this function:

Field Documentation

◆ db_filename

std::string QNLP::DBHelper::db_filename
private

Definition at line 72 of file db_helper.hpp.

Referenced by closeDB(), getFilename(), and openDB().

◆ db_ptr

sqlite3* QNLP::DBHelper::db_ptr
private

Definition at line 71 of file db_helper.hpp.

Referenced by closeDB(), getDBRef(), and openDB().


The documentation for this class was generated from the following files: