summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2015-12-29 02:42:43 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2015-12-29 06:00:07 +0000
commit469f502e9056309e4ffd34b7c427cc034b9725f2 (patch)
tree3ab90d5c435bffd552b9e1ae2da88ee002e1b01b
parentTest a connection is suitably finished before adding back to the pool. (diff)
downloadlibdbpp-469f502e9056309e4ffd34b7c427cc034b9725f2.tar.bz2
libdbpp-469f502e9056309e4ffd34b7c427cc034b9725f2.tar.xz
libdbpp-469f502e9056309e4ffd34b7c427cc034b9725f2.zip
Reshuffle and add new exceptions
-rw-r--r--libdbpp/column.h11
-rw-r--r--libdbpp/command.cpp8
-rw-r--r--libdbpp/command.h13
-rw-r--r--libdbpp/connection.cpp16
-rw-r--r--libdbpp/connection.h31
-rw-r--r--libdbpp/error.cpp14
-rw-r--r--libdbpp/error.h36
-rw-r--r--libdbpp/modifycommand.cpp4
-rw-r--r--libdbpp/modifycommand.h7
-rw-r--r--libdbpp/unittests/testConnection.cpp5
10 files changed, 107 insertions, 38 deletions
diff --git a/libdbpp/column.h b/libdbpp/column.h
index 981cde6..53e912a 100644
--- a/libdbpp/column.h
+++ b/libdbpp/column.h
@@ -10,17 +10,6 @@
#include "error.h"
namespace DB {
- /// Exception thrown on an attempt to convert betweem incompatible types.
- class DLL_PUBLIC InvalidConversion : public AdHoc::Exception<Error> {
- public:
- InvalidConversion(const char * const, const char * const);
-
- private:
- std::string message() const throw() override;
- const char * from;
- const char * to;
- };
-
/// Abstract class for something that can handle field data. See Column::apply.
class DLL_PUBLIC HandleField {
public:
diff --git a/libdbpp/command.cpp b/libdbpp/command.cpp
index 8bdb96c..abbb53f 100644
--- a/libdbpp/command.cpp
+++ b/libdbpp/command.cpp
@@ -9,3 +9,11 @@ DB::Command::~Command()
{
}
+DB::ParameterTypeNotSupported::ParameterTypeNotSupported()
+{
+}
+
+DB::ParameterOutOfRange::ParameterOutOfRange()
+{
+}
+
diff --git a/libdbpp/command.h b/libdbpp/command.h
index a8ca0c3..3305342 100644
--- a/libdbpp/command.h
+++ b/libdbpp/command.h
@@ -5,8 +5,21 @@
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/shared_ptr.hpp>
#include <visibility.h>
+#include "error.h"
namespace DB {
+ /// Exception thrown when binding a parameter of type the connector doesn't support.
+ class DLL_PUBLIC ParameterTypeNotSupported : public Error {
+ public:
+ ParameterTypeNotSupported();
+ };
+
+ /// Exception thrown when binding a parameter out of range of those defined in the command.
+ class DLL_PUBLIC ParameterOutOfRange : public Error {
+ public:
+ ParameterOutOfRange();
+ };
+
/// Represents the basics of any command to be executed against a database.
class DLL_PUBLIC Command {
public:
diff --git a/libdbpp/connection.cpp b/libdbpp/connection.cpp
index 1624ce6..7a287d2 100644
--- a/libdbpp/connection.cpp
+++ b/libdbpp/connection.cpp
@@ -6,6 +6,17 @@
#include <sqlParse.h>
#include <boost/shared_ptr.hpp>
+DB::ConnectionError::ConnectionError() :
+ FailureTime(time(NULL))
+{
+}
+
+std::string
+DB::TransactionStillOpen::message() const throw()
+{
+ return "A transaction is still open.";
+}
+
DB::Connection::~Connection()
{
}
@@ -69,9 +80,10 @@ DB::SqlWriter::bindParams(DB::Command *, unsigned int &)
{
}
-DB::TransactionRequired::TransactionRequired() :
- std::logic_error("A transaction must be opened before performing this operation")
+std::string
+DB::TransactionRequired::message() const throw()
{
+ return "A transaction must be opened before performing this operation";
}
DB::TransactionScope::TransactionScope(DB::Connection * c) :
diff --git a/libdbpp/connection.h b/libdbpp/connection.h
index ab3882d..8328fe0 100644
--- a/libdbpp/connection.h
+++ b/libdbpp/connection.h
@@ -8,6 +8,7 @@
#include <visibility.h>
#include <boost/filesystem/path.hpp>
#include <boost/shared_ptr.hpp>
+#include "error.h"
namespace AdHoc {
class Buffer;
@@ -51,6 +52,16 @@ namespace DB {
virtual void bindParams(Command *, unsigned int &);
};
+ /// Base class for database connectivity errors.
+ class DLL_PUBLIC ConnectionError : public Error {
+ public:
+ /// Default constructor, sets FailureTime to now.
+ ConnectionError();
+
+ /// The time of connectivity failure.
+ const time_t FailureTime;
+ };
+
class DLL_PUBLIC TablePatch {
public:
TablePatch();
@@ -64,15 +75,28 @@ namespace DB {
SqlWriter * order;
};
+ /// Exception thrown when finishing a connection that still has a transaction open.
+ class DLL_PUBLIC TransactionStillOpen : public AdHoc::StdException {
+ private:
+ std::string message() const throw() override;
+ };
+
+ /// Exception thrown when attempting to open a transaction when one is already open.
+ class DLL_PUBLIC TransactionAlreadyOpen : public AdHoc::StdException {
+ private:
+ std::string message() const throw() override;
+ };
+
/// Exception thrown when attempting to perform a table patch with invalid settings.
class DLL_PUBLIC PatchCheckFailure : public AdHoc::StdException {
private:
std::string message() const throw() override;
};
- class DLL_PUBLIC TransactionRequired : public std::logic_error {
- public:
- TransactionRequired();
+ /// Exception thrown when attempting to perform an action that requires a transaction when one is not open.
+ class DLL_PUBLIC TransactionRequired : public AdHoc::StdException {
+ private:
+ std::string message() const throw() override;
};
/// Base class for connections to a database.
@@ -131,6 +155,7 @@ namespace DB {
/// AdHoc plugin resolver helper for database connectors.
static boost::optional<std::string> resolvePlugin(const std::type_info &, const std::string &);
+
protected:
unsigned int patchDeletes(TablePatch * tp);
unsigned int patchUpdates(TablePatch * tp);
diff --git a/libdbpp/error.cpp b/libdbpp/error.cpp
index 372cc4b..5d0a937 100644
--- a/libdbpp/error.cpp
+++ b/libdbpp/error.cpp
@@ -1,13 +1,13 @@
#include "error.h"
#include <time.h>
-DB::ConnectionError::ConnectionError() :
- FailureTime(time(NULL))
-{
-}
+namespace DB {
+ ColumnTypeNotSupported::ColumnTypeNotSupported()
+ {
+ }
-DB::ConnectionError::ConnectionError(time_t t) :
- FailureTime(t)
-{
+ BulkUploadNotSupported::BulkUploadNotSupported()
+ {
+ }
}
diff --git a/libdbpp/error.h b/libdbpp/error.h
index 8e5c659..6e8ab18 100644
--- a/libdbpp/error.h
+++ b/libdbpp/error.h
@@ -2,22 +2,38 @@
#define DB_ERROR_H
#include <stdlib.h>
-#include <exception>
+#include <exception.h>
#include <visibility.h>
namespace DB {
/// Base class for database errors.
- class DLL_PUBLIC Error : public virtual std::exception { };
- /// Base class for database connectivity errors.
- class DLL_PUBLIC ConnectionError : public Error {
+ class DLL_PUBLIC Error : public virtual std::exception {
+ };
+
+ /// Exception thrown when attempting to bulk upload with a connector that doesn't support it.
+ class DLL_PUBLIC BulkUploadNotSupported : public Error {
+ public:
+ BulkUploadNotSupported();
+ };
+
+ /// Exception thrown when a query returns an unsupported column type.
+ class DLL_PUBLIC ColumnTypeNotSupported : public Error {
+ public:
+ ColumnTypeNotSupported();
+ };
+
+ /// Exception thrown on an attempt to convert betweem incompatible types.
+ class DLL_PUBLIC InvalidConversion : public AdHoc::Exception<Error> {
public:
- /// Default constructor, sets FailureTime to now.
- ConnectionError();
- /// Construct with a specific failure time.
- ConnectionError(time_t);
+ /// Create a new InvalidConversion exception with the names of the conversion types.
+ /// @param from Source type
+ /// @param to Destination type
+ InvalidConversion(const char * const from, const char * const to);
- /// The time of connectivity failure.
- const time_t FailureTime;
+ private:
+ std::string message() const throw() override;
+ const char * from;
+ const char * to;
};
}
diff --git a/libdbpp/modifycommand.cpp b/libdbpp/modifycommand.cpp
index f864b72..f46a6a2 100644
--- a/libdbpp/modifycommand.cpp
+++ b/libdbpp/modifycommand.cpp
@@ -9,3 +9,7 @@ DB::ModifyCommand::~ModifyCommand()
{
}
+DB::NoRowsAffected::NoRowsAffected()
+{
+}
+
diff --git a/libdbpp/modifycommand.h b/libdbpp/modifycommand.h
index 104142e..0e225f4 100644
--- a/libdbpp/modifycommand.h
+++ b/libdbpp/modifycommand.h
@@ -2,10 +2,17 @@
#define DB_MODIFYCOMMAND_H
#include "command.h"
+#include "error.h"
#include <visibility.h>
#include <boost/shared_ptr.hpp>
namespace DB {
+ /// Exception thrown when an update affected no rows when some were expected.
+ class DLL_PUBLIC NoRowsAffected : public Error {
+ public:
+ NoRowsAffected();
+ };
+
/// Presents a command not expected to return any data.
class DLL_PUBLIC ModifyCommand : public virtual Command {
public:
diff --git a/libdbpp/unittests/testConnection.cpp b/libdbpp/unittests/testConnection.cpp
index 76758a7..bc1a71b 100644
--- a/libdbpp/unittests/testConnection.cpp
+++ b/libdbpp/unittests/testConnection.cpp
@@ -165,8 +165,3 @@ BOOST_AUTO_TEST_CASE( savepoints )
delete mock;
}
-BOOST_AUTO_TEST_CASE( connectError )
-{
- BOOST_REQUIRE_THROW(DB::ConnectionFactory::createNew("postgresql", "user=fail dbname=nodb"), DB::ConnectionError);
-}
-