diff options
author | unknown <tomas@mc05.(none)> | 2004-05-03 06:33:35 +0200 |
---|---|---|
committer | unknown <tomas@mc05.(none)> | 2004-05-03 06:33:35 +0200 |
commit | d5d6c4fc1f0f90b3ad9564eeb57d08683a597e8d (patch) | |
tree | 58ad6e123387e7ad235d7eae9f4c4cf16076ae2f | |
parent | 73ff0958c05d771b719538135bc146cc5ffd9aae (diff) | |
parent | 1fa5853260607deed24a24c58a6730db7ffef9a2 (diff) | |
download | mariadb-git-d5d6c4fc1f0f90b3ad9564eeb57d08683a597e8d.tar.gz |
Merge tulin@bk-internal.mysql.com:/home/bk/mysql-4.1
into mc05.(none):/space2/tomas/mysql-4.1
-rw-r--r-- | ndb/src/ndbapi/Makefile | 1 | ||||
-rw-r--r-- | ndb/src/ndbapi/NdbErrorOut.cpp | 107 | ||||
-rw-r--r-- | ndb/src/ndbapi/Ndberror.cpp | 194 |
3 files changed, 181 insertions, 121 deletions
diff --git a/ndb/src/ndbapi/Makefile b/ndb/src/ndbapi/Makefile index 932fbd844d2..23a5cb946d1 100644 --- a/ndb/src/ndbapi/Makefile +++ b/ndb/src/ndbapi/Makefile @@ -32,6 +32,7 @@ SOURCES = \ Ndbif.cpp \ Ndbinit.cpp \ Ndberror.cpp \ + NdbErrorOut.cpp \ NdbConnection.cpp \ NdbConnectionScan.cpp \ NdbOperation.cpp \ diff --git a/ndb/src/ndbapi/NdbErrorOut.cpp b/ndb/src/ndbapi/NdbErrorOut.cpp new file mode 100644 index 00000000000..286f8216bf7 --- /dev/null +++ b/ndb/src/ndbapi/NdbErrorOut.cpp @@ -0,0 +1,107 @@ +/* Copyright (C) 2003 MySQL AB + + 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 2 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, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + + +#include <NdbError.hpp> +#include <NdbStdio.h> +#include <stdarg.h> + +#include <assert.h> + +#include <NdbOut.hpp> + +const char *ndberror_status_message(const NdbError::Status & status); +const char *ndberror_classification_message(const NdbError::Classification & classification); +int ndb_error_string(int err_no, char *str, size_t size); +void ndberror_update(const NdbError & _err); + +/** + * operators + */ +NdbOut & +operator<<(NdbOut & out, const NdbError & error){ + if(error.message != 0) + out << error.code << ": " << error.message; + else + out << error.code << ": "; + return out; +} + +NdbOut & +operator<<(NdbOut & out, const NdbError::Status & status){ + return out << ndberror_status_message(status); +} + +NdbOut & +operator<<(NdbOut & out, const NdbError::Classification & classification){ + return out << ndberror_classification_message(classification); +} + +/****************************************************** + * + */ +#include "NdbImpl.hpp" +#include "NdbDictionaryImpl.hpp" +#include <NdbSchemaCon.hpp> +#include <NdbOperation.hpp> +#include <NdbConnection.hpp> + + +const +NdbError & +Ndb::getNdbError(int code){ + theError.code = code; + ndberror_update(theError); + return theError; +} + +const +NdbError & +Ndb::getNdbError() const { + ndberror_update(theError); + return theError; +} + +const +NdbError & +NdbDictionaryImpl::getNdbError() const { + ndberror_update(m_error); + return m_error; +} + +const +NdbError & +NdbConnection::getNdbError() const { + ndberror_update(theError); + return theError; +} + +const +NdbError & +NdbOperation::getNdbError() const { + ndberror_update(theError); + return theError; +} + +const +NdbError & +NdbSchemaCon::getNdbError() const { + ndberror_update(theError); + return theError; +} + + + diff --git a/ndb/src/ndbapi/Ndberror.cpp b/ndb/src/ndbapi/Ndberror.cpp index 2aa890b0918..4e2cbc0b257 100644 --- a/ndb/src/ndbapi/Ndberror.cpp +++ b/ndb/src/ndbapi/Ndberror.cpp @@ -16,9 +16,8 @@ #include <NdbError.hpp> -#include <NdbStdio.h> +#include <stdio.h> #include <stdarg.h> - #include <assert.h> struct ErrorBundle { @@ -50,6 +49,8 @@ static const NdbError::Classification IE = NdbError::InternalError; static const NdbError::Classification NI = NdbError::FunctionNotImplemented; static const NdbError::Classification UE = NdbError::UnknownErrorCode; +static const char* empty_string = ""; + static const ErrorBundle ErrorCodes[] = { @@ -420,9 +421,15 @@ static const int NbErrorCodes = sizeof(ErrorCodes)/sizeof(ErrorBundle); +struct ErrorStatusMessage { + NdbError::Status status; + const char * message; +}; + struct ErrorStatusClassification { NdbError::Status status; NdbError::Classification classification; + const char * message; }; /** @@ -430,31 +437,44 @@ struct ErrorStatusClassification { */ static const +ErrorStatusMessage StatusMessageMapping[] = { + { NdbError::Success, "Success"}, + { NdbError::PermanentError, "Permanent error"}, + { NdbError::TemporaryError, "Temporary error"}, + { NdbError::UnknownResult , "Unknown result"} +}; + +static +const +int NbStatus = sizeof(StatusMessageMapping)/sizeof(ErrorStatusMessage); + +static +const ErrorStatusClassification StatusClassificationMapping[] = { - { NdbError::Success, NdbError::NoError }, - { NdbError::PermanentError, NdbError::ApplicationError }, - { NdbError::PermanentError, NdbError::NoDataFound }, - { NdbError::PermanentError, NdbError::ConstraintViolation }, - { NdbError::PermanentError, NdbError::SchemaError }, - { NdbError::PermanentError, NdbError::UserDefinedError }, - { NdbError::PermanentError, NdbError::InsufficientSpace }, + { NdbError::Success, NdbError::NoError, "No error"}, + { NdbError::PermanentError, NdbError::ApplicationError, "Application error"}, + { NdbError::PermanentError, NdbError::NoDataFound, "No data found"}, + { NdbError::PermanentError, NdbError::ConstraintViolation, "Constraint violation"}, + { NdbError::PermanentError, NdbError::SchemaError, "Schema error"}, + { NdbError::PermanentError, NdbError::UserDefinedError, "User defined error"}, + { NdbError::PermanentError, NdbError::InsufficientSpace, "Insufficient space"}, - { NdbError::TemporaryError, NdbError::TemporaryResourceError }, - { NdbError::TemporaryError, NdbError::NodeRecoveryError }, - { NdbError::TemporaryError, NdbError::OverloadError }, - { NdbError::TemporaryError, NdbError::TimeoutExpired }, - { NdbError::TemporaryError, NdbError::NodeShutdown }, + { NdbError::TemporaryError, NdbError::TemporaryResourceError, "Temporary Resource error"}, + { NdbError::TemporaryError, NdbError::NodeRecoveryError, "Node Recovery error"}, + { NdbError::TemporaryError, NdbError::OverloadError, "Overload error"}, + { NdbError::TemporaryError, NdbError::TimeoutExpired, "Timeout expired"}, + { NdbError::TemporaryError, NdbError::NodeShutdown, "Node shutdown"}, - { NdbError::UnknownResult , NdbError::UnknownResultError }, - { NdbError::UnknownResult , NdbError::UnknownErrorCode }, + { NdbError::UnknownResult , NdbError::UnknownResultError, "Unknown result error"}, + { NdbError::UnknownResult , NdbError::UnknownErrorCode, "Unknown error code"}, - { NdbError::PermanentError, NdbError::InternalError }, - { NdbError::PermanentError, NdbError::FunctionNotImplemented } + { NdbError::PermanentError, NdbError::InternalError, "Internal error"}, + { NdbError::PermanentError, NdbError::FunctionNotImplemented, "Function not implemented"} }; static const -int Nb = sizeof(StatusClassificationMapping)/sizeof(ErrorStatusClassification); +int NbClassification = sizeof(StatusClassificationMapping)/sizeof(ErrorStatusClassification); /** * Complete all fields of an NdbError given the error code @@ -471,9 +491,9 @@ set(NdbError & error, int code, const char * details, ...){ va_end(ap); } -static + void -update(const NdbError & _err){ +ndberror_update(const NdbError & _err){ NdbError & error = (NdbError &) _err; bool found = false; @@ -492,7 +512,7 @@ update(const NdbError & _err){ } found = false; - for(int i = 0; i<Nb; i++){ + for(int i = 0; i<NbClassification; i++){ if(StatusClassificationMapping[i].classification == error.classification){ error.status = StatusClassificationMapping[i].status; found = true; @@ -528,108 +548,40 @@ int main(void){ } #endif -#include <NdbOut.hpp> - -/** - * operators - */ -NdbOut & -operator<<(NdbOut & out, const NdbError & error){ - if(error.message != 0) - out << error.code << ": " << error.message; - else - out << error.code << ": "; - return out; -} - -NdbOut & -operator<<(NdbOut & out, const NdbError::Status & status){ - switch(status) { - case NdbError::Success: out << "Success"; break; - case NdbError::TemporaryError: out << "Temporary error"; break; - case NdbError::PermanentError: out << "Permanent error"; break; - case NdbError::UnknownResult: out << "Unknown result"; break; - } - return out; -} - -NdbOut & -operator<<(NdbOut & out, const NdbError::Classification & classification){ - switch(classification) { - case NdbError::NoError: out << "No error"; break; - case NdbError::ApplicationError: out << "Application error"; break; - case NdbError::NoDataFound: out << "No data found"; break; - case NdbError::ConstraintViolation: out << "Constraint violation"; break; - case NdbError::SchemaError: out << "Schema error"; break; - case NdbError::UserDefinedError: out << "User defined error"; break; - case NdbError::InsufficientSpace: out << "Insufficient space"; break; - case NdbError::TemporaryResourceError: out << "Temporary Resource error"; - break; - case NdbError::NodeRecoveryError: out << "Node Recovery error"; break; - case NdbError::OverloadError: out << "Overload error"; break; - case NdbError::TimeoutExpired: out << "Timeout expired"; break; - case NdbError::UnknownResultError: out << "Unknown result error"; break; - case NdbError::InternalError: out << "Internal error"; break; - case NdbError::FunctionNotImplemented: out << "Function not implemented"; - break; - case NdbError::UnknownErrorCode: out << "Unknown error code"; break; - case NdbError::NodeShutdown: out << "Node shutdown"; break; - } - return out; -} - -/****************************************************** - * - */ -#include "NdbImpl.hpp" -#include "NdbDictionaryImpl.hpp" -#include <NdbSchemaCon.hpp> -#include <NdbOperation.hpp> -#include <NdbConnection.hpp> - - -const -NdbError & -Ndb::getNdbError(int code){ - theError.code = code; - update(theError); - return theError; -} - -const -NdbError & -Ndb::getNdbError() const { - update(theError); - return theError; +const char *ndberror_status_message(const NdbError::Status & status) +{ + for (int i= 0; i < NbStatus; i++) + if (StatusMessageMapping[i].status == status) + return StatusMessageMapping[i].message; + return empty_string; } -const -NdbError & -NdbDictionaryImpl::getNdbError() const { - update(m_error); - return m_error; +const char *ndberror_classification_message(const NdbError::Classification & classification) +{ + for (int i= 0; i < NbClassification; i++) + if (StatusClassificationMapping[i].classification == classification) + return StatusClassificationMapping[i].message; + return empty_string; } -const -NdbError & -NdbConnection::getNdbError() const { - update(theError); - return theError; +extern "C" { +int ndb_error_string(int err_no, char *str, size_t size) +{ + NdbError error; + int len= 0, tlen= 0; + + error.code = err_no; + ndberror_update(error); + + len+= snprintf(str+tlen, size-tlen, "%s", error.message); + tlen= len < size ? len : size; + len+= snprintf(str+tlen, size-tlen, ": "); + tlen= len < size ? len : size; + len+= snprintf(str+tlen, size-tlen, "%s", ndberror_status_message(error.status)); + tlen= len < size ? len : size; + len+= snprintf(str+tlen, size-tlen, ": "); + tlen= len < size ? len : size; + len+= snprintf(str+tlen, size-tlen, "%s", ndberror_classification_message(error.classification)); + return len; } - -const -NdbError & -NdbOperation::getNdbError() const { - update(theError); - return theError; } - -const -NdbError & -NdbSchemaCon::getNdbError() const { - update(theError); - return theError; -} - - - |