8 #ifndef ONTOLOGYDATABASE_H
9 #define ONTOLOGYDATABASE_H
18 const QString DBPATH_ONT =
"../../Granular-Extractor/ont_db.sqlite";
29 static QSqlDatabase mOntDB;
30 vector<string> vectorQuestionQuery(
const string &qrStr);
34 void InsertionQuery(
const string &qrStr);
35 void QuestionQuery (
const string &qrStr,
string& result);
47 QSqlDatabase OntologyDatabase::mOntDB = QSqlDatabase::addDatabase(
"QSQLITE",
"ONT_DB");
55 mOntDB.setDatabaseName (DBPATH_ONT);
56 if( !mOntDB.open() ) {
57 qDebug() << mOntDB.lastError();
58 qFatal(
"Failed to connect to database." );
59 throw std::invalid_argument(
"Error: Invalid database");
72 QSqlQuery mLiteQr(this->mOntDB);
73 mLiteQr.prepare(qrStr.c_str());
74 if( !mLiteQr.exec() ) {
75 qDebug() << mLiteQr.lastError();
76 throw std::invalid_argument(
"Invalid query.");
88 vector<string> v_result = vectorQuestionQuery (qrStr);
90 for(
string R : v_result)
93 result = result.substr (0, result.size () - 2);
105 vector<string> OntologyDatabase::vectorQuestionQuery(
const string &qrStr)
107 QSqlQuery mLiteQr(this->mOntDB);
108 mLiteQr.prepare (qrStr.c_str ());
109 if( !mLiteQr.exec() ) {
110 qDebug() << mLiteQr.lastError();
111 throw std::invalid_argument(
"Invalid query.");
114 vector<string> resultList;
116 while( mLiteQr.next() ) {
117 resultList.push_back (mLiteQr.value(0).toString().toStdString());
void QuestionQuery(const string &qrStr, string &result)
QuestionQuery.
Definition: OntologyDatabase.h:86
The OntologyDatabase class The class acts as the interface that allows communication with database...
Definition: OntologyDatabase.h:26
~OntologyDatabase()
Upper function.
Definition: OntologyDatabase.h:123
OntologyDatabase()
lower function
Definition: OntologyDatabase.h:53
void InsertionQuery(const string &qrStr)
OntologyDatabase::InsertionQuery Given a string that is a valid SQLite form The function will proceed...
Definition: OntologyDatabase.h:70