diff options
Diffstat (limited to 'cpp/src/Freeze/Util.cpp')
-rw-r--r-- | cpp/src/Freeze/Util.cpp | 78 |
1 files changed, 48 insertions, 30 deletions
diff --git a/cpp/src/Freeze/Util.cpp b/cpp/src/Freeze/Util.cpp index e3d86328e58..73ef47cb4eb 100644 --- a/cpp/src/Freeze/Util.cpp +++ b/cpp/src/Freeze/Util.cpp @@ -15,9 +15,25 @@ using namespace Ice; using namespace std; void -Freeze::handleMemoryException(const DbMemoryException& dx, Key& key, Dbt& dbKey) +Freeze::handleDbException(const DbException& dx, + const char* file, int line) { - if(dbKey.get_size() > dbKey.get_ulen()) + throw DatabaseException(file, line, dx.what()); +} + +void +Freeze::handleDbException(const DbException& dx, + Key& key, Dbt& dbKey, + const char* file, int line) +{ + bool bufferSmallException = +#if (DB_VERSION_MAJOR == 4) && (DB_VERSION_MINOR == 2) + (dx.get_errno() == ENOMEM); +#else + (dx.get_errno() == DB_BUFFER_SMALL); +#endif + + if(bufferSmallException && (dbKey.get_size() > dbKey.get_ulen())) { // // Keep the old key size in case it's used as input @@ -30,43 +46,45 @@ Freeze::handleMemoryException(const DbMemoryException& dx, Key& key, Dbt& dbKey) } else { - // - // Real problem - // - DatabaseException ex(__FILE__, __LINE__); - ex.message = dx.what(); - throw ex; + handleDbException(dx, file, line); } } void -Freeze::handleMemoryException(const DbMemoryException& dx, Key& key, Dbt& dbKey, - Value& value, Dbt& dbValue) +Freeze::handleDbException(const DbException& dx, + Key& key, Dbt& dbKey, + Value& value, Dbt& dbValue, + const char* file, int line) { - bool resized = false; - if(dbKey.get_size() > dbKey.get_ulen()) - { - size_t oldKeySize = key.size(); - key.resize(dbKey.get_size()); - initializeOutDbt(key, dbKey); - dbKey.set_size(static_cast<u_int32_t>(oldKeySize)); - resized = true; - } - - if(dbValue.get_size() > dbValue.get_ulen()) + bool bufferSmallException = +#if (DB_VERSION_MAJOR == 4) && (DB_VERSION_MINOR == 2) + (dx.get_errno() == ENOMEM); +#else + (dx.get_errno() == DB_BUFFER_SMALL); +#endif + + bool resized = false; + if(bufferSmallException) { - value.resize(dbValue.get_size()); - initializeOutDbt(value, dbValue); - resized = true; + if(dbKey.get_size() > dbKey.get_ulen()) + { + size_t oldKeySize = key.size(); + key.resize(dbKey.get_size()); + initializeOutDbt(key, dbKey); + dbKey.set_size(static_cast<u_int32_t>(oldKeySize)); + resized = true; + } + + if(dbValue.get_size() > dbValue.get_ulen()) + { + value.resize(dbValue.get_size()); + initializeOutDbt(value, dbValue); + resized = true; + } } if(!resized) { - // - // Real problem - // - DatabaseException ex(__FILE__, __LINE__); - ex.message = dx.what(); - throw ex; + handleDbException(dx, file, line); } } |