### Db::upgrade |

`

###

    #include <db_cxx.h>

    int
    Db::upgrade(const char *file, u_int32_t flags);

### Description: Db::upgrade

The Db::upgrade method upgrades all of the databases included in the file file, if necessary. If no upgrade is necessary, Db::upgrade always returns success.

Database upgrades are done in place and are destructive. For example, if pages need to be allocated and no disk space is available, the database may be left corrupted. Backups should be made before databases are upgraded. See Upgrading databases for more information.

Unlike all other database operations, Db::upgrade may only be done on a system with the same byte-order as the database.

The Db::upgrade method either returns a non-zero error value or throws an exception that encapsulates a non-zero error value on failure, and returns 0 on success.

### Parameters

file
  The file parameter is the physical file containing the databases to be upgraded.
flags
  The flags parameter must be set to 0 or the following value:
  DB_DUPSORT
    This flag is only meaningful when upgrading databases from releases before the Berkeley DB 3.1 release.

    As part of the upgrade from the Berkeley DB 3.0 release to the 3.1 release, the on-disk format of duplicate data items changed. To correctly upgrade the format requires applications to specify whether duplicate data items in the database are sorted or not. Specifying the DB_DUPSORT flag informs Db::upgrade that the duplicates are sorted; otherwise they are assumed to be unsorted. Incorrectly specifying the value of this flag may lead to database corruption.

    Further, because the Db::upgrade method upgrades a physical file (including all the databases it contains), it is not possible to use Db::upgrade to upgrade files in which some of the databases it includes have sorted duplicate data items, and some of the databases it includes have unsorted duplicate data items. If the file does not have more than a single database, if the databases do not support duplicate data items, or if all of the databases that support duplicate data items support the same style of duplicates (either sorted or unsorted), Db::upgrade will work correctly as long as the DB_DUPSORT flag is correctly specified. Otherwise, the file cannot be upgraded using Db::upgrade; it must be upgraded manually by dumping and reloading the databases.

### Environment Variables

If the database was opened within a database environment, the environment variable DB_HOME may be used as the path of the database environment home.

Db::upgrade is affected by any database directory specified using the DbEnv::set_data_dir method, or by setting the "set_data_dir" string in the environment's DB_CONFIG file.

### Errors

The Db::upgrade method may fail and throw DbException, encapsulating one of the following non-zero errors, or return one of the following non-zero errors:

DB_OLD_VERSION
  The database cannot be upgraded by this version of the Berkeley DB software.

EINVAL
  If the database is not in the same byte-order as the system; or if an invalid flag value or parameter was specified.

### Class

Db

### See Also

Databases and Related Methods`

Copyright (c) 1996,2007 Oracle. All rights reserved.