1/* 2 * ColAttribute.c 3 * 4 * $Id: ColAttribute.c,v 1.7 2006/01/20 15:58:35 source Exp $ 5 * 6 * SQLColAttribute trace functions 7 * 8 * The iODBC driver manager. 9 * 10 * Copyright (C) 1996-2006 by OpenLink Software <iodbc@openlinksw.com> 11 * All Rights Reserved. 12 * 13 * This software is released under the terms of either of the following 14 * licenses: 15 * 16 * - GNU Library General Public License (see LICENSE.LGPL) 17 * - The BSD License (see LICENSE.BSD). 18 * 19 * Note that the only valid version of the LGPL license as far as this 20 * project is concerned is the original GNU Library General Public License 21 * Version 2, dated June 1991. 22 * 23 * While not mandated by the BSD license, any patches you make to the 24 * iODBC source code may be contributed back into the iODBC project 25 * at your discretion. Contributions will benefit the Open Source and 26 * Data Access community as a whole. Submissions may be made at: 27 * 28 * http://www.iodbc.org 29 * 30 * 31 * GNU Library Generic Public License Version 2 32 * ============================================ 33 * This library is free software; you can redistribute it and/or 34 * modify it under the terms of the GNU Library General Public 35 * License as published by the Free Software Foundation; only 36 * Version 2 of the License dated June 1991. 37 * 38 * This library is distributed in the hope that it will be useful, 39 * but WITHOUT ANY WARRANTY; without even the implied warranty of 40 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 41 * Library General Public License for more details. 42 * 43 * You should have received a copy of the GNU Library General Public 44 * License along with this library; if not, write to the Free 45 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 46 * 47 * 48 * The BSD License 49 * =============== 50 * Redistribution and use in source and binary forms, with or without 51 * modification, are permitted provided that the following conditions 52 * are met: 53 * 54 * 1. Redistributions of source code must retain the above copyright 55 * notice, this list of conditions and the following disclaimer. 56 * 2. Redistributions in binary form must reproduce the above copyright 57 * notice, this list of conditions and the following disclaimer in 58 * the documentation and/or other materials provided with the 59 * distribution. 60 * 3. Neither the name of OpenLink Software Inc. nor the names of its 61 * contributors may be used to endorse or promote products derived 62 * from this software without specific prior written permission. 63 * 64 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 65 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 66 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 67 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL OPENLINK OR 68 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 69 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 70 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 71 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 72 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 73 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 74 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 75 */ 76 77#include "trace.h" 78 79 80void 81_trace_colattr2_type (SQLUSMALLINT type) 82{ 83 char *ptr = "unknown option"; 84 85 switch (type) 86 { 87 _S (SQL_COLUMN_COUNT); 88 _S (SQL_COLUMN_NAME); 89 _S (SQL_COLUMN_TYPE); 90 _S (SQL_COLUMN_LENGTH); 91 _S (SQL_COLUMN_PRECISION); 92 _S (SQL_COLUMN_SCALE); 93 _S (SQL_COLUMN_DISPLAY_SIZE); 94 _S (SQL_COLUMN_NULLABLE); 95 _S (SQL_COLUMN_UNSIGNED); 96 _S (SQL_COLUMN_MONEY); 97 _S (SQL_COLUMN_UPDATABLE); 98 _S (SQL_COLUMN_AUTO_INCREMENT); 99 _S (SQL_COLUMN_CASE_SENSITIVE); 100 _S (SQL_COLUMN_SEARCHABLE); 101 _S (SQL_COLUMN_TYPE_NAME); 102 _S (SQL_COLUMN_TABLE_NAME); 103 _S (SQL_COLUMN_OWNER_NAME); 104 _S (SQL_COLUMN_QUALIFIER_NAME); 105 _S (SQL_COLUMN_LABEL); 106 } 107 108 trace_emit ("\t\t%-15.15s %ld (%s)\n", "SQLUSMALLINT ", (int) type, ptr); 109} 110 111 112#if ODBCVER >= 0x0300 113void 114_trace_colattr3_type (SQLUSMALLINT type) 115{ 116 char *ptr = "unknown option"; 117 118 switch (type) 119 { 120 _S (SQL_DESC_AUTO_UNIQUE_VALUE); 121 _S (SQL_DESC_BASE_COLUMN_NAME); 122 _S (SQL_DESC_BASE_TABLE_NAME); 123 _S (SQL_DESC_CASE_SENSITIVE); 124 _S (SQL_DESC_CATALOG_NAME); 125 _S (SQL_DESC_CONCISE_TYPE); 126 _S (SQL_DESC_COUNT); 127 _S (SQL_DESC_DISPLAY_SIZE); 128 _S (SQL_DESC_FIXED_PREC_SCALE); 129 _S (SQL_DESC_LABEL); 130 _S (SQL_DESC_LENGTH); 131 _S (SQL_DESC_LITERAL_PREFIX); 132 _S (SQL_DESC_LITERAL_SUFFIX); 133 _S (SQL_DESC_LOCAL_TYPE_NAME); 134 _S (SQL_DESC_NAME); 135 _S (SQL_DESC_NULLABLE); 136 _S (SQL_DESC_NUM_PREC_RADIX); 137 _S (SQL_DESC_OCTET_LENGTH); 138 _S (SQL_DESC_PRECISION); 139 _S (SQL_DESC_SCALE); 140 _S (SQL_DESC_SCHEMA_NAME); 141 _S (SQL_DESC_SEARCHABLE); 142 _S (SQL_DESC_TABLE_NAME); 143 _S (SQL_DESC_TYPE); 144 _S (SQL_DESC_TYPE_NAME); 145 _S (SQL_DESC_UNNAMED); 146 _S (SQL_DESC_UNSIGNED); 147 _S (SQL_DESC_UPDATABLE); 148 } 149 150 trace_emit ("\t\t%-15.15s %d (%s)\n", "SQLUSMALLINT ", (int) type, ptr); 151} 152#endif 153 154 155#if ODBCVER >= 0x0300 156static void 157_trace_colattr3_data ( 158 SQLUSMALLINT FieldIdentifier, 159 SQLPOINTER CharacterAttributePtr, 160 SQLSMALLINT BufferLength, 161 SQLSMALLINT * StringLengthPtr, 162 SQLLEN * NumericAttributePtr, 163 int w_mode, 164 int output) 165{ 166 int type = 0; 167 168 switch (FieldIdentifier) 169 { 170 case SQL_DESC_BASE_COLUMN_NAME: 171 case SQL_DESC_BASE_TABLE_NAME: 172 case SQL_DESC_CATALOG_NAME: 173 case SQL_DESC_LABEL: 174 case SQL_DESC_LITERAL_PREFIX: 175 case SQL_DESC_LITERAL_SUFFIX: 176 case SQL_DESC_LOCAL_TYPE_NAME: 177 case SQL_DESC_NAME: 178 case SQL_DESC_SCHEMA_NAME: 179 case SQL_DESC_TYPE_NAME: 180 case SQL_DESC_TABLE_NAME: 181 type = 1; /* string */ 182 break; 183 184 case SQL_DESC_CONCISE_TYPE: 185 case SQL_DESC_COUNT: 186 case SQL_DESC_DISPLAY_SIZE: 187 case SQL_DESC_LENGTH: 188 case SQL_DESC_NUM_PREC_RADIX: 189 case SQL_DESC_OCTET_LENGTH: 190 case SQL_DESC_PRECISION: 191 case SQL_DESC_SCALE: 192 case SQL_DESC_TYPE: 193 type = 2; /* integer */ 194 break; 195 196 case SQL_DESC_AUTO_UNIQUE_VALUE: 197 case SQL_DESC_CASE_SENSITIVE: 198 case SQL_DESC_FIXED_PREC_SCALE: 199 case SQL_DESC_UNSIGNED: 200 type = 3; /* boolean */ 201 break; 202 203 case SQL_DESC_NULLABLE: 204 type = 4; 205 break; 206 207 case SQL_DESC_SEARCHABLE: 208 type = 5; 209 break; 210 211 case SQL_DESC_UNNAMED: 212 type = 6; 213 break; 214 215 case SQL_DESC_UPDATABLE: 216 type = 7; 217 break; 218 219 default: 220 type = 0; /* unknown */ 221 break; 222 } 223 224 /* 225 * If we cannot determine the type or we are entering, just 226 * emit the pointers 227 */ 228 if (type == 0 || !output) 229 { 230 _trace_pointer (CharacterAttributePtr); 231 _trace_bufferlen ((SQLINTEGER) BufferLength); 232 _trace_smallint_p (StringLengthPtr, output); 233 _trace_len_p (NumericAttributePtr, output); 234 return; 235 } 236 237 if (type == 1) /* string */ 238 { 239 if (w_mode) 240 _trace_string_w (CharacterAttributePtr, BufferLength, StringLengthPtr, 241 output); 242 else 243 _trace_string (CharacterAttributePtr, BufferLength, StringLengthPtr, 244 output); 245 _trace_bufferlen ((SQLINTEGER) BufferLength); 246 _trace_smallint_p (StringLengthPtr, output); 247 _trace_len_p (NumericAttributePtr, 0); /* just display pointer */ 248 } 249 else /* integer */ 250 { 251 _trace_pointer (CharacterAttributePtr); 252 _trace_bufferlen ((SQLINTEGER) BufferLength); 253 _trace_smallint_p (StringLengthPtr, 0); /* just display pointer */ 254 255 if (!NumericAttributePtr) /* null pointer */ 256 trace_emit ("\t\t%-15.15s * 0x0\n", "SQLLEN"); 257 else if (type == 3) /* boolean */ 258 { 259 trace_emit ("\t\t%-15.15s * %p (%s)\n", "SQLLEN", 260 NumericAttributePtr, 261 *(SQLLEN *) NumericAttributePtr ? "SQL_TRUE" : "SQL_FALSE"); 262 } 263 else if (type == 4) /* nullable */ 264 { 265 char *ptr = "unknown nullable type"; 266 267 switch (*NumericAttributePtr) 268 { 269 _S (SQL_NULLABLE); 270 _S (SQL_NULLABLE_UNKNOWN); 271 _S (SQL_NO_NULLS); 272 } 273 trace_emit ("\t\t%-15.15s * %p (%s)\n", "SQLLEN", 274 NumericAttributePtr, ptr); 275 } 276 else if (type == 5) /* searchable */ 277 { 278 char *ptr = "unknown searchable type"; 279 280 switch (*NumericAttributePtr) 281 { 282 _S (SQL_PRED_NONE); 283 _S (SQL_PRED_CHAR); 284 _S (SQL_PRED_BASIC); 285 _S (SQL_PRED_SEARCHABLE); 286 } 287 trace_emit ("\t\t%-15.15s * %p (%s)\n", "SQLLEN", 288 NumericAttributePtr, ptr); 289 } 290 else if (type == 6) /* named */ 291 { 292 char *ptr = "unknown named type"; 293 294 switch (*NumericAttributePtr) 295 { 296 _S (SQL_NAMED); 297 _S (SQL_UNNAMED); 298 } 299 trace_emit ("\t\t%-15.15s * %p (%s)\n", "SQLLEN", 300 NumericAttributePtr, ptr); 301 } 302 else if (type == 7) /* updatable */ 303 { 304 char *ptr = "unknown ubdatable type"; 305 306 switch (*NumericAttributePtr) 307 { 308 _S (SQL_ATTR_READONLY); 309 _S (SQL_ATTR_WRITE); 310 _S (SQL_ATTR_READWRITE_UNKNOWN); 311 312 } 313 trace_emit ("\t\t%-15.15s * %p (%s)\n", "SQLLEN", 314 NumericAttributePtr, ptr); 315 } 316 else /* just a value */ 317 { 318 _trace_len_p (NumericAttributePtr, output); 319 } 320 } 321 322 return; 323} 324#endif 325 326 327#if ODBCVER >= 0x0300 328void 329trace_SQLColAttribute (int trace_leave, int retcode, 330 SQLHSTMT StatementHandle, 331 SQLUSMALLINT ColumnNumber, 332 SQLUSMALLINT FieldIdentifier, 333 SQLPOINTER CharacterAttributePtr, 334 SQLSMALLINT BufferLength, 335 SQLSMALLINT * StringLengthPtr, 336 SQLLEN * NumericAttributePtr 337 ) 338{ 339 /* Trace function */ 340 _trace_print_function (en_ColAttribute, trace_leave, retcode); 341 342 /* Trace Arguments */ 343 _trace_handle (SQL_HANDLE_STMT, StatementHandle); 344 _trace_usmallint (ColumnNumber); 345 _trace_colattr3_type (FieldIdentifier); 346 347 _trace_colattr3_data (FieldIdentifier, CharacterAttributePtr, BufferLength, 348 StringLengthPtr, NumericAttributePtr, 0, TRACE_OUTPUT_SUCCESS); 349} 350#endif 351 352 353#if ODBCVER >= 0x0300 354void 355trace_SQLColAttributeW (int trace_leave, int retcode, 356 SQLHSTMT StatementHandle, 357 SQLUSMALLINT ColumnNumber, 358 SQLUSMALLINT FieldIdentifier, 359 SQLPOINTER CharacterAttributePtr, 360 SQLSMALLINT BufferLength, 361 SQLSMALLINT * StringLengthPtr, 362 SQLLEN * NumericAttributePtr 363 ) 364{ 365 /* Trace function */ 366 _trace_print_function (en_ColAttributeW, trace_leave, retcode); 367 368 /* Trace Arguments */ 369 _trace_handle (SQL_HANDLE_STMT, StatementHandle); 370 _trace_usmallint (ColumnNumber); 371 _trace_colattr3_type (FieldIdentifier); 372 373 _trace_colattr3_data (FieldIdentifier, CharacterAttributePtr, BufferLength, 374 StringLengthPtr, NumericAttributePtr, 1, TRACE_OUTPUT_SUCCESS); 375} 376#endif 377 378 379void 380trace_SQLColAttributes (int trace_leave, int retcode, 381 SQLHSTMT StatementHandle, 382 SQLUSMALLINT icol, 383 SQLUSMALLINT fDescType, 384 SQLPOINTER rgbDesc, 385 SQLSMALLINT cbDescMax, 386 SQLSMALLINT * pcbDesc, 387 SQLLEN * pfDesc) 388{ 389 /* Trace function */ 390 _trace_print_function (en_ColAttributes, trace_leave, retcode); 391 392 /* Trace Arguments */ 393 _trace_handle (SQL_HANDLE_STMT, StatementHandle); 394 _trace_usmallint (icol); 395 _trace_colattr2_type (fDescType); 396 _trace_pointer (rgbDesc); /* TODO */ 397 _trace_smallint (cbDescMax); 398 _trace_smallint_p (pcbDesc, TRACE_OUTPUT_SUCCESS); 399 _trace_len_p (pfDesc, TRACE_OUTPUT_SUCCESS); 400} 401 402 403#if ODBCVER >= 0x0300 404void 405trace_SQLColAttributesW (int trace_leave, int retcode, 406 SQLHSTMT StatementHandle, 407 SQLUSMALLINT icol, 408 SQLUSMALLINT fDescType, 409 SQLPOINTER rgbDesc, 410 SQLSMALLINT cbDescMax, 411 SQLSMALLINT * pcbDesc, 412 SQLLEN * pfDesc) 413{ 414 /* Trace function */ 415 _trace_print_function (en_ColAttributeW, trace_leave, retcode); 416 417 /* Trace Arguments */ 418 _trace_handle (SQL_HANDLE_STMT, StatementHandle); 419 _trace_usmallint (icol); 420 _trace_colattr2_type (fDescType); 421 _trace_pointer (rgbDesc); /* TODO */ 422 _trace_smallint (cbDescMax); 423 _trace_smallint_p (pcbDesc, TRACE_OUTPUT_SUCCESS); 424 _trace_len_p (pfDesc, TRACE_OUTPUT_SUCCESS); 425} 426#endif 427