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: SQLNumResultCols.c,v 1.5 2009/02/18 17:59:08 lurcher Exp $ |
31 | * |
32 | * $Log: SQLNumResultCols.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 2007/01/02 10:27:50 lurcher |
37 | * Fix descriptor leak with unicode only driver |
38 | * |
39 | * Revision 1.3 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.2 2002/12/05 17:44:31 lurcher |
47 | * |
48 | * Display unknown return values in return logging |
49 | * |
50 | * Revision 1.1.1.1 2001/10/17 16:40:06 lurcher |
51 | * |
52 | * First upload to SourceForge |
53 | * |
54 | * Revision 1.3 2001/07/03 09:30:41 nick |
55 | * |
56 | * Add ability to alter size of displayed message in the log |
57 | * |
58 | * Revision 1.2 2001/04/12 17:43:36 nick |
59 | * |
60 | * Change logging and added autotest to odbctest |
61 | * |
62 | * Revision 1.1.1.1 2000/09/04 16:42:52 nick |
63 | * Imported Sources |
64 | * |
65 | * Revision 1.8 1999/11/13 23:41:00 ngorham |
66 | * |
67 | * Alter the way DM logging works |
68 | * Upgrade the Postgres driver to 6.4.6 |
69 | * |
70 | * Revision 1.7 1999/10/24 23:54:18 ngorham |
71 | * |
72 | * First part of the changes to the error reporting |
73 | * |
74 | * Revision 1.6 1999/10/14 06:49:24 ngorham |
75 | * |
76 | * Remove @all_includes@ from Drivers/MiniSQL/Makefile.am |
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:08 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:08 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.4 1999/05/03 19:50:43 nick |
103 | * Another check point |
104 | * |
105 | * Revision 1.3 1999/04/30 16:22:47 nick |
106 | * Another checkpoint |
107 | * |
108 | * Revision 1.2 1999/04/29 20:47:37 nick |
109 | * Another checkpoint |
110 | * |
111 | * Revision 1.1 1999/04/25 23:06:11 nick |
112 | * Initial revision |
113 | * |
114 | * |
115 | **********************************************************************/ |
116 | |
117 | #include <config.h> |
118 | #include "drivermanager.h" |
119 | |
120 | static char const rcsid[]= "$RCSfile: SQLNumResultCols.c,v $ $Revision: 1.5 $" ; |
121 | |
122 | SQLRETURN SQLNumResultCols( SQLHSTMT statement_handle, |
123 | SQLSMALLINT *column_count ) |
124 | { |
125 | DMHSTMT statement = (DMHSTMT) statement_handle; |
126 | SQLRETURN ret; |
127 | SQLCHAR s1[ 100 + LOG_MESSAGE_LEN ]; |
128 | SQLCHAR s2[ 100 + LOG_MESSAGE_LEN ]; |
129 | |
130 | /* |
131 | * check statement |
132 | */ |
133 | |
134 | if ( !__validate_stmt( statement )) |
135 | { |
136 | dm_log_write( __FILE__, |
137 | __LINE__, |
138 | LOG_INFO, |
139 | LOG_INFO, |
140 | "Error: SQL_INVALID_HANDLE" ); |
141 | |
142 | return SQL_INVALID_HANDLE; |
143 | } |
144 | |
145 | function_entry( statement ); |
146 | |
147 | if ( log_info.log_flag ) |
148 | { |
149 | sprintf( statement -> msg, "\n\t\tEntry:\ |
150 | \n\t\t\tStatement = %p\ |
151 | \n\t\t\tColumn Count = %p" , |
152 | statement, |
153 | column_count ); |
154 | |
155 | dm_log_write( __FILE__, |
156 | __LINE__, |
157 | LOG_INFO, |
158 | LOG_INFO, |
159 | statement -> msg ); |
160 | } |
161 | |
162 | thread_protect( SQL_HANDLE_STMT, statement ); |
163 | |
164 | /* |
165 | * check states |
166 | */ |
167 | |
168 | if ( statement -> state == STATE_S1 || |
169 | statement -> state == STATE_S8 || |
170 | statement -> state == STATE_S9 || |
171 | statement -> state == STATE_S10 || |
172 | statement -> state == STATE_S13 || |
173 | statement -> state == STATE_S14 || |
174 | statement -> state == STATE_S15 ) |
175 | { |
176 | dm_log_write( __FILE__, |
177 | __LINE__, |
178 | LOG_INFO, |
179 | LOG_INFO, |
180 | "Error: HY010" ); |
181 | |
182 | __post_internal_error( &statement -> error, |
183 | ERROR_HY010, NULL, |
184 | statement -> connection -> environment -> requested_version ); |
185 | |
186 | return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR ); |
187 | } |
188 | |
189 | if ( statement -> state == STATE_S11 || |
190 | statement -> state == STATE_S12 ) |
191 | { |
192 | if ( statement -> interupted_func != SQL_API_SQLNUMRESULTCOLS ) |
193 | { |
194 | dm_log_write( __FILE__, |
195 | __LINE__, |
196 | LOG_INFO, |
197 | LOG_INFO, |
198 | "Error: HY010" ); |
199 | |
200 | __post_internal_error( &statement -> error, |
201 | ERROR_HY010, NULL, |
202 | statement -> connection -> environment -> requested_version ); |
203 | |
204 | return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR ); |
205 | } |
206 | } |
207 | |
208 | if ( !CHECK_SQLNUMRESULTCOLS( statement -> connection )) |
209 | { |
210 | dm_log_write( __FILE__, |
211 | __LINE__, |
212 | LOG_INFO, |
213 | LOG_INFO, |
214 | "Error: IM001" ); |
215 | |
216 | __post_internal_error( &statement -> error, |
217 | ERROR_IM001, NULL, |
218 | statement -> connection -> environment -> requested_version ); |
219 | |
220 | return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR ); |
221 | } |
222 | |
223 | ret = SQLNUMRESULTCOLS( statement -> connection, |
224 | statement -> driver_stmt, |
225 | column_count ); |
226 | |
227 | if ( ret == SQL_STILL_EXECUTING ) |
228 | { |
229 | statement -> interupted_func = SQL_API_SQLNUMRESULTCOLS; |
230 | if ( statement -> state != STATE_S11 && |
231 | statement -> state != STATE_S12 ) |
232 | statement -> state = STATE_S11; |
233 | } |
234 | |
235 | if ( log_info.log_flag ) |
236 | { |
237 | if ( SQL_SUCCEEDED( ret )) { |
238 | sprintf( statement -> msg, |
239 | "\n\t\tExit:[%s]\ |
240 | \n\t\t\tCount = %s" , |
241 | __get_return_status( ret, s2 ), |
242 | __sptr_as_string( s1, column_count )); |
243 | } |
244 | else { |
245 | sprintf( statement -> msg, |
246 | "\n\t\tExit:[%s]" , |
247 | __get_return_status( ret, s2 )); |
248 | } |
249 | |
250 | dm_log_write( __FILE__, |
251 | __LINE__, |
252 | LOG_INFO, |
253 | LOG_INFO, |
254 | statement -> msg ); |
255 | } |
256 | |
257 | return function_return( SQL_HANDLE_STMT, statement, ret ); |
258 | } |
259 | |