1/* 2 * hdbc.h 3 * 4 * $Id: hdbc.h,v 1.17 2006/07/10 13:49:29 source Exp $ 5 * 6 * Data source connect object management functions 7 * 8 * The iODBC driver manager. 9 * 10 * Copyright (C) 1995 by Ke Jin <kejin@empress.com> 11 * Copyright (C) 1996-2006 by OpenLink Software <iodbc@openlinksw.com> 12 * All Rights Reserved. 13 * 14 * This software is released under the terms of either of the following 15 * licenses: 16 * 17 * - GNU Library General Public License (see LICENSE.LGPL) 18 * - The BSD License (see LICENSE.BSD). 19 * 20 * Note that the only valid version of the LGPL license as far as this 21 * project is concerned is the original GNU Library General Public License 22 * Version 2, dated June 1991. 23 * 24 * While not mandated by the BSD license, any patches you make to the 25 * iODBC source code may be contributed back into the iODBC project 26 * at your discretion. Contributions will benefit the Open Source and 27 * Data Access community as a whole. Submissions may be made at: 28 * 29 * http://www.iodbc.org 30 * 31 * 32 * GNU Library Generic Public License Version 2 33 * ============================================ 34 * This library is free software; you can redistribute it and/or 35 * modify it under the terms of the GNU Library General Public 36 * License as published by the Free Software Foundation; only 37 * Version 2 of the License dated June 1991. 38 * 39 * This library is distributed in the hope that it will be useful, 40 * but WITHOUT ANY WARRANTY; without even the implied warranty of 41 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 42 * Library General Public License for more details. 43 * 44 * You should have received a copy of the GNU Library General Public 45 * License along with this library; if not, write to the Free 46 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 47 * 48 * 49 * The BSD License 50 * =============== 51 * Redistribution and use in source and binary forms, with or without 52 * modification, are permitted provided that the following conditions 53 * are met: 54 * 55 * 1. Redistributions of source code must retain the above copyright 56 * notice, this list of conditions and the following disclaimer. 57 * 2. Redistributions in binary form must reproduce the above copyright 58 * notice, this list of conditions and the following disclaimer in 59 * the documentation and/or other materials provided with the 60 * distribution. 61 * 3. Neither the name of OpenLink Software Inc. nor the names of its 62 * contributors may be used to endorse or promote products derived 63 * from this software without specific prior written permission. 64 * 65 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 66 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 67 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 68 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL OPENLINK OR 69 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 70 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 71 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 72 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 73 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 74 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 75 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 76 */ 77 78#ifndef _HDBC_H 79#define _HDBC_H 80 81#if (ODBCVER >= 0x0300) 82#include <hdesc.h> 83#endif 84 85typedef struct _drvopt 86 { 87 SQLUSMALLINT Option; 88 SQLULEN Param; 89 SQLCHAR waMode; 90 91 struct _drvopt *next; 92 } 93DRVOPT; 94 95typedef struct DBC 96 { 97 int type; /* must be 1st field */ 98 HERR herr; 99 SQLRETURN rc; 100 101 struct DBC * next; 102 103 HENV genv; /* back point to global env object */ 104 105 HDBC dhdbc; /* driver's private dbc */ 106 HENV henv; /* back point to instant env object */ 107 HSTMT hstmt; /* list of statement object handle(s) */ 108#if (ODBCVER >= 0x300) 109 HDESC hdesc; /* list of connection descriptors */ 110 111 struct DBC * cp_pdbc; /* pooled connection */ 112 BOOL cp_in_use; /* connection in pool is in use */ 113 time_t cp_timeout; /* CPTimeout parameter */ 114 time_t cp_expiry_time; /* expiration time (abs time value) */ 115 time_t cp_retry_wait; /* timeout before retry (abs time value) */ 116 char *cp_probe; /* CPProbe -- probe SQL statement */ 117 char *cp_dsn; 118 char *cp_uid; 119 char *cp_pwd; 120 char *cp_connstr; 121#endif 122 123 int state; 124 125 /* options */ 126 UDWORD access_mode; 127 UDWORD autocommit; 128 129 UDWORD login_timeout; 130 UDWORD odbc_cursors; 131 UDWORD packet_size; 132 UDWORD quiet_mode; 133 UDWORD txn_isolation; 134 SWORD cb_commit; 135 SWORD cb_rollback; 136 137 wchar_t * current_qualifier; 138 char current_qualifier_WA; 139 140 SWORD dbc_cip; /* Call in Progess flag */ 141 142 DRVOPT *drvopt; /* Driver specific connect options */ 143 SQLSMALLINT err_rec; 144 } 145DBC_t; 146 147 148#define IS_VALID_HDBC(x) \ 149 ((x) != SQL_NULL_HDBC && ((DBC_t *)(x))->type == SQL_HANDLE_DBC) 150 151 152#define ENTER_HDBC(hdbc, holdlock, trace) \ 153 CONN(pdbc, hdbc); \ 154 SQLRETURN retcode = SQL_SUCCESS; \ 155 ODBC_LOCK();\ 156 TRACE(trace); \ 157 if (!IS_VALID_HDBC (pdbc)) \ 158 { \ 159 retcode = SQL_INVALID_HANDLE; \ 160 goto done; \ 161 } \ 162 else if (pdbc->dbc_cip) \ 163 { \ 164 PUSHSQLERR (pdbc->herr, en_S1010); \ 165 retcode = SQL_ERROR; \ 166 goto done; \ 167 } \ 168 pdbc->dbc_cip = 1; \ 169 CLEAR_ERRORS (pdbc); \ 170 if (!holdlock) \ 171 ODBC_UNLOCK() 172 173 174#define LEAVE_HDBC(hdbc, holdlock, trace) \ 175 if (!holdlock) \ 176 ODBC_LOCK (); \ 177 pdbc->dbc_cip = 0; \ 178 done: \ 179 TRACE(trace); \ 180 ODBC_UNLOCK (); \ 181 return (retcode) 182 183 184/* 185 * Note: 186 * - ODBC applications can see address of driver manager's 187 * connection object, i.e connection handle -- a void pointer, 188 * but not detail of it. ODBC applications can neither see 189 * detail driver's connection object nor its address. 190 * 191 * - ODBC driver manager knows its own connection objects and 192 * exposes their address to an ODBC application. Driver manager 193 * also knows address of driver's connection objects and keeps 194 * it via dhdbc field in driver manager's connection object. 195 * 196 * - ODBC driver exposes address of its own connection object to 197 * driver manager without detail. 198 * 199 * - Applications can get driver's connection object handle by 200 * SQLGetInfo() with fInfoType equals to SQL_DRIVER_HDBC. 201 */ 202 203enum 204 { 205 en_dbc_allocated, 206 en_dbc_needdata, 207 en_dbc_connected, 208 en_dbc_hstmt 209 }; 210 211 212/* 213 * Internal prototypes 214 */ 215SQLRETURN SQL_API _iodbcdm_SetConnectOption ( 216 SQLHDBC hdbc, 217 SQLUSMALLINT fOption, 218 SQLULEN vParam, 219 SQLCHAR waMode); 220SQLRETURN SQL_API _iodbcdm_GetConnectOption ( 221 SQLHDBC hdbc, 222 SQLUSMALLINT fOption, 223 SQLPOINTER pvParam, 224 SQLCHAR waMode); 225#endif 226