km_pg_con.h

Go to the documentation of this file.
00001 /*
00002  * $Id$
00003  *
00004  * Copyright (C) 2003 August.Net Services, LLC
00005  * Copyright (C) 2008 1&1 Internet AG
00006  *
00007  * This file is part of Kamailio, a free SIP server.
00008  *
00009  * Kamailio 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  * Kamailio 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  * History
00024  * -------
00025  * 2003-04-06 initial code written (Greg Fausak/Andy Fullford)
00026  */
00027 
00034 #ifndef KM_PG_CON_H
00035 #define KM_PG_CON_H
00036 
00037 #include "../../lib/srdb1/db_pool.h"
00038 #include "../../lib/srdb1/db_id.h"
00039 
00040 #include <time.h>
00041 #include <libpq-fe.h>
00042 
00043 
00045 struct pg_con {
00046         struct db_id* id;        
00047         unsigned int ref;        
00048         struct pool_con* next;   
00050         int connected;      
00051         char *sqlurl;           
00052         PGconn *con;            
00053         PGresult *res;          
00054         char**  row;            
00055         time_t timestamp;       
00056         int affected_rows;      
00057         int transaction;        
00058 };
00059 
00060 #define CON_SQLURL(db_con)     (((struct pg_con*)((db_con)->tail))->sqlurl)
00061 #define CON_RESULT(db_con)     (((struct pg_con*)((db_con)->tail))->res)
00062 #define CON_CONNECTION(db_con) (((struct pg_con*)((db_con)->tail))->con)
00063 #define CON_CONNECTED(db_con)  (((struct pg_con*)((db_con)->tail))->connected)
00064 #define CON_ROW(db_con)        (((struct pg_con*)((db_con)->tail))->row)
00065 #define CON_TIMESTAMP(db_con)  (((struct pg_con*)((db_con)->tail))->timestamp)
00066 #define CON_ID(db_con)         (((struct pg_con*)((db_con)->tail))->id)
00067 #define CON_AFFECTED(db_con)   (((struct pg_con*)((db_con)->tail))->affected_rows)
00068 #define CON_TRANSACTION(db_con) (((struct pg_con*)((db_con)->tail))->transaction)
00069 
00070 /*
00071  * Create a new connection structure,
00072  * open the PostgreSQL connection and set reference count to 1
00073  */
00074 struct pg_con* db_postgres_new_connection(struct db_id* id);
00075 
00076 /*
00077  * Close the connection and release memory
00078  */
00079 void db_postgres_free_connection(struct pool_con* con);
00080 
00081 #endif /* KM_PG_CON_H */