File: pg_con.h

package info (click to toggle)
kamailio 4.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 56,100 kB
  • sloc: ansic: 552,832; xml: 166,484; sh: 8,659; makefile: 7,676; sql: 6,235; perl: 3,487; yacc: 3,428; python: 1,457; cpp: 1,219; php: 1,047; java: 449; pascal: 194; cs: 40; awk: 27
file content (104 lines) | stat: -rw-r--r-- 3,504 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* 
 * $Id$ 
 *
 * PostgreSQL Database Driver for SER
 *
 * Portions Copyright (C) 2001-2003 FhG FOKUS
 * Copyright (C) 2003 August.Net Services, LLC
 * Portions Copyright (C) 2005-2008 iptelorg GmbH
 *
 * This file is part of SER, a free SIP server.
 *
 * SER is free software; you can redistribute it and/or modify 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
 *
 * For a license to use the ser software under conditions other than those
 * described here, or to purchase support for this software, please contact
 * iptel.org by e-mail at the following addresses: info@iptel.org
 *
 * SER is distributed in the hope that it will be useful, 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 Foundation, Inc., 59
 * Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#ifndef _PG_CON_H
#define _PG_CON_H

/** \addtogroup postgres
 * @{ 
 */

/** \file 
 * Implementation of PostgreSQL connection related data structures and functions.
 */

#include "pg_oid.h"

#include "../../lib/srdb2/db_pool.h"
#include "../../lib/srdb2/db_con.h"
#include "../../lib/srdb2/db_uri.h"

#include <time.h>
#include <libpq-fe.h>

/** 
 * Per-connection flags for PostgreSQL connections.
 */
enum pg_con_flags {
	PG_CONNECTED      = (1 << 0), /**< The connection has been connected successfully */
	PG_INT8_TIMESTAMP = (1 << 1)  /**< The server uses 8-byte integer format for timestamps */
};


/** A structure representing a connection to PostgreSQL server.
 * This structure represents connections to PostgreSQL servers. It contains
 * PostgreSQL specific data, such as PostgreSQL connection handle, connection
 * flags, and an array with data types supported by the server.
 */
typedef struct pg_con {
	db_pool_entry_t gen;  /**< Generic part of the structure */
	PGconn* con;          /**< Postgres connection handle */
	unsigned int flags;   /**< Flags (currently only binary data format) */
	pg_type_t* oid;       /**< Data types and their Oids obtained from the server */
} pg_con_t;


/** Create a new pg_con structure.
 * This function creates a new pg_con structure and attachs the structure to
 * the generic db_con structure in the parameter.
 * @param con A generic db_con structure to be extended with PostgreSQL
 *            payload
 * @retval 0 on success
 * @retval A negative number on error
 */
int pg_con(db_con_t* con);


/** Establish a new connection to server.  
 * This function is called when a SER module calls db_connect to establish a
 * new connection to the database server. After the connection is established
 * the function sends an SQL query to the server to determine the format of
 * timestamp fields and also obtains the list of supported field types.
 * @param con A structure representing database connection.
 * @retval 0 on success.
 * @retval A negative number on error.
 */
int pg_con_connect(db_con_t* con);


/** Disconnected from PostgreSQL server.
 * Disconnects a previously connected connection to PostgreSQL server.
 * @param con A structure representing the connection to be disconnected.
 */
void pg_con_disconnect(db_con_t* con);

/** @} */

#endif /* _PG_CON_H */