FreeSWITCH API Documentation  1.7.0
switch_pgsql.h
Go to the documentation of this file.
1 /*
2  * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
3  * Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
4  *
5  * Version: MPL 1.1
6  *
7  * The contents of this file are subject to the Mozilla Public License Version
8  * 1.1 (the "License"); you may not use this file except in compliance with
9  * the License. You may obtain a copy of the License at
10  * http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
18  *
19  * The Initial Developer of the Original Code is
20  * Anthony Minessale II <anthm@freeswitch.org>
21  * Portions created by the Initial Developer are Copyright (C)
22  * the Initial Developer. All Rights Reserved.
23  *
24  * Contributor(s):
25  *
26  * Anthony Minessale II <anthm@freeswitch.org>
27  * Eliot Gable <egable@gmail.com>
28  *
29  * switch_pgsql.h -- PGSQL Driver
30  *
31  */
32 
33 #ifndef SWITCH_PGSQL_H
34 #define SWITCH_PGSQL_H
35 
36 #include <switch.h>
37 
38 #define DEFAULT_PGSQL_RETRIES 120
39 
41 
42 struct switch_pgsql_handle;
43 struct switch_pgsql_result;
44 
45 
46 typedef enum {
52 
53 typedef enum {
57 
58 /*!
59  \brief Create a new handle for the PGSQL connection.
60  \param dsn The DSN of the database to connect to. See documentation for PQconnectdb() at
61  http://www.postgresql.org/docs/9.0/static/libpq-connect.html. The DSN *MUST* be
62  prefixed with 'pgsql;' to use the switch_cache_db* functionality. However, the DSN
63  passed to this function directly *MUST NOT* be prefixed with 'pgsql;'.
64  \return Returns a pointer to a newly allocated switch_pgsql_handle_t type or NULL on failure.
65  */
67 
68 /*!
69  \brief Sets the number of retries if the PGSQL connection fails.
70  \param handle A fully allocated switch_pgsql_handle_t returned from a call to switch_pgsql_handle_new().
71  \param num_retries How many times to retry connecting to the database if this connection fails.
72  */
74 
75 /*!
76  \brief Disconnects a PGSQL connection from the database.
77  \param handle The PGSQL database handle to disconnect.
78  \return Returns SWITCH_PGSQL_SUCCESS or SWITCH_PGSQL_FAIL.
79  */
81 #if 0
82  ) /* Emacs formatting issue */
83 #endif
84 /*!
85  \brief Connect to the database specified by the DSN passed to the switch_pgsql_handle_new() call which
86  initialized this handle.
87  \param The database handle to connect to the database.
88  \return Returns SWITCH_PGSQL_SUCCESS or SWITCH_PGSQL_FAIL.
89  */
91 
92 /*!
93  */
95 
97 
98 SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_cancel_real(const char *file, const char *func, int line, switch_pgsql_handle_t *handle);
99 #define switch_pgsql_cancel(handle) switch_pgsql_cancel_real(__FILE__, (char * )__SWITCH_FUNC__, __LINE__, handle)
100 
102 #define switch_pgsql_next_result(h, r) switch_pgsql_next_result_timed(h, r, 10000)
103 
105 
106 SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_finish_results_real(const char* file, const char *func, int line, switch_pgsql_handle_t *handle);
107 #define switch_pgsql_finish_results(handle) switch_pgsql_finish_results_real(__FILE__, (char * )__SWITCH_FUNC__, __LINE__, handle)
108 
109 SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_handle_exec_base_detailed(const char *file, const char *func, int line,
110  switch_pgsql_handle_t *handle, const char *sql, char **err);
111 #define switch_pgsql_handle_exec_base(handle, sql, err) switch_pgsql_handle_exec_base_detailed(__FILE__, (char * )__SWITCH_FUNC__, __LINE__, handle, sql, err)
112 
114 
115 SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_handle_exec_detailed(const char *file, const char *func, int line,
116  switch_pgsql_handle_t *handle, const char *sql, char **err);
117 #define switch_pgsql_handle_exec(handle, sql, err) switch_pgsql_handle_exec_detailed(__FILE__, (char * )__SWITCH_FUNC__, __LINE__, handle, sql, err)
118 
119 SWITCH_DECLARE(switch_pgsql_status_t) switch_pgsql_handle_exec_string_detailed(const char *file, const char *func, int line,
120  switch_pgsql_handle_t *handle, const char *sql, char *resbuf, size_t len, char **err);
121 #define switch_pgsql_handle_exec_string(handle, sql, resbuf, len, err) switch_pgsql_handle_exec_string_detailed(__FILE__, (char * )__SWITCH_FUNC__, __LINE__, handle, sql, resbuf, len, err)
122 
126 
127 /*!
128  \brief Execute the sql query and issue a callback for each row returned
129  \param file the file from which this function is called
130  \param func the function from which this function is called
131  \param line the line from which this function is called
132  \param handle the PGSQL handle
133  \param sql the sql string to execute
134  \param callback the callback function to execute
135  \param pdata the state data passed on each callback invocation
136  \return SWITCH_STATUS_SUCCESS if the operation was successful
137  \note none
138 */
140  const char *sql, switch_core_db_callback_func_t callback, void *pdata,
141  char **err);
142 /*!
143  \brief Execute the sql query and issue a callback for each row returned
144  \param handle the PGSQL handle
145  \param sql the sql string to execute
146  \param callback the callback function to execute
147  \param pdata the state data passed on each callback invocation
148  \return SWITCH_STATUS_SUCCESS if the operation was successful
149  \note none
150 */
151 #define switch_pgsql_handle_callback_exec(handle, sql, callback, pdata, err) \
152  switch_pgsql_handle_callback_exec_detailed(__FILE__, (char * )__SWITCH_FUNC__, __LINE__, \
153  handle, sql, callback, pdata, err)
154 
155 
157 
160 
161 
163 #endif
164 /* For Emacs:
165  * Local Variables:
166  * mode:c
167  * indent-tabs-mode:t
168  * tab-width:4
169  * c-basic-offset:4
170  * End:
171  * For VIM:
172  * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
173  */
switch_pgsql_status_t
Definition: switch_pgsql.h:53
switch_bool_t switch_pgsql_available(void)
Definition: switch_pgsql.c:819
#define SWITCH_END_EXTERN_C
Definition: switch.h:43
void switch_pgsql_set_num_retries(switch_pgsql_handle_t *handle, int num_retries)
Sets the number of retries if the PGSQL connection fails.
Definition: switch_pgsql.c:216
switch_bool_t
Definition: switch_types.h:405
struct switch_pgsql_handle switch_pgsql_handle_t
switch_pgsql_state_t switch_pgsql_handle_get_state(switch_pgsql_handle_t *handle)
Definition: switch_pgsql.c:787
switch_pgsql_status_t switch_pgsql_SQLEndTran(switch_pgsql_handle_t *handle, switch_bool_t commit)
Definition: switch_pgsql.c:865
switch_pgsql_status_t switch_pgsql_SQLSetAutoCommitAttr(switch_pgsql_handle_t *handle, switch_bool_t on)
Definition: switch_pgsql.c:828
int(* switch_core_db_callback_func_t)(void *pArg, int argc, char **argv, char **columnNames)
void switch_pgsql_free_result(switch_pgsql_result_t **result)
Definition: switch_pgsql.c:439
switch_pgsql_status_t switch_pgsql_handle_exec_string_detailed(const char *file, const char *func, int line, switch_pgsql_handle_t *handle, const char *sql, char *resbuf, size_t len, char **err)
Definition: switch_pgsql.c:521
switch_pgsql_status_t switch_pgsql_cancel_real(const char *file, const char *func, int line, switch_pgsql_handle_t *handle)
Definition: switch_pgsql.c:266
struct switch_pgsql_result switch_pgsql_result_t
switch_pgsql_status_t switch_pgsql_handle_exec_detailed(const char *file, const char *func, int line, switch_pgsql_handle_t *handle, const char *sql, char **err)
Definition: switch_pgsql.c:648
switch_pgsql_status_t switch_pgsql_flush(switch_pgsql_handle_t *handle)
Definition: switch_pgsql.c:842
switch_pgsql_status_t switch_pgsql_finish_results_real(const char *file, const char *func, int line, switch_pgsql_handle_t *handle)
Definition: switch_pgsql.c:457
switch_pgsql_status_t switch_pgsql_send_query(switch_pgsql_handle_t *handle, const char *sql)
Definition: switch_pgsql.c:246
switch_pgsql_status_t switch_pgsql_handle_callback_exec_detailed(const char *file, const char *func, int line, switch_pgsql_handle_t *handle, const char *sql, switch_core_db_callback_func_t callback, void *pdata, char **err)
Execute the sql query and issue a callback for each row returned.
Definition: switch_pgsql.c:662
Main Library Header.
switch_pgsql_state_t
Definition: switch_pgsql.h:46
#define SWITCH_DECLARE(type)
int switch_pgsql_handle_affected_rows(switch_pgsql_handle_t *handle)
Definition: switch_pgsql.c:810
switch_pgsql_handle_t * switch_pgsql_handle_new(const char *dsn)
Create a new handle for the PGSQL connection.
Definition: switch_pgsql.c:66
switch_pgsql_status_t switch_pgsql_handle_disconnect(switch_pgsql_handle_t *handle)
Disconnects a PGSQL connection from the database.
Definition: switch_pgsql.c:225
char * switch_pgsql_handle_get_error(switch_pgsql_handle_t *handle)
Definition: switch_pgsql.c:796
void switch_pgsql_handle_destroy(switch_pgsql_handle_t **handlep)
Definition: switch_pgsql.c:764
switch_pgsql_status_t switch_pgsql_handle_connect(switch_pgsql_handle_t *handle)
Connect to the database specified by the DSN passed to the switch_pgsql_handle_new() call which initi...
Definition: switch_pgsql.c:489
switch_pgsql_status_t switch_pgsql_next_result_timed(switch_pgsql_handle_t *handle, switch_pgsql_result_t **result_out, int seconds)
Definition: switch_pgsql.c:287
switch_pgsql_status_t switch_pgsql_handle_exec_base_detailed(const char *file, const char *func, int line, switch_pgsql_handle_t *handle, const char *sql, char **err)
Definition: switch_pgsql.c:576
#define SWITCH_BEGIN_EXTERN_C
Definition: switch.h:42