1/*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 1997-2009 Oracle.  All rights reserved.
5 *
6 * $Id$
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(cmp, (Dbc *other_cursor, int *result, u_int32_t _flags),
50    (dbc, other_cursor, result, _flags), DB_RETOK_STD)
51DBC_METHOD(count, (db_recno_t *countp, u_int32_t _flags),
52    (dbc, countp, _flags), DB_RETOK_STD)
53DBC_METHOD(del, (u_int32_t _flags),
54    (dbc, _flags), DB_RETOK_DBCDEL)
55
56int Dbc::dup(Dbc** cursorp, u_int32_t _flags)
57{
58	int ret;
59	DBC *dbc = this;
60	DBC *new_cursor = 0;
61
62	ret = dbc->dup(dbc, &new_cursor, _flags);
63
64	if (DB_RETOK_STD(ret))
65		// The following cast implies that Dbc can be no larger than DBC
66		*cursorp = (Dbc*)new_cursor;
67	else
68		DB_ERROR(DbEnv::get_DbEnv(dbc->dbenv),
69			"Dbc::dup", ret, ON_ERROR_UNKNOWN);
70
71	return (ret);
72}
73
74int Dbc::get(Dbt* key, Dbt *data, u_int32_t _flags)
75{
76	int ret;
77	DBC *dbc = this;
78
79	ret = dbc->get(dbc, key, data, _flags);
80
81	if (!DB_RETOK_DBCGET(ret)) {
82		if (ret == DB_BUFFER_SMALL && DB_OVERFLOWED_DBT(key))
83			DB_ERROR_DBT(DbEnv::get_DbEnv(dbc->dbenv),
84				"Dbc::get", key, ON_ERROR_UNKNOWN);
85		else if (ret == DB_BUFFER_SMALL && DB_OVERFLOWED_DBT(data))
86			DB_ERROR_DBT(DbEnv::get_DbEnv(dbc->dbenv),
87				"Dbc::get", data, ON_ERROR_UNKNOWN);
88		else
89			DB_ERROR(DbEnv::get_DbEnv(dbc->dbenv),
90				"Dbc::get", ret, ON_ERROR_UNKNOWN);
91	}
92
93	return (ret);
94}
95
96int Dbc::pget(Dbt* key, Dbt *pkey, Dbt *data, u_int32_t _flags)
97{
98	int ret;
99	DBC *dbc = this;
100
101	ret = dbc->pget(dbc, key, pkey, data, _flags);
102
103	/* Logic is the same as for Dbc::get - reusing macro. */
104	if (!DB_RETOK_DBCGET(ret)) {
105		if (ret == DB_BUFFER_SMALL && DB_OVERFLOWED_DBT(key))
106			DB_ERROR_DBT(DbEnv::get_DbEnv(dbc->dbenv),
107				"Dbc::pget", key, ON_ERROR_UNKNOWN);
108		else if (ret == DB_BUFFER_SMALL && DB_OVERFLOWED_DBT(data))
109			DB_ERROR_DBT(DbEnv::get_DbEnv(dbc->dbenv),
110				"Dbc::pget", data, ON_ERROR_UNKNOWN);
111		else
112			DB_ERROR(DbEnv::get_DbEnv(dbc->dbenv),
113				"Dbc::pget", ret, ON_ERROR_UNKNOWN);
114	}
115
116	return (ret);
117}
118
119DBC_METHOD(put, (Dbt* key, Dbt *data, u_int32_t _flags),
120    (dbc, key, data, _flags), DB_RETOK_DBCPUT)
121DBC_METHOD(get_priority, (DB_CACHE_PRIORITY *priorityp),
122    (dbc, priorityp), DB_RETOK_STD)
123DBC_METHOD(set_priority, (DB_CACHE_PRIORITY pri), (dbc, pri), DB_RETOK_STD)
124