Fri Aug 24 02:22:16 2007

Asterisk developer's documentation


res_odbc.h

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2005, Digium, Inc.
00005  * Copyright (C) 2004 - 2005, Anthony Minessale II
00006  * Copyright (C) 2006, Tilghman Lesher
00007  *
00008  * Mark Spencer <markster@digium.com>
00009  * Anthony Minessale <anthmct@yahoo.com>
00010  * Tilghman Lesher <res_odbc_200603@the-tilghman.com>
00011  *
00012  * See http://www.asterisk.org for more information about
00013  * the Asterisk project. Please do not directly contact
00014  * any of the maintainers of this project for assistance;
00015  * the project provides a web site, mailing lists and IRC
00016  * channels for your use.
00017  *
00018  * This program is free software, distributed under the terms of
00019  * the GNU General Public License Version 2. See the LICENSE file
00020  * at the top of the source tree.
00021  */
00022 
00023 /*! \file
00024  * \brief ODBC resource manager
00025  */
00026 
00027 #ifndef _ASTERISK_RES_ODBC_H
00028 #define _ASTERISK_RES_ODBC_H
00029 
00030 #include <sql.h>
00031 #include <sqlext.h>
00032 #include <sqltypes.h>
00033 
00034 typedef enum { ODBC_SUCCESS=0, ODBC_FAIL=-1} odbc_status;
00035 
00036 struct odbc_obj {
00037    ast_mutex_t lock;
00038    SQLHDBC  con;                   /* ODBC Connection Handle */
00039    struct odbc_class *parent;      /* Information about the connection is protected */
00040    unsigned int used:1;
00041    unsigned int up:1;
00042    AST_LIST_ENTRY(odbc_obj) list;
00043 };
00044 
00045 /* functions */
00046 
00047 /*! \brief Executes a prepared statement handle
00048  * \param obj The non-NULL result of odbc_request_obj()
00049  * \param stmt The prepared statement handle
00050  * \return Returns 0 on success or -1 on failure
00051  *
00052  * This function was originally designed simply to execute a prepared
00053  * statement handle and to retry if the initial execution failed.
00054  * Unfortunately, it did this by disconnecting and reconnecting the database
00055  * handle which on most databases causes the statement handle to become
00056  * invalid.  Therefore, this method has been deprecated in favor of
00057  * odbc_prepare_and_execute() which allows the statement to be prepared
00058  * multiple times, if necessary, in case of a loss of connection.
00059  *
00060  * This function really only ever worked with MySQL, where the statement handle is
00061  * not prepared on the server.  If you are not using MySQL, you should avoid it.
00062  */
00063 int ast_odbc_smart_execute(struct odbc_obj *obj, SQLHSTMT stmt); /* DEPRECATED */
00064 
00065 /*! \brief Retrieves a connected ODBC object
00066  * \param name The name of the ODBC class for which a connection is needed.
00067  * \param check Whether to ensure that a connection is valid before returning the handle.  Usually unnecessary.
00068  * \return Returns an ODBC object or NULL if there is no connection available with the requested name.
00069  *
00070  * Connection classes may, in fact, contain multiple connection handles.  If
00071  * the connection is pooled, then each connection will be dedicated to the
00072  * thread which requests it.  Note that all connections should be released
00073  * when the thread is done by calling odbc_release_obj(), below.
00074  */
00075 struct odbc_obj *ast_odbc_request_obj(const char *name, int check);
00076 
00077 /*! \brief Releases an ODBC object previously allocated by odbc_request_obj()
00078  * \param obj The ODBC object
00079  */
00080 void ast_odbc_release_obj(struct odbc_obj *obj);
00081 
00082 /*! \brief Checks an ODBC object to ensure it is still connected
00083  * \param obj The ODBC object
00084  * \return Returns 0 if connected, -1 otherwise.
00085  */
00086 int ast_odbc_sanity_check(struct odbc_obj *obj);
00087 
00088 /*! \brief Prepares, executes, and returns the resulting statement handle.
00089  * \param obj The ODBC object
00090  * \param prepare_cb A function callback, which, when called, should return a statement handle prepared, with any necessary parameters or result columns bound.
00091  * \param data A parameter to be passed to the prepare_cb parameter function, indicating which statement handle is to be prepared.
00092  * \return Returns a statement handle or NULL on error.
00093  */
00094 SQLHSTMT ast_odbc_prepare_and_execute(struct odbc_obj *obj, SQLHSTMT (*prepare_cb)(struct odbc_obj *obj, void *data), void *data);
00095 
00096 #endif /* _ASTERISK_RES_ODBC_H */

Generated on Fri Aug 24 02:22:16 2007 for Asterisk - the Open Source PBX by  doxygen 1.5.1