### Berkeley DB Reference Guide: Upgrading Berkeley DB Applications |

### Release 3.1: DB->put

For the Queue and Recno access methods, when the DB_APPEND flag is specified to the DB->put method, the allocated record number is returned to the application in the key DBT argument. In previous releases of Berkeley DB, this DBT structure did not follow the usual DBT conventions. For example, it was not possible to cause Berkeley DB to allocate space for the returned record number. Rather, it was always assumed that the data field of the key structure referred to memory that could be used as storage for a db_recno_t type.

As of the Berkeley DB 3.1.0 release, the key structure behaves as described in the DBT C++/Java class or C structure documentation.

Applications which are using the DB_APPEND flag for Queue and Recno access method databases will require a change to upgrade to the Berkeley DB 3.1 releases. The simplest change is likely to be to add the DB_DBT_USERMEM flag to the key structure. For example, code that appears as follows:

>     DBT key;
>     db_recno_t recno;

>     memset(&key, 0, sizeof(DBT));
>     key.data = &recno;
>     key.size = sizeof(recno);
>     DB->put(DB, NULL, &key, &data, DB_APPEND);
>     printf("new record number is %lu\n", (u_long)recno);

would be changed to:

>     DBT key;
>     db_recno_t recno;

>     memset(&key, 0, sizeof(DBT));
>     key.data = &recno;
>     key.ulen = sizeof(recno);
>     key.flags = DB_DBT_USERMEM;
>     DB->put(DB, NULL, &key, &data, DB_APPEND);
>     printf("new record number is %lu\n", (u_long)recno);

Note that the ulen field is now set as well as the flag value. An alternative change would be:

>     DBT key;
>     db_recno_t recno;

>     memset(&key, 0, sizeof(DBT));
>     DB->put(DB, NULL, &key, &data, DB_APPEND);
>     recno = *(db_recno_t *)key->data;
>     printf("new record number is %lu\n", (u_long)recno);

Copyright (c) 1996-2004 Sleepycat Software, Inc. - All rights reserved.