#include <db_cxx.h> int DbStream::write(Dbt *data, db_off_t offset, u_int32_t flags);
The DbStream::write()
method writes data
to an existing external file object in the database. This method
writes data contained in the Dbt
data to the external file stream.
Data is written into the stream starting at the position indicated by
offset. The amount of data
written is determined by the size
field in the
Dbt.
If this method writes data in the middle of the external file, it will overwrite existing data, instead of shifting it. If this method writes data to the end of the external file, the data is appended to the existing external file. You can determine how large an external file is using DbStream::size() .
To open a stream, use Dbc::db_stream() .
Unless otherwise specified, the
DbStream::write()
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.
The data parameter is
the Dbt containing the
data to be written to the external file. The amount of data
to be written is determined by the Dbt's
size
field.
The offset parameter identifies the position in the external file where the write operation will begin.
The flags parameter must be set to 0 or the following value:
A sync to disk operation is performed on the stream at the end of the write operation. By default, the sync is performed only when the stream is closed using DbStream::close() . Note that this flag can also be specified when the stream is created using Dbc::db_stream() , in which case the sync behavior becomes the default behavior for this stream instance.
The DbStream::write()
method may fail and throw a DbException
exception, encapsulating one of the following non-zero errors, or return one
of the following non-zero errors:
An invalid flag value or parameter was specified; or if the stream is read-only; or if the input Dbt was configured with DB_DBT_PARTIAL.