From dbdb41800b6bc489234cf0fc065156273933274b Mon Sep 17 00:00:00 2001 From: Jose Date: Tue, 7 Aug 2012 23:05:18 +0200 Subject: ICE-4755 - Freeze and DB 5.x --- cpp/src/Freeze/IndexI.cpp | 22 +++++++++++++++++++++- cpp/src/Freeze/MapI.cpp | 21 ++++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) (limited to 'cpp') diff --git a/cpp/src/Freeze/IndexI.cpp b/cpp/src/Freeze/IndexI.cpp index aae8b8335cc..bdf62773819 100644 --- a/cpp/src/Freeze/IndexI.cpp +++ b/cpp/src/Freeze/IndexI.cpp @@ -43,13 +43,23 @@ Freeze::IndexI::untypedFindFirst(const Key& bytes, Int firstN) const Dbt dbKey; initializeInDbt(bytes, dbKey); +#if (DB_VERSION_MAJOR <= 4) || (DB_VERSION_MAJOR == 5 && DB_VERSION_MINOR <= 1) // // When we have a custom-comparison function, Berkeley DB returns // the key on-disk (when it finds one). We disable this behavior: // (ref Oracle SR 5925672.992) // dbKey.set_flags(DB_DBT_USERMEM | DB_DBT_PARTIAL); - +#else + // + // In DB > 5.1 we can not set DB_DBT_PARTIAL in the key Dbt, + // when using DB_SET, we must resize the Dbt key param to hold enought + // space or Dbc::get fails with DB_BUFFER_SMALL. + // + dbKey.set_flags(DB_DBT_USERMEM); + dbKey.set_ulen(static_cast(bytes.size())); +#endif + Key pkey(1024); Dbt pdbKey; initializeOutDbt(pkey, pdbKey); @@ -200,12 +210,22 @@ Freeze::IndexI::untypedCount(const Key& bytes) const Dbt dbKey; initializeInDbt(bytes, dbKey); +#if (DB_VERSION_MAJOR <= 4) || (DB_VERSION_MAJOR == 5 && DB_VERSION_MINOR <= 1) // // When we have a custom-comparison function, Berkeley DB returns // the key on-disk (when it finds one). We disable this behavior: // (ref Oracle SR 5925672.992) // dbKey.set_flags(DB_DBT_USERMEM | DB_DBT_PARTIAL); +#else + // + // In DB > 5.1 we can not set DB_DBT_PARTIAL in the key Dbt, + // when using DB_SET, we must resize the Dbt key param to hold enought + // space or Dbc::get fails with DB_BUFFER_SMALL. + // + dbKey.set_flags(DB_DBT_USERMEM); + dbKey.set_ulen(static_cast(bytes.size())); +#endif Dbt dbValue; dbValue.set_flags(DB_DBT_USERMEM | DB_DBT_PARTIAL); diff --git a/cpp/src/Freeze/MapI.cpp b/cpp/src/Freeze/MapI.cpp index a136dee7a46..97911587265 100644 --- a/cpp/src/Freeze/MapI.cpp +++ b/cpp/src/Freeze/MapI.cpp @@ -440,13 +440,22 @@ Freeze::IteratorHelperI::find(const Key& key) const { Dbt dbKey; initializeInDbt(key, dbKey); +#if (DB_VERSION_MAJOR <= 4) || (DB_VERSION_MAJOR == 5 && DB_VERSION_MINOR <= 1) // // When we have a custom-comparison function, Berkeley DB returns // the key on-disk (when it finds one). We disable this behavior: // (ref Oracle SR 5925672.992) // dbKey.set_flags(DB_DBT_USERMEM | DB_DBT_PARTIAL); - +#else + // + // In DB > 5.1 we can not set DB_DBT_PARTIAL in the key Dbt, + // when using DB_SET, we must resize the Dbt key param to hold enought + // space or Dbc::get fails with DB_BUFFER_SMALL. + // + dbKey.set_flags(DB_DBT_USERMEM); + dbKey.set_ulen(static_cast(key.size())); +#endif // // Keep 0 length since we're not interested in the data // @@ -1766,12 +1775,22 @@ Freeze::MapIndexI::untypedCount(const Key& k, const ConnectionIPtr& connection) { Dbt dbKey; initializeInDbt(k, dbKey); +#if (DB_VERSION_MAJOR <= 4) // // When we have a custom-comparison function, Berkeley DB returns // the key on-disk (when it finds one). We disable this behavior: // (ref Oracle SR 5925672.992) // dbKey.set_flags(DB_DBT_USERMEM | DB_DBT_PARTIAL); +#else + // + // In DB 5.x we can not set DB_DBT_PARTIAL in the key Dbt, + // when using DB_SET, we must resize the Dbt key param to hold enought + // space or Dbc::get fails with DB_BUFFER_SMALL. + // + dbKey.set_flags(DB_DBT_USERMEM); + dbKey.set_ulen(static_cast(k.size())); +#endif Dbt dbValue; -- cgit v1.2.3