LCOV - code coverage report
Current view: top level - clients/odbc/driver - SQLSetConnectOption.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 28 0.0 %
Date: 2021-10-13 02:24:04 Functions: 0 1 0.0 %

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

Generated by: LCOV version 1.14