feature/documentation #12

Merged
cromer merged 26 commits from feature/documentation into develop 2023-02-03 23:21:29 -03:00
5 changed files with 102 additions and 144 deletions
Showing only changes of commit 74de3c67c0 - Show all commits

View File

@ -93,7 +93,7 @@ void obelisk::KnowledgeBase::addEntities(std::vector<obelisk::Entity>& entities)
{ {
entity.insertEntity(dbConnection_); entity.insertEntity(dbConnection_);
} }
catch (obelisk::DatabaseException::ConstraintException& exception) catch (obelisk::DatabaseConstraintException& exception)
{ {
// ignore unique constraint error // ignore unique constraint error
if (std::strcmp(exception.what(), if (std::strcmp(exception.what(),
@ -114,7 +114,7 @@ void obelisk::KnowledgeBase::addVerbs(std::vector<obelisk::Verb>& verbs)
{ {
verb.insertVerb(dbConnection_); verb.insertVerb(dbConnection_);
} }
catch (obelisk::DatabaseException::ConstraintException& exception) catch (obelisk::DatabaseConstraintException& exception)
{ {
// ignore unique constraint error // ignore unique constraint error
if (std::strcmp(exception.what(), if (std::strcmp(exception.what(),
@ -135,7 +135,7 @@ void obelisk::KnowledgeBase::addFacts(std::vector<obelisk::Fact>& facts)
{ {
fact.insertFact(dbConnection_); fact.insertFact(dbConnection_);
} }
catch (obelisk::DatabaseException::ConstraintException& exception) catch (obelisk::DatabaseConstraintException& exception)
{ {
// ignore unique constraint error // ignore unique constraint error
if (std::strcmp(exception.what(), if (std::strcmp(exception.what(),

View File

@ -38,13 +38,13 @@ void obelisk::Entity::selectEntity(sqlite3* dbConnection)
case SQLITE_OK : case SQLITE_OK :
break; break;
case SQLITE_TOOBIG : case SQLITE_TOOBIG :
throw obelisk::DatabaseException::SizeException(); throw obelisk::DatabaseSizeException();
break; break;
case SQLITE_RANGE : case SQLITE_RANGE :
throw obelisk::DatabaseException::RangeException(); throw obelisk::DatabaseRangeException();
break; break;
case SQLITE_NOMEM : case SQLITE_NOMEM :
throw obelisk::DatabaseException::MemoryException(); throw obelisk::DatabaseMemoryException();
break; break;
default : default :
throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection)); throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection));
@ -62,10 +62,10 @@ void obelisk::Entity::selectEntity(sqlite3* dbConnection)
setName((char*) sqlite3_column_text(ppStmt, 1)); setName((char*) sqlite3_column_text(ppStmt, 1));
break; break;
case SQLITE_BUSY : case SQLITE_BUSY :
throw obelisk::DatabaseException::BusyException(); throw obelisk::DatabaseBusyException();
break; break;
case SQLITE_MISUSE : case SQLITE_MISUSE :
throw obelisk::DatabaseException::MisuseException(); throw obelisk::DatabaseMisuseException();
break; break;
default : default :
throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection)); throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection));
@ -106,13 +106,13 @@ void obelisk::Entity::insertEntity(sqlite3* dbConnection)
case SQLITE_OK : case SQLITE_OK :
break; break;
case SQLITE_TOOBIG : case SQLITE_TOOBIG :
throw obelisk::DatabaseException::SizeException(); throw obelisk::DatabaseSizeException();
break; break;
case SQLITE_RANGE : case SQLITE_RANGE :
throw obelisk::DatabaseException::RangeException(); throw obelisk::DatabaseRangeException();
break; break;
case SQLITE_NOMEM : case SQLITE_NOMEM :
throw obelisk::DatabaseException::MemoryException(); throw obelisk::DatabaseMemoryException();
break; break;
default : default :
throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection)); throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection));
@ -127,13 +127,13 @@ void obelisk::Entity::insertEntity(sqlite3* dbConnection)
sqlite3_set_last_insert_rowid(dbConnection, 0); sqlite3_set_last_insert_rowid(dbConnection, 0);
break; break;
case SQLITE_CONSTRAINT : case SQLITE_CONSTRAINT :
throw obelisk::DatabaseException::ConstraintException( throw obelisk::DatabaseConstraintException(
sqlite3_errmsg(dbConnection)); sqlite3_errmsg(dbConnection));
case SQLITE_BUSY : case SQLITE_BUSY :
throw obelisk::DatabaseException::BusyException(); throw obelisk::DatabaseBusyException();
break; break;
case SQLITE_MISUSE : case SQLITE_MISUSE :
throw obelisk::DatabaseException::MisuseException(); throw obelisk::DatabaseMisuseException();
break; break;
default : default :
throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection)); throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection));

View File

@ -8,8 +8,8 @@ namespace obelisk
{ {
class DatabaseException : public std::exception class DatabaseException : public std::exception
{ {
private: protected:
const std::string errorMessage_; std::string errorMessage_;
public: public:
DatabaseException() : DatabaseException() :
@ -28,118 +28,76 @@ namespace obelisk
{ {
} }
const char* what() const noexcept virtual const char* what() const noexcept
{ {
return errorMessage_.c_str(); return errorMessage_.c_str();
} }
class SizeException : public std::exception virtual void setErrorMessage(const std::string errorMessage)
{ {
private: errorMessage_ = errorMessage;
const std::string errorMessage_;
public:
SizeException() :
errorMessage_("size of string or blob exceeds limits")
{
}
const char* what() const noexcept
{
return errorMessage_.c_str();
} }
}; };
class RangeException : public std::exception class DatabaseSizeException : public obelisk::DatabaseException
{ {
private:
const std::string errorMessage_;
public: public:
RangeException() : DatabaseSizeException()
errorMessage_("parameter index is out of range")
{ {
} setErrorMessage("size of string or blob exceeds limits");
const char* what() const noexcept
{
return errorMessage_.c_str();
} }
}; };
class MemoryException : public std::exception class DatabaseRangeException : public obelisk::DatabaseException
{ {
private:
const std::string errorMessage_;
public: public:
MemoryException() : DatabaseRangeException()
errorMessage_("not enough memory for operation")
{ {
} setErrorMessage("parameter index is out of range");
const char* what() const noexcept
{
return errorMessage_.c_str();
} }
}; };
class BusyException : public std::exception class DatabaseMemoryException : public obelisk::DatabaseException
{ {
private:
const std::string errorMessage_;
public: public:
BusyException() : DatabaseMemoryException()
errorMessage_(
"database was busy and operation not performed")
{ {
} setErrorMessage("not enough memory for operation");
const char* what() const noexcept
{
return errorMessage_.c_str();
} }
}; };
class MisuseException : public std::exception class DatabaseBusyException : public obelisk::DatabaseException
{ {
private:
const std::string errorMessage_;
public: public:
MisuseException() : DatabaseBusyException()
errorMessage_("misuse of the database routine")
{ {
} setErrorMessage(
"database was busy and operation was not performed");
const char* what() const noexcept
{
return errorMessage_.c_str();
} }
}; };
class ConstraintException : public std::exception class DatabaseMisuseException : public obelisk::DatabaseException
{ {
private:
const std::string errorMessage_;
public: public:
ConstraintException() : DatabaseMisuseException()
errorMessage_("a constraint exception occurred")
{
}
ConstraintException(const std::string& errorMessage) :
errorMessage_(errorMessage)
{ {
} setErrorMessage("misuse of the database routine");
const char* what() const noexcept
{
return errorMessage_.c_str();
} }
}; };
class DatabaseConstraintException : public obelisk::DatabaseException
{
public:
DatabaseConstraintException()
{
setErrorMessage("a constraint exception occurred");
}
DatabaseConstraintException(const std::string& errorMessage)
{
setErrorMessage(errorMessage);
}
}; };
} // namespace obelisk } // namespace obelisk

View File

@ -43,13 +43,13 @@ void obelisk::Fact::selectFact(sqlite3* dbConnection)
case SQLITE_OK : case SQLITE_OK :
break; break;
case SQLITE_TOOBIG : case SQLITE_TOOBIG :
throw obelisk::DatabaseException::SizeException(); throw obelisk::DatabaseSizeException();
break; break;
case SQLITE_RANGE : case SQLITE_RANGE :
throw obelisk::DatabaseException::RangeException(); throw obelisk::DatabaseRangeException();
break; break;
case SQLITE_NOMEM : case SQLITE_NOMEM :
throw obelisk::DatabaseException::MemoryException(); throw obelisk::DatabaseMemoryException();
break; break;
default : default :
throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection)); throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection));
@ -62,13 +62,13 @@ void obelisk::Fact::selectFact(sqlite3* dbConnection)
case SQLITE_OK : case SQLITE_OK :
break; break;
case SQLITE_TOOBIG : case SQLITE_TOOBIG :
throw obelisk::DatabaseException::SizeException(); throw obelisk::DatabaseSizeException();
break; break;
case SQLITE_RANGE : case SQLITE_RANGE :
throw obelisk::DatabaseException::RangeException(); throw obelisk::DatabaseRangeException();
break; break;
case SQLITE_NOMEM : case SQLITE_NOMEM :
throw obelisk::DatabaseException::MemoryException(); throw obelisk::DatabaseMemoryException();
break; break;
default : default :
throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection)); throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection));
@ -81,13 +81,13 @@ void obelisk::Fact::selectFact(sqlite3* dbConnection)
case SQLITE_OK : case SQLITE_OK :
break; break;
case SQLITE_TOOBIG : case SQLITE_TOOBIG :
throw obelisk::DatabaseException::SizeException(); throw obelisk::DatabaseSizeException();
break; break;
case SQLITE_RANGE : case SQLITE_RANGE :
throw obelisk::DatabaseException::RangeException(); throw obelisk::DatabaseRangeException();
break; break;
case SQLITE_NOMEM : case SQLITE_NOMEM :
throw obelisk::DatabaseException::MemoryException(); throw obelisk::DatabaseMemoryException();
break; break;
default : default :
throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection)); throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection));
@ -107,10 +107,10 @@ void obelisk::Fact::selectFact(sqlite3* dbConnection)
getVerb().setId(sqlite3_column_int(ppStmt, 3)); getVerb().setId(sqlite3_column_int(ppStmt, 3));
break; break;
case SQLITE_BUSY : case SQLITE_BUSY :
throw obelisk::DatabaseException::BusyException(); throw obelisk::DatabaseBusyException();
break; break;
case SQLITE_MISUSE : case SQLITE_MISUSE :
throw obelisk::DatabaseException::MisuseException(); throw obelisk::DatabaseMisuseException();
break; break;
default : default :
throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection)); throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection));
@ -149,13 +149,13 @@ void obelisk::Fact::insertFact(sqlite3* dbConnection)
case SQLITE_OK : case SQLITE_OK :
break; break;
case SQLITE_TOOBIG : case SQLITE_TOOBIG :
throw obelisk::DatabaseException::SizeException(); throw obelisk::DatabaseSizeException();
break; break;
case SQLITE_RANGE : case SQLITE_RANGE :
throw obelisk::DatabaseException::RangeException(); throw obelisk::DatabaseRangeException();
break; break;
case SQLITE_NOMEM : case SQLITE_NOMEM :
throw obelisk::DatabaseException::MemoryException(); throw obelisk::DatabaseMemoryException();
break; break;
default : default :
throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection)); throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection));
@ -168,13 +168,13 @@ void obelisk::Fact::insertFact(sqlite3* dbConnection)
case SQLITE_OK : case SQLITE_OK :
break; break;
case SQLITE_TOOBIG : case SQLITE_TOOBIG :
throw obelisk::DatabaseException::SizeException(); throw obelisk::DatabaseSizeException();
break; break;
case SQLITE_RANGE : case SQLITE_RANGE :
throw obelisk::DatabaseException::RangeException(); throw obelisk::DatabaseRangeException();
break; break;
case SQLITE_NOMEM : case SQLITE_NOMEM :
throw obelisk::DatabaseException::MemoryException(); throw obelisk::DatabaseMemoryException();
break; break;
default : default :
throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection)); throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection));
@ -187,13 +187,13 @@ void obelisk::Fact::insertFact(sqlite3* dbConnection)
case SQLITE_OK : case SQLITE_OK :
break; break;
case SQLITE_TOOBIG : case SQLITE_TOOBIG :
throw obelisk::DatabaseException::SizeException(); throw obelisk::DatabaseSizeException();
break; break;
case SQLITE_RANGE : case SQLITE_RANGE :
throw obelisk::DatabaseException::RangeException(); throw obelisk::DatabaseRangeException();
break; break;
case SQLITE_NOMEM : case SQLITE_NOMEM :
throw obelisk::DatabaseException::MemoryException(); throw obelisk::DatabaseMemoryException();
break; break;
default : default :
throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection)); throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection));
@ -208,13 +208,13 @@ void obelisk::Fact::insertFact(sqlite3* dbConnection)
sqlite3_set_last_insert_rowid(dbConnection, 0); sqlite3_set_last_insert_rowid(dbConnection, 0);
break; break;
case SQLITE_CONSTRAINT : case SQLITE_CONSTRAINT :
throw obelisk::DatabaseException::ConstraintException( throw obelisk::DatabaseConstraintException(
sqlite3_errmsg(dbConnection)); sqlite3_errmsg(dbConnection));
case SQLITE_BUSY : case SQLITE_BUSY :
throw obelisk::DatabaseException::BusyException(); throw obelisk::DatabaseBusyException();
break; break;
case SQLITE_MISUSE : case SQLITE_MISUSE :
throw obelisk::DatabaseException::MisuseException(); throw obelisk::DatabaseMisuseException();
break; break;
default : default :
throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection)); throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection));

View File

@ -39,13 +39,13 @@ void obelisk::Verb::selectVerb(sqlite3* dbConnection)
case SQLITE_OK : case SQLITE_OK :
break; break;
case SQLITE_TOOBIG : case SQLITE_TOOBIG :
throw obelisk::DatabaseException::SizeException(); throw obelisk::DatabaseSizeException();
break; break;
case SQLITE_RANGE : case SQLITE_RANGE :
throw obelisk::DatabaseException::RangeException(); throw obelisk::DatabaseRangeException();
break; break;
case SQLITE_NOMEM : case SQLITE_NOMEM :
throw obelisk::DatabaseException::MemoryException(); throw obelisk::DatabaseMemoryException();
break; break;
default : default :
throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection)); throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection));
@ -63,10 +63,10 @@ void obelisk::Verb::selectVerb(sqlite3* dbConnection)
setName((char*) sqlite3_column_text(ppStmt, 1)); setName((char*) sqlite3_column_text(ppStmt, 1));
break; break;
case SQLITE_BUSY : case SQLITE_BUSY :
throw obelisk::DatabaseException::BusyException(); throw obelisk::DatabaseBusyException();
break; break;
case SQLITE_MISUSE : case SQLITE_MISUSE :
throw obelisk::DatabaseException::MisuseException(); throw obelisk::DatabaseMisuseException();
break; break;
default : default :
throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection)); throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection));
@ -106,13 +106,13 @@ void obelisk::Verb::insertVerb(sqlite3* dbConnection)
case SQLITE_OK : case SQLITE_OK :
break; break;
case SQLITE_TOOBIG : case SQLITE_TOOBIG :
throw obelisk::DatabaseException::SizeException(); throw obelisk::DatabaseSizeException();
break; break;
case SQLITE_RANGE : case SQLITE_RANGE :
throw obelisk::DatabaseException::RangeException(); throw obelisk::DatabaseRangeException();
break; break;
case SQLITE_NOMEM : case SQLITE_NOMEM :
throw obelisk::DatabaseException::MemoryException(); throw obelisk::DatabaseMemoryException();
break; break;
default : default :
throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection)); throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection));
@ -127,13 +127,13 @@ void obelisk::Verb::insertVerb(sqlite3* dbConnection)
sqlite3_set_last_insert_rowid(dbConnection, 0); sqlite3_set_last_insert_rowid(dbConnection, 0);
break; break;
case SQLITE_CONSTRAINT : case SQLITE_CONSTRAINT :
throw obelisk::DatabaseException::ConstraintException( throw obelisk::DatabaseConstraintException(
sqlite3_errmsg(dbConnection)); sqlite3_errmsg(dbConnection));
case SQLITE_BUSY : case SQLITE_BUSY :
throw obelisk::DatabaseException::BusyException(); throw obelisk::DatabaseBusyException();
break; break;
case SQLITE_MISUSE : case SQLITE_MISUSE :
throw obelisk::DatabaseException::MisuseException(); throw obelisk::DatabaseMisuseException();
break; break;
default : default :
throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection)); throw obelisk::DatabaseException(sqlite3_errmsg(dbConnection));