bdb_res.c

Go to the documentation of this file.
00001 /* 
00002  * $Id$
00003  *
00004  * Copyright (C) 2001-2003 FhG Fokus
00005  * Copyright (C) 2006-2007 iptelorg GmbH
00006  *
00007  * This file is part of SIP-router, a free SIP server.
00008  *
00009  * SIP-router is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version
00013  *
00014  * SIP-router is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License 
00020  * along with this program; if not, write to the Free Software 
00021  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022  */
00023 
00031 #include <db.h>
00032 
00033 #include "bdb_res.h"
00034 #include "bdb_cmd.h"
00035 #include "bdb_crs_compat.h"
00036 
00037 #include "../../mem/mem.h"
00038 #include "../../dprint.h"
00039 #include "../../lib/srdb2/db_gen.h"
00040 
00041 
00042 void bdb_res_free(db_res_t* res, bdb_res_t *payload)
00043 {
00044         bdb_cmd_t *bcmd;
00045 
00046         bcmd = DB_GET_PAYLOAD(res->cmd);
00047 
00048         /* free bdb result */
00049 
00050         if(bcmd->dbcp!=NULL)
00051         {
00052                 bcmd->dbcp->CLOSE_CURSOR(bcmd->dbcp);
00053                 bcmd->dbcp = NULL;
00054         }
00055         db_drv_free(&payload->gen);
00056         pkg_free(payload);
00057 }
00058 
00059 
00060 /*
00061  * Attach bdb specific structure to db_res, this structure contains a pointer
00062  * to bdb_res_free which releases the result stored in the oracle statement
00063  * and if there is a cursor open in the statement then it will be closed as well
00064  */
00065 int bdb_res(db_res_t* res)
00066 {
00067         bdb_res_t *br;
00068 
00069         br = (bdb_res_t*)pkg_malloc(sizeof(bdb_res_t));
00070         if (br == NULL) {
00071                 ERR("bdb: No memory left\n");
00072                 return -1;
00073         }
00074         if (db_drv_init(&br->gen, bdb_res_free) < 0) goto error;
00075         DB_SET_PAYLOAD(res, br);
00076         return 0;
00077         
00078 error:
00079         if (br) {
00080                 db_drv_free(&br->gen);
00081                 pkg_free(br);
00082         }
00083         return -1;
00084 }