Sat Aug 6 00:39:32 2011

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    struct timeval last_used;
00041    unsigned int used:1;
00042    unsigned int up:1;
00043    AST_LIST_ENTRY(odbc_obj) list;
00044 };
00045 
00046 /* functions */
00047 
00048 /*! \brief Executes a prepared statement handle
00049  * \param obj The non-NULL result of odbc_request_obj()
00050  * \param stmt The prepared statement handle
00051  * \return Returns 0 on success or -1 on failure
00052  *
00053  * This function was originally designed simply to execute a prepared
00054  * statement handle and to retry if the initial execution failed.
00055  * Unfortunately, it did this by disconnecting and reconnecting the database
00056  * handle which on most databases causes the statement handle to become
00057  * invalid.  Therefore, this method has been deprecated in favor of
00058  * odbc_prepare_and_execute() which allows the statement to be prepared
00059  * multiple times, if necessary, in case of a loss of connection.
00060  *
00061  * This function really only ever worked with MySQL, where the statement handle is
00062  * not prepared on the server.  If you are not using MySQL, you should avoid it.
00063  */
00064 int ast_odbc_smart_execute(struct odbc_obj *obj, SQLHSTMT stmt) __attribute__((deprecated));
00065 
00066 /*! \brief Retrieves a connected ODBC object
00067  * \param name The name of the ODBC class for which a connection is needed.
00068  * \param check Whether to ensure that a connection is valid before returning the handle.  Usually unnecessary.
00069  * \return Returns an ODBC object or NULL if there is no connection available with the requested name.
00070  *
00071  * Connection classes may, in fact, contain multiple connection handles.  If
00072  * the connection is pooled, then each connection will be dedicated to the
00073  * thread which requests it.  Note that all connections should be released
00074  * when the thread is done by calling odbc_release_obj(), below.
00075  */
00076 struct odbc_obj *ast_odbc_request_obj(const char *name, int check);
00077 
00078 /*! \brief Releases an ODBC object previously allocated by odbc_request_obj()
00079  * \param obj The ODBC object
00080  */
00081 void ast_odbc_release_obj(struct odbc_obj *obj);
00082 
00083 /*! \brief Checks an ODBC object to ensure it is still connected
00084  * \param obj The ODBC object
00085  * \return Returns 0 if connected, -1 otherwise.
00086  */
00087 int ast_odbc_sanity_check(struct odbc_obj *obj);
00088 
00089 /*! \brief Checks if the database natively supports backslash as an escape character.
00090  * \param obj The ODBC object
00091  * \return Returns 1 if backslash is a native escape character, 0 if an ESCAPE clause is needed to support '\'
00092  */
00093 int ast_odbc_backslash_is_escape(struct odbc_obj *obj);
00094 
00095 /*! \brief Prepares, executes, and returns the resulting statement handle.
00096  * \param obj The ODBC object
00097  * \param prepare_cb A function callback, which, when called, should return a statement handle prepared, with any necessary parameters or result columns bound.
00098  * \param data A parameter to be passed to the prepare_cb parameter function, indicating which statement handle is to be prepared.
00099  * \return Returns a statement handle or NULL on error.
00100  */
00101 SQLHSTMT ast_odbc_prepare_and_execute(struct odbc_obj *obj, SQLHSTMT (*prepare_cb)(struct odbc_obj *obj, void *data), void *data);
00102 
00103 #endif /* _ASTERISK_RES_ODBC_H */

Generated on Sat Aug 6 00:39:32 2011 for Asterisk - the Open Source PBX by  doxygen 1.4.7