2004-06-11 00:12:35 +00:00
|
|
|
/*
|
2005-08-30 18:32:10 +00:00
|
|
|
* Asterisk -- An open source telephony toolkit.
|
2004-06-11 00:12:35 +00:00
|
|
|
*
|
2005-08-30 18:32:10 +00:00
|
|
|
* Copyright (C) 1999 - 2005, Digium, Inc.
|
|
|
|
* Copyright (C) 2004 - 2005, Anthony Minessale II
|
2006-04-18 18:16:32 +00:00
|
|
|
* Copyright (C) 2006, Tilghman Lesher
|
2004-06-11 00:12:35 +00:00
|
|
|
*
|
2005-08-30 18:32:10 +00:00
|
|
|
* Mark Spencer <markster@digium.com>
|
|
|
|
* Anthony Minessale <anthmct@yahoo.com>
|
2006-04-18 18:16:32 +00:00
|
|
|
* Tilghman Lesher <res_odbc_200603@the-tilghman.com>
|
2004-06-11 00:12:35 +00:00
|
|
|
*
|
2005-08-30 18:32:10 +00:00
|
|
|
* See http://www.asterisk.org for more information about
|
|
|
|
* the Asterisk project. Please do not directly contact
|
|
|
|
* any of the maintainers of this project for assistance;
|
|
|
|
* the project provides a web site, mailing lists and IRC
|
|
|
|
* channels for your use.
|
|
|
|
*
|
|
|
|
* This program is free software, distributed under the terms of
|
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
* at the top of the source tree.
|
|
|
|
*/
|
|
|
|
|
2005-10-24 20:12:06 +00:00
|
|
|
/*! \file
|
|
|
|
* \brief ODBC resource manager
|
2004-06-11 00:12:35 +00:00
|
|
|
*/
|
|
|
|
|
2005-08-30 18:32:10 +00:00
|
|
|
#ifndef _ASTERISK_RES_ODBC_H
|
|
|
|
#define _ASTERISK_RES_ODBC_H
|
2004-06-11 00:12:35 +00:00
|
|
|
|
|
|
|
#include <sql.h>
|
|
|
|
#include <sqlext.h>
|
|
|
|
#include <sqltypes.h>
|
|
|
|
|
2006-04-18 18:16:32 +00:00
|
|
|
typedef enum { ODBC_SUCCESS=0, ODBC_FAIL=-1} odbc_status;
|
2004-06-11 00:12:35 +00:00
|
|
|
|
2007-07-16 02:51:56 +00:00
|
|
|
/*! \brief ODBC container */
|
2004-06-11 00:12:35 +00:00
|
|
|
struct odbc_obj {
|
|
|
|
ast_mutex_t lock;
|
2006-04-18 18:16:32 +00:00
|
|
|
SQLHDBC con; /* ODBC Connection Handle */
|
|
|
|
struct odbc_class *parent; /* Information about the connection is protected */
|
|
|
|
unsigned int used:1;
|
|
|
|
unsigned int up:1;
|
|
|
|
AST_LIST_ENTRY(odbc_obj) list;
|
2004-06-11 00:12:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* functions */
|
2006-04-18 18:16:32 +00:00
|
|
|
|
2007-07-16 02:51:56 +00:00
|
|
|
/*!
|
|
|
|
* \brief Executes a prepared statement handle
|
2006-04-18 18:16:32 +00:00
|
|
|
* \param obj The non-NULL result of odbc_request_obj()
|
|
|
|
* \param stmt The prepared statement handle
|
2007-07-16 02:51:56 +00:00
|
|
|
* \retval 0 on success
|
|
|
|
* \retval -1 on failure
|
2006-04-18 18:16:32 +00:00
|
|
|
*
|
|
|
|
* This function was originally designed simply to execute a prepared
|
|
|
|
* statement handle and to retry if the initial execution failed.
|
|
|
|
* Unfortunately, it did this by disconnecting and reconnecting the database
|
|
|
|
* handle which on most databases causes the statement handle to become
|
|
|
|
* invalid. Therefore, this method has been deprecated in favor of
|
|
|
|
* odbc_prepare_and_execute() which allows the statement to be prepared
|
|
|
|
* multiple times, if necessary, in case of a loss of connection.
|
|
|
|
*
|
|
|
|
* This function really only ever worked with MySQL, where the statement handle is
|
|
|
|
* not prepared on the server. If you are not using MySQL, you should avoid it.
|
|
|
|
*/
|
2006-09-20 04:57:20 +00:00
|
|
|
int ast_odbc_smart_execute(struct odbc_obj *obj, SQLHSTMT stmt); /* DEPRECATED */
|
2006-04-18 18:16:32 +00:00
|
|
|
|
2007-07-16 02:51:56 +00:00
|
|
|
/*!
|
|
|
|
* \brief Retrieves a connected ODBC object
|
2006-04-18 18:16:32 +00:00
|
|
|
* \param name The name of the ODBC class for which a connection is needed.
|
|
|
|
* \param check Whether to ensure that a connection is valid before returning the handle. Usually unnecessary.
|
2007-07-16 02:51:56 +00:00
|
|
|
* \retval ODBC object
|
|
|
|
* \retval NULL if there is no connection available with the requested name.
|
2006-04-18 18:16:32 +00:00
|
|
|
*
|
|
|
|
* Connection classes may, in fact, contain multiple connection handles. If
|
|
|
|
* the connection is pooled, then each connection will be dedicated to the
|
|
|
|
* thread which requests it. Note that all connections should be released
|
|
|
|
* when the thread is done by calling odbc_release_obj(), below.
|
|
|
|
*/
|
2006-09-20 04:57:20 +00:00
|
|
|
struct odbc_obj *ast_odbc_request_obj(const char *name, int check);
|
2006-04-18 18:16:32 +00:00
|
|
|
|
2007-07-16 02:51:56 +00:00
|
|
|
/*!
|
|
|
|
* \brief Releases an ODBC object previously allocated by odbc_request_obj()
|
2006-04-18 18:16:32 +00:00
|
|
|
* \param obj The ODBC object
|
|
|
|
*/
|
2006-09-20 04:57:20 +00:00
|
|
|
void ast_odbc_release_obj(struct odbc_obj *obj);
|
2006-04-18 18:16:32 +00:00
|
|
|
|
2007-07-16 02:51:56 +00:00
|
|
|
/*!
|
|
|
|
* \brief Checks an ODBC object to ensure it is still connected
|
2006-04-18 18:16:32 +00:00
|
|
|
* \param obj The ODBC object
|
2007-07-16 02:51:56 +00:00
|
|
|
* \retval 0 if connected
|
|
|
|
* \retval -1 otherwise.
|
2006-04-18 18:16:32 +00:00
|
|
|
*/
|
2006-09-20 04:57:20 +00:00
|
|
|
int ast_odbc_sanity_check(struct odbc_obj *obj);
|
2006-04-18 18:16:32 +00:00
|
|
|
|
2007-07-16 02:51:56 +00:00
|
|
|
/*!
|
|
|
|
* \brief Prepares, executes, and returns the resulting statement handle.
|
2006-04-18 18:16:32 +00:00
|
|
|
* \param obj The ODBC object
|
|
|
|
* \param prepare_cb A function callback, which, when called, should return a statement handle prepared, with any necessary parameters or result columns bound.
|
|
|
|
* \param data A parameter to be passed to the prepare_cb parameter function, indicating which statement handle is to be prepared.
|
2007-07-16 02:51:56 +00:00
|
|
|
* \retval a statement handle
|
|
|
|
* \retval NULL on error
|
2006-04-18 18:16:32 +00:00
|
|
|
*/
|
2006-09-20 04:57:20 +00:00
|
|
|
SQLHSTMT ast_odbc_prepare_and_execute(struct odbc_obj *obj, SQLHSTMT (*prepare_cb)(struct odbc_obj *obj, void *data), void *data);
|
2005-08-30 18:32:10 +00:00
|
|
|
|
|
|
|
#endif /* _ASTERISK_RES_ODBC_H */
|