Commit d5d6c4fc authored by unknown's avatar unknown

Merge tulin@bk-internal.mysql.com:/home/bk/mysql-4.1

into mc05.(none):/space2/tomas/mysql-4.1

parents 73ff0958 1fa58532
...@@ -32,6 +32,7 @@ SOURCES = \ ...@@ -32,6 +32,7 @@ SOURCES = \
Ndbif.cpp \ Ndbif.cpp \
Ndbinit.cpp \ Ndbinit.cpp \
Ndberror.cpp \ Ndberror.cpp \
NdbErrorOut.cpp \
NdbConnection.cpp \ NdbConnection.cpp \
NdbConnectionScan.cpp \ NdbConnectionScan.cpp \
NdbOperation.cpp \ NdbOperation.cpp \
......
/* 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;
}
...@@ -16,9 +16,8 @@ ...@@ -16,9 +16,8 @@
#include <NdbError.hpp> #include <NdbError.hpp>
#include <NdbStdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include <assert.h> #include <assert.h>
struct ErrorBundle { struct ErrorBundle {
...@@ -50,6 +49,8 @@ static const NdbError::Classification IE = NdbError::InternalError; ...@@ -50,6 +49,8 @@ static const NdbError::Classification IE = NdbError::InternalError;
static const NdbError::Classification NI = NdbError::FunctionNotImplemented; static const NdbError::Classification NI = NdbError::FunctionNotImplemented;
static const NdbError::Classification UE = NdbError::UnknownErrorCode; static const NdbError::Classification UE = NdbError::UnknownErrorCode;
static const char* empty_string = "";
static static
const const
ErrorBundle ErrorCodes[] = { ErrorBundle ErrorCodes[] = {
...@@ -420,41 +421,60 @@ static ...@@ -420,41 +421,60 @@ static
const const
int NbErrorCodes = sizeof(ErrorCodes)/sizeof(ErrorBundle); int NbErrorCodes = sizeof(ErrorCodes)/sizeof(ErrorBundle);
struct ErrorStatusMessage {
NdbError::Status status;
const char * message;
};
struct ErrorStatusClassification { struct ErrorStatusClassification {
NdbError::Status status; NdbError::Status status;
NdbError::Classification classification; NdbError::Classification classification;
const char * message;
}; };
/** /**
* Mapping between classification and status * Mapping between classification and status
*/ */
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 static
const const
ErrorStatusClassification StatusClassificationMapping[] = { ErrorStatusClassification StatusClassificationMapping[] = {
{ NdbError::Success, NdbError::NoError }, { NdbError::Success, NdbError::NoError, "No error"},
{ NdbError::PermanentError, NdbError::ApplicationError }, { NdbError::PermanentError, NdbError::ApplicationError, "Application error"},
{ NdbError::PermanentError, NdbError::NoDataFound }, { NdbError::PermanentError, NdbError::NoDataFound, "No data found"},
{ NdbError::PermanentError, NdbError::ConstraintViolation }, { NdbError::PermanentError, NdbError::ConstraintViolation, "Constraint violation"},
{ NdbError::PermanentError, NdbError::SchemaError }, { NdbError::PermanentError, NdbError::SchemaError, "Schema error"},
{ NdbError::PermanentError, NdbError::UserDefinedError }, { NdbError::PermanentError, NdbError::UserDefinedError, "User defined error"},
{ NdbError::PermanentError, NdbError::InsufficientSpace }, { NdbError::PermanentError, NdbError::InsufficientSpace, "Insufficient space"},
{ NdbError::TemporaryError, NdbError::TemporaryResourceError }, { NdbError::TemporaryError, NdbError::TemporaryResourceError, "Temporary Resource error"},
{ NdbError::TemporaryError, NdbError::NodeRecoveryError }, { NdbError::TemporaryError, NdbError::NodeRecoveryError, "Node Recovery error"},
{ NdbError::TemporaryError, NdbError::OverloadError }, { NdbError::TemporaryError, NdbError::OverloadError, "Overload error"},
{ NdbError::TemporaryError, NdbError::TimeoutExpired }, { NdbError::TemporaryError, NdbError::TimeoutExpired, "Timeout expired"},
{ NdbError::TemporaryError, NdbError::NodeShutdown }, { NdbError::TemporaryError, NdbError::NodeShutdown, "Node shutdown"},
{ NdbError::UnknownResult , NdbError::UnknownResultError }, { NdbError::UnknownResult , NdbError::UnknownResultError, "Unknown result error"},
{ NdbError::UnknownResult , NdbError::UnknownErrorCode }, { NdbError::UnknownResult , NdbError::UnknownErrorCode, "Unknown error code"},
{ NdbError::PermanentError, NdbError::InternalError }, { NdbError::PermanentError, NdbError::InternalError, "Internal error"},
{ NdbError::PermanentError, NdbError::FunctionNotImplemented } { NdbError::PermanentError, NdbError::FunctionNotImplemented, "Function not implemented"}
}; };
static static
const const
int Nb = sizeof(StatusClassificationMapping)/sizeof(ErrorStatusClassification); int NbClassification = sizeof(StatusClassificationMapping)/sizeof(ErrorStatusClassification);
/** /**
* Complete all fields of an NdbError given the error code * Complete all fields of an NdbError given the error code
...@@ -471,9 +491,9 @@ set(NdbError & error, int code, const char * details, ...){ ...@@ -471,9 +491,9 @@ set(NdbError & error, int code, const char * details, ...){
va_end(ap); va_end(ap);
} }
static
void void
update(const NdbError & _err){ ndberror_update(const NdbError & _err){
NdbError & error = (NdbError &) _err; NdbError & error = (NdbError &) _err;
bool found = false; bool found = false;
...@@ -492,7 +512,7 @@ update(const NdbError & _err){ ...@@ -492,7 +512,7 @@ update(const NdbError & _err){
} }
found = false; found = false;
for(int i = 0; i<Nb; i++){ for(int i = 0; i<NbClassification; i++){
if(StatusClassificationMapping[i].classification == error.classification){ if(StatusClassificationMapping[i].classification == error.classification){
error.status = StatusClassificationMapping[i].status; error.status = StatusClassificationMapping[i].status;
found = true; found = true;
...@@ -528,108 +548,40 @@ int main(void){ ...@@ -528,108 +548,40 @@ int main(void){
} }
#endif #endif
#include <NdbOut.hpp> const char *ndberror_status_message(const NdbError::Status & status)
{
/** for (int i= 0; i < NbStatus; i++)
* operators if (StatusMessageMapping[i].status == status)
*/ return StatusMessageMapping[i].message;
NdbOut & return empty_string;
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 const char *ndberror_classification_message(const NdbError::Classification & classification)
NdbError & {
NdbDictionaryImpl::getNdbError() const { for (int i= 0; i < NbClassification; i++)
update(m_error); if (StatusClassificationMapping[i].classification == classification)
return m_error; return StatusClassificationMapping[i].message;
return empty_string;
} }
const extern "C" {
NdbError & int ndb_error_string(int err_no, char *str, size_t size)
NdbConnection::getNdbError() const { {
update(theError); NdbError error;
return theError; 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;
}
Markdown is supported
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