1/*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 1997,2008 Oracle.  All rights reserved.
5 *
6 * $Id: cxx_dbc.cpp,v 12.12 2008/01/08 20:58:09 bostic Exp $
7 */
8
9#include "db_config.h"
10
11#include "db_int.h"
12
13#include "db_cxx.h"
14#include "dbinc/cxx_int.h"
15
16#include "dbinc/db_page.h"
17#include "dbinc_auto/db_auto.h"
18#include "dbinc_auto/crdel_auto.h"
19#include "dbinc/db_dispatch.h"
20#include "dbinc_auto/db_ext.h"
21#include "dbinc_auto/common_ext.h"
22
23// Helper macro for simple methods that pass through to the
24// underlying C method. It may return an error or raise an exception.
25// Note this macro expects that input _argspec is an argument
26// list element (e.g., "char *arg") and that _arglist is the arguments
27// that should be passed through to the C method (e.g., "(db, arg)")
28//
29#define	DBC_METHOD(_name, _argspec, _arglist, _retok)			\
30int Dbc::_name _argspec							\
31{									\
32	int ret;							\
33	DBC *dbc = this;						\
34									\
35	ret = dbc->_name _arglist;					\
36	if (!_retok(ret))						\
37		DB_ERROR(DbEnv::get_DbEnv(dbc->dbenv),			\
38			"Dbc::" # _name, ret, ON_ERROR_UNKNOWN);	\
39	return (ret);							\
40}
41
42// It's private, and should never be called, but VC4.0 needs it resolved
43//
44Dbc::~Dbc()
45{
46}
47
48DBC_METHOD(close, (void), (dbc), DB_RETOK_STD)
49DBC_METHOD(count, (db_recno_t *countp, u_int32_t _flags),
50    (dbc, countp, _flags), DB_RETOK_STD)
51DBC_METHOD(del, (u_int32_t _flags),
52    (dbc, _flags), DB_RETOK_DBCDEL)
53
54int Dbc::dup(Dbc** cursorp, u_int32_t _flags)
55{
56	int ret;
57	DBC *dbc = this;
58	DBC *new_cursor = 0;
59
60	ret = dbc->dup(dbc, &new_cursor, _flags);
61
62	if (DB_RETOK_STD(ret))
63		// The following cast implies that Dbc can be no larger than DBC
64		*cursorp = (Dbc*)new_cursor;
65	else
66		DB_ERROR(DbEnv::get_DbEnv(dbc->dbenv),
67			"Dbc::dup", ret, ON_ERROR_UNKNOWN);
68
69	return (ret);
70}
71
72int Dbc::get(Dbt* key, Dbt *data, u_int32_t _flags)
73{
74	int ret;
75	DBC *dbc = this;
76
77	ret = dbc->get(dbc, key, data, _flags);
78
79	if (!DB_RETOK_DBCGET(ret)) {
80		if (ret == DB_BUFFER_SMALL && DB_OVERFLOWED_DBT(key))
81			DB_ERROR_DBT(DbEnv::get_DbEnv(dbc->dbenv),
82				"Dbc::get", key, ON_ERROR_UNKNOWN);
83		else if (ret == DB_BUFFER_SMALL && DB_OVERFLOWED_DBT(data))
84			DB_ERROR_DBT(DbEnv::get_DbEnv(dbc->dbenv),
85				"Dbc::get", data, ON_ERROR_UNKNOWN);
86		else
87			DB_ERROR(DbEnv::get_DbEnv(dbc->dbenv),
88				"Dbc::get", ret, ON_ERROR_UNKNOWN);
89	}
90
91	return (ret);
92}
93
94int Dbc::pget(Dbt* key, Dbt *pkey, Dbt *data, u_int32_t _flags)
95{
96	int ret;
97	DBC *dbc = this;
98
99	ret = dbc->pget(dbc, key, pkey, data, _flags);
100
101	/* Logic is the same as for Dbc::get - reusing macro. */
102	if (!DB_RETOK_DBCGET(ret)) {
103		if (ret == DB_BUFFER_SMALL && DB_OVERFLOWED_DBT(key))
104			DB_ERROR_DBT(DbEnv::get_DbEnv(dbc->dbenv),
105				"Dbc::pget", key, ON_ERROR_UNKNOWN);
106		else if (ret == DB_BUFFER_SMALL && DB_OVERFLOWED_DBT(data))
107			DB_ERROR_DBT(DbEnv::get_DbEnv(dbc->dbenv),
108				"Dbc::pget", data, ON_ERROR_UNKNOWN);
109		else
110			DB_ERROR(DbEnv::get_DbEnv(dbc->dbenv),
111				"Dbc::pget", ret, ON_ERROR_UNKNOWN);
112	}
113
114	return (ret);
115}
116
117DBC_METHOD(put, (Dbt* key, Dbt *data, u_int32_t _flags),
118    (dbc, key, data, _flags), DB_RETOK_DBCPUT)
119DBC_METHOD(get_priority, (DB_CACHE_PRIORITY *priorityp),
120    (dbc, priorityp), DB_RETOK_STD)
121DBC_METHOD(set_priority, (DB_CACHE_PRIORITY pri), (dbc, pri), DB_RETOK_STD)
122