Commit 9af0c83a authored by Steven Murray's avatar Steven Murray
Browse files

SqliteCatalogue::fileWrittenToTape() now handles DatabasePrimaryKeyError

parent 28ab5bb7
......@@ -23,6 +23,7 @@
#include "catalogue/SqliteCatalogueSchema.hpp"
#include "catalogue/SqliteCatalogue.hpp"
#include "common/exception/DatabaseConstraintError.hpp"
#include "common/exception/DatabasePrimaryKeyError.hpp"
#include "common/exception/Exception.hpp"
#include "common/exception/UserError.hpp"
#include "common/make_unique.hpp"
......@@ -483,7 +484,7 @@ void SqliteCatalogue::fileWrittenToTape(const rdbms::AutocommitMode autocommitMo
row.diskFileGroup = event.diskFileGroup;
row.diskFileRecoveryBlob = event.diskFileRecoveryBlob;
insertArchiveFile(conn, autocommitMode, row);
} catch(exception::DatabaseConstraintError &) {
} catch(exception::DatabasePrimaryKeyError &) {
// Ignore this error
} catch(...) {
throw;
......
......@@ -83,6 +83,8 @@ std::string Sqlite::rcToStr(const int rc) {
return "TEXT or BLOCK too big";
case SQLITE_ERROR:
return "Generic error";
case SQLITE_CONSTRAINT_PRIMARYKEY:
return "Primary key error";
default: {
std::ostringstream oss;
oss << "Unknown SQLite return code " << rc;
......
......@@ -44,6 +44,9 @@ SqliteConn::SqliteConn(const std::string &filename):
throw exception::Exception(msg);
}
// Enable extended result codes
sqlite3_extended_result_codes(m_sqliteConn, 1);
// Give SQLite upto 120 seconds to avoid a busy error
sqlite3_busy_timeout(m_sqliteConn, 120000);
......
......@@ -17,6 +17,7 @@
*/
#include "common/exception/DatabaseConstraintError.hpp"
#include "common/exception/DatabasePrimaryKeyError.hpp"
#include "common/exception/Exception.hpp"
#include "common/exception/Errnum.hpp"
#include "rdbms/NullDbValue.hpp"
......@@ -155,9 +156,12 @@ bool SqliteRset::next() {
msg << __FUNCTION__ << " failed for SQL statement " << m_stmt.getSqlForException() + ": " <<
Sqlite::rcToStr(stepRc);
if(SQLITE_CONSTRAINT == stepRc) {
switch(stepRc) {
case SQLITE_CONSTRAINT_PRIMARYKEY:
throw exception::DatabasePrimaryKeyError(msg.str());
case SQLITE_CONSTRAINT:
throw exception::DatabaseConstraintError(msg.str());
} else {
default:
throw exception::Exception(msg.str());
}
}
......
......@@ -17,6 +17,7 @@
*/
#include "common/exception/DatabaseConstraintError.hpp"
#include "common/exception/DatabasePrimaryKeyError.hpp"
#include "common/exception/Exception.hpp"
#include "common/make_unique.hpp"
#include "common/threading/MutexLocker.hpp"
......@@ -266,9 +267,12 @@ void SqliteStmt::executeNonQuery() {
std::ostringstream msg;
msg << __FUNCTION__ << " failed for SQL statement " << getSqlForException() + ": " << Sqlite::rcToStr(stepRc);
if(SQLITE_CONSTRAINT == stepRc) {
switch(stepRc) {
case SQLITE_CONSTRAINT_PRIMARYKEY:
throw exception::DatabasePrimaryKeyError(msg.str());
case SQLITE_CONSTRAINT:
throw exception::DatabaseConstraintError(msg.str());
} else {
default:
throw exception::Exception(msg.str());
}
}
......
......@@ -17,6 +17,7 @@
*/
#include "common/exception/DatabaseConstraintError.hpp"
#include "common/exception/DatabasePrimaryKeyError.hpp"
#include "rdbms/wrapper/SqliteConn.hpp"
#include "rdbms/wrapper/SqliteRset.hpp"
#include "rdbms/wrapper/SqliteStmt.hpp"
......@@ -401,7 +402,7 @@ TEST_F(cta_rdbms_wrapper_SqliteStmtTest, executeNonQuery_insert_violating_primar
":COL1);";
auto stmt = conn.createStmt(sql, rdbms::AutocommitMode::ON);
stmt->bindUint64(":COL1", 1);
ASSERT_THROW(stmt->executeNonQuery(), exception::DatabaseConstraintError);
ASSERT_THROW(stmt->executeNonQuery(), exception::DatabasePrimaryKeyError);
}
}
......@@ -448,7 +449,7 @@ TEST_F(cta_rdbms_wrapper_SqliteStmtTest, executeQuery_insert_violating_primary_k
auto stmt = conn.createStmt(sql, rdbms::AutocommitMode::ON);
stmt->bindUint64(":COL1", 1);
auto rset = stmt->executeQuery();
ASSERT_THROW(rset->next(), exception::DatabaseConstraintError);
ASSERT_THROW(rset->next(), exception::DatabasePrimaryKeyError);
}
}
......
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