2022-09-05 20:25:39 +00:00
|
|
|
// Squawk messenger.
|
|
|
|
// Copyright (C) 2019 Yury Gubich <blue@macaw.me>
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
#ifndef CORE_DATABASE_EXCEPTIONS_H
|
|
|
|
#define CORE_DATABASE_EXCEPTIONS_H
|
|
|
|
|
2022-09-15 21:34:39 +00:00
|
|
|
#include <stdexcept>
|
|
|
|
#include <string>
|
2022-10-10 20:51:48 +00:00
|
|
|
#include <optional>
|
|
|
|
|
2022-09-05 20:25:39 +00:00
|
|
|
#include "database.h"
|
|
|
|
|
2022-09-15 21:34:39 +00:00
|
|
|
class DataBase::Exception : public std::exception
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Exception();
|
|
|
|
virtual ~Exception();
|
|
|
|
|
|
|
|
virtual std::string getMessage() const = 0;
|
|
|
|
|
|
|
|
const char* what() const noexcept( true );
|
|
|
|
};
|
|
|
|
|
|
|
|
class DataBase::Directory: public DataBase::Exception {
|
2022-09-05 20:25:39 +00:00
|
|
|
public:
|
2022-09-09 17:15:40 +00:00
|
|
|
Directory(const std::string& path);
|
2022-09-05 20:25:39 +00:00
|
|
|
|
2022-09-09 17:15:40 +00:00
|
|
|
std::string getMessage() const;
|
2022-09-05 20:25:39 +00:00
|
|
|
private:
|
|
|
|
std::string path;
|
|
|
|
};
|
|
|
|
|
2022-09-15 21:34:39 +00:00
|
|
|
class DataBase::Closed : public DataBase::Exception {
|
2022-09-05 20:25:39 +00:00
|
|
|
public:
|
2022-09-17 12:31:58 +00:00
|
|
|
Closed(const std::string& p_operation, const std::string& dbName, const std::optional<std::string>& tableName = std::nullopt);
|
2022-09-05 20:25:39 +00:00
|
|
|
|
2022-09-09 17:15:40 +00:00
|
|
|
std::string getMessage() const;
|
2022-09-05 20:25:39 +00:00
|
|
|
private:
|
|
|
|
std::string operation;
|
2022-09-09 17:15:40 +00:00
|
|
|
std::string dbName;
|
2022-09-17 12:31:58 +00:00
|
|
|
std::optional<std::string> tableName;
|
2022-09-05 20:25:39 +00:00
|
|
|
};
|
|
|
|
|
2022-09-15 21:34:39 +00:00
|
|
|
class DataBase::Opened : public DataBase::Exception {
|
2022-09-05 20:25:39 +00:00
|
|
|
public:
|
2022-09-17 12:31:58 +00:00
|
|
|
Opened(const std::string& dbName, const std::string& action);
|
2022-09-05 20:25:39 +00:00
|
|
|
|
2022-09-09 17:15:40 +00:00
|
|
|
std::string getMessage() const;
|
2022-09-05 20:25:39 +00:00
|
|
|
private:
|
2022-09-09 17:15:40 +00:00
|
|
|
std::string dbName;
|
2022-09-17 12:31:58 +00:00
|
|
|
std::string action;
|
2022-09-05 20:25:39 +00:00
|
|
|
};
|
|
|
|
|
2022-09-15 21:34:39 +00:00
|
|
|
class DataBase::NotFound : public DataBase::Exception {
|
2022-09-05 20:25:39 +00:00
|
|
|
public:
|
2022-09-09 17:15:40 +00:00
|
|
|
NotFound(const std::string& key, const std::string& dbName, const std::string& tableName);
|
2022-09-05 20:25:39 +00:00
|
|
|
|
2022-09-09 17:15:40 +00:00
|
|
|
std::string getMessage() const;
|
2022-09-05 20:25:39 +00:00
|
|
|
private:
|
|
|
|
std::string key;
|
2022-09-09 17:15:40 +00:00
|
|
|
std::string dbName;
|
|
|
|
std::string tableName;
|
2022-09-05 20:25:39 +00:00
|
|
|
};
|
|
|
|
|
2022-09-15 21:34:39 +00:00
|
|
|
class DataBase::Exist : public DataBase::Exception {
|
2022-09-05 20:25:39 +00:00
|
|
|
public:
|
2022-09-09 17:15:40 +00:00
|
|
|
Exist(const std::string& key, const std::string& dbName, const std::string& tableName);
|
2022-09-05 20:25:39 +00:00
|
|
|
|
2022-09-09 17:15:40 +00:00
|
|
|
std::string getMessage() const;
|
2022-09-05 20:25:39 +00:00
|
|
|
private:
|
|
|
|
std::string key;
|
2022-09-09 17:15:40 +00:00
|
|
|
std::string dbName;
|
|
|
|
std::string tableName;
|
2022-09-05 20:25:39 +00:00
|
|
|
};
|
|
|
|
|
2022-09-15 21:34:39 +00:00
|
|
|
class DataBase::Unknown : public DataBase::Exception {
|
2022-09-05 20:25:39 +00:00
|
|
|
public:
|
2022-09-09 17:15:40 +00:00
|
|
|
Unknown(const std::string& dbName, const std::string& message, const std::optional<std::string>& tableName = std::nullopt);
|
2022-09-05 20:25:39 +00:00
|
|
|
|
2022-09-09 17:15:40 +00:00
|
|
|
std::string getMessage() const;
|
2022-09-05 20:25:39 +00:00
|
|
|
private:
|
2022-09-09 17:15:40 +00:00
|
|
|
std::string dbName;
|
|
|
|
std::optional<std::string> tableName;
|
2022-09-05 20:25:39 +00:00
|
|
|
std::string msg;
|
|
|
|
};
|
2022-09-14 22:18:31 +00:00
|
|
|
|
2022-09-05 20:25:39 +00:00
|
|
|
#endif //CORE_DATABASE_EXCEPTIONS_H
|