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: SQLFreeStmt.c,v 1.6 2009/02/18 17:59:08 lurcher Exp $ |
31 | * |
32 | * $Log: SQLFreeStmt.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 2003/10/30 18:20:45 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.4 2002/12/05 17:44:30 lurcher |
44 | * |
45 | * Display unknown return values in return logging |
46 | * |
47 | * Revision 1.3 2002/07/04 17:27:56 lurcher |
48 | * |
49 | * Small bug fixes |
50 | * |
51 | * Revision 1.1.1.1 2001/10/17 16:40:05 lurcher |
52 | * |
53 | * First upload to SourceForge |
54 | * |
55 | * Revision 1.2 2001/04/12 17:43:36 nick |
56 | * |
57 | * Change logging and added autotest to odbctest |
58 | * |
59 | * Revision 1.1.1.1 2000/09/04 16:42:52 nick |
60 | * Imported Sources |
61 | * |
62 | * Revision 1.7 1999/11/13 23:40:59 ngorham |
63 | * |
64 | * Alter the way DM logging works |
65 | * Upgrade the Postgres driver to 6.4.6 |
66 | * |
67 | * Revision 1.6 1999/10/24 23:54:18 ngorham |
68 | * |
69 | * First part of the changes to the error reporting |
70 | * |
71 | * Revision 1.5 1999/09/21 22:34:24 ngorham |
72 | * |
73 | * Improve performance by removing unneeded logging calls when logging is |
74 | * disabled |
75 | * |
76 | * Revision 1.4 1999/07/10 21:10:16 ngorham |
77 | * |
78 | * Adjust error sqlstate from driver manager, depending on requested |
79 | * version (ODBC2/3) |
80 | * |
81 | * Revision 1.3 1999/07/04 21:05:07 ngorham |
82 | * |
83 | * Add LGPL Headers to code |
84 | * |
85 | * Revision 1.2 1999/06/30 23:56:55 ngorham |
86 | * |
87 | * Add initial thread safety code |
88 | * |
89 | * Revision 1.1.1.1 1999/05/29 13:41:07 sShandyb |
90 | * first go at it |
91 | * |
92 | * Revision 1.1.1.1 1999/05/27 18:23:17 pharvey |
93 | * Imported sources |
94 | * |
95 | * Revision 1.3 1999/04/30 16:22:47 nick |
96 | * Another checkpoint |
97 | * |
98 | * Revision 1.2 1999/04/29 20:47:37 nick |
99 | * Another checkpoint |
100 | * |
101 | * Revision 1.1 1999/04/25 23:06:11 nick |
102 | * Initial revision |
103 | * |
104 | * |
105 | **********************************************************************/ |
106 | |
107 | #include <config.h> |
108 | #include "drivermanager.h" |
109 | |
110 | static char const rcsid[]= "$RCSfile: SQLFreeStmt.c,v $ $Revision: 1.6 $" ; |
111 | |
112 | SQLRETURN SQLFreeStmt( SQLHSTMT statement_handle, |
113 | SQLUSMALLINT option ) |
114 | { |
115 | DMHSTMT statement = (DMHSTMT) statement_handle; |
116 | SQLRETURN ret; |
117 | SQLCHAR s1[ 100 + LOG_MESSAGE_LEN ]; |
118 | |
119 | /* |
120 | * check statement |
121 | */ |
122 | if ( !__validate_stmt( statement )) |
123 | { |
124 | dm_log_write( __FILE__, |
125 | __LINE__, |
126 | LOG_INFO, |
127 | LOG_INFO, |
128 | "Error: SQL_INVALID_HANDLE" ); |
129 | |
130 | return SQL_INVALID_HANDLE; |
131 | } |
132 | |
133 | function_entry( statement ); |
134 | |
135 | if ( log_info.log_flag ) |
136 | { |
137 | sprintf( statement -> msg, "\n\t\tEntry:\ |
138 | \n\t\t\tStatement = %p\ |
139 | \n\t\t\tOption = %d" , |
140 | statement, |
141 | option ); |
142 | |
143 | dm_log_write( __FILE__, |
144 | __LINE__, |
145 | LOG_INFO, |
146 | LOG_INFO, |
147 | statement -> msg ); |
148 | } |
149 | |
150 | thread_protect( SQL_HANDLE_STMT, statement ); |
151 | |
152 | switch ( option ) |
153 | { |
154 | case SQL_CLOSE: |
155 | case SQL_DROP: |
156 | case SQL_RESET_PARAMS: |
157 | case SQL_UNBIND: |
158 | break; |
159 | |
160 | default: |
161 | dm_log_write( __FILE__, |
162 | __LINE__, |
163 | LOG_INFO, |
164 | LOG_INFO, |
165 | "Error: HY092" ); |
166 | |
167 | __post_internal_error( &statement -> error, |
168 | ERROR_HY092, NULL, |
169 | statement -> connection -> environment -> requested_version ); |
170 | |
171 | return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR ); |
172 | } |
173 | |
174 | if ( statement -> state == STATE_S8 || |
175 | statement -> state == STATE_S9 || |
176 | statement -> state == STATE_S10 || |
177 | statement -> state == STATE_S11 || |
178 | statement -> state == STATE_S12 || |
179 | statement -> state == STATE_S13 || |
180 | statement -> state == STATE_S14 || |
181 | statement -> state == STATE_S15 ) |
182 | { |
183 | dm_log_write( __FILE__, |
184 | __LINE__, |
185 | LOG_INFO, |
186 | LOG_INFO, |
187 | "Error: HY010" ); |
188 | |
189 | __post_internal_error( &statement -> error, |
190 | ERROR_HY010, NULL, |
191 | statement -> connection -> environment -> requested_version ); |
192 | |
193 | return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR ); |
194 | } |
195 | |
196 | if ( !CHECK_SQLFREESTMT( statement -> connection )) |
197 | { |
198 | dm_log_write( __FILE__, |
199 | __LINE__, |
200 | LOG_INFO, |
201 | LOG_INFO, |
202 | "Error: IM001" ); |
203 | |
204 | __post_internal_error( &statement -> error, |
205 | ERROR_IM001, NULL, |
206 | statement -> connection -> environment -> requested_version ); |
207 | |
208 | return function_return_nodrv( SQL_HANDLE_STMT, statement, SQL_ERROR ); |
209 | } |
210 | |
211 | /* |
212 | * option has already been checked and found valid |
213 | */ |
214 | |
215 | switch ( option ) |
216 | { |
217 | case SQL_CLOSE: |
218 | ret = SQLFREESTMT( statement -> connection, |
219 | statement -> driver_stmt, |
220 | option ); |
221 | if ( SQL_SUCCEEDED( ret )) |
222 | { |
223 | if ( statement -> state == STATE_S4 ) |
224 | { |
225 | if ( statement -> prepared ) |
226 | statement -> state = STATE_S2; |
227 | else |
228 | statement -> state = STATE_S1; |
229 | } |
230 | else if ( statement -> state >= STATE_S5 && statement -> state <= STATE_S7 ) |
231 | { |
232 | if ( statement -> prepared ) |
233 | statement -> state = STATE_S3; |
234 | else |
235 | statement -> state = STATE_S1; |
236 | } |
237 | statement -> hascols = 0; |
238 | } |
239 | break; |
240 | |
241 | case SQL_DROP: |
242 | /* |
243 | * call SQLFreeHandle(); |
244 | */ |
245 | thread_release( SQL_HANDLE_STMT, statement ); |
246 | return function_return( IGNORE_THREAD, statement, __SQLFreeHandle( SQL_HANDLE_STMT, statement_handle )); |
247 | |
248 | case SQL_RESET_PARAMS: |
249 | case SQL_UNBIND: |
250 | ret = SQLFREESTMT( statement -> connection, |
251 | statement -> driver_stmt, |
252 | option ); |
253 | /* |
254 | * TO_DO reset any information about parameters or bound columns |
255 | */ |
256 | break; |
257 | } |
258 | |
259 | if ( log_info.log_flag ) |
260 | { |
261 | sprintf( statement -> msg, |
262 | "\n\t\tExit:[%s]" , |
263 | __get_return_status( ret, s1 )); |
264 | |
265 | dm_log_write( __FILE__, |
266 | __LINE__, |
267 | LOG_INFO, |
268 | LOG_INFO, |
269 | statement -> msg ); |
270 | } |
271 | |
272 | return function_return( SQL_HANDLE_STMT, statement, ret ); |
273 | } |
274 | |