pg_con.h

Go to the documentation of this file.
00001 /*
00002  * $Id: pg_con.h 4963 2008-09-19 09:45:51Z henningw $
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 
00028 /*! \file
00029  *  \brief DB_POSTGRES :: Core
00030  *  \ingroup db_postgres
00031  *  Module: \ref db_mysql
00032  */
00033 
00034 #ifndef PG_CON_H
00035 #define PG_CON_H
00036 
00037 #include "../../db/db_pool.h"
00038 #include "../../db/db_id.h"
00039 
00040 #include <time.h>
00041 #include <libpq-fe.h>
00042 
00043 
00044 /*! Postgres specific connection data */
00045 struct pg_con {
00046    struct db_id* id;        /*!< Connection identifier */
00047    unsigned int ref;        /*!< Reference count */
00048    struct pool_con* next;   /*!< Next connection in the pool */
00049 
00050    int connected;      /*!< connection status */
00051    char *sqlurl;     /*!< the url we are connected to, all connection memory parents from this */
00052    PGconn *con;      /*!< this is the postgres connection */
00053    PGresult *res;    /*!< this is the current result */
00054    char**  row;      /*!< Actual row in the result */
00055    time_t timestamp; /*!< Timestamp of last query */
00056 
00057 };
00058 
00059 #define CON_SQLURL(db_con)     (((struct pg_con*)((db_con)->tail))->sqlurl)
00060 #define CON_RESULT(db_con)     (((struct pg_con*)((db_con)->tail))->res)
00061 #define CON_CONNECTION(db_con) (((struct pg_con*)((db_con)->tail))->con)
00062 #define CON_CONNECTED(db_con)  (((struct pg_con*)((db_con)->tail))->connected)
00063 #define CON_ROW(db_con)        (((struct pg_con*)((db_con)->tail))->row)
00064 #define CON_TIMESTAMP(db_con)  (((struct pg_con*)((db_con)->tail))->timestamp)
00065 #define CON_ID(db_con)         (((struct pg_con*)((db_con)->tail))->id)
00066 
00067 /*
00068  * Create a new connection structure,
00069  * open the PostgreSQL connection and set reference count to 1
00070  */
00071 struct pg_con* db_postgres_new_connection(struct db_id* id);
00072 
00073 /*
00074  * Close the connection and release memory
00075  */
00076 void db_postgres_free_connection(struct pool_con* con);
00077 
00078 #endif /* PG_CON_H */

Generated on Thu May 24 02:00:29 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6