| 1 | /********************************************************************* | 
|---|
| 2 | * | 
|---|
| 3 | * This is based on code created by Peter Harvey, | 
|---|
| 4 | * (pharvey@codebydesign.com). | 
|---|
| 5 | * | 
|---|
| 6 | * Modified and extended by Nick Gorham | 
|---|
| 7 | * (nick@lurcher.org). | 
|---|
| 8 | * | 
|---|
| 9 | * Any bugs or problems should be considered the fault of Nick and not | 
|---|
| 10 | * Peter. | 
|---|
| 11 | * | 
|---|
| 12 | * copyright (c) 1999 Nick Gorham | 
|---|
| 13 | * | 
|---|
| 14 | * This library is free software; you can redistribute it and/or | 
|---|
| 15 | * modify it under the terms of the GNU Lesser General Public | 
|---|
| 16 | * License as published by the Free Software Foundation; either | 
|---|
| 17 | * version 2 of the License, or (at your option) any later version. | 
|---|
| 18 | * | 
|---|
| 19 | * This library is distributed in the hope that it will be useful, | 
|---|
| 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
|---|
| 22 | * Lesser General Public License for more details. | 
|---|
| 23 | * | 
|---|
| 24 | * You should have received a copy of the GNU Lesser General Public | 
|---|
| 25 | * License along with this library; if not, write to the Free Software | 
|---|
| 26 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA | 
|---|
| 27 | * | 
|---|
| 28 | ********************************************************************** | 
|---|
| 29 | * | 
|---|
| 30 | * $Id: SQLGetTypeInfo.c,v 1.6 2009/02/18 17:59:08 lurcher Exp $ | 
|---|
| 31 | * | 
|---|
| 32 | * $Log: SQLGetTypeInfo.c,v $ | 
|---|
| 33 | * Revision 1.6  2009/02/18 17:59:08  lurcher | 
|---|
| 34 | * Shift to using config.h, the compile lines were making it hard to spot warnings | 
|---|
| 35 | * | 
|---|
| 36 | * Revision 1.5  2004/01/12 09:54:39  lurcher | 
|---|
| 37 | * | 
|---|
| 38 | * Fix problem where STATE_S5 stops metadata calls | 
|---|
| 39 | * | 
|---|
| 40 | * Revision 1.4  2003/10/30 18:20:46  lurcher | 
|---|
| 41 | * | 
|---|
| 42 | * Fix broken thread protection | 
|---|
| 43 | * Remove SQLNumResultCols after execute, lease S4/S% to driver | 
|---|
| 44 | * Fix string overrun in SQLDriverConnect | 
|---|
| 45 | * Add initial support for Interix | 
|---|
| 46 | * | 
|---|
| 47 | * Revision 1.3  2003/02/27 12:19:39  lurcher | 
|---|
| 48 | * | 
|---|
| 49 | * Add the A functions as well as the W | 
|---|
| 50 | * | 
|---|
| 51 | * Revision 1.2  2002/12/05 17:44:31  lurcher | 
|---|
| 52 | * | 
|---|
| 53 | * Display unknown return values in return logging | 
|---|
| 54 | * | 
|---|
| 55 | * Revision 1.1.1.1  2001/10/17 16:40:06  lurcher | 
|---|
| 56 | * | 
|---|
| 57 | * First upload to SourceForge | 
|---|
| 58 | * | 
|---|
| 59 | * Revision 1.5  2001/07/03 09:30:41  nick | 
|---|
| 60 | * | 
|---|
| 61 | * Add ability to alter size of displayed message in the log | 
|---|
| 62 | * | 
|---|
| 63 | * Revision 1.4  2001/04/18 15:03:37  nick | 
|---|
| 64 | * | 
|---|
| 65 | * Fix problem when going to DB2 unicode driver | 
|---|
| 66 | * | 
|---|
| 67 | * Revision 1.3  2001/04/12 17:43:36  nick | 
|---|
| 68 | * | 
|---|
| 69 | * Change logging and added autotest to odbctest | 
|---|
| 70 | * | 
|---|
| 71 | * Revision 1.2  2000/12/31 20:30:54  nick | 
|---|
| 72 | * | 
|---|
| 73 | * Add UNICODE support | 
|---|
| 74 | * | 
|---|
| 75 | * Revision 1.1.1.1  2000/09/04 16:42:52  nick | 
|---|
| 76 | * Imported Sources | 
|---|
| 77 | * | 
|---|
| 78 | * Revision 1.7  1999/11/13 23:41:00  ngorham | 
|---|
| 79 | * | 
|---|
| 80 | * Alter the way DM logging works | 
|---|
| 81 | * Upgrade the Postgres driver to 6.4.6 | 
|---|
| 82 | * | 
|---|
| 83 | * Revision 1.6  1999/10/24 23:54:18  ngorham | 
|---|
| 84 | * | 
|---|
| 85 | * First part of the changes to the error reporting | 
|---|
| 86 | * | 
|---|
| 87 | * Revision 1.5  1999/09/21 22:34:25  ngorham | 
|---|
| 88 | * | 
|---|
| 89 | * Improve performance by removing unneeded logging calls when logging is | 
|---|
| 90 | * disabled | 
|---|
| 91 | * | 
|---|
| 92 | * Revision 1.4  1999/07/10 21:10:16  ngorham | 
|---|
| 93 | * | 
|---|
| 94 | * Adjust error sqlstate from driver manager, depending on requested | 
|---|
| 95 | * version (ODBC2/3) | 
|---|
| 96 | * | 
|---|
| 97 | * Revision 1.3  1999/07/04 21:05:08  ngorham | 
|---|
| 98 | * | 
|---|
| 99 | * Add LGPL Headers to code | 
|---|
| 100 | * | 
|---|
| 101 | * Revision 1.2  1999/06/30 23:56:55  ngorham | 
|---|
| 102 | * | 
|---|
| 103 | * Add initial thread safety code | 
|---|
| 104 | * | 
|---|
| 105 | * Revision 1.1.1.1  1999/05/29 13:41:07  sShandyb | 
|---|
| 106 | * first go at it | 
|---|
| 107 | * | 
|---|
| 108 | * Revision 1.1.1.1  1999/05/27 18:23:18  pharvey | 
|---|
| 109 | * Imported sources | 
|---|
| 110 | * | 
|---|
| 111 | * Revision 1.3  1999/05/03 19:50:43  nick | 
|---|
| 112 | * Another check point | 
|---|
| 113 | * | 
|---|
| 114 | * Revision 1.2  1999/04/30 16:22:47  nick | 
|---|
| 115 | * Another checkpoint | 
|---|
| 116 | * | 
|---|
| 117 | * Revision 1.1  1999/04/25 23:06:11  nick | 
|---|
| 118 | * Initial revision | 
|---|
| 119 | * | 
|---|
| 120 | * | 
|---|
| 121 | **********************************************************************/ | 
|---|
| 122 |  | 
|---|
| 123 | #include <config.h> | 
|---|
| 124 | #include "drivermanager.h" | 
|---|
| 125 |  | 
|---|
| 126 | static char const rcsid[]= "$RCSfile: SQLGetTypeInfo.c,v $ $Revision: 1.6 $"; | 
|---|
| 127 |  | 
|---|
| 128 | SQLRETURN SQLGetTypeInfoA( SQLHSTMT statement_handle, | 
|---|
| 129 | SQLSMALLINT data_type ) | 
|---|
| 130 | { | 
|---|
| 131 | return SQLGetTypeInfo( statement_handle, | 
|---|
| 132 | data_type ); | 
|---|
| 133 | } | 
|---|
| 134 |  | 
|---|
| 135 | SQLRETURN SQLGetTypeInfo( SQLHSTMT statement_handle, | 
|---|
| 136 | SQLSMALLINT data_type ) | 
|---|
| 137 | { | 
|---|
| 138 | DMHSTMT statement = (DMHSTMT) statement_handle; | 
|---|
| 139 | SQLRETURN ret; | 
|---|
| 140 | SQLCHAR s1[ 100 + LOG_MESSAGE_LEN ]; | 
|---|
| 141 |  | 
|---|
| 142 | /* | 
|---|
| 143 | * check statement | 
|---|
| 144 | */ | 
|---|
| 145 |  | 
|---|
| 146 | if ( !__validate_stmt( statement )) | 
|---|
| 147 | { | 
|---|
| 148 | dm_log_write( __FILE__, | 
|---|
| 149 | __LINE__, | 
|---|
| 150 | LOG_INFO, | 
|---|
| 151 | LOG_INFO, | 
|---|
| 152 | "Error: SQL_INVALID_HANDLE"); | 
|---|
| 153 |  | 
|---|
| 154 | return SQL_INVALID_HANDLE; | 
|---|
| 155 | } | 
|---|
| 156 |  | 
|---|
| 157 | function_entry( statement ); | 
|---|
| 158 |  | 
|---|
| 159 | if ( log_info.log_flag ) | 
|---|
| 160 | { | 
|---|
| 161 | sprintf( statement -> msg, "\n\t\tEntry:\ | 
|---|
| 162 | \n\t\t\tStatement = %p\ | 
|---|
| 163 | \n\t\t\tData Type = %s", | 
|---|
| 164 | statement, | 
|---|
| 165 | __type_as_string( s1, data_type )); | 
|---|
| 166 |  | 
|---|
| 167 | dm_log_write( __FILE__, | 
|---|
| 168 | __LINE__, | 
|---|
| 169 | LOG_INFO, | 
|---|
| 170 | LOG_INFO, | 
|---|
| 171 | statement -> msg ); | 
|---|
| 172 | } | 
|---|
| 173 |  | 
|---|
| 174 | thread_protect( SQL_HANDLE_STMT, statement ); | 
|---|
| 175 |  | 
|---|
| 176 | /* | 
|---|
| 177 | * check states | 
|---|
| 178 | */ | 
|---|
| 179 |  | 
|---|
| 180 | #ifdef NR_PROBE | 
|---|
| 181 | if ( statement -> state == STATE_S5 || | 
|---|
| 182 | statement -> state == STATE_S6 || | 
|---|
| 183 | statement -> state == STATE_S7 ) | 
|---|
| 184 | #else | 
|---|
| 185 | if (( statement -> state == STATE_S6 && statement -> eod == 0 ) || | 
|---|
| 186 | statement -> state == STATE_S7 ) | 
|---|
| 187 | #endif | 
|---|
| 188 | { | 
|---|
| 189 | dm_log_write( __FILE__, | 
|---|
| 190 | __LINE__, | 
|---|
| 191 | LOG_INFO, | 
|---|
| 192 | LOG_INFO, | 
|---|
| 193 | "Error: 24000"); | 
|---|
| 194 |  | 
|---|
| 195 | __post_internal_error( &statement -> error, | 
|---|
| 196 | ERROR_24000, NULL, | 
|---|
| 197 | statement -> connection -> environment -> requested_version ); | 
|---|
| 198 |  | 
|---|
| 199 | return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR ); | 
|---|
| 200 | } | 
|---|
| 201 | else if ( statement -> state == STATE_S8 || | 
|---|
| 202 | statement -> state == STATE_S9 || | 
|---|
| 203 | statement -> state == STATE_S10 || | 
|---|
| 204 | statement -> state == STATE_S13 || | 
|---|
| 205 | statement -> state == STATE_S14 || | 
|---|
| 206 | statement -> state == STATE_S15 ) | 
|---|
| 207 | { | 
|---|
| 208 | dm_log_write( __FILE__, | 
|---|
| 209 | __LINE__, | 
|---|
| 210 | LOG_INFO, | 
|---|
| 211 | LOG_INFO, | 
|---|
| 212 | "Error: HY010"); | 
|---|
| 213 |  | 
|---|
| 214 | __post_internal_error( &statement -> error, | 
|---|
| 215 | ERROR_HY010, NULL, | 
|---|
| 216 | statement -> connection -> environment -> requested_version ); | 
|---|
| 217 |  | 
|---|
| 218 | return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR ); | 
|---|
| 219 | } | 
|---|
| 220 |  | 
|---|
| 221 | if ( statement -> state == STATE_S11 || | 
|---|
| 222 | statement -> state == STATE_S12 ) | 
|---|
| 223 | { | 
|---|
| 224 | if ( statement -> interupted_func != SQL_API_SQLGETTYPEINFO ) | 
|---|
| 225 | { | 
|---|
| 226 | dm_log_write( __FILE__, | 
|---|
| 227 | __LINE__, | 
|---|
| 228 | LOG_INFO, | 
|---|
| 229 | LOG_INFO, | 
|---|
| 230 | "Error: HY010"); | 
|---|
| 231 |  | 
|---|
| 232 | __post_internal_error( &statement -> error, | 
|---|
| 233 | ERROR_HY010, NULL, | 
|---|
| 234 | statement -> connection -> environment -> requested_version ); | 
|---|
| 235 |  | 
|---|
| 236 | return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR ); | 
|---|
| 237 | } | 
|---|
| 238 | } | 
|---|
| 239 |  | 
|---|
| 240 | /* | 
|---|
| 241 | * TO_DO Check the SQL_ATTR_METADATA_ID settings | 
|---|
| 242 | */ | 
|---|
| 243 |  | 
|---|
| 244 | if ( statement -> connection -> unicode_driver ) | 
|---|
| 245 | { | 
|---|
| 246 | if ( !CHECK_SQLGETTYPEINFOW( statement -> connection ) && | 
|---|
| 247 | !CHECK_SQLGETTYPEINFO( statement -> connection )) | 
|---|
| 248 | { | 
|---|
| 249 | dm_log_write( __FILE__, | 
|---|
| 250 | __LINE__, | 
|---|
| 251 | LOG_INFO, | 
|---|
| 252 | LOG_INFO, | 
|---|
| 253 | "Error: IM001"); | 
|---|
| 254 |  | 
|---|
| 255 | __post_internal_error( &statement -> error, | 
|---|
| 256 | ERROR_IM001, NULL, | 
|---|
| 257 | statement -> connection -> environment -> requested_version ); | 
|---|
| 258 |  | 
|---|
| 259 | return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR ); | 
|---|
| 260 | } | 
|---|
| 261 |  | 
|---|
| 262 | if ( CHECK_SQLGETTYPEINFOW( statement -> connection ) ) | 
|---|
| 263 | { | 
|---|
| 264 | ret = SQLGETTYPEINFOW( statement -> connection , | 
|---|
| 265 | statement -> driver_stmt, | 
|---|
| 266 | data_type ); | 
|---|
| 267 | } | 
|---|
| 268 | else | 
|---|
| 269 | { | 
|---|
| 270 | ret = SQLGETTYPEINFO( statement -> connection , | 
|---|
| 271 | statement -> driver_stmt, | 
|---|
| 272 | data_type ); | 
|---|
| 273 | } | 
|---|
| 274 | } | 
|---|
| 275 | else | 
|---|
| 276 | { | 
|---|
| 277 | if ( !CHECK_SQLGETTYPEINFO( statement -> connection )) | 
|---|
| 278 | { | 
|---|
| 279 | dm_log_write( __FILE__, | 
|---|
| 280 | __LINE__, | 
|---|
| 281 | LOG_INFO, | 
|---|
| 282 | LOG_INFO, | 
|---|
| 283 | "Error: IM001"); | 
|---|
| 284 |  | 
|---|
| 285 | __post_internal_error( &statement -> error, | 
|---|
| 286 | ERROR_IM001, NULL, | 
|---|
| 287 | statement -> connection -> environment -> requested_version ); | 
|---|
| 288 |  | 
|---|
| 289 | return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR ); | 
|---|
| 290 | } | 
|---|
| 291 |  | 
|---|
| 292 | ret = SQLGETTYPEINFO( statement -> connection , | 
|---|
| 293 | statement -> driver_stmt, | 
|---|
| 294 | data_type ); | 
|---|
| 295 | } | 
|---|
| 296 |  | 
|---|
| 297 | if ( SQL_SUCCEEDED( ret )) | 
|---|
| 298 | { | 
|---|
| 299 | statement -> state = STATE_S5; | 
|---|
| 300 | statement -> prepared = 0; | 
|---|
| 301 | } | 
|---|
| 302 | else if ( ret == SQL_STILL_EXECUTING ) | 
|---|
| 303 | { | 
|---|
| 304 | statement -> interupted_func = SQL_API_SQLGETTYPEINFO; | 
|---|
| 305 | if ( statement -> state != STATE_S11 && | 
|---|
| 306 | statement -> state != STATE_S12 ) | 
|---|
| 307 | statement -> state = STATE_S11; | 
|---|
| 308 | } | 
|---|
| 309 | else | 
|---|
| 310 | { | 
|---|
| 311 | statement -> state = STATE_S1; | 
|---|
| 312 | } | 
|---|
| 313 |  | 
|---|
| 314 | if ( log_info.log_flag ) | 
|---|
| 315 | { | 
|---|
| 316 | sprintf( statement -> msg, | 
|---|
| 317 | "\n\t\tExit:[%s]", | 
|---|
| 318 | __get_return_status( ret, s1 )); | 
|---|
| 319 |  | 
|---|
| 320 | dm_log_write( __FILE__, | 
|---|
| 321 | __LINE__, | 
|---|
| 322 | LOG_INFO, | 
|---|
| 323 | LOG_INFO, | 
|---|
| 324 | statement -> msg ); | 
|---|
| 325 | } | 
|---|
| 326 |  | 
|---|
| 327 | return function_return( SQL_HANDLE_STMT, statement, ret ); | 
|---|
| 328 | } | 
|---|
| 329 |  | 
|---|