Commit b22d8865 authored by Steven Murray's avatar Steven Murray
Browse files

Added DatabaseCheckConstraintError

parent b73e1bef
......@@ -81,6 +81,7 @@ set (COMMON_LIB_SRC_FILES
exception/Backtrace.cpp
exception/BadAlloc.cpp
exception/CommandLineNotParsed.cpp
exception/DatabaseCheckConstraintError.cpp
exception/DatabaseConstraintError.cpp
exception/DatabasePrimaryKeyError.cpp
exception/DismountFailed.cpp
......
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* 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/>.
*/
#include "common/exception/DatabaseCheckConstraintError.hpp"
namespace cta {
namespace exception {
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
DatabaseCheckConstraintError::DatabaseCheckConstraintError(
const std::string &context,
const bool embedBacktrace):
DatabaseConstraintError(context, embedBacktrace) {
}
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
DatabaseCheckConstraintError::~DatabaseCheckConstraintError() noexcept {
}
} // namespace exception
} // namespace cta
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* 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/>.
*/
#pragma once
#include "common/exception/DatabaseConstraintError.hpp"
#include <string>
namespace cta {
namespace exception {
/**
* A database constraint error.
*/
class DatabaseCheckConstraintError : public DatabaseConstraintError {
public:
/**
* Constructor.
*
* @param context optional context string added to the message
* at initialisation time.
* @param embedBacktrace whether to embed a backtrace of where the
* exception was throw in the message
*/
DatabaseCheckConstraintError(const std::string &context = "", const bool embedBacktrace = true);
/**
* Empty Destructor, explicitely non-throwing (needed for std::exception
* inheritance)
*/
~DatabaseCheckConstraintError() noexcept override;
}; // class DatabaseCheckConstraintError
} // namespace exception
} // namespace cta
......@@ -16,7 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "common/exception/DatabaseConstraintError.hpp"
#include "common/exception/DatabaseCheckConstraintError.hpp"
#include "common/exception/DatabasePrimaryKeyError.hpp"
#include "common/exception/Exception.hpp"
#include "common/make_unique.hpp"
#include "common/utils/utils.hpp"
......@@ -399,7 +400,8 @@ TEST_P(cta_rdbms_StmtTest, insert_with_bindString_invalid_bool_value) {
":BOOL_COL)";
auto stmt = m_conn.createStmt(sql);
stmt.bindString(":BOOL_COL", insertValue);
ASSERT_THROW(stmt.executeNonQuery(), cta::exception::DatabaseConstraintError);
ASSERT_THROW(stmt.executeNonQuery(), cta::exception::DatabaseCheckConstraintError);
}
}
......
......@@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "common/exception/DatabaseConstraintError.hpp"
#include "common/exception/DatabaseCheckConstraintError.hpp"
#include "common/exception/DatabasePrimaryKeyError.hpp"
#include "common/exception/Exception.hpp"
#include "common/make_unique.hpp"
......@@ -383,7 +383,7 @@ void MysqlStmt::executeNonQuery() {
throw exception::DatabasePrimaryKeyError(std::string(__FUNCTION__) + " " + msg);
break;
case 4025: // Newer MariaDB versions have ER_CONSTRAINT_FAILED = 4025
throw exception::DatabaseConstraintError(std::string(__FUNCTION__) + " " + msg);
throw exception::DatabaseCheckConstraintError(std::string(__FUNCTION__) + " " + msg);
break;
}
......
......@@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "common/exception/DatabaseConstraintError.hpp"
#include "common/exception/DatabaseCheckConstraintError.hpp"
#include "common/exception/Exception.hpp"
#include "common/exception/LostDatabaseConnection.hpp"
#include "common/make_unique.hpp"
......@@ -269,7 +269,7 @@ void OcciStmt::executeNonQuery() {
throw exception::LostDatabaseConnection(msg.str());
}
if(2290 == ex.getErrorCode()) {
throw exception::DatabaseConstraintError(msg.str());
throw exception::DatabaseCheckConstraintError(msg.str());
} else {
throw exception::Exception(msg.str());
}
......
......@@ -18,7 +18,7 @@
#pragma once
#include "common/exception/DatabaseConstraintError.hpp"
#include "common/exception/DatabaseCheckConstraintError.hpp"
#include "common/exception/Exception.hpp"
#include "common/exception/LostDatabaseConnection.hpp"
......@@ -91,7 +91,7 @@ public:
throw exception::LostDatabaseConnection(dbmsg);
}
if (checkViolation) {
throw exception::DatabaseConstraintError(dbmsg);
throw exception::DatabaseCheckConstraintError(dbmsg);
}
throw exception::Exception(dbmsg);
}
......
......@@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "common/exception/DatabaseCheckConstraintError.hpp"
#include "common/exception/DatabaseConstraintError.hpp"
#include "common/exception/DatabasePrimaryKeyError.hpp"
#include "common/exception/Exception.hpp"
......@@ -287,6 +288,8 @@ void SqliteStmt::executeNonQuery() {
switch(stepRc) {
case SQLITE_CONSTRAINT_PRIMARYKEY:
throw exception::DatabasePrimaryKeyError(msg.str());
case SQLITE_CONSTRAINT_CHECK:
throw exception::DatabaseCheckConstraintError(msg.str());
case SQLITE_CONSTRAINT:
throw exception::DatabaseConstraintError(msg.str());
default:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment