2018-02-02 12:27:57 +00:00
|
|
|
#ifndef DATABASE_H
|
|
|
|
#define DATABASE_H
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "SQLite/sqlite3.h"
|
2018-02-12 14:15:04 +00:00
|
|
|
#include "model/recipe/ingredients/ingredient.h"
|
2018-03-01 16:19:13 +00:00
|
|
|
#include "resulttable.h"
|
2018-02-02 12:27:57 +00:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2018-03-01 16:19:13 +00:00
|
|
|
/**
|
|
|
|
* @brief The Database class is responsible for generic abstraction of commonly used database features.
|
|
|
|
*/
|
|
|
|
|
2018-02-02 12:27:57 +00:00
|
|
|
class Database
|
|
|
|
{
|
|
|
|
public:
|
2018-03-01 16:19:13 +00:00
|
|
|
//Creates and opens a database connection to a file of the given name. If not there, this will generate a database.
|
2018-02-02 12:27:57 +00:00
|
|
|
Database(string filename);
|
2018-03-01 16:19:13 +00:00
|
|
|
~Database();
|
2018-02-02 12:27:57 +00:00
|
|
|
|
2018-03-01 16:19:13 +00:00
|
|
|
//Executes an SQL string statement in a safe way and returns the result.
|
|
|
|
ResultTable executeSQL(string statement);
|
2018-02-12 13:24:11 +00:00
|
|
|
|
2018-03-01 16:19:13 +00:00
|
|
|
bool tableExists(string tableName);
|
2018-02-02 12:27:57 +00:00
|
|
|
private:
|
2018-02-12 13:24:11 +00:00
|
|
|
//SQL Instance variables.
|
2018-02-02 12:27:57 +00:00
|
|
|
string filename;
|
|
|
|
sqlite3* db;
|
2018-02-12 13:24:11 +00:00
|
|
|
bool dbIsOpen;
|
2018-02-02 12:27:57 +00:00
|
|
|
int returnCode;
|
|
|
|
string sql;
|
|
|
|
char* errorMsg;
|
|
|
|
|
|
|
|
void openConnection();
|
2018-03-01 16:19:13 +00:00
|
|
|
void closeConnection();
|
2018-02-02 12:27:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // DATABASE_H
|