| 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: SQLGetEnvAttr.c,v 1.6 2009/02/18 17:59:08 lurcher Exp $ |
| 31 | * |
| 32 | * $Log: SQLGetEnvAttr.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 2008/09/29 14:02:45 lurcher |
| 37 | * Fix missing dlfcn group option |
| 38 | * |
| 39 | * Revision 1.4 2003/10/30 18:20:46 lurcher |
| 40 | * |
| 41 | * Fix broken thread protection |
| 42 | * Remove SQLNumResultCols after execute, lease S4/S% to driver |
| 43 | * Fix string overrun in SQLDriverConnect |
| 44 | * Add initial support for Interix |
| 45 | * |
| 46 | * Revision 1.3 2002/12/05 17:44:31 lurcher |
| 47 | * |
| 48 | * Display unknown return values in return logging |
| 49 | * |
| 50 | * Revision 1.2 2001/10/29 09:54:53 lurcher |
| 51 | * |
| 52 | * Add automake to libodbcinstQ |
| 53 | * |
| 54 | * Revision 1.1.1.1 2001/10/17 16:40:05 lurcher |
| 55 | * |
| 56 | * First upload to SourceForge |
| 57 | * |
| 58 | * Revision 1.3 2001/07/03 09:30:41 nick |
| 59 | * |
| 60 | * Add ability to alter size of displayed message in the log |
| 61 | * |
| 62 | * Revision 1.2 2001/04/12 17:43:36 nick |
| 63 | * |
| 64 | * Change logging and added autotest to odbctest |
| 65 | * |
| 66 | * Revision 1.1.1.1 2000/09/04 16:42:52 nick |
| 67 | * Imported Sources |
| 68 | * |
| 69 | * Revision 1.7 1999/11/13 23:40:59 ngorham |
| 70 | * |
| 71 | * Alter the way DM logging works |
| 72 | * Upgrade the Postgres driver to 6.4.6 |
| 73 | * |
| 74 | * Revision 1.6 1999/10/24 23:54:18 ngorham |
| 75 | * |
| 76 | * First part of the changes to the error reporting |
| 77 | * |
| 78 | * Revision 1.5 1999/09/21 22:34:25 ngorham |
| 79 | * |
| 80 | * Improve performance by removing unneeded logging calls when logging is |
| 81 | * disabled |
| 82 | * |
| 83 | * Revision 1.4 1999/07/10 21:10:16 ngorham |
| 84 | * |
| 85 | * Adjust error sqlstate from driver manager, depending on requested |
| 86 | * version (ODBC2/3) |
| 87 | * |
| 88 | * Revision 1.3 1999/07/04 21:05:07 ngorham |
| 89 | * |
| 90 | * Add LGPL Headers to code |
| 91 | * |
| 92 | * Revision 1.2 1999/06/30 23:56:55 ngorham |
| 93 | * |
| 94 | * Add initial thread safety code |
| 95 | * |
| 96 | * Revision 1.1.1.1 1999/05/29 13:41:07 sShandyb |
| 97 | * first go at it |
| 98 | * |
| 99 | * Revision 1.1.1.1 1999/05/27 18:23:17 pharvey |
| 100 | * Imported sources |
| 101 | * |
| 102 | * Revision 1.2 1999/05/09 23:27:11 nick |
| 103 | * All the API done now |
| 104 | * |
| 105 | * Revision 1.1 1999/04/25 23:06:11 nick |
| 106 | * Initial revision |
| 107 | * |
| 108 | * |
| 109 | **********************************************************************/ |
| 110 | |
| 111 | #include <config.h> |
| 112 | #include "drivermanager.h" |
| 113 | |
| 114 | static char const rcsid[]= "$RCSfile: SQLGetEnvAttr.c,v $ $Revision: 1.6 $" ; |
| 115 | |
| 116 | SQLRETURN SQLGetEnvAttr( SQLHENV environment_handle, |
| 117 | SQLINTEGER attribute, |
| 118 | SQLPOINTER value, |
| 119 | SQLINTEGER buffer_length, |
| 120 | SQLINTEGER *string_length ) |
| 121 | { |
| 122 | DMHENV environment = (DMHENV) environment_handle; |
| 123 | SQLCHAR s1[ 100 + LOG_MESSAGE_LEN ]; |
| 124 | |
| 125 | /* |
| 126 | * check environment |
| 127 | */ |
| 128 | |
| 129 | if ( !__validate_env( environment )) |
| 130 | { |
| 131 | dm_log_write( __FILE__, |
| 132 | __LINE__, |
| 133 | LOG_INFO, |
| 134 | LOG_INFO, |
| 135 | "Error: SQL_INVALID_HANDLE" ); |
| 136 | |
| 137 | return SQL_INVALID_HANDLE; |
| 138 | } |
| 139 | |
| 140 | function_entry( environment ); |
| 141 | |
| 142 | if ( log_info.log_flag ) |
| 143 | { |
| 144 | sprintf( environment -> msg, "\n\t\tEntry:\ |
| 145 | \n\t\t\tEnvironment = %p\ |
| 146 | \n\t\t\tAttribute = %s\ |
| 147 | \n\t\t\tValue = %p\ |
| 148 | \n\t\t\tBuffer Len = %d\ |
| 149 | \n\t\t\tStrLen = %p" , |
| 150 | environment, |
| 151 | __env_attr_as_string( s1, attribute ), |
| 152 | value, |
| 153 | (int)buffer_length, |
| 154 | (void*)string_length ); |
| 155 | |
| 156 | dm_log_write( __FILE__, |
| 157 | __LINE__, |
| 158 | LOG_INFO, |
| 159 | LOG_INFO, |
| 160 | environment -> msg ); |
| 161 | } |
| 162 | |
| 163 | thread_protect( SQL_HANDLE_ENV, environment ); |
| 164 | |
| 165 | switch ( attribute ) |
| 166 | { |
| 167 | case SQL_ATTR_CONNECTION_POOLING: |
| 168 | if ( value ) |
| 169 | { |
| 170 | memcpy( value, &environment -> connection_pooling, |
| 171 | sizeof( environment -> connection_pooling )); |
| 172 | } |
| 173 | break; |
| 174 | |
| 175 | case SQL_ATTR_CP_MATCH: |
| 176 | if ( value ) |
| 177 | { |
| 178 | memcpy( value, &environment -> cp_match, |
| 179 | sizeof( environment -> cp_match )); |
| 180 | } |
| 181 | break; |
| 182 | |
| 183 | case SQL_ATTR_ODBC_VERSION: |
| 184 | if ( !environment -> version_set ) |
| 185 | { |
| 186 | __post_internal_error( &environment -> error, |
| 187 | ERROR_HY010, NULL, |
| 188 | SQL_OV_ODBC3 ); |
| 189 | |
| 190 | return function_return( SQL_HANDLE_ENV, environment, SQL_ERROR ); |
| 191 | } |
| 192 | |
| 193 | if ( value ) |
| 194 | { |
| 195 | memcpy( value, &environment -> requested_version, |
| 196 | sizeof( environment -> requested_version )); |
| 197 | } |
| 198 | break; |
| 199 | |
| 200 | case SQL_ATTR_OUTPUT_NTS: |
| 201 | if ( value ) |
| 202 | { |
| 203 | SQLINTEGER i = SQL_TRUE; |
| 204 | memcpy( value, &i, sizeof( i )); |
| 205 | } |
| 206 | break; |
| 207 | |
| 208 | /* |
| 209 | * unixODBC additions |
| 210 | */ |
| 211 | |
| 212 | case SQL_ATTR_UNIXODBC_VERSION: |
| 213 | if ( value ) |
| 214 | { |
| 215 | if ( buffer_length >= strlen( VERSION )) |
| 216 | { |
| 217 | strcpy( value, VERSION ); |
| 218 | } |
| 219 | else |
| 220 | { |
| 221 | memcpy( value, VERSION, buffer_length ); |
| 222 | ((char*)value)[ buffer_length ] = '\0'; |
| 223 | } |
| 224 | if ( string_length ) |
| 225 | { |
| 226 | *string_length = strlen( VERSION ); |
| 227 | } |
| 228 | } |
| 229 | break; |
| 230 | |
| 231 | case SQL_ATTR_UNIXODBC_SYSPATH: |
| 232 | if ( value ) |
| 233 | { |
| 234 | char b1[ 512 ]; |
| 235 | |
| 236 | if ( buffer_length >= strlen( odbcinst_system_file_path( b1 ))) |
| 237 | { |
| 238 | strcpy( value, odbcinst_system_file_path( b1 )); |
| 239 | } |
| 240 | else |
| 241 | { |
| 242 | memcpy( value, odbcinst_system_file_path( b1 ), buffer_length ); |
| 243 | ((char*)value)[ buffer_length ] = '\0'; |
| 244 | } |
| 245 | if ( string_length ) |
| 246 | { |
| 247 | *string_length = strlen( odbcinst_system_file_path( b1 )); |
| 248 | } |
| 249 | } |
| 250 | break; |
| 251 | |
| 252 | default: |
| 253 | dm_log_write( __FILE__, |
| 254 | __LINE__, |
| 255 | LOG_INFO, |
| 256 | LOG_INFO, |
| 257 | "Error: HY092" ); |
| 258 | |
| 259 | __post_internal_error( &environment -> error, |
| 260 | ERROR_HY092, NULL, |
| 261 | environment -> requested_version ); |
| 262 | |
| 263 | return function_return_nodrv( SQL_HANDLE_ENV, environment, SQL_ERROR ); |
| 264 | } |
| 265 | |
| 266 | if ( log_info.log_flag ) |
| 267 | { |
| 268 | sprintf( environment -> msg, |
| 269 | "\n\t\tExit:[%s]" , |
| 270 | __get_return_status( SQL_SUCCESS, s1 )); |
| 271 | |
| 272 | dm_log_write( __FILE__, |
| 273 | __LINE__, |
| 274 | LOG_INFO, |
| 275 | LOG_INFO, |
| 276 | environment -> msg ); |
| 277 | } |
| 278 | |
| 279 | return function_return( SQL_HANDLE_ENV, environment, SQL_SUCCESS ); |
| 280 | } |
| 281 | |