Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

cxx_dbc.cpp

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1997-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: cxx_dbc.cpp,v 12.2 2005/09/30 07:38:25 mjc Exp $
00008  */
00009 
00010 #include "db_config.h"
00011 
00012 #include <errno.h>
00013 #include <string.h>
00014 
00015 #include "db_cxx.h"
00016 #include "dbinc/cxx_int.h"
00017 
00018 #include "db_int.h"
00019 #include "dbinc/db_page.h"
00020 #include "dbinc_auto/db_auto.h"
00021 #include "dbinc_auto/crdel_auto.h"
00022 #include "dbinc/db_dispatch.h"
00023 #include "dbinc_auto/db_ext.h"
00024 #include "dbinc_auto/common_ext.h"
00025 
00026 // Helper macro for simple methods that pass through to the
00027 // underlying C method. It may return an error or raise an exception.
00028 // Note this macro expects that input _argspec is an argument
00029 // list element (e.g., "char *arg") and that _arglist is the arguments
00030 // that should be passed through to the C method (e.g., "(db, arg)")
00031 //
00032 #define DBC_METHOD(_name, _argspec, _arglist, _retok)                   \
00033 int Dbc::_name _argspec                                                 \
00034 {                                                                       \
00035         int ret;                                                        \
00036         DBC *dbc = this;                                                \
00037                                                                         \
00038         ret = dbc->c_##_name _arglist;                                  \
00039         if (!_retok(ret))                                               \
00040                 DB_ERROR(DbEnv::get_DbEnv(dbc->dbp->dbenv), \
00041                         "Dbc::" # _name, ret, ON_ERROR_UNKNOWN); \
00042         return (ret);                                                   \
00043 }
00044 
00045 // It's private, and should never be called, but VC4.0 needs it resolved
00046 //
00047 Dbc::~Dbc()
00048 {
00049 }
00050 
00051 DBC_METHOD(close, (void), (dbc), DB_RETOK_STD)
00052 DBC_METHOD(count, (db_recno_t *countp, u_int32_t _flags),
00053     (dbc, countp, _flags), DB_RETOK_STD)
00054 DBC_METHOD(del, (u_int32_t _flags),
00055     (dbc, _flags), DB_RETOK_DBCDEL)
00056 
00057 int Dbc::dup(Dbc** cursorp, u_int32_t _flags)
00058 {
00059         int ret;
00060         DBC *dbc = this;
00061         DBC *new_cursor = 0;
00062 
00063         ret = dbc->c_dup(dbc, &new_cursor, _flags);
00064 
00065         if (DB_RETOK_STD(ret))
00066                 // The following cast implies that Dbc can be no larger than DBC
00067                 *cursorp = (Dbc*)new_cursor;
00068         else
00069                 DB_ERROR(DbEnv::get_DbEnv(dbc->dbp->dbenv),
00070                         "Dbc::dup", ret, ON_ERROR_UNKNOWN);
00071 
00072         return (ret);
00073 }
00074 
00075 int Dbc::get(Dbt* key, Dbt *data, u_int32_t _flags)
00076 {
00077         int ret;
00078         DBC *dbc = this;
00079 
00080         ret = dbc->c_get(dbc, key, data, _flags);
00081 
00082         if (!DB_RETOK_DBCGET(ret)) {
00083                 if (ret == DB_BUFFER_SMALL && DB_OVERFLOWED_DBT(key))
00084                         DB_ERROR_DBT(DbEnv::get_DbEnv(dbc->dbp->dbenv),
00085                                 "Dbc::get", key, ON_ERROR_UNKNOWN);
00086                 else if (ret == DB_BUFFER_SMALL && DB_OVERFLOWED_DBT(data))
00087                         DB_ERROR_DBT(DbEnv::get_DbEnv(dbc->dbp->dbenv),
00088                                 "Dbc::get", data, ON_ERROR_UNKNOWN);
00089                 else
00090                         DB_ERROR(DbEnv::get_DbEnv(dbc->dbp->dbenv),
00091                                 "Dbc::get", ret, ON_ERROR_UNKNOWN);
00092         }
00093 
00094         return (ret);
00095 }
00096 
00097 int Dbc::pget(Dbt* key, Dbt *pkey, Dbt *data, u_int32_t _flags)
00098 {
00099         int ret;
00100         DBC *dbc = this;
00101 
00102         ret = dbc->c_pget(dbc, key, pkey, data, _flags);
00103 
00104         /* Logic is the same as for Dbc::get - reusing macro. */
00105         if (!DB_RETOK_DBCGET(ret)) {
00106                 if (ret == DB_BUFFER_SMALL && DB_OVERFLOWED_DBT(key))
00107                         DB_ERROR_DBT(DbEnv::get_DbEnv(dbc->dbp->dbenv),
00108                                 "Dbc::pget", key, ON_ERROR_UNKNOWN);
00109                 else if (ret == DB_BUFFER_SMALL && DB_OVERFLOWED_DBT(data))
00110                         DB_ERROR_DBT(DbEnv::get_DbEnv(dbc->dbp->dbenv),
00111                                 "Dbc::pget", data, ON_ERROR_UNKNOWN);
00112                 else
00113                         DB_ERROR(DbEnv::get_DbEnv(dbc->dbp->dbenv),
00114                                 "Dbc::pget", ret, ON_ERROR_UNKNOWN);
00115         }
00116 
00117         return (ret);
00118 }
00119 
00120 DBC_METHOD(put, (Dbt* key, Dbt *data, u_int32_t _flags),
00121     (dbc, key, data, _flags), DB_RETOK_DBCPUT)

Generated on Sun Dec 25 12:14:18 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2