modules/db_mysql/my_res.c
78aa2030
 /* 
d54e993e
  * Copyright (C) 2001-2003 FhG Fokus
4198a3a2
  * Copyright (C) 2006-2007 iptelorg GmbH
e280d3a5
  *
db26c5ce
  * This file is part of Kamailio, a free SIP server.
e280d3a5
  *
db26c5ce
  * Kamailio is free software; you can redistribute it and/or modify
e280d3a5
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version
  *
db26c5ce
  * Kamailio is distributed in the hope that it will be useful,
e280d3a5
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License 
  * along with this program; if not, write to the Free Software 
9e1ff448
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
78aa2030
  */
 
a201f9ae
 #include "my_res.h"
 
 #include "my_cmd.h"
 
6fa0cfe5
 #include "../../mem/mem.h"
4198a3a2
 #include "../../dprint.h"
9bbb835a
 #include "../../lib/srdb2/db_gen.h"
a201f9ae
 
 #include <mysql/mysql.h>
4198a3a2
 
 
 void my_res_free(db_res_t* res, struct my_res* payload)
 {
 	struct my_cmd* mcmd;
 
 	mcmd = DB_GET_PAYLOAD(res->cmd);
 
ea3fd384
 	if (mcmd->st && mysql_stmt_free_result(mcmd->st)) {
a201f9ae
 		ERR("mysql: Error while freeing MySQL result: %d, %s\n", 
 			mysql_stmt_errno(mcmd->st), mysql_stmt_error(mcmd->st));
4198a3a2
 	}
 
 	db_drv_free(&payload->gen);
 	pkg_free(payload);
 }
c811180f
 
 
e7d533a7
 /*
4198a3a2
  * Attach a mysql specific structure to db_res, this structure contains a pointer
  * to my_res_free which releases the mysql result stored in the mysql statement
  * and if there is a cursor open in the statement then it will be closed as well
e7d533a7
  */
4198a3a2
 int my_res(db_res_t* res)
c811180f
 {
4198a3a2
 	struct my_res* mr;
 
 	mr = (struct my_res*)pkg_malloc(sizeof(struct my_res));
 	if (mr == NULL) {
a201f9ae
 		ERR("mysql: No memory left\n");
452ba322
 		return -1;
c4553b38
 	}
4198a3a2
 	if (db_drv_init(&mr->gen, my_res_free) < 0) goto error;
 	DB_SET_PAYLOAD(res, mr);
dc117346
 	return 0;
4198a3a2
 	
  error:
 	if (mr) {
 		db_drv_free(&mr->gen);
 		pkg_free(mr);
 	}
 	return -1;
c811180f
 }