Program Listing for File SQLiteHandler.h

Return to documentation for file (necsim/SQLiteHandler.h)

// This file is part of necsim project which is released under MIT license.
// See file **LICENSE.txt** or visit https://opensource.org/licenses/MIT) for full license details.

#ifndef SQLITEHANDLER_H
#define SQLITEHANDLER_H

#include <sqlite3.h>
#include <utility>
#include <memory>

#ifdef WIN_INSTALL
#include <windows.h>
#define sleep Sleep
#else
#include <unistd.h>
#endif // WIN_INSTALL


#include "file_system.h"
#include "custom_exceptions.h"
namespace necsim
{
    struct SQLStatement
    {
    public:
        std::string last_command;
        sqlite3_stmt* stmt;

        SQLStatement();

        int step();

        void clearAndReset();

    };

    class SQLiteHandler
    {
    protected:
        sqlite3* database;
        std::string file_name;
        shared_ptr<SQLStatement> stmt;
    public:
        SQLiteHandler();

        ~SQLiteHandler();

        void open(const std::string &file_name);

        void close();

        std::string getErrorMsg(int rc);

        std::string getErrorMsg();

        void backupFrom(SQLiteHandler &sqlite_handler);

        shared_ptr<SQLStatement> prepare(const std::string &command);

        void createStatement();

        void useStatement(shared_ptr<SQLStatement> stmt);

        void step();

        void finalise();

        void execute(const string &command);

        void beginTransaction();

        void endTransaction();

        bool isOpen();

        bool hasTable(const std::string &table_name);
    };
}
#endif //SQLITEHANDLER_H