1/* 2 * hstmt.h 3 * 4 * $Id: hstmt.h,v 1.18 2006/01/20 15:58:34 source Exp $ 5 * 6 * Query statement 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 _HSTMT_H 79#define _HSTMT_H 80 81typedef struct PARAM 82 { 83 void *data; 84 int length; 85 } 86PARAM_t; 87 88#define STMT_PARAMS_MAX 8 89 90 91/* 92 * Binding parameter from SQLBindCol 93 */ 94typedef struct BIND { 95 UWORD bn_col; /* Column # */ 96 SWORD bn_type; /* ODBC C data type */ 97 void * bn_data; /* Pointer to data */ 98 SDWORD bn_size; /* Size of data area */ 99 SQLLEN *bn_pInd; /* Holds SQL_NULL_DATA | 0. 100 * And length of returned char/bin data 101 */ 102} BIND_t; 103 104typedef struct SBLST TBLST, *PBLST; 105/* 106 * Binding cell on the linked list 107 */ 108struct SBLST { 109 PBLST bl_nextBind; /* Next binding */ 110 BIND_t bl_bind; /* Binding information */ 111}; 112 113 114typedef struct STMT 115 { 116 int type; /* must be 1st field */ 117 HERR herr; 118 SQLRETURN rc; /* Return code of last function */ 119 120 struct STMT *next; 121 122 HDBC hdbc; /* back point to connection object */ 123 124 HSTMT dhstmt; /* driver's stmt handle */ 125 126 int state; 127 int cursor_state; 128 int prep_state; 129 int asyn_on; /* async executing which odbc call */ 130 int need_on; /* which call return SQL_NEED_DATA */ 131 132 int stmt_cip; /* Call in progress on this handle */ 133 134 SQLUINTEGER rowset_size; 135 SQLUINTEGER bind_type; 136 137#if (ODBCVER >= 0x0300) 138 DESC_t * imp_desc[4]; 139 DESC_t * desc[4]; 140 SQLUINTEGER row_array_size; 141 SQLPOINTER fetch_bookmark_ptr, params_processed_ptr; 142 SQLUINTEGER paramset_size; 143 SQLPOINTER row_status_ptr; 144 SQLPOINTER rows_fetched_ptr; 145 SQLUSMALLINT row_status_allocated; 146#endif 147 148 SQLSMALLINT err_rec; 149 150 PARAM_t params[STMT_PARAMS_MAX]; /* for a conversion parameters ansi<=>unicode*/ 151 int params_inserted; 152 153 PBLST st_pbinding; /* API user bindings from SQLBindCol */ 154 } 155STMT_t; 156 157 158#define IS_VALID_HSTMT(x) \ 159 ((x) != SQL_NULL_HSTMT && \ 160 ((STMT_t *)(x))->type == SQL_HANDLE_STMT && \ 161 ((STMT_t *)(x))->hdbc != SQL_NULL_HDBC) 162 163 164#define ENTER_STMT(hstmt, trace) \ 165 STMT (pstmt, hstmt); \ 166 SQLRETURN retcode = SQL_SUCCESS; \ 167 ODBC_LOCK(); \ 168 TRACE (trace); \ 169 if (!IS_VALID_HSTMT (pstmt)) \ 170 { \ 171 retcode = SQL_INVALID_HANDLE; \ 172 goto done; \ 173 } \ 174 else if (pstmt->stmt_cip) \ 175 { \ 176 PUSHSQLERR (pstmt->herr, en_S1010); \ 177 retcode = SQL_ERROR; \ 178 goto done; \ 179 } \ 180 pstmt->stmt_cip = 1; \ 181 CLEAR_ERRORS (pstmt); \ 182 if (pstmt->asyn_on == en_NullProc && pstmt->params_inserted > 0) \ 183 _iodbcdm_FreeStmtParams(pstmt); \ 184 ODBC_UNLOCK() 185 186 187#define LEAVE_STMT(hstmt, trace) \ 188 ODBC_LOCK (); \ 189 pstmt->stmt_cip = 0; \ 190 done: \ 191 TRACE(trace); \ 192 ODBC_UNLOCK (); \ 193 return (retcode) 194 195 196enum 197 { 198 en_stmt_allocated = 0, 199 en_stmt_prepared, 200 en_stmt_executed_with_info, 201 en_stmt_executed, 202 en_stmt_cursoropen, 203 en_stmt_fetched, 204 en_stmt_xfetched, 205 en_stmt_needdata, /* not call SQLParamData() yet */ 206 en_stmt_mustput, /* not call SQLPutData() yet */ 207 en_stmt_canput /* SQLPutData() called */ 208 }; /* for statement handle state */ 209 210enum 211 { 212 en_stmt_cursor_no = 0, 213 en_stmt_cursor_named, 214 en_stmt_cursor_opened, 215 en_stmt_cursor_fetched, 216 en_stmt_cursor_xfetched 217 }; /* for statement cursor state */ 218 219 220/* 221 * Internal prototypes 222 */ 223SQLRETURN _iodbcdm_dropstmt (HSTMT stmt); 224 225void _iodbcdm_FreeStmtParams(STMT_t *pstmt); 226void *_iodbcdm_alloc_param(STMT_t *pstmt, int i, int size); 227wchar_t *_iodbcdm_conv_param_A2W(STMT_t *pstmt, int i, SQLCHAR *pData, int pDataLength); 228char *_iodbcdm_conv_param_W2A(STMT_t *pstmt, int i, SQLWCHAR *pData, int pDataLength); 229void _iodbcdm_ConvBindData (STMT_t *pstmt); 230SQLRETURN _iodbcdm_BindColumn (STMT_t *pstmt, BIND_t *pbind); 231int _iodbcdm_UnBindColumn (STMT_t *pstmt, BIND_t *pbind); 232void _iodbcdm_RemoveBind (STMT_t *pstmt); 233void _iodbcdm_do_cursoropen (STMT_t * pstmt); 234SQLSMALLINT _iodbcdm_map_sql_type (int type, int odbcver); 235SQLSMALLINT _iodbcdm_map_c_type (int type, int odbcver); 236 237 238SQLRETURN SQL_API _iodbcdm_ExtendedFetch ( 239 SQLHSTMT hstmt, 240 SQLUSMALLINT fFetchType, 241 SQLLEN irow, 242 SQLULEN * pcrow, 243 SQLUSMALLINT * rgfRowStatus); 244 245SQLRETURN SQL_API _iodbcdm_SetPos ( 246 SQLHSTMT hstmt, 247 SQLSETPOSIROW irow, 248 SQLUSMALLINT fOption, 249 SQLUSMALLINT fLock); 250 251SQLRETURN SQL_API _iodbcdm_NumResultCols ( 252 SQLHSTMT hstmt, 253 SQLSMALLINT * pccol); 254 255SQLRETURN SQLGetStmtOption_Internal ( 256 SQLHSTMT hstmt, 257 SQLUSMALLINT fOption, 258 SQLPOINTER pvParam); 259#endif 260