Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
dCache
cta
Commits
b22d8865
Commit
b22d8865
authored
Dec 02, 2019
by
Steven Murray
Browse files
Added DatabaseCheckConstraintError
parent
b73e1bef
Changes
8
Hide whitespace changes
Inline
Side-by-side
common/CMakeLists.txt
View file @
b22d8865
...
...
@@ -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
...
...
common/exception/DatabaseCheckConstraintError.cpp
0 → 100644
View file @
b22d8865
/*
* 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
common/exception/DatabaseCheckConstraintError.hpp
0 → 100644
View file @
b22d8865
/*
* 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
rdbms/StmtTest.cpp
View file @
b22d8865
...
...
@@ -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
);
}
}
...
...
rdbms/wrapper/MysqlStmt.cpp
View file @
b22d8865
...
...
@@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "common/exception/DatabaseConstraintError.hpp"
#include "common/exception/DatabaseC
heckC
onstraintError.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
::
DatabaseC
heckC
onstraintError
(
std
::
string
(
__FUNCTION__
)
+
" "
+
msg
);
break
;
}
...
...
rdbms/wrapper/OcciStmt.cpp
View file @
b22d8865
...
...
@@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "common/exception/DatabaseConstraintError.hpp"
#include "common/exception/DatabaseC
heckC
onstraintError.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
::
DatabaseC
heckC
onstraintError
(
msg
.
str
());
}
else
{
throw
exception
::
Exception
(
msg
.
str
());
}
...
...
rdbms/wrapper/Postgres.hpp
View file @
b22d8865
...
...
@@ -18,7 +18,7 @@
#pragma once
#include "common/exception/DatabaseConstraintError.hpp"
#include "common/exception/DatabaseC
heckC
onstraintError.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
::
DatabaseC
heckC
onstraintError
(
dbmsg
);
}
throw
exception
::
Exception
(
dbmsg
);
}
...
...
rdbms/wrapper/SqliteStmt.cpp
View file @
b22d8865
...
...
@@ -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:
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment