Line data Source code
1 : /*
2 : * SPDX-License-Identifier: MPL-2.0
3 : *
4 : * This Source Code Form is subject to the terms of the Mozilla Public
5 : * License, v. 2.0. If a copy of the MPL was not distributed with this
6 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 : *
8 : * Copyright 2024 MonetDB Foundation;
9 : * Copyright August 2008 - 2023 MonetDB B.V.;
10 : * Copyright 1997 - July 2008 CWI.
11 : */
12 :
13 : /*
14 : * This code was created by Peter Harvey (mostly during Christmas 98/99).
15 : * This code is LGPL. Please ensure that this message remains in future
16 : * distributions and uses of this code (thats about all I get out of it).
17 : * - Peter Harvey pharvey@codebydesign.com
18 : *
19 : * This file has been modified for the MonetDB project. See the file
20 : * Copyright in this directory for more information.
21 : */
22 :
23 : /**********************************************************************
24 : * SQLSetConnectOption()
25 : * CLI Compliance: deprecated in ODBC 3.0 (replaced by SQLSetConnectAttr())
26 : * Provided here for old (pre ODBC 3.0) applications and driver managers.
27 : *
28 : * Author: Martin van Dinther, Sjoerd Mullender
29 : * Date : 30 aug 2002
30 : *
31 : **********************************************************************/
32 :
33 : #include "ODBCGlobal.h"
34 : #include "ODBCDbc.h"
35 : #include "ODBCUtil.h"
36 :
37 : #ifdef _MSC_VER
38 : /* can't call them by their real name with Visual Studio 12.0 since we
39 : * would then get a warning which we translate to an error during
40 : * compilation (also see ODBC.syms) */
41 : #define SQLSetConnectOption SQLSetConnectOption_deprecated
42 : #define SQLSetConnectOptionA SQLSetConnectOptionA_deprecated
43 : #define SQLSetConnectOptionW SQLSetConnectOptionW_deprecated
44 : #endif
45 :
46 : static SQLRETURN
47 0 : MNDBSetConnectOption(ODBCDbc *dbc,
48 : SQLUSMALLINT Option,
49 : SQLULEN ValuePtr)
50 : {
51 : /* use mapping as described in ODBC 3 SDK Help file */
52 0 : switch (Option) {
53 : /* connection attributes (ODBC 1 and 2 only) */
54 0 : case SQL_ACCESS_MODE:
55 : case SQL_AUTOCOMMIT:
56 : case SQL_LOGIN_TIMEOUT:
57 : case SQL_ODBC_CURSORS:
58 : case SQL_OPT_TRACE:
59 : case SQL_PACKET_SIZE:
60 : case SQL_TRANSLATE_OPTION:
61 : case SQL_TXN_ISOLATION:
62 : /* 32 bit integer argument */
63 0 : return MNDBSetConnectAttr(dbc, Option,
64 : (SQLPOINTER) (uintptr_t) ValuePtr, 0);
65 0 : case SQL_QUIET_MODE:
66 : /* 32/64 bit integer argument */
67 0 : return MNDBSetConnectAttr(dbc, Option,
68 : (SQLPOINTER) (uintptr_t) ValuePtr, 0);
69 :
70 0 : case SQL_CURRENT_QUALIFIER:
71 : case SQL_OPT_TRACEFILE:
72 : case SQL_TRANSLATE_DLL:
73 : /* null terminated string argument */
74 0 : return MNDBSetConnectAttr(dbc, Option,
75 : (SQLPOINTER) (uintptr_t) ValuePtr,
76 : SQL_NTS);
77 :
78 0 : default:
79 : /* other options (e.g. ODBC 3) are NOT valid */
80 : /* Invalid attribute/option identifier */
81 0 : addDbcError(dbc, "HY092", NULL, 0);
82 0 : break;
83 : }
84 :
85 0 : return SQL_ERROR;
86 : }
87 :
88 : SQLRETURN SQL_API
89 : SQLSetConnectOption(SQLHDBC ConnectionHandle,
90 : SQLUSMALLINT Option,
91 : SQLULEN ValuePtr)
92 : {
93 0 : ODBCDbc *dbc = (ODBCDbc *) ConnectionHandle;
94 :
95 : #ifdef ODBCDEBUG
96 0 : ODBCLOG("SQLSetConnectOption %p %s " ULENFMT "\n",
97 : ConnectionHandle, translateConnectOption(Option),
98 : ULENCAST ValuePtr);
99 : #endif
100 :
101 0 : if (!isValidDbc(dbc))
102 : return SQL_INVALID_HANDLE;
103 :
104 0 : clearDbcErrors(dbc);
105 :
106 0 : return MNDBSetConnectOption(dbc, Option, ValuePtr);
107 : }
108 :
109 : SQLRETURN SQL_API
110 : SQLSetConnectOptionA(SQLHDBC ConnectionHandle,
111 : SQLUSMALLINT Option,
112 : SQLULEN ValuePtr)
113 : {
114 0 : return SQLSetConnectOption(ConnectionHandle, Option, ValuePtr);
115 : }
116 :
117 : SQLRETURN SQL_API
118 : SQLSetConnectOptionW(SQLHDBC ConnectionHandle,
119 : SQLUSMALLINT Option,
120 : SQLULEN ValuePtr)
121 : {
122 0 : ODBCDbc *dbc = (ODBCDbc *) ConnectionHandle;
123 0 : SQLPOINTER ptr = (SQLPOINTER) (uintptr_t) ValuePtr;
124 0 : SQLULEN p;
125 0 : SQLRETURN rc;
126 :
127 : #ifdef ODBCDEBUG
128 0 : ODBCLOG("SQLSetConnectOptionW %p %s " ULENFMT "\n",
129 : ConnectionHandle, translateConnectOption(Option),
130 : ULENCAST ValuePtr);
131 : #endif
132 :
133 0 : if (!isValidDbc(dbc))
134 : return SQL_INVALID_HANDLE;
135 :
136 0 : clearDbcErrors(dbc);
137 :
138 0 : switch (Option) {
139 0 : case SQL_ATTR_CURRENT_CATALOG:
140 : case SQL_ATTR_TRACEFILE:
141 : case SQL_ATTR_TRANSLATE_LIB:
142 0 : fixWcharIn((SQLPOINTER) (uintptr_t) ValuePtr, SQL_NTS, SQLCHAR,
143 : ptr, addDbcError, dbc, return SQL_ERROR);
144 0 : p = (SQLULEN) (uintptr_t) ptr;
145 0 : break;
146 : default:
147 : p = ValuePtr;
148 : break;
149 : }
150 :
151 0 : rc = MNDBSetConnectOption(dbc, Option, p);
152 :
153 0 : if (ptr &&p != ValuePtr)
154 0 : free(ptr);
155 :
156 : return rc;
157 : }
|