4 * Description: This module contains routines for getting/setting
5 * connection and statement options.
9 * API functions: SQLSetConnectOption, SQLSetStmtOption, SQLGetConnectOption,
12 * Comments: See "notice.txt" for copyright and license information.
33 #include "connection.h"
34 #include "statement.h"
37 extern GLOBAL_VALUES globals;
40 /* Implements only SQL_AUTOCOMMIT */
41 RETCODE SQL_API SQLSetConnectOption(
46 char *func="SQLSetConnectOption";
47 ConnectionClass *conn = (ConnectionClass *) hdbc;
50 CC_log_error(func, "", NULL);
51 return SQL_INVALID_HANDLE;
58 /* Since we are almost always in a transaction, this is now ok.
59 Even if we were, the logic will handle it by sending a commit
62 if (CC_is_in_trans(conn)) {
63 conn->errormsg = "Cannot switch commit mode while a transaction is in progres";
64 conn->errornumber = CONN_TRANSACT_IN_PROGRES;
65 CC_log_error(func, "", conn);
70 mylog("SQLSetConnectOption: AUTOCOMMIT: transact_status=%d, vparam=%d\n", conn->transact_status, vParam);
73 case SQL_AUTOCOMMIT_OFF:
74 CC_set_autocommit_off(conn);
77 case SQL_AUTOCOMMIT_ON:
78 CC_set_autocommit_on(conn);
82 conn->errormsg = "Illegal parameter value for SQL_AUTOCOMMIT";
83 conn->errornumber = CONN_INVALID_ARGUMENT_NO;
84 CC_log_error(func, "", conn);
90 case SQL_LOGIN_TIMEOUT:
96 case SQL_TXN_ISOLATION:
102 conn->errormsg = "Driver does not support setting this connect option";
103 conn->errornumber = CONN_UNSUPPORTED_OPTION;
104 sprintf(option, "fOption=%d, vParam=%d", fOption, vParam);
105 CC_log_error(func, option, conn);
115 /* This function just can tell you whether you are in Autcommit mode or not */
116 RETCODE SQL_API SQLGetConnectOption(
121 char *func="SQLGetConnectOption";
122 ConnectionClass *conn = (ConnectionClass *) hdbc;
125 CC_log_error(func, "", NULL);
126 return SQL_INVALID_HANDLE;
131 *((UDWORD *)pvParam) = (UDWORD)( CC_is_in_autocommit(conn) ?
132 SQL_AUTOCOMMIT_ON : SQL_AUTOCOMMIT_OFF);
135 /* don't use qualifiers */
136 case SQL_CURRENT_QUALIFIER:
145 conn->errormsg = "Driver does not support getting this connect option";
146 conn->errornumber = CONN_UNSUPPORTED_OPTION;
147 sprintf(option, "fOption=%d", fOption);
148 CC_log_error(func, option, conn);
160 RETCODE SQL_API SQLSetStmtOption(
165 char *func="SQLSetStmtOption";
166 StatementClass *stmt = (StatementClass *) hstmt;
167 char changed = FALSE;
169 // thought we could fake Access out by just returning SQL_SUCCESS
170 // all the time, but it tries to set a huge value for SQL_MAX_LENGTH
171 // and expects the driver to reduce it to the real value
174 SC_log_error(func, "", NULL);
175 return SQL_INVALID_HANDLE;
179 case SQL_QUERY_TIMEOUT:
180 mylog("SetStmtOption: vParam = %d\n", vParam);
181 // "0" returned in SQLGetStmtOption
185 // "4096" returned in SQLGetStmtOption
189 mylog("SetStmtOption(): SQL_MAX_ROWS = %d, returning success\n", vParam);
190 stmt->maxRows = vParam;
194 case SQL_ROWSET_SIZE:
195 mylog("SetStmtOption(): SQL_ROWSET_SIZE = %d\n", vParam);
197 stmt->rowset_size = 1; // only support 1 row at a time
203 case SQL_KEYSET_SIZE:
204 mylog("SetStmtOption(): SQL_KEYSET_SIZE = %d\n", vParam);
206 stmt->keyset_size = vParam;
208 stmt->errornumber = STMT_NOT_IMPLEMENTED_ERROR;
209 stmt->errormsg = "Driver does not support keyset size option";
210 SC_log_error(func, "", stmt);
215 case SQL_CONCURRENCY:
216 // positioned update isn't supported so cursor concurrency is read-only
217 mylog("SetStmtOption(): SQL_CONCURRENCY = %d\n", vParam);
220 stmt->scroll_concurrency = vParam;
222 stmt->scroll_concurrency = SQL_CONCUR_READ_ONLY;
223 if (vParam != SQL_CONCUR_READ_ONLY)
228 case SQL_CURSOR_TYPE:
229 // if declare/fetch, then type can only be forward.
230 // otherwise, it can only be forward or static.
231 mylog("SetStmtOption(): SQL_CURSOR_TYPE = %d\n", vParam);
234 stmt->cursor_type = vParam;
236 if (globals.use_declarefetch) {
237 stmt->cursor_type = SQL_CURSOR_FORWARD_ONLY;
238 if (vParam != SQL_CURSOR_FORWARD_ONLY)
242 if (vParam == SQL_CURSOR_FORWARD_ONLY || vParam == SQL_CURSOR_STATIC)
243 stmt->cursor_type = vParam; // valid type
245 stmt->cursor_type = SQL_CURSOR_STATIC;
252 case SQL_SIMULATE_CURSOR:
253 stmt->errornumber = STMT_NOT_IMPLEMENTED_ERROR;
254 stmt->errormsg = "Simulated positioned update/delete not supported. Use the cursor library.";
255 SC_log_error(func, "", stmt);
261 stmt->errornumber = STMT_NOT_IMPLEMENTED_ERROR;
262 stmt->errormsg = "Driver does not support setting this statement option";
263 sprintf(option, "fOption=%d, vParam=%d", fOption, vParam);
264 SC_log_error(func, option, stmt);
270 stmt->errormsg = "Requested value changed.";
271 stmt->errornumber = STMT_OPTION_VALUE_CHANGED;
272 return SQL_SUCCESS_WITH_INFO;
281 RETCODE SQL_API SQLGetStmtOption(
286 char *func="SQLGetStmtOption";
287 StatementClass *stmt = (StatementClass *) hstmt;
289 // thought we could fake Access out by just returning SQL_SUCCESS
290 // all the time, but it tries to set a huge value for SQL_MAX_LENGTH
291 // and expects the driver to reduce it to the real value
294 SC_log_error(func, "", NULL);
295 return SQL_INVALID_HANDLE;
299 case SQL_QUERY_TIMEOUT:
300 // how long we wait on a query before returning to the
301 // application (0 == forever)
302 *((SDWORD *)pvParam) = 0;
306 // what is the maximum length that will be returned in
308 *((SDWORD *)pvParam) = 4096;
312 *((SDWORD *)pvParam) = stmt->maxRows;
313 mylog("GetSmtOption: MAX_ROWS, returning %d\n", stmt->maxRows);
316 case SQL_ROWSET_SIZE:
317 mylog("GetStmtOption(): SQL_ROWSET_SIZE\n");
318 *((SDWORD *)pvParam) = stmt->rowset_size;
321 case SQL_KEYSET_SIZE:
322 mylog("GetStmtOption(): SQL_KEYSET_SIZE\n");
323 *((SDWORD *)pvParam) = stmt->keyset_size;
326 case SQL_CONCURRENCY:
327 mylog("GetStmtOption(): SQL_CONCURRENCY\n");
328 *((SDWORD *)pvParam) = stmt->scroll_concurrency;
331 case SQL_CURSOR_TYPE:
332 mylog("GetStmtOption(): SQL_CURSOR_TYPE\n");
333 *((SDWORD *)pvParam) = stmt->cursor_type;
336 case SQL_SIMULATE_CURSOR:
337 stmt->errornumber = STMT_NOT_IMPLEMENTED_ERROR;
338 stmt->errormsg = "Simulated positioned update/delete not supported. Use the cursor library.";
339 SC_log_error(func, "", stmt);
345 stmt->errornumber = STMT_NOT_IMPLEMENTED_ERROR;
346 stmt->errormsg = "Driver does not support getting this statement option";
347 sprintf(option, "fOption=%d", fOption);
348 SC_log_error(func, option, stmt);