From 97c3d4c1604b525e4522814e34723488c59a83f5 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 29 Dec 2015 02:42:43 +0000 Subject: Reshuffle and add new exceptions --- libmysqlpp/my-connection.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'libmysqlpp/my-connection.cpp') diff --git a/libmysqlpp/my-connection.cpp b/libmysqlpp/my-connection.cpp index 3e1aed3..4aa0ab9 100644 --- a/libmysqlpp/my-connection.cpp +++ b/libmysqlpp/my-connection.cpp @@ -9,6 +9,11 @@ NAMEDFACTORY("mysql", MySQL::Connection, DB::ConnectionFactory); +MySQL::ConnectionError::ConnectionError(MYSQL * m) : + MySQL::Error(m) +{ +} + class Opts { public: Opts() { port = 3306; } @@ -66,10 +71,10 @@ MySQL::Connection::Connection(const std::string & str) : } if (mysql_real_connect(&conn, ~o.server, ~o.user, ~o.password, ~o.database, o.port, ~o.unix_socket, CLIENT_LOCAL_FILES | CLIENT_MULTI_STATEMENTS) == NULL) { - throw ConnectionError(); + throw ConnectionError(&conn); } if (mysql_set_character_set(&conn, "utf8")) { - throw ConnectionError(); + throw ConnectionError(&conn); } } @@ -83,7 +88,7 @@ MySQL::Connection::finish() const { if (txDepth != 0) { rollbackTx(); - throw Error("Transaction still open"); + throw DB::TransactionStillOpen(); } } @@ -92,7 +97,7 @@ MySQL::Connection::beginTx() const { if (txDepth == 0) { if (mysql_autocommit(&conn, 0)) { - throw Error(mysql_error(&conn)); + throw Error(&conn); } rolledback = false; } @@ -107,7 +112,7 @@ MySQL::Connection::commitTx() const } if (--txDepth == 0) { if (mysql_commit(&conn)) { - throw Error(mysql_error(&conn)); + throw Error(&conn); } } return txDepth; @@ -118,7 +123,7 @@ MySQL::Connection::rollbackTx() const { if (--txDepth == 0) { if (mysql_rollback(&conn)) { - throw Error(mysql_error(&conn)); + throw Error(&conn); } } else { @@ -149,7 +154,7 @@ void MySQL::Connection::ping() const { if (mysql_ping(&conn)) { - throw Error(mysql_error(&conn)); + throw Error(&conn); } } @@ -244,7 +249,7 @@ MySQL::Connection::endBulkUpload(const char * msg) const if (!msg) { if (ctx->loadReturn) { ctx.reset(); - throw Error(mysql_error(&conn)); + throw Error(&conn); } } ctx.reset(); -- cgit v1.2.3