db_cxx.in 32.8 KB
Newer Older
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
1 2 3
/*-
 * See the file LICENSE for redistribution information.
 *
jimw@mysql.com's avatar
jimw@mysql.com committed
4
 * Copyright (c) 1997-2004
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
5 6
 *	Sleepycat Software.  All rights reserved.
 *
jimw@mysql.com's avatar
jimw@mysql.com committed
7
 * $Id: db_cxx.in,v 11.147 2004/10/07 21:39:48 bostic Exp $
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
 */

#ifndef _DB_CXX_H_
#define	_DB_CXX_H_
//
// C++ assumptions:
//
// To ensure portability to many platforms, both new and old, we make
// few assumptions about the C++ compiler and library.  For example,
// we do not expect STL, templates or namespaces to be available.  The
// "newest" C++ feature used is exceptions, which are used liberally
// to transmit error information.  Even the use of exceptions can be
// disabled at runtime, to do so, use the DB_CXX_NO_EXCEPTIONS flags
// with the DbEnv or Db constructor.
//
// C++ naming conventions:
//
//  - All top level class names start with Db.
//  - All class members start with lower case letter.
//  - All private data members are suffixed with underscore.
//  - Use underscores to divide names into multiple words.
//  - Simple data accessors are named with get_ or set_ prefix.
//  - All method names are taken from names of functions in the C
//    layer of db (usually by dropping a prefix like "db_").
//    These methods have the same argument types and order,
//    other than dropping the explicit arg that acts as "this".
//
// As a rule, each DbFoo object has exactly one underlying DB_FOO struct
// (defined in db.h) associated with it.  In some cases, we inherit directly
// from the DB_FOO structure to make this relationship explicit.  Often,
// the underlying C layer allocates and deallocates these structures, so
// there is no easy way to add any data to the DbFoo class.  When you see
// a comment about whether data is permitted to be added, this is what
// is going on.  Of course, if we need to add data to such C++ classes
// in the future, we will arrange to have an indirect pointer to the
// DB_FOO struct (as some of the classes already have).
//

////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
//
// Forward declarations
//

#include <stdarg.h>

@cxx_have_stdheaders@
#ifdef HAVE_CXX_STDHEADERS
#include <iostream>
jimw@mysql.com's avatar
jimw@mysql.com committed
57 58
#include <exception>
#define	__DB_STD(x)	std::x
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
59 60
#else
#include <iostream.h>
jimw@mysql.com's avatar
jimw@mysql.com committed
61 62
#include <exception.h>
#define	__DB_STD(x)	x
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
#endif

#include "db.h"

class Db;                                        // forward
class Dbc;                                       // forward
class DbEnv;                                     // forward
class DbInfo;                                    // forward
class DbLock;                                    // forward
class DbLogc;                                    // forward
class DbLsn;                                     // forward
class DbMpoolFile;                               // forward
class DbPreplist;                                // forward
class Dbt;                                       // forward
class DbTxn;                                     // forward
jimw@mysql.com's avatar
jimw@mysql.com committed
78 79 80
class DbLock;                                    // forward
class DbSequence;                                // forward
class Dbt;                                       // forward
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
81

jimw@mysql.com's avatar
jimw@mysql.com committed
82 83 84 85
class DbMultipleIterator;                        // forward
class DbMultipleKeyDataIterator;                 // forward
class DbMultipleRecnoDataIterator;               // forward
class DbMultipleDataIterator;                    // forward
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
86

jimw@mysql.com's avatar
jimw@mysql.com committed
87 88 89 90 91
class DbException;                               // forward
class DbDeadlockException;                       // forward
class DbLockNotGrantedException;                 // forward
class DbMemoryException;                         // forward
class DbRunRecoveryException;                    // forward
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115

////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
//
// Turn off inappropriate compiler warnings
//

#ifdef _MSC_VER

// These are level 4 warnings that are explicitly disabled.
// With Visual C++, by default you do not see above level 3 unless
// you use /W4.  But we like to compile with the highest level
// warnings to catch other errors.
//
// 4201: nameless struct/union
//       triggered by standard include file <winnt.h>
//
// 4514: unreferenced inline function has been removed
//       certain include files in MSVC define methods that are not called
//
#pragma warning(disable: 4201 4514)

#endif

jimw@mysql.com's avatar
jimw@mysql.com committed
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
//
// Mechanisms for declaring classes
//

//
// Every class defined in this file has an _exported next to the class name.
// This is needed for WinTel machines so that the class methods can
// be exported or imported in a DLL as appropriate.  Users of the DLL
// use the define DB_USE_DLL.  When the DLL is built, DB_CREATE_DLL
// must be defined.
//
#if defined(_MSC_VER)

#  if defined(DB_CREATE_DLL)
#    define _exported __declspec(dllexport)      // creator of dll
#  elif defined(DB_USE_DLL)
#    define _exported __declspec(dllimport)      // user of dll
#  else
#    define _exported                            // static lib creator or user
#  endif

#else /* _MSC_VER */

#  define _exported

#endif /* _MSC_VER */

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
// Some interfaces can be customized by allowing users to define
// callback functions.  For performance and logistical reasons, some
// callback functions must be declared in extern "C" blocks.  For others,
// we allow you to declare the callbacks in C++ or C (or an extern "C"
// block) as you wish.  See the set methods for the callbacks for
// the choices.
//
extern "C" {
	typedef void * (*db_malloc_fcn_type)
		(size_t);
	typedef void * (*db_realloc_fcn_type)
		(void *, size_t);
	typedef void (*db_free_fcn_type)
		(void *);
	typedef int (*bt_compare_fcn_type)          /*C++ version available*/
		(DB *, const DBT *, const DBT *);
	typedef size_t (*bt_prefix_fcn_type)        /*C++ version available*/
		(DB *, const DBT *, const DBT *);
	typedef int (*dup_compare_fcn_type)         /*C++ version available*/
		(DB *, const DBT *, const DBT *);
	typedef u_int32_t (*h_hash_fcn_type)        /*C++ version available*/
		(DB *, const void *, u_int32_t);
	typedef int (*pgin_fcn_type)
		(DB_ENV *dbenv, db_pgno_t pgno, void *pgaddr, DBT *pgcookie);
	typedef int (*pgout_fcn_type)
		(DB_ENV *dbenv, db_pgno_t pgno, void *pgaddr, DBT *pgcookie);
jimw@mysql.com's avatar
jimw@mysql.com committed
171
}
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
172 173

//
jimw@mysql.com's avatar
jimw@mysql.com committed
174
// Represents a database table = a set of keys with associated values.
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
175
//
jimw@mysql.com's avatar
jimw@mysql.com committed
176
class _exported Db
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
177 178 179 180
{
	friend class DbEnv;

public:
jimw@mysql.com's avatar
jimw@mysql.com committed
181 182
	Db(DbEnv*, u_int32_t);      // create a Db object, then call open()
	virtual ~Db();              // does *not* call close.
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
183

jimw@mysql.com's avatar
jimw@mysql.com committed
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
	// These methods exactly match those in the C interface.
	//
	virtual int associate(DbTxn *txn, Db *secondary,
	    int (*callback)(Db *, const Dbt *, const Dbt *, Dbt *),
	    u_int32_t flags);
	virtual int close(u_int32_t flags);
	virtual int cursor(DbTxn *txnid, Dbc **cursorp, u_int32_t flags);
	virtual int del(DbTxn *txnid, Dbt *key, u_int32_t flags);
	virtual void err(int, const char *, ...);
	virtual void errx(const char *, ...);
	virtual int fd(int *fdp);
	virtual int get(DbTxn *txnid, Dbt *key, Dbt *data, u_int32_t flags);
	virtual void *get_app_private() const;
	virtual int get_byteswapped(int *);
	virtual int get_dbname(const char **, const char **);
	virtual int get_open_flags(u_int32_t *);
	virtual int get_type(DBTYPE *);
	virtual int get_transactional();
	virtual int join(Dbc **curslist, Dbc **dbcp, u_int32_t flags);
	virtual int key_range(DbTxn *, Dbt *, DB_KEY_RANGE *, u_int32_t);
	virtual int open(DbTxn *txnid,
	    const char *, const char *subname, DBTYPE, u_int32_t, int);
	virtual int pget(DbTxn *txnid, Dbt *key, Dbt *pkey, Dbt *data,
		 u_int32_t flags);
	virtual int put(DbTxn *, Dbt *, Dbt *, u_int32_t);
	virtual int remove(const char *, const char *, u_int32_t);
	virtual int rename(const char *, const char *, const char *, u_int32_t);
	virtual int set_alloc(db_malloc_fcn_type, db_realloc_fcn_type,
		      db_free_fcn_type);
	virtual void set_app_private(void *);
	virtual int set_append_recno(int (*)(Db *, Dbt *, db_recno_t));
	virtual int set_bt_compare(bt_compare_fcn_type); /*deprecated*/
	virtual int set_bt_compare(int (*)(Db *, const Dbt *, const Dbt *));
	virtual int set_bt_maxkey(u_int32_t);
	virtual int get_bt_minkey(u_int32_t *);
	virtual int set_bt_minkey(u_int32_t);
	virtual int set_bt_prefix(bt_prefix_fcn_type); /*deprecated*/
	virtual int set_bt_prefix(size_t (*)(Db *, const Dbt *, const Dbt *));
	virtual int get_cachesize(u_int32_t *, u_int32_t *, int *);
	virtual int set_cachesize(u_int32_t, u_int32_t, int);
	virtual int set_dup_compare(dup_compare_fcn_type); /*deprecated*/
	virtual int set_dup_compare(int (*)(Db *, const Dbt *, const Dbt *));
	virtual int get_encrypt_flags(u_int32_t *);
	virtual int set_encrypt(const char *, u_int32_t);
	virtual void set_errcall(
			void (*)(const DbEnv *, const char *, const char *));
	virtual void get_errfile(FILE **);
	virtual void set_errfile(FILE *);
	virtual void get_errpfx(const char **);
	virtual void set_errpfx(const char *);
	virtual int set_feedback(void (*)(Db *, int, int));
	virtual int get_flags(u_int32_t *);
	virtual int set_flags(u_int32_t);
	virtual int get_h_ffactor(u_int32_t *);
	virtual int set_h_ffactor(u_int32_t);
	virtual int set_h_hash(h_hash_fcn_type); /*deprecated*/
	virtual int set_h_hash(u_int32_t (*)(Db *, const void *, u_int32_t));
	virtual int get_h_nelem(u_int32_t *);
	virtual int set_h_nelem(u_int32_t);
	virtual int get_lorder(int *);
	virtual int set_lorder(int);
	virtual void set_msgcall(void (*)(const DbEnv *, const char *));
	virtual void get_msgfile(FILE **);
	virtual void set_msgfile(FILE *);
	virtual int get_pagesize(u_int32_t *);
	virtual int set_pagesize(u_int32_t);
	virtual int set_paniccall(void (*)(DbEnv *, int));
	virtual int get_re_delim(int *);
	virtual int set_re_delim(int);
	virtual int get_re_len(u_int32_t *);
	virtual int set_re_len(u_int32_t);
	virtual int get_re_pad(int *);
	virtual int set_re_pad(int);
	virtual int get_re_source(const char **);
	virtual int set_re_source(const char *);
	virtual int get_q_extentsize(u_int32_t *);
	virtual int set_q_extentsize(u_int32_t);
	virtual int stat(DbTxn *, void *sp, u_int32_t flags);
	virtual int stat_print(u_int32_t flags);
	virtual int sync(u_int32_t flags);
	virtual int truncate(DbTxn *, u_int32_t *, u_int32_t);
	virtual int upgrade(const char *name, u_int32_t flags);
	virtual int verify(const char *, const char *, __DB_STD(ostream) *,
		      u_int32_t);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
268

jimw@mysql.com's avatar
jimw@mysql.com committed
269 270 271 272 273 274 275
	// These additional methods are not in the C interface, and
	// are only available for C++.
	//
	virtual __DB_STD(ostream) *get_error_stream();
	virtual void set_error_stream(__DB_STD(ostream) *);
	virtual __DB_STD(ostream) *get_message_stream();
	virtual void set_message_stream(__DB_STD(ostream) *);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
276

jimw@mysql.com's avatar
jimw@mysql.com committed
277 278
	virtual DbEnv *get_env();
	virtual DbMpoolFile *get_mpf();
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
279

jimw@mysql.com's avatar
jimw@mysql.com committed
280
	virtual DB *get_DB()
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
281
	{
jimw@mysql.com's avatar
jimw@mysql.com committed
282
		return imp_;
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
283 284
	}

jimw@mysql.com's avatar
jimw@mysql.com committed
285
	virtual const DB *get_const_DB() const
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
286
	{
jimw@mysql.com's avatar
jimw@mysql.com committed
287
		return imp_;
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
288 289
	}

jimw@mysql.com's avatar
jimw@mysql.com committed
290 291 292 293
	static Db* get_Db(DB *db)
	{
		return (Db *)db->api_internal;
	}
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
294

jimw@mysql.com's avatar
jimw@mysql.com committed
295 296 297 298
	static const Db* get_const_Db(const DB *db)
	{
		return (const Db *)db->api_internal;
	}
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
299 300 301

private:
	// no copying
jimw@mysql.com's avatar
jimw@mysql.com committed
302 303
	Db(const Db &);
	Db &operator = (const Db &);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
304

jimw@mysql.com's avatar
jimw@mysql.com committed
305 306 307 308 309 310 311 312 313 314 315
	void cleanup();
	int initialize();
	int error_policy();

	// instance data
	DB *imp_;
	DbEnv *env_;
	DbMpoolFile *mpf_;
	int construct_error_;
	u_int32_t flags_;
	u_int32_t construct_flags_;
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
316 317

public:
jimw@mysql.com's avatar
jimw@mysql.com committed
318 319 320 321 322 323 324 325 326 327 328
	// These are public only because they need to be called
	// via C callback functions.  They should never be used by
	// external users of this class.
	//
	int (*append_recno_callback_)(Db *, Dbt *, db_recno_t);
	int (*associate_callback_)(Db *, const Dbt *, const Dbt *, Dbt *);
	int (*bt_compare_callback_)(Db *, const Dbt *, const Dbt *);
	size_t (*bt_prefix_callback_)(Db *, const Dbt *, const Dbt *);
	int (*dup_compare_callback_)(Db *, const Dbt *, const Dbt *);
	void (*feedback_callback_)(Db *, int, int);
	u_int32_t (*h_hash_callback_)(Db *, const void *, u_int32_t);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
329 330 331
};

//
jimw@mysql.com's avatar
jimw@mysql.com committed
332
// Cursor
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
333
//
jimw@mysql.com's avatar
jimw@mysql.com committed
334
class _exported Dbc : protected DBC
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
335
{
jimw@mysql.com's avatar
jimw@mysql.com committed
336
	friend class Db;
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
337 338

public:
jimw@mysql.com's avatar
jimw@mysql.com committed
339 340 341 342 343 344 345
	int close();
	int count(db_recno_t *countp, u_int32_t flags);
	int del(u_int32_t flags);
	int dup(Dbc** cursorp, u_int32_t flags);
	int get(Dbt* key, Dbt *data, u_int32_t flags);
	int pget(Dbt* key, Dbt* pkey, Dbt *data, u_int32_t flags);
	int put(Dbt* key, Dbt *data, u_int32_t flags);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
346 347

private:
jimw@mysql.com's avatar
jimw@mysql.com committed
348
	// No data is permitted in this class (see comment at top)
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
349

jimw@mysql.com's avatar
jimw@mysql.com committed
350 351
	// Note: use Db::cursor() to get pointers to a Dbc,
	// and call Dbc::close() rather than delete to release them.
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
352
	//
jimw@mysql.com's avatar
jimw@mysql.com committed
353 354
	Dbc();
	~Dbc();
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
355 356

	// no copying
jimw@mysql.com's avatar
jimw@mysql.com committed
357 358
	Dbc(const Dbc &);
	Dbc &operator = (const Dbc &);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395
};

//
// Berkeley DB environment class.  Provides functions for opening databases.
// User of this library can use this class as a starting point for
// developing a DB application - derive their application class from
// this one, add application control logic.
//
// Note that if you use the default constructor, you must explicitly
// call appinit() before any other db activity (e.g. opening files)
//
class _exported DbEnv
{
	friend class Db;
	friend class DbLock;
	friend class DbMpoolFile;

public:
	// After using this constructor, you can set any needed
	// parameters for the environment using the set_* methods.
	// Then call open() to finish initializing the environment
	// and attaching it to underlying files.
	//
	DbEnv(u_int32_t flags);

	virtual ~DbEnv();

	// These methods match those in the C interface.
	//
	virtual int close(u_int32_t);
	virtual int dbremove(DbTxn *txn, const char *name, const char *subdb,
	    u_int32_t flags);
	virtual int dbrename(DbTxn *txn, const char *name, const char *subdb,
	    const char *newname, u_int32_t flags);
	virtual void err(int, const char *, ...);
	virtual void errx(const char *, ...);
	virtual void *get_app_private() const;
jimw@mysql.com's avatar
jimw@mysql.com committed
396 397
	virtual int get_home(const char **);
	virtual int get_open_flags(u_int32_t *);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
398 399 400
	virtual int open(const char *, u_int32_t, int);
	virtual int remove(const char *, u_int32_t);
	virtual int set_alloc(db_malloc_fcn_type, db_realloc_fcn_type,
jimw@mysql.com's avatar
jimw@mysql.com committed
401
			      db_free_fcn_type);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
402
	virtual void set_app_private(void *);
jimw@mysql.com's avatar
jimw@mysql.com committed
403
	virtual int get_cachesize(u_int32_t *, u_int32_t *, int *);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
404
	virtual int set_cachesize(u_int32_t, u_int32_t, int);
jimw@mysql.com's avatar
jimw@mysql.com committed
405
	virtual int get_data_dirs(const char ***);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
406
	virtual int set_data_dir(const char *);
jimw@mysql.com's avatar
jimw@mysql.com committed
407 408 409 410 411
	virtual int get_encrypt_flags(u_int32_t *);
	virtual int set_encrypt(const char *, u_int32_t);
	virtual void set_errcall(
			void (*)(const DbEnv *, const char *, const char *));
	virtual void get_errfile(FILE **);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
412
	virtual void set_errfile(FILE *);
jimw@mysql.com's avatar
jimw@mysql.com committed
413
	virtual void get_errpfx(const char **);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
414
	virtual void set_errpfx(const char *);
jimw@mysql.com's avatar
jimw@mysql.com committed
415
	virtual int get_flags(u_int32_t *);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
416 417
	virtual int set_flags(u_int32_t, int);
	virtual int set_feedback(void (*)(DbEnv *, int, int));
jimw@mysql.com's avatar
jimw@mysql.com committed
418
	virtual int get_lg_bsize(u_int32_t *);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
419
	virtual int set_lg_bsize(u_int32_t);
jimw@mysql.com's avatar
jimw@mysql.com committed
420
	virtual int get_lg_dir(const char **);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
421
	virtual int set_lg_dir(const char *);
jimw@mysql.com's avatar
jimw@mysql.com committed
422
	virtual int get_lg_max(u_int32_t *);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
423
	virtual int set_lg_max(u_int32_t);
jimw@mysql.com's avatar
jimw@mysql.com committed
424
	virtual int get_lg_regionmax(u_int32_t *);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
425
	virtual int set_lg_regionmax(u_int32_t);
jimw@mysql.com's avatar
jimw@mysql.com committed
426
	virtual int get_lk_conflicts(const u_int8_t **, int *);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
427
	virtual int set_lk_conflicts(u_int8_t *, int);
jimw@mysql.com's avatar
jimw@mysql.com committed
428
	virtual int get_lk_detect(u_int32_t *);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
429 430
	virtual int set_lk_detect(u_int32_t);
	virtual int set_lk_max(u_int32_t);
jimw@mysql.com's avatar
jimw@mysql.com committed
431
	virtual int get_lk_max_lockers(u_int32_t *);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
432
	virtual int set_lk_max_lockers(u_int32_t);
jimw@mysql.com's avatar
jimw@mysql.com committed
433
	virtual int get_lk_max_locks(u_int32_t *);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
434
	virtual int set_lk_max_locks(u_int32_t);
jimw@mysql.com's avatar
jimw@mysql.com committed
435
	virtual int get_lk_max_objects(u_int32_t *);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
436
	virtual int set_lk_max_objects(u_int32_t);
jimw@mysql.com's avatar
jimw@mysql.com committed
437
	virtual int get_mp_mmapsize(size_t *);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
438
	virtual int set_mp_mmapsize(size_t);
jimw@mysql.com's avatar
jimw@mysql.com committed
439 440 441
	virtual void set_msgcall(void (*)(const DbEnv *, const char *));
	virtual void get_msgfile(FILE **);
	virtual void set_msgfile(FILE *);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
442 443
	virtual int set_paniccall(void (*)(DbEnv *, int));
	virtual int set_rpc_server(void *, char *, long, long, u_int32_t);
jimw@mysql.com's avatar
jimw@mysql.com committed
444
	virtual int get_shm_key(long *);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
445
	virtual int set_shm_key(long);
jimw@mysql.com's avatar
jimw@mysql.com committed
446 447 448
	virtual int get_timeout(db_timeout_t *, u_int32_t);
	virtual int set_timeout(db_timeout_t, u_int32_t);
	virtual int get_tmp_dir(const char **);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
449
	virtual int set_tmp_dir(const char *);
jimw@mysql.com's avatar
jimw@mysql.com committed
450
	virtual int get_tas_spins(u_int32_t *);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
451
	virtual int set_tas_spins(u_int32_t);
jimw@mysql.com's avatar
jimw@mysql.com committed
452
	virtual int get_tx_max(u_int32_t *);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
453 454 455
	virtual int set_tx_max(u_int32_t);
	virtual int set_app_dispatch(int (*)(DbEnv *,
	    Dbt *, DbLsn *, db_recops));
jimw@mysql.com's avatar
jimw@mysql.com committed
456
	virtual int get_tx_timestamp(time_t *);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
457
	virtual int set_tx_timestamp(time_t *);
jimw@mysql.com's avatar
jimw@mysql.com committed
458 459
	virtual int get_verbose(u_int32_t which, int *);
	virtual int set_verbose(u_int32_t which, int);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476

	// Version information.  A static method so it can be obtained anytime.
	//
	static char *version(int *major, int *minor, int *patch);

	// Convert DB errors to strings
	static char *strerror(int);

	// If an error is detected and the error call function
	// or stream is set, a message is dispatched or printed.
	// If a prefix is set, each message is prefixed.
	//
	// You can use set_errcall() or set_errfile() above to control
	// error functionality.  Alternatively, you can call
	// set_error_stream() to force all errors to a C++ stream.
	// It is unwise to mix these approaches.
	//
jimw@mysql.com's avatar
jimw@mysql.com committed
477 478 479 480
	virtual __DB_STD(ostream) *get_error_stream();
	virtual void set_error_stream(__DB_STD(ostream) *);
	virtual __DB_STD(ostream) *get_message_stream();
	virtual void set_message_stream(__DB_STD(ostream) *);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
481 482

	// used internally
jimw@mysql.com's avatar
jimw@mysql.com committed
483
	static void runtime_error(DbEnv *env, const char *caller, int err,
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
484
				  int error_policy);
jimw@mysql.com's avatar
jimw@mysql.com committed
485
	static void runtime_error_dbt(DbEnv *env, const char *caller, Dbt *dbt,
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
486
				  int error_policy);
jimw@mysql.com's avatar
jimw@mysql.com committed
487 488
	static void runtime_error_lock_get(DbEnv *env, const char *caller,
				  int err, db_lockop_t op, db_lockmode_t mode,
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
489 490 491 492 493 494 495 496 497 498 499 500
				  const Dbt *obj, DbLock lock, int index,
				  int error_policy);

	// Lock functions
	//
	virtual int lock_detect(u_int32_t flags, u_int32_t atype, int *aborted);
	virtual int lock_get(u_int32_t locker, u_int32_t flags, const Dbt *obj,
		     db_lockmode_t lock_mode, DbLock *lock);
	virtual int lock_id(u_int32_t *idp);
	virtual int lock_id_free(u_int32_t id);
	virtual int lock_put(DbLock *lock);
	virtual int lock_stat(DB_LOCK_STAT **statp, u_int32_t flags);
jimw@mysql.com's avatar
jimw@mysql.com committed
501 502 503
	virtual int lock_stat_print(u_int32_t flags);
	virtual int lock_vec(u_int32_t locker, u_int32_t flags,
		     DB_LOCKREQ list[], int nlist, DB_LOCKREQ **elistp);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
504 505 506 507 508 509 510 511 512 513 514

	// Log functions
	//
	virtual int log_archive(char **list[], u_int32_t flags);
	static int log_compare(const DbLsn *lsn0, const DbLsn *lsn1);
	virtual int log_cursor(DbLogc **cursorp, u_int32_t flags);
	virtual int log_file(DbLsn *lsn, char *namep, size_t len);
	virtual int log_flush(const DbLsn *lsn);
	virtual int log_put(DbLsn *lsn, const Dbt *data, u_int32_t flags);

	virtual int log_stat(DB_LOG_STAT **spp, u_int32_t flags);
jimw@mysql.com's avatar
jimw@mysql.com committed
515
	virtual int log_stat_print(u_int32_t flags);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
516 517 518 519 520 521 522 523 524

	// Mpool functions
	//
	virtual int memp_fcreate(DbMpoolFile **dbmfp, u_int32_t flags);
	virtual int memp_register(int ftype,
			  pgin_fcn_type pgin_fcn,
			  pgout_fcn_type pgout_fcn);
	virtual int memp_stat(DB_MPOOL_STAT
		      **gsp, DB_MPOOL_FSTAT ***fsp, u_int32_t flags);
jimw@mysql.com's avatar
jimw@mysql.com committed
525
	virtual int memp_stat_print(u_int32_t flags);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
526 527 528 529 530 531
	virtual int memp_sync(DbLsn *lsn);
	virtual int memp_trickle(int pct, int *nwrotep);

	// Transaction functions
	//
	virtual int txn_begin(DbTxn *pid, DbTxn **tid, u_int32_t flags);
jimw@mysql.com's avatar
jimw@mysql.com committed
532 533
	virtual int txn_checkpoint(u_int32_t kbyte, u_int32_t min,
			u_int32_t flags);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
534 535 536
	virtual int txn_recover(DbPreplist *preplist, long count,
			long *retp, u_int32_t flags);
	virtual int txn_stat(DB_TXN_STAT **statp, u_int32_t flags);
jimw@mysql.com's avatar
jimw@mysql.com committed
537
	virtual int txn_stat_print(u_int32_t flags);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
538 539 540

	// Replication functions
	//
jimw@mysql.com's avatar
jimw@mysql.com committed
541 542
	virtual int rep_elect(int, int, int, u_int32_t, int *, u_int32_t);
	virtual int rep_process_message(Dbt *, Dbt *, int *, DbLsn *);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
543 544
	virtual int rep_start(Dbt *, u_int32_t);
	virtual int rep_stat(DB_REP_STAT **statp, u_int32_t flags);
jimw@mysql.com's avatar
jimw@mysql.com committed
545 546
	virtual int rep_stat_print(u_int32_t flags);
	virtual int get_rep_limit(u_int32_t *, u_int32_t *);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
547
	virtual int set_rep_limit(u_int32_t, u_int32_t);
jimw@mysql.com's avatar
jimw@mysql.com committed
548 549
	virtual int set_rep_transport(int, int (*)(DbEnv *,
	    const Dbt *, const Dbt *, const DbLsn *, int, u_int32_t));
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
550 551 552 553 554

	// Conversion functions
	//
	virtual DB_ENV *get_DB_ENV()
	{
jimw@mysql.com's avatar
jimw@mysql.com committed
555
		return imp_;
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
556 557 558 559
	}

	virtual const DB_ENV *get_const_DB_ENV() const
	{
jimw@mysql.com's avatar
jimw@mysql.com committed
560
		return imp_;
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
561 562 563 564
	}

	static DbEnv* get_DbEnv(DB_ENV *dbenv)
	{
jimw@mysql.com's avatar
jimw@mysql.com committed
565
		return dbenv ? (DbEnv *)dbenv->api1_internal : 0;
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
566 567 568 569
	}

	static const DbEnv* get_const_DbEnv(const DB_ENV *dbenv)
	{
jimw@mysql.com's avatar
jimw@mysql.com committed
570
		return dbenv ? (const DbEnv *)dbenv->api1_internal : 0;
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
571 572 573 574 575 576 577 578 579 580
	}

	// For internal use only.
	static DbEnv* wrap_DB_ENV(DB_ENV *dbenv);

	// These are public only because they need to be called
	// via C functions.  They should never be called by users
	// of this class.
	//
	static int _app_dispatch_intercept(DB_ENV *env, DBT *dbt, DB_LSN *lsn,
jimw@mysql.com's avatar
jimw@mysql.com committed
581
				       db_recops op);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
582 583 584 585
	static void _paniccall_intercept(DB_ENV *env, int errval);
	static void _feedback_intercept(DB_ENV *env, int opcode, int pct);
	static int _rep_send_intercept(DB_ENV *env,
				       const DBT *cntrl, const DBT *data,
jimw@mysql.com's avatar
jimw@mysql.com committed
586 587 588 589 590 591 592
				       const DB_LSN *lsn, int id,
				       u_int32_t flags);
	static void _stream_error_function(const DB_ENV *env,
					   const char *prefix,
					   const char *message);
	static void _stream_message_function(const DB_ENV *env,
					     const char *message);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
593 594 595 596 597 598 599 600 601 602 603 604 605 606

private:
	void cleanup();
	int initialize(DB_ENV *env);
	int error_policy();

	// For internal use only.
	DbEnv(DB_ENV *, u_int32_t flags);

	// no copying
	DbEnv(const DbEnv &);
	void operator = (const DbEnv &);

	// instance data
jimw@mysql.com's avatar
jimw@mysql.com committed
607
	DB_ENV *imp_;
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
608 609
	int construct_error_;
	u_int32_t construct_flags_;
jimw@mysql.com's avatar
jimw@mysql.com committed
610 611 612
	__DB_STD(ostream) *error_stream_;
	__DB_STD(ostream) *message_stream_;

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
613
	int (*app_dispatch_callback_)(DbEnv *, Dbt *, DbLsn *, db_recops);
jimw@mysql.com's avatar
jimw@mysql.com committed
614
	void (*error_callback_)(const DbEnv *, const char *, const char *);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
615
	void (*feedback_callback_)(DbEnv *, int, int);
jimw@mysql.com's avatar
jimw@mysql.com committed
616
	void (*message_callback_)(const DbEnv *, const char *);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
617 618 619 620 621 622
	void (*paniccall_callback_)(DbEnv *, int);
	int (*pgin_callback_)(DbEnv *dbenv, db_pgno_t pgno,
			      void *pgaddr, Dbt *pgcookie);
	int (*pgout_callback_)(DbEnv *dbenv, db_pgno_t pgno,
			       void *pgaddr, Dbt *pgcookie);
	int (*rep_send_callback_)(DbEnv *,
jimw@mysql.com's avatar
jimw@mysql.com committed
623
	    const Dbt *, const Dbt *, const DbLsn *, int, u_int32_t);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
624 625 626
};

//
jimw@mysql.com's avatar
jimw@mysql.com committed
627
// Lock
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
628
//
jimw@mysql.com's avatar
jimw@mysql.com committed
629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645
class _exported DbLock
{
	friend class DbEnv;

public:
	DbLock();
	DbLock(const DbLock &);
	DbLock &operator = (const DbLock &);

protected:
	// We can add data to this class if needed
	// since its contained class is not allocated by db.
	// (see comment at top)

	DbLock(DB_LOCK);
	DB_LOCK lock_;
};
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
646 647

//
jimw@mysql.com's avatar
jimw@mysql.com committed
648
// Log cursor
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
649
//
jimw@mysql.com's avatar
jimw@mysql.com committed
650
class _exported DbLogc : protected DB_LOGC
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
651 652 653
{
	friend class DbEnv;

jimw@mysql.com's avatar
jimw@mysql.com committed
654 655 656 657
public:
	int close(u_int32_t _flags);
	int get(DbLsn *lsn, Dbt *data, u_int32_t _flags);

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
658
private:
jimw@mysql.com's avatar
jimw@mysql.com committed
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687
	// No data is permitted in this class (see comment at top)

	// Note: use Db::cursor() to get pointers to a Dbc,
	// and call Dbc::close() rather than delete to release them.
	//
	DbLogc();
	~DbLogc();

	// no copying
	DbLogc(const Dbc &);
	DbLogc &operator = (const Dbc &);
};

//
// Log sequence number
//
class _exported DbLsn : public DB_LSN
{
	friend class DbEnv;          // friendship needed to cast to base class
	friend class DbLogc;         // friendship needed to cast to base class
};

//
// Memory pool file
//
class _exported DbMpoolFile
{
	friend class DbEnv;
	friend class Db;
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
688 689

public:
jimw@mysql.com's avatar
jimw@mysql.com committed
690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712
	int close(u_int32_t flags);
	int get(db_pgno_t *pgnoaddr, u_int32_t flags, void *pagep);
	int open(const char *file, u_int32_t flags, int mode, size_t pagesize);
	int get_transactional(void);
	int put(void *pgaddr, u_int32_t flags);
	int set(void *pgaddr, u_int32_t flags);
	int get_clear_len(u_int32_t *len);
	int set_clear_len(u_int32_t len);
	int get_fileid(u_int8_t *fileid);
	int set_fileid(u_int8_t *fileid);
	int get_flags(u_int32_t *flagsp);
	int set_flags(u_int32_t flags, int onoff);
	int get_ftype(int *ftype);
	int set_ftype(int ftype);
	int get_lsn_offset(int32_t *offsetp);
	int set_lsn_offset(int32_t offset);
	int get_maxsize(u_int32_t *gbytes, u_int32_t *bytes);
	int set_maxsize(u_int32_t gbytes, u_int32_t bytes);
	int get_pgcookie(DBT *dbt);
	int set_pgcookie(DBT *dbt);
	int get_priority(DB_CACHE_PRIORITY *priorityp);
	int set_priority(DB_CACHE_PRIORITY priority);
	int sync();
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
713

jimw@mysql.com's avatar
jimw@mysql.com committed
714 715 716 717
	virtual DB_MPOOLFILE *get_DB_MPOOLFILE()
	{
		return imp_;
	}
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
718

jimw@mysql.com's avatar
jimw@mysql.com committed
719 720 721 722 723 724 725 726 727 728 729 730 731 732
	virtual const DB_MPOOLFILE *get_const_DB_MPOOLFILE() const
	{
		return imp_;
	}

private:
	DB_MPOOLFILE *imp_;

	// We can add data to this class if needed
	// since it is implemented via a pointer.
	// (see comment at top)

	// Note: use DbEnv::memp_fcreate() to get pointers to a DbMpoolFile,
	// and call DbMpoolFile::close() rather than delete to release them.
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
733
	//
jimw@mysql.com's avatar
jimw@mysql.com committed
734
	DbMpoolFile();
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
735

jimw@mysql.com's avatar
jimw@mysql.com committed
736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783
	// Shut g++ up.
protected:
	virtual ~DbMpoolFile();

private:
	// no copying
	DbMpoolFile(const DbMpoolFile &);
	void operator = (const DbMpoolFile &);
};

//
// This is filled in and returned by the DbEnv::txn_recover() method.
//
class _exported DbPreplist
{
public:
	DbTxn *txn;
	u_int8_t gid[DB_XIDDATASIZE];
};

//
// A sequence record in a database
//
class _exported DbSequence
{
public:
	DbSequence(Db *db, u_int32_t flags);
	virtual ~DbSequence();

	int open(DbTxn *txnid, Dbt *key, u_int32_t flags);
	int initial_value(db_seq_t value);
	int close(u_int32_t flags);
	int remove(DbTxn *txnid, u_int32_t flags);
	int stat(DB_SEQUENCE_STAT **sp, u_int32_t flags);
	int stat_print(u_int32_t flags);
	
	int get(DbTxn *txnid, int32_t delta, db_seq_t *retp, u_int32_t flags);
	int get_cachesize(int32_t *sizep);
	int set_cachesize(int32_t size);
	int get_flags(u_int32_t *flagsp);
	int set_flags(u_int32_t flags);
	int get_range(db_seq_t *minp, db_seq_t *maxp);
	int set_range(db_seq_t min, db_seq_t max);

	Db *get_db();
	Dbt *get_key();

	virtual DB_SEQUENCE *get_DB_SEQUENCE()
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
784
	{
jimw@mysql.com's avatar
jimw@mysql.com committed
785
		return imp_;
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
786 787
	}

jimw@mysql.com's avatar
jimw@mysql.com committed
788
	virtual const DB_SEQUENCE *get_const_DB_SEQUENCE() const
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
789
	{
jimw@mysql.com's avatar
jimw@mysql.com committed
790
		return imp_;
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
791 792
	}

jimw@mysql.com's avatar
jimw@mysql.com committed
793
	static DbSequence* get_DbSequence(DB_SEQUENCE *seq)
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
794
	{
jimw@mysql.com's avatar
jimw@mysql.com committed
795
		return (DbSequence *)seq->api_internal;
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
796 797
	}

jimw@mysql.com's avatar
jimw@mysql.com committed
798
	static const DbSequence* get_const_DbSequence(const DB_SEQUENCE *seq)
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
799
	{
jimw@mysql.com's avatar
jimw@mysql.com committed
800
		return (const DbSequence *)seq->api_internal;
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
801 802
	}

jimw@mysql.com's avatar
jimw@mysql.com committed
803 804 805
	// For internal use only.
	static DbSequence* wrap_DB_SEQUENCE(DB_SEQUENCE *seq);

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
806
private:
jimw@mysql.com's avatar
jimw@mysql.com committed
807
	DbSequence(DB_SEQUENCE *seq);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
808
	// no copying
jimw@mysql.com's avatar
jimw@mysql.com committed
809 810
	DbSequence(const DbSequence &);
	DbSequence &operator = (const DbSequence &);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
811

jimw@mysql.com's avatar
jimw@mysql.com committed
812 813 814
	DB_SEQUENCE *imp_;
	DBT key_;
};
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
815

jimw@mysql.com's avatar
jimw@mysql.com committed
816 817 818 819 820 821
//
// Transaction
//
class _exported DbTxn
{
	friend class DbEnv;
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
822 823

public:
jimw@mysql.com's avatar
jimw@mysql.com committed
824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863
	int abort();
	int commit(u_int32_t flags);
	int discard(u_int32_t flags);
	u_int32_t id();
	int prepare(u_int8_t *gid);
	int set_timeout(db_timeout_t timeout, u_int32_t flags);

	virtual DB_TXN *get_DB_TXN()
	{
		return imp_;
	}

	virtual const DB_TXN *get_const_DB_TXN() const
	{
		return imp_;
	}

	static DbTxn* get_DbTxn(DB_TXN *txn)
	{
		return (DbTxn *)txn->api_internal;
	}

	static const DbTxn* get_const_DbTxn(const DB_TXN *txn)
	{
		return (const DbTxn *)txn->api_internal;
	}

	// For internal use only.
	static DbTxn* wrap_DB_TXN(DB_TXN *txn);

private:
	DB_TXN *imp_;

	// We can add data to this class if needed
	// since it is implemented via a pointer.
	// (see comment at top)

	// Note: use DbEnv::txn_begin() to get pointers to a DbTxn,
	// and call DbTxn::abort() or DbTxn::commit rather than
	// delete to release them.
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
864
	//
jimw@mysql.com's avatar
jimw@mysql.com committed
865 866 867 868 869 870 871 872
	DbTxn();
	// For internal use only.
	DbTxn(DB_TXN *txn);
	virtual ~DbTxn();

	// no copying
	DbTxn(const DbTxn &);
	void operator = (const DbTxn &);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
873 874 875 876 877 878 879 880
};

//
// A chunk of data, maybe a key or value.
//
class _exported Dbt : private DBT
{
	friend class Db;
jimw@mysql.com's avatar
jimw@mysql.com committed
881
	friend class Dbc;
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
882 883
	friend class DbEnv;
	friend class DbLogc;
jimw@mysql.com's avatar
jimw@mysql.com committed
884
	friend class DbSequence;
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936

public:
	// key/data
	void *get_data() const                 { return data; }
	void set_data(void *value)             { data = value; }

	// key/data length
	u_int32_t get_size() const             { return size; }
	void set_size(u_int32_t value)         { size = value; }

	// RO: length of user buffer.
	u_int32_t get_ulen() const             { return ulen; }
	void set_ulen(u_int32_t value)         { ulen = value; }

	// RO: get/put record length.
	u_int32_t get_dlen() const             { return dlen; }
	void set_dlen(u_int32_t value)         { dlen = value; }

	// RO: get/put record offset.
	u_int32_t get_doff() const             { return doff; }
	void set_doff(u_int32_t value)         { doff = value; }

	// flags
	u_int32_t get_flags() const            { return flags; }
	void set_flags(u_int32_t value)        { flags = value; }

	// Conversion functions
	DBT *get_DBT()                         { return (DBT *)this; }
	const DBT *get_const_DBT() const       { return (const DBT *)this; }

	static Dbt* get_Dbt(DBT *dbt)          { return (Dbt *)dbt; }
	static const Dbt* get_const_Dbt(const DBT *dbt)
					       { return (const Dbt *)dbt; }

	Dbt(void *data, u_int32_t size);
	Dbt();
	~Dbt();
	Dbt(const Dbt &);
	Dbt &operator = (const Dbt &);

private:
	// Note: no extra data appears in this class (other than
	// inherited from DBT) since we need DBT and Dbt objects
	// to have interchangable pointers.
	//
	// When subclassing this class, remember that callback
	// methods like bt_compare, bt_prefix, dup_compare may
	// internally manufacture DBT objects (which later are
	// cast to Dbt), so such callbacks might receive objects
	// not of your subclassed type.
};

jimw@mysql.com's avatar
jimw@mysql.com committed
937 938 939 940 941 942 943 944 945 946
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
//
// multiple key/data/reco iterator classes
//

// DbMultipleIterator is a shared private base class for the three types
// of bulk-return Iterator;  it should never be instantiated directly,
// but it handles the functionality shared by its subclasses.
class _exported DbMultipleIterator
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
947
{
jimw@mysql.com's avatar
jimw@mysql.com committed
948 949 950 951 952 953
public:
	DbMultipleIterator(const Dbt &dbt);
protected:
	u_int8_t *data_;
	u_int32_t *p_;
};
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
954

jimw@mysql.com's avatar
jimw@mysql.com committed
955 956
class _exported DbMultipleKeyDataIterator : private DbMultipleIterator
{
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
957
public:
jimw@mysql.com's avatar
jimw@mysql.com committed
958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000
	DbMultipleKeyDataIterator(const Dbt &dbt) : DbMultipleIterator(dbt) {}
	bool next(Dbt &key, Dbt &data);
};

class _exported DbMultipleRecnoDataIterator : private DbMultipleIterator
{
public:
	DbMultipleRecnoDataIterator(const Dbt &dbt) : DbMultipleIterator(dbt) {}
	bool next(db_recno_t &recno, Dbt &data);
};

class _exported DbMultipleDataIterator : private DbMultipleIterator
{
public:
	DbMultipleDataIterator(const Dbt &dbt) : DbMultipleIterator(dbt) {}
	bool next(Dbt &data);
};

////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
//
// Exception classes
//

// Almost any error in the DB library throws a DbException.
// Every exception should be considered an abnormality
// (e.g. bug, misuse of DB, file system error).
//
class _exported DbException : public __DB_STD(exception)
{
public:
	virtual ~DbException() throw();
	DbException(int err);
	DbException(const char *description);
	DbException(const char *description, int err);
	DbException(const char *prefix, const char *description, int err);
	int get_errno() const;
	virtual const char *what() const throw();
	DbEnv *get_env() const;
	void set_env(DbEnv *env);

	DbException(const DbException &);
	DbException &operator = (const DbException &);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
1001 1002

private:
jimw@mysql.com's avatar
jimw@mysql.com committed
1003
	void describe(const char *prefix, const char *description);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
1004

jimw@mysql.com's avatar
jimw@mysql.com committed
1005 1006 1007 1008
	char *what_;
	int err_;                   // errno
	DbEnv *env_;
};
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
1009

jimw@mysql.com's avatar
jimw@mysql.com committed
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021
//
// A specific sort of exception that occurs when
// an operation is aborted to resolve a deadlock.
//
class _exported DbDeadlockException : public DbException
{
public:
	virtual ~DbDeadlockException() throw();
	DbDeadlockException(const char *description);

	DbDeadlockException(const DbDeadlockException &);
	DbDeadlockException &operator = (const DbDeadlockException &);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
1022 1023
};

jimw@mysql.com's avatar
jimw@mysql.com committed
1024 1025 1026 1027 1028 1029 1030
//
// A specific sort of exception that occurs when
// a lock is not granted, e.g. by lock_get or lock_vec.
// Note that the Dbt is only live as long as the Dbt used
// in the offending call.
//
class _exported DbLockNotGrantedException : public DbException
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
1031
{
jimw@mysql.com's avatar
jimw@mysql.com committed
1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054
public:
	virtual ~DbLockNotGrantedException() throw();
	DbLockNotGrantedException(const char *prefix, db_lockop_t op,
	    db_lockmode_t mode, const Dbt *obj, const DbLock lock, int index);
	DbLockNotGrantedException(const char *description);

	DbLockNotGrantedException(const DbLockNotGrantedException &);
	DbLockNotGrantedException &operator =
	    (const DbLockNotGrantedException &);

	db_lockop_t get_op() const;
	db_lockmode_t get_mode() const;
	const Dbt* get_obj() const;
	DbLock *get_lock() const;
	int get_index() const;

private:
	db_lockop_t op_;
	db_lockmode_t mode_;
	const Dbt *obj_;
	DbLock *lock_;
	int index_;
};
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
1055

jimw@mysql.com's avatar
jimw@mysql.com committed
1056 1057 1058 1059 1060 1061
//
// A specific sort of exception that occurs when
// user declared memory is insufficient in a Dbt.
//
class _exported DbMemoryException : public DbException
{
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
1062
public:
jimw@mysql.com's avatar
jimw@mysql.com committed
1063 1064 1065
	virtual ~DbMemoryException() throw();
	DbMemoryException(Dbt *dbt);
	DbMemoryException(const char *prefix, Dbt *dbt);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
1066

jimw@mysql.com's avatar
jimw@mysql.com committed
1067 1068 1069 1070
	DbMemoryException(const DbMemoryException &);
	DbMemoryException &operator = (const DbMemoryException &);

	Dbt *get_dbt() const;
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
1071
private:
jimw@mysql.com's avatar
jimw@mysql.com committed
1072 1073
	Dbt *dbt_;
};
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
1074

jimw@mysql.com's avatar
jimw@mysql.com committed
1075 1076 1077 1078 1079 1080 1081 1082 1083
//
// A specific sort of exception that occurs when
// recovery is required before continuing DB activity.
//
class _exported DbRunRecoveryException : public DbException
{
public:
	virtual ~DbRunRecoveryException() throw();
	DbRunRecoveryException(const char *description);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
1084

jimw@mysql.com's avatar
jimw@mysql.com committed
1085 1086
	DbRunRecoveryException(const DbRunRecoveryException &);
	DbRunRecoveryException &operator = (const DbRunRecoveryException &);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
1087 1088
};
#endif /* !_DB_CXX_H_ */