diff --git a/CMakeLists.txt b/CMakeLists.txt index 6197ff043..95b8804d2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,6 +70,7 @@ set(HEADERS src/backend/JasmineGraphBackend.h src/k8s/K8sWorkerController.h src/streamingdb/StreamingSQLiteDBInterface.h src/frontend/core/executor/impl/PageRankExecutor.h + src/util/dbinterface/DBInterface.h ) set(SOURCES src/backend/JasmineGraphBackend.cpp @@ -130,6 +131,7 @@ set(SOURCES src/backend/JasmineGraphBackend.cpp src/k8s/K8sWorkerController.cpp src/streamingdb/StreamingSQLiteDBInterface.cpp src/frontend/core/executor/impl/PageRankExecutor.cpp + src/util/dbinterface/DBInterface.cpp ) add_library(JasmineGraphLib ${HEADERS} ${SOURCES}) diff --git a/src/metadb/SQLiteDBInterface.cpp b/src/metadb/SQLiteDBInterface.cpp index ab6d61a6b..af2a42724 100644 --- a/src/metadb/SQLiteDBInterface.cpp +++ b/src/metadb/SQLiteDBInterface.cpp @@ -14,8 +14,6 @@ limitations under the License. #include "SQLiteDBInterface.h" #include -#include -#include #include "../util/Utils.h" #include "../util/logger/Logger.h" @@ -45,124 +43,3 @@ int SQLiteDBInterface::init() { db_logger.info("Database opened successfully :" + this->databaseLocation); return 0; } - -int SQLiteDBInterface::finalize() { return sqlite3_close(database); } - - -typedef vector>> table_type; - -static int callback(void *ptr, int argc, char **argv, char **azColName) { - int i; - table_type *dbResults = static_cast(ptr); - vector> results; - - for (i = 0; i < argc; i++) { - results.push_back(make_pair(azColName[i], argv[i] ? argv[i] : "NULL")); - // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL"); - } - dbResults->push_back(results); - return 0; -} - -vector>> SQLiteDBInterface::runSelect(std::string query) { - char *zErrMsg = 0; - vector>> dbResults; - - if (sqlite3_exec(database, query.c_str(), callback, &dbResults, &zErrMsg) != SQLITE_OK) { - db_logger.log("SQL Error: " + string(zErrMsg) + " " + query, "error"); - sqlite3_free(zErrMsg); - } else { - db_logger.log("Operation done successfully", "info"); - } - return dbResults; -} - -// This function inserts a new row to the DB and returns the last inserted row id -// returns -1 on error -int SQLiteDBInterface::runInsert(std::string query) { - char *zErrMsg = 0; - int rc = sqlite3_exec(database, query.c_str(), NULL, NULL, &zErrMsg); - if (rc != SQLITE_OK) { - db_logger.log("SQL Error: " + string(zErrMsg) + " " + query, "error"); - sqlite3_free(zErrMsg); - return -1; - } - db_logger.log("Insert operation done successfully", "info"); - vector>> dbResults; - string q2 = "SELECT last_insert_rowid();"; - - int rc2 = sqlite3_exec(database, q2.c_str(), callback, &dbResults, &zErrMsg); - - if (rc2 != SQLITE_OK) { - db_logger.log("SQL Error: " + string(zErrMsg) + " " + query, "error"); - sqlite3_free(zErrMsg); - return -1; - } - return std::stoi(dbResults[0][0].second); -} - -// This function inserts one or more rows of the DB and nothing is returned -// This is used for inserting tables which do not have primary IDs -void SQLiteDBInterface::runInsertNoIDReturn(std::string query) { - char *zErrMsg = 0; - int rc = sqlite3_exec(database, query.c_str(), NULL, NULL, &zErrMsg); - if (rc != SQLITE_OK) { - db_logger.log("SQL Error: " + string(zErrMsg) + " " + query, "error"); - sqlite3_free(zErrMsg); - } else { - db_logger.log("Insert operation done successfully: " + query, "info"); - } -} - -// This function updates one or more rows of the DB -void SQLiteDBInterface::runUpdate(std::string query) { - char *zErrMsg = 0; - - int rc = sqlite3_exec(database, query.c_str(), NULL, NULL, &zErrMsg); - - if (rc != SQLITE_OK) { - db_logger.log("SQL Error: " + string(zErrMsg) + " " + query, "error"); - sqlite3_free(zErrMsg); - } else { - db_logger.log("Update operation done successfully: " + query, "info"); - } -} - -int SQLiteDBInterface::RunSqlNoCallback(const char *zSql) { - sqlite3_stmt *stmt = NULL; - int rc = sqlite3_prepare_v2(database, zSql, -1, &stmt, NULL); - if (rc != SQLITE_OK) return rc; - - int rowCount = 0; - rc = sqlite3_step(stmt); - while (rc != SQLITE_DONE && rc != SQLITE_OK) { - rowCount++; - int colCount = sqlite3_column_count(stmt); - for (int colIndex = 0; colIndex < colCount; colIndex++) { - int type = sqlite3_column_type(stmt, colIndex); - const char *columnName = sqlite3_column_name(stmt, colIndex); - if (type == SQLITE_INTEGER) { - int valInt = sqlite3_column_int(stmt, colIndex); - printf("columnName = %s, Integer val = %d", columnName, valInt); - } else if (type == SQLITE_FLOAT) { - double valDouble = sqlite3_column_double(stmt, colIndex); - printf("columnName = %s,Double val = %f", columnName, valDouble); - } else if (type == SQLITE_TEXT) { - const unsigned char *valChar = sqlite3_column_text(stmt, colIndex); - printf("columnName = %s,Text val = %s", columnName, valChar); - // free((void *) valChar); - } else if (type == SQLITE_BLOB) { - printf("columnName = %s,BLOB", columnName); - } else if (type == SQLITE_NULL) { - printf("columnName = %s,NULL", columnName); - } - } - printf("Line %d, rowCount = %d", rowCount, colCount); - - rc = sqlite3_step(stmt); - } - - rc = sqlite3_finalize(stmt); - - return rc; -} diff --git a/src/metadb/SQLiteDBInterface.h b/src/metadb/SQLiteDBInterface.h index ce1d4ba6e..7b4664a4b 100644 --- a/src/metadb/SQLiteDBInterface.h +++ b/src/metadb/SQLiteDBInterface.h @@ -19,28 +19,13 @@ limitations under the License. #include #include #include +#include "../util/dbinterface/DBInterface.h" -class SQLiteDBInterface { - private: - sqlite3 *database; - std::string databaseLocation; - +class SQLiteDBInterface : public DBInterface { public: explicit SQLiteDBInterface(std::string databaseLocation); - int init(); - - int finalize(); - - std::vector>> runSelect(std::string); - - int runInsert(std::string); - - void runUpdate(std::string); - - void runInsertNoIDReturn(std::string); - - int RunSqlNoCallback(const char *zSql); + int init() override; SQLiteDBInterface(); }; diff --git a/src/performancedb/PerformanceSQLiteDBInterface.cpp b/src/performancedb/PerformanceSQLiteDBInterface.cpp index 8b9638974..f89b72c26 100644 --- a/src/performancedb/PerformanceSQLiteDBInterface.cpp +++ b/src/performancedb/PerformanceSQLiteDBInterface.cpp @@ -38,8 +38,6 @@ int PerformanceSQLiteDBInterface::init() { return 0; } -int PerformanceSQLiteDBInterface::finalize() { return sqlite3_close(database); } - PerformanceSQLiteDBInterface::PerformanceSQLiteDBInterface() { this->databaseLocation = Utils::getJasmineGraphProperty("org.jasminegraph.performance.db.location"); } @@ -47,124 +45,3 @@ PerformanceSQLiteDBInterface::PerformanceSQLiteDBInterface() { PerformanceSQLiteDBInterface::PerformanceSQLiteDBInterface(string databaseLocation) { this->databaseLocation = databaseLocation; } - -typedef vector>> table_type; - -static int callback(void *ptr, int argc, char **argv, char **azColName) { - int i; - table_type *dbResults = static_cast(ptr); - vector> results; - - for (i = 0; i < argc; i++) { - results.push_back(make_pair(azColName[i], argv[i] ? argv[i] : "NULL")); - // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL"); - } - dbResults->push_back(results); - return 0; -} - -vector>> PerformanceSQLiteDBInterface::runSelect(std::string query) { - char *zErrMsg = 0; - int rc; - vector>> dbResults; - - rc = sqlite3_exec(database, query.c_str(), callback, &dbResults, &zErrMsg); - - if (rc != SQLITE_OK) { - perfdb_logger.log("SQL Error: " + string(zErrMsg), "error"); - perfdb_logger.error("SQL Error: " + string(zErrMsg)); - sqlite3_free(zErrMsg); - } else { - perfdb_logger.info("Operation done successfully"); - } - return dbResults; -} - -// This function inserts a new row to the DB and returns the last inserted row id -int PerformanceSQLiteDBInterface::runInsert(std::string query) { - char *zErrMsg = 0; - int rc = sqlite3_exec(database, query.c_str(), NULL, NULL, &zErrMsg); - if (rc != SQLITE_OK) { - perfdb_logger.log("SQL Error: " + string(zErrMsg), "error"); - sqlite3_free(zErrMsg); - return -1; - } - perfdb_logger.log("Insert operation done successfully", "info"); - vector>> dbResults; - string q2 = "SELECT last_insert_rowid();"; - - int rc2 = sqlite3_exec(database, q2.c_str(), callback, &dbResults, &zErrMsg); - - if (rc2 != SQLITE_OK) { - fprintf(stderr, "SQL error: %s\n", zErrMsg); - sqlite3_free(zErrMsg); - return -1; - } - return std::stoi(dbResults[0][0].second); -} - -// This function inserts one or more rows of the DB and nothing is returned -// This is used for inserting tables which do not have primary IDs -void PerformanceSQLiteDBInterface::runInsertNoIDReturn(std::string query) { - char *zErrMsg = 0; - int rc = sqlite3_exec(database, query.c_str(), NULL, NULL, &zErrMsg); - if (rc != SQLITE_OK) { - perfdb_logger.log("SQL Error: " + string(zErrMsg), "error"); - sqlite3_free(zErrMsg); - } else { - perfdb_logger.log("Insert operation done successfully", "info"); - } -} - -// This function updates one or more rows of the DB -void PerformanceSQLiteDBInterface::runUpdate(std::string query) { - char *zErrMsg = 0; - - int rc = sqlite3_exec(database, query.c_str(), NULL, NULL, &zErrMsg); - - if (rc != SQLITE_OK) { - perfdb_logger.log("SQL Error: " + string(zErrMsg), "error"); - sqlite3_free(zErrMsg); - } else { - perfdb_logger.log("Update operation done successfully", "info"); - } -} - -int PerformanceSQLiteDBInterface::RunSqlNoCallback(const char *zSql) { - sqlite3_stmt *stmt = NULL; - int rc = sqlite3_prepare_v2(database, zSql, -1, &stmt, NULL); - if (rc != SQLITE_OK) return rc; - - int rowCount = 0; - rc = sqlite3_step(stmt); - while (rc != SQLITE_DONE && rc != SQLITE_OK) { - rowCount++; - int colCount = sqlite3_column_count(stmt); - for (int colIndex = 0; colIndex < colCount; colIndex++) { - int type = sqlite3_column_type(stmt, colIndex); - const char *columnName = sqlite3_column_name(stmt, colIndex); - if (type == SQLITE_INTEGER) { - int valInt = sqlite3_column_int(stmt, colIndex); - printf("columnName = %s, Integer val = %d", columnName, valInt); - } else if (type == SQLITE_FLOAT) { - double valDouble = sqlite3_column_double(stmt, colIndex); - printf("columnName = %s,Double val = %f", columnName, valDouble); - } else if (type == SQLITE_TEXT) { - const unsigned char *valChar = sqlite3_column_text(stmt, colIndex); - printf("columnName = %s,Text val = %s", columnName, valChar); - // free((void *) valChar); - } else if (type == SQLITE_BLOB) { - printf("columnName = %s,BLOB", columnName); - } else if (type == SQLITE_NULL) { - printf("columnName = %s,NULL", columnName); - } - } - printf("Line %d, rowCount = %d", rowCount, colCount); - - rc = sqlite3_step(stmt); - } - - rc = sqlite3_finalize(stmt); - - return rc; -} diff --git a/src/performancedb/PerformanceSQLiteDBInterface.h b/src/performancedb/PerformanceSQLiteDBInterface.h index 85c74e92c..1d6b3ae1e 100644 --- a/src/performancedb/PerformanceSQLiteDBInterface.h +++ b/src/performancedb/PerformanceSQLiteDBInterface.h @@ -19,26 +19,11 @@ limitations under the License. #include #include #include +#include "../util/dbinterface/DBInterface.h" -class PerformanceSQLiteDBInterface { - private: - sqlite3 *database; - std::string databaseLocation; - +class PerformanceSQLiteDBInterface : public DBInterface { public: - int init(); - - int finalize(); - - std::vector>> runSelect(std::string); - - int runInsert(std::string); - - void runUpdate(std::string); - - void runInsertNoIDReturn(std::string); - - int RunSqlNoCallback(const char *zSql); + int init() override; PerformanceSQLiteDBInterface(); diff --git a/src/streamingdb/StreamingSQLiteDBInterface.cpp b/src/streamingdb/StreamingSQLiteDBInterface.cpp index a85033623..cf57f537b 100644 --- a/src/streamingdb/StreamingSQLiteDBInterface.cpp +++ b/src/streamingdb/StreamingSQLiteDBInterface.cpp @@ -39,8 +39,6 @@ int StreamingSQLiteDBInterface::init() { } } -int StreamingSQLiteDBInterface::finalize() { return sqlite3_close(database); } - StreamingSQLiteDBInterface::StreamingSQLiteDBInterface() { this->databaseLocation = Utils::getJasmineGraphProperty("org.jasminegraph.streaming.db.location"); } @@ -48,125 +46,3 @@ StreamingSQLiteDBInterface::StreamingSQLiteDBInterface() { StreamingSQLiteDBInterface::StreamingSQLiteDBInterface(string databaseLocation) { this->databaseLocation = databaseLocation; } - -typedef vector>> table_type; - -static int callback(void *ptr, int argc, char **argv, char **azColName) { - int i; - table_type *dbResults = static_cast(ptr); - vector> results; - - for (i = 0; i < argc; i++) { - results.push_back(make_pair(azColName[i], argv[i] ? argv[i] : "NULL")); - // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL"); - } - dbResults->push_back(results); - return 0; -} - -vector>> StreamingSQLiteDBInterface::runSelect(std::string query) { - char *zErrMsg = 0; - int rc; - vector>> dbResults; - - rc = sqlite3_exec(database, query.c_str(), callback, &dbResults, &zErrMsg); - - if (rc != SQLITE_OK) { - streamdb_logger.error("SQL Error: " + string(zErrMsg)); - sqlite3_free(zErrMsg); - } else { - streamdb_logger.info("Operation done successfully"); - } - return dbResults; -} - -// This function inserts a new row to the DB and returns the last inserted row id -int StreamingSQLiteDBInterface::runInsert(std::string query) { - char *zErrMsg = 0; - int rc = sqlite3_exec(database, query.c_str(), NULL, NULL, &zErrMsg); - if (rc != SQLITE_OK) { - streamdb_logger.error("SQL Error: " + string(zErrMsg)); - sqlite3_free(zErrMsg); - return -1; - } else { - streamdb_logger.info("Insert operation done successfully"); - vector>> dbResults; - string q2 = "SELECT last_insert_rowid();"; - - int rc2 = sqlite3_exec(database, q2.c_str(), callback, &dbResults, &zErrMsg); - - if (rc2 != SQLITE_OK) { - fprintf(stderr, "SQL error: %s\n", zErrMsg); - sqlite3_free(zErrMsg); - return -1; - } else { - return std::stoi(dbResults[0][0].second); - } - } -} - -// This function inserts one or more rows of the DB and nothing is returned -// This is used for inserting tables which do not have primary IDs -void StreamingSQLiteDBInterface::runInsertNoIDReturn(std::string query) { - char *zErrMsg = 0; - int rc = sqlite3_exec(database, query.c_str(), NULL, NULL, &zErrMsg); - if (rc != SQLITE_OK) { - streamdb_logger.error("SQL Error: " + string(zErrMsg)); - sqlite3_free(zErrMsg); - } else { - streamdb_logger.info("Insert operation done successfully"); - } -} - -// This function updates one or more rows of the DB -void StreamingSQLiteDBInterface::runUpdate(std::string query) { - char *zErrMsg = 0; - - int rc = sqlite3_exec(database, query.c_str(), NULL, NULL, &zErrMsg); - - if (rc != SQLITE_OK) { - streamdb_logger.error("SQL Error: " + string(zErrMsg)); - sqlite3_free(zErrMsg); - } else { - streamdb_logger.info("Update operation done successfully"); - } -} - -int StreamingSQLiteDBInterface::RunSqlNoCallback(const char *zSql) { - sqlite3_stmt *stmt = NULL; - int rc = sqlite3_prepare_v2(database, zSql, -1, &stmt, NULL); - if (rc != SQLITE_OK) return rc; - - int rowCount = 0; - rc = sqlite3_step(stmt); - while (rc != SQLITE_DONE && rc != SQLITE_OK) { - rowCount++; - int colCount = sqlite3_column_count(stmt); - for (int colIndex = 0; colIndex < colCount; colIndex++) { - int type = sqlite3_column_type(stmt, colIndex); - const char *columnName = sqlite3_column_name(stmt, colIndex); - if (type == SQLITE_INTEGER) { - int valInt = sqlite3_column_int(stmt, colIndex); - printf("columnName = %s, Integer val = %d", columnName, valInt); - } else if (type == SQLITE_FLOAT) { - double valDouble = sqlite3_column_double(stmt, colIndex); - printf("columnName = %s,Double val = %f", columnName, valDouble); - } else if (type == SQLITE_TEXT) { - const unsigned char *valChar = sqlite3_column_text(stmt, colIndex); - printf("columnName = %s,Text val = %s", columnName, valChar); - // free((void *) valChar); - } else if (type == SQLITE_BLOB) { - printf("columnName = %s,BLOB", columnName); - } else if (type == SQLITE_NULL) { - printf("columnName = %s,NULL", columnName); - } - } - printf("Line %d, rowCount = %d", rowCount, colCount); - - rc = sqlite3_step(stmt); - } - - rc = sqlite3_finalize(stmt); - - return rc; -} diff --git a/src/streamingdb/StreamingSQLiteDBInterface.h b/src/streamingdb/StreamingSQLiteDBInterface.h index d17b43f5e..1f3ac37eb 100644 --- a/src/streamingdb/StreamingSQLiteDBInterface.h +++ b/src/streamingdb/StreamingSQLiteDBInterface.h @@ -19,28 +19,14 @@ limitations under the License. #include #include #include +#include "../util/dbinterface/DBInterface.h" -class StreamingSQLiteDBInterface { - private: - sqlite3 *database; - std::string databaseLocation; - +class StreamingSQLiteDBInterface : public DBInterface { public: - int init(); - - int finalize(); - - std::vector>> runSelect(std::string); - - int runInsert(std::string); - - void runUpdate(std::string); - - void runInsertNoIDReturn(std::string); - - int RunSqlNoCallback(const char *zSql); + int init() override; StreamingSQLiteDBInterface(); + StreamingSQLiteDBInterface(std::string databaseLocation); }; diff --git a/src/util/dbinterface/DBInterface.cpp b/src/util/dbinterface/DBInterface.cpp new file mode 100644 index 000000000..11a296057 --- /dev/null +++ b/src/util/dbinterface/DBInterface.cpp @@ -0,0 +1,126 @@ +/** +Copyright 2024 JasmineGraph Team +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + */ + +#include "DBInterface.h" +#include "../logger/Logger.h" + +Logger interface_logger; + +int DBInterface::finalize() { + return sqlite3_close(database); +} + +typedef vector>> table_type; + +static int callback(void *ptr, int argc, char **argv, char **columnName) { + table_type *dbResults = static_cast(ptr); + vector> results; + + for (int i = 0; i < argc; i++) { + results.push_back(make_pair(columnName[i], argv[i] ? argv[i] : "NULL")); + } + dbResults->push_back(results); + return 0; +} + +vector>> DBInterface::runSelect(string query) { + char *errorMessage = 0; + vector>> dbResults; + + if (sqlite3_exec(database, query.c_str(), callback, &dbResults, &errorMessage) != SQLITE_OK) { + interface_logger.error("SQL Error: " + string(errorMessage) + " " + query); + sqlite3_free(errorMessage); + } + return dbResults; +} + +// This function inserts a new row to the DB and returns the last inserted row id +// returns -1 on error +int DBInterface::runInsert(std::string query) { + char *errorMessage = 0; + int rc = sqlite3_exec(database, query.c_str(), NULL, NULL, &errorMessage); + if (rc != SQLITE_OK) { + interface_logger.error("SQL Error: " + string(errorMessage) + " " + query); + sqlite3_free(errorMessage); + return -1; + } + vector>> dbResults; + string q2 = "SELECT last_insert_rowid();"; + + int rc2 = sqlite3_exec(database, q2.c_str(), callback, &dbResults, &errorMessage); + + if (rc2 != SQLITE_OK) { + interface_logger.error("SQL Error: " + string(errorMessage) + " " + query); + sqlite3_free(errorMessage); + return -1; + } + + if (dbResults.empty() || dbResults[0].empty()) { + return -1; + } + return std::stoi(dbResults[0][0].second); +} + +// This function inserts one or more rows of the DB and nothing is returned +// This is used for inserting tables which do not have primary IDs +void DBInterface::runInsertNoIDReturn(std::string query) { + char *errorMessage = 0; + int rc = sqlite3_exec(database, query.c_str(), NULL, NULL, &errorMessage); + if (rc != SQLITE_OK) { + interface_logger.error("SQL Error: " + string(errorMessage) + " " + query); + sqlite3_free(errorMessage); + } +} + +// This function updates one or more rows of the DB +void DBInterface::runUpdate(std::string query) { + char *errorMessage = 0; + + int rc = sqlite3_exec(database, query.c_str(), NULL, NULL, &errorMessage); + + if (rc != SQLITE_OK) { + interface_logger.error("SQL Error: " + string(errorMessage) + " " + query); + sqlite3_free(errorMessage); + } +} + +int DBInterface::runSqlNoCallback(const char *zSql) { + sqlite3_stmt *stmt = NULL; + int rc = sqlite3_prepare_v2(database, zSql, -1, &stmt, NULL); + if (rc != SQLITE_OK) return rc; + + int rowCount = 0; + rc = sqlite3_step(stmt); + while (rc != SQLITE_DONE && rc != SQLITE_OK) { + rowCount++; + int colCount = sqlite3_column_count(stmt); + for (int colIndex = 0; colIndex < colCount; colIndex++) { + int type = sqlite3_column_type(stmt, colIndex); + const char *columnName = sqlite3_column_name(stmt, colIndex); + if (type == SQLITE_INTEGER) { + int valInt = sqlite3_column_int(stmt, colIndex); + } else if (type == SQLITE_FLOAT) { + double valDouble = sqlite3_column_double(stmt, colIndex); + } else if (type == SQLITE_TEXT) { + const unsigned char *valChar = sqlite3_column_text(stmt, colIndex); + } + } + interface_logger.info("Line " + std::to_string(rowCount) + ", rowCount " + std::to_string(colCount)); + + rc = sqlite3_step(stmt); + } + + rc = sqlite3_finalize(stmt); + + return rc; +} diff --git a/src/util/dbinterface/DBInterface.h b/src/util/dbinterface/DBInterface.h new file mode 100644 index 000000000..f434a7119 --- /dev/null +++ b/src/util/dbinterface/DBInterface.h @@ -0,0 +1,44 @@ +/** +Copyright 2024 JasmineGraph Team +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + */ + +#ifndef JASMINEGRAPH_SRC_UTIL_DBINTERFACE_H_ +#define JASMINEGRAPH_SRC_UTIL_DBINTERFACE_H_ + +#include +#include +#include + +using namespace std; + +class DBInterface { + protected: + sqlite3 *database; + std::string databaseLocation; + + public: + virtual int init() = 0; + + int finalize(); + + std::vector>> runSelect(std::string); + + int runInsert(std::string); + + void runUpdate(std::string); + + void runInsertNoIDReturn(std::string); + + int runSqlNoCallback(const char *zSql); +}; + +#endif // JASMINEGRAPH_SRC_UTIL_DBINTERFACE_H_