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: SQLGetFunctions.c,v 1.5 2009/02/18 17:59:08 lurcher Exp $
31 *
32 * $Log: SQLGetFunctions.c,v $
33 * Revision 1.5 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.4 2003/10/30 18:20:46 lurcher
37 *
38 * Fix broken thread protection
39 * Remove SQLNumResultCols after execute, lease S4/S% to driver
40 * Fix string overrun in SQLDriverConnect
41 * Add initial support for Interix
42 *
43 * Revision 1.3 2002/12/05 17:44:31 lurcher
44 *
45 * Display unknown return values in return logging
46 *
47 * Revision 1.2 2001/12/13 13:00:32 lurcher
48 *
49 * Remove most if not all warnings on 64 bit platforms
50 * Add support for new MS 3.52 64 bit changes
51 * Add override to disable the stopping of tracing
52 * Add MAX_ROWS support in postgres driver
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:18 pharvey
100 * Imported sources
101 *
102 * Revision 1.2 1999/04/30 16:22:47 nick
103 * Another checkpoint
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
114static char const rcsid[]= "$RCSfile: SQLGetFunctions.c,v $ $Revision: 1.5 $";
115
116SQLRETURN SQLGetFunctions( SQLHDBC connection_handle,
117 SQLUSMALLINT function_id,
118 SQLUSMALLINT *supported )
119{
120 DMHDBC connection = (DMHDBC)connection_handle;
121 SQLCHAR s1[ 100 + LOG_MESSAGE_LEN ];
122
123 /*
124 * check connection
125 */
126
127 if ( !__validate_dbc( connection ))
128 {
129 dm_log_write( __FILE__,
130 __LINE__,
131 LOG_INFO,
132 LOG_INFO,
133 "Error: SQL_INVALID_HANDLE" );
134
135 return SQL_INVALID_HANDLE;
136 }
137
138 function_entry( connection );
139
140 if ( log_info.log_flag )
141 {
142 sprintf( connection -> msg, "\n\t\tEntry:\
143\n\t\t\tConnection = %p\
144\n\t\t\tId = %s\
145\n\t\t\tSupported = %p",
146 connection,
147 __fid_as_string( s1, function_id ),
148 supported );
149
150 dm_log_write( __FILE__,
151 __LINE__,
152 LOG_INFO,
153 LOG_INFO,
154 connection -> msg );
155 }
156
157 thread_protect( SQL_HANDLE_DBC, connection );
158
159 if ( function_id == SQL_API_SQLGETFUNCTIONS ||
160 function_id == SQL_API_SQLDATASOURCES ||
161 function_id == SQL_API_SQLDRIVERS ||
162 function_id == SQL_API_SQLGETENVATTR ||
163 function_id == SQL_API_SQLSETENVATTR )
164 {
165 *supported = SQL_TRUE;
166 return function_return_nodrv( SQL_HANDLE_DBC, connection, SQL_SUCCESS );
167 }
168
169 if ( connection -> state == STATE_C3 ||
170 connection -> state == STATE_C2 )
171 {
172 dm_log_write( __FILE__,
173 __LINE__,
174 LOG_INFO,
175 LOG_INFO,
176 "Error: HY010" );
177
178 __post_internal_error( &connection -> error,
179 ERROR_HY010, NULL,
180 connection -> environment -> requested_version );
181
182 return function_return_nodrv( SQL_HANDLE_DBC, connection, SQL_ERROR );
183 }
184
185 if ( function_id > SQL_API_SQLBULKOPERATIONS && function_id < SQL_API_SQLCOLUMNS ||
186 function_id > SQL_API_SQLALLOCHANDLESTD && function_id < SQL_API_LOADBYORDINAL ||
187 function_id > SQL_API_LOADBYORDINAL && function_id < SQL_API_ODBC3_ALL_FUNCTIONS ||
188 function_id > SQL_API_ODBC3_ALL_FUNCTIONS && function_id < SQL_API_SQLALLOCHANDLE ||
189 function_id > SQL_API_SQLFETCHSCROLL )
190 {
191 __post_internal_error( &connection -> error,
192 ERROR_HY095, NULL,
193 connection -> environment -> requested_version );
194
195 return function_return_nodrv( SQL_HANDLE_DBC, connection, SQL_ERROR );
196 }
197
198 __check_for_function( connection, function_id, supported );
199
200 if ( log_info.log_flag )
201 {
202 sprintf( connection -> msg,
203 "\n\t\tExit:[%s]\
204\n\t\t\tSupported = %s",
205 __get_return_status( SQL_SUCCESS, s1 ),
206 __sptr_as_string( s1, (short*)supported ));
207
208 dm_log_write( __FILE__,
209 __LINE__,
210 LOG_INFO,
211 LOG_INFO,
212 connection -> msg );
213 }
214
215 return function_return_nodrv( SQL_HANDLE_DBC, connection, SQL_SUCCESS );
216}
217