con.h

00001 /* 
00002  * $Id$
00003  *
00004  * UNIXODBC module
00005  *
00006  * Copyright (C) 2005-2006 Marco Lorrai
00007  * Copyright (C) 2008 1&1 Internet AG
00008  *
00009  * This file is part of Kamailio, a free SIP server.
00010  *
00011  * Kamailio is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version
00015  *
00016  * Kamailio is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024  *
00025  *
00026  * History:
00027  * --------
00028  *  2005-12-01  initial commit (chgen)
00029  */
00030 
00031 
00032 #ifndef MY_CON_H
00033 #define MY_CON_H
00034 
00035 #include "../../lib/srdb1/db_pool.h"
00036 #include "../../lib/srdb1/db_id.h"
00037 
00038 #include <time.h>
00039 #include <stdio.h>
00040 #include <string.h>
00041 #include <sql.h>
00042 #include <sqlext.h>
00043 #include <sqlucode.h>
00044 
00045 
00046 #define STRN_LEN 1024
00047 
00048 typedef struct strn
00049 {
00050         char s[STRN_LEN];
00051 } strn;
00052 
00053 
00054 struct my_con
00055 {
00056         struct db_id* id;               
00057         unsigned int ref;               
00058         struct pool_con* next;          
00059         SQLHENV env;                    
00060         SQLHSTMT stmt_handle;           
00061         SQLHDBC dbc;                    
00062         char** row;                     
00063         time_t timestamp;               
00064 };
00065 
00066 /*
00067  * Some convenience wrappers
00068  */
00069 #define CON_RESULT(db_con)       (((struct my_con*)((db_con)->tail))->stmt_handle)
00070 #define CON_CONNECTION(db_con) (((struct my_con*)((db_con)->tail))->dbc)
00071 #define CON_ROW(db_con)         (((struct my_con*)((db_con)->tail))->row)
00072 #define CON_TIMESTAMP(db_con)  (((struct my_con*)((db_con)->tail))->timestamp)
00073 #define CON_ID(db_con)          (((struct my_con*)((db_con)->tail))->id)
00074 #define CON_ENV(db_con)         (((struct my_con*)((db_con)->tail))->env)
00075 
00076 #define MAX_CONN_STR_LEN 2048
00077 
00078 /*
00079  * Create a new connection structure,
00080  * open the UNIXODBC connection and set reference count to 1
00081  */
00082 struct my_con* db_unixodbc_new_connection(struct db_id* id);
00083 
00084 /*
00085  * Close the connection and release memory
00086  */
00087 void db_unixodbc_free_connection(struct my_con* con);
00088 
00089 char *db_unixodbc_build_conn_str(const struct db_id* id, char *buf);
00090 
00091 void db_unixodbc_extract_error(const char *fn, const SQLHANDLE handle, const SQLSMALLINT type, char* stret);
00092 
00093 #endif  /* MY_CON_H */