LCOV - code coverage report
Current view: top level - clients/odbc/driver - SQLSetConnectAttr.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 27 60 45.0 %
Date: 2024-04-26 00:35:57 Functions: 1 1 100.0 %

          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             :  * SQLSetConnectAttr()
      25             :  * CLI Compliance: ISO 92
      26             :  *
      27             :  * Author: Martin van Dinther, Sjoerd Mullender
      28             :  * Date  : 30 Aug 2002
      29             :  *
      30             :  **********************************************************************/
      31             : 
      32             : #include "ODBCGlobal.h"
      33             : #include "ODBCDbc.h"
      34             : #include "ODBCUtil.h"
      35             : 
      36             : 
      37             : SQLRETURN
      38           4 : MNDBSetConnectAttr(ODBCDbc *dbc,
      39             :                    SQLINTEGER Attribute,
      40             :                    SQLPOINTER ValuePtr,
      41             :                    SQLINTEGER StringLength)
      42             : {
      43           4 :         (void) StringLength;    /* Stefan: unused!? */
      44             : 
      45           4 :         switch (Attribute) {
      46           3 :         case SQL_ATTR_AUTOCOMMIT:               /* SQLUINTEGER */
      47           3 :                 switch ((SQLUINTEGER) (uintptr_t) ValuePtr) {
      48           3 :                 case SQL_AUTOCOMMIT_ON:
      49             :                 case SQL_AUTOCOMMIT_OFF:
      50           3 :                         dbc->sql_attr_autocommit = (SQLUINTEGER) (uintptr_t) ValuePtr;
      51             : #ifdef ODBCDEBUG
      52           3 :                         ODBCLOG("SQLSetConnectAttr set autocommit %s\n",
      53             :                                 dbc->sql_attr_autocommit == SQL_AUTOCOMMIT_ON ? "on" : "off");
      54             : #endif
      55           3 :                         if (dbc->mid)
      56           3 :                                 mapi_setAutocommit(dbc->mid, dbc->sql_attr_autocommit == SQL_AUTOCOMMIT_ON);
      57             :                         break;
      58           0 :                 default:
      59             :                         /* Invalid attribute value */
      60           0 :                         addDbcError(dbc, "HY024", NULL, 0);
      61           0 :                         return SQL_ERROR;
      62             :                 }
      63             :                 return SQL_SUCCESS;
      64           0 :         case SQL_ATTR_CURRENT_CATALOG:          /* SQLCHAR* */
      65             :                 /* Driver does not support this function */
      66           0 :                 addDbcError(dbc, "IM001", NULL, 0);
      67           0 :                 return SQL_ERROR;
      68           0 :         case SQL_ATTR_CONNECTION_TIMEOUT:       /* SQLUINTEGER */
      69           0 :                 dbc->sql_attr_connection_timeout = (SQLUINTEGER) (uintptr_t) ValuePtr;
      70           0 :                 if (dbc->mid)
      71           0 :                         mapi_timeout(dbc->mid, dbc->sql_attr_connection_timeout * 1000);
      72             :                 break;
      73           0 :         case SQL_ATTR_LOGIN_TIMEOUT:            /* SQLUINTEGER */
      74             :                 /* currently only value 0 (no timeout) is accepted
      75             :                  * as mapilib currently does not provide a way to set login timeout */
      76           0 :                 if ((SQLUINTEGER) (uintptr_t) ValuePtr > 0) {
      77             :                         /* add Warning: Option value changed */
      78           0 :                         addDbcError(dbc, "01S02", NULL, 0);
      79           0 :                         return SQL_SUCCESS_WITH_INFO;
      80             :                 }
      81             :                 break;
      82           0 :         case SQL_ATTR_METADATA_ID:              /* SQLUINTEGER */
      83           0 :                 switch ((SQLUINTEGER) (uintptr_t) ValuePtr) {
      84           0 :                 case SQL_TRUE:
      85             :                 case SQL_FALSE:
      86           0 :                         dbc->sql_attr_metadata_id = (SQLUINTEGER) (uintptr_t) ValuePtr;
      87             : #ifdef ODBCDEBUG
      88           0 :                         ODBCLOG("SQLSetConnectAttr set metadata_id %s\n",
      89             :                                 dbc->sql_attr_metadata_id == SQL_TRUE ? "true" : "false");
      90             : #endif
      91             :                         break;
      92           0 :                 default:
      93             :                         /* Invalid attribute value */
      94           0 :                         addDbcError(dbc, "HY024", NULL, 0);
      95           0 :                         return SQL_ERROR;
      96             :                 }
      97             :                 return SQL_SUCCESS;
      98             :         case SQL_ATTR_TXN_ISOLATION:            /* SQLUINTEGER */
      99             :                 /* nothing to change, we only do the highest level */
     100             :                 break;
     101             : 
     102             :                 /* TODO: implement connection attribute behavior */
     103           0 :         case SQL_ATTR_ACCESS_MODE:              /* SQLUINTEGER */
     104             : #ifdef SQL_ATTR_ASYNC_DBC_EVENT
     105             :         case SQL_ATTR_ASYNC_DBC_EVENT:          /* SQLPOINTER */
     106             : #endif
     107             : #ifdef SQL_ATTR_ASYNC_DBC_FUNCTIONS_ENABLE
     108             :         case SQL_ATTR_ASYNC_DBC_FUNCTIONS_ENABLE: /* SQLUINTEGER */
     109             : #endif
     110             : #ifdef SQL_ATTR_ASYNC_DBC_PCALLBACK
     111             :         case SQL_ATTR_ASYNC_DBC_PCALLBACK:      /* SQLPOINTER */
     112             : #endif
     113             : #ifdef SQL_ATTR_ASYNC_DBC_PCONTEXT
     114             :         case SQL_ATTR_ASYNC_DBC_PCONTEXT:       /* SQLPOINTER */
     115             : #endif
     116             :         case SQL_ATTR_ASYNC_ENABLE:             /* SQLULEN */
     117             : #ifdef SQL_ATTR_DBC_INFO_TOKEN
     118             :         case SQL_ATTR_DBC_INFO_TOKEN:           /* SQLPOINTER */
     119             : #endif
     120             :         case SQL_ATTR_ENLIST_IN_DTC:            /* SQLPOINTER */
     121             :         case SQL_ATTR_ODBC_CURSORS:             /* SQLULEN */
     122             :         case SQL_ATTR_PACKET_SIZE:              /* SQLUINTEGER */
     123             :         case SQL_ATTR_QUIET_MODE:               /* HWND (SQLPOINTER) */
     124             :         case SQL_ATTR_TRACE:                    /* SQLUINTEGER */
     125             :         case SQL_ATTR_TRACEFILE:                /* SQLCHAR* */
     126             :         case SQL_ATTR_TRANSLATE_LIB:            /* SQLCHAR* */
     127             :         case SQL_ATTR_TRANSLATE_OPTION:         /* SQLUINTEGER */
     128             :                 /* Optional feature not implemented */
     129           0 :                 addDbcError(dbc, "HYC00", NULL, 0);
     130           0 :                 return SQL_ERROR;
     131             : 
     132           1 :         case SQL_ATTR_AUTO_IPD:                 /* SQLUINTEGER */
     133             :         case SQL_ATTR_CONNECTION_DEAD:          /* SQLUINTEGER */
     134             :                 /* read-only attribute */
     135             :         default:
     136             :                 /* Invalid attribute/option identifier */
     137           1 :                 addDbcError(dbc, "HY092", NULL, 0);
     138           1 :                 return SQL_ERROR;
     139             :         }
     140             : 
     141             :         return SQL_SUCCESS;
     142             : }
     143             : 
     144             : SQLRETURN SQL_API
     145             : SQLSetConnectAttr(SQLHDBC ConnectionHandle,
     146             :                   SQLINTEGER Attribute,
     147             :                   SQLPOINTER ValuePtr,
     148             :                   SQLINTEGER StringLength)
     149             : {
     150             : #ifdef ODBCDEBUG
     151           3 :         ODBCLOG("SQLSetConnectAttr %p %s %p %d\n",
     152             :                 ConnectionHandle,
     153             :                 translateConnectAttribute(Attribute),
     154             :                 ValuePtr, (int) StringLength);
     155             : #endif
     156             : 
     157           3 :         if (!isValidDbc((ODBCDbc *) ConnectionHandle))
     158             :                 return SQL_INVALID_HANDLE;
     159             : 
     160           3 :         clearDbcErrors((ODBCDbc *) ConnectionHandle);
     161             : 
     162           3 :         return MNDBSetConnectAttr((ODBCDbc *) ConnectionHandle,
     163             :                                   Attribute,
     164             :                                   ValuePtr,
     165             :                                   StringLength);
     166             : }
     167             : 
     168             : SQLRETURN SQL_API
     169             : SQLSetConnectAttrA(SQLHDBC ConnectionHandle,
     170             :                    SQLINTEGER Attribute,
     171             :                    SQLPOINTER ValuePtr,
     172             :                    SQLINTEGER StringLength)
     173             : {
     174           0 :         return SQLSetConnectAttr(ConnectionHandle,
     175             :                                  Attribute,
     176             :                                  ValuePtr,
     177             :                                  StringLength);
     178             : }
     179             : 
     180             : SQLRETURN SQL_API
     181             : SQLSetConnectAttrW(SQLHDBC ConnectionHandle,
     182             :                    SQLINTEGER Attribute,
     183             :                    SQLPOINTER ValuePtr,
     184             :                    SQLINTEGER StringLength)
     185             : {
     186           1 :         ODBCDbc *dbc = (ODBCDbc *) ConnectionHandle;
     187           1 :         SQLPOINTER ptr;
     188           1 :         SQLINTEGER n;
     189           1 :         SQLRETURN rc;
     190             : 
     191             : #ifdef ODBCDEBUG
     192           1 :         ODBCLOG("SQLSetConnectAttrW %p %s %p %d\n",
     193             :                 ConnectionHandle,
     194             :                 translateConnectAttribute(Attribute),
     195             :                 ValuePtr, (int) StringLength);
     196             : #endif
     197             : 
     198           1 :         if (!isValidDbc(dbc))
     199             :                 return SQL_INVALID_HANDLE;
     200             : 
     201           1 :         clearDbcErrors(dbc);
     202             : 
     203           1 :         switch (Attribute) {
     204           0 :         case SQL_ATTR_CURRENT_CATALOG:
     205             :         case SQL_ATTR_TRACEFILE:
     206             :         case SQL_ATTR_TRANSLATE_LIB:
     207           0 :                 if (StringLength > 0)        /* convert from bytes to characters */
     208           0 :                         StringLength /= 2;
     209           0 :                 fixWcharIn(ValuePtr, StringLength, SQLCHAR, ptr,
     210             :                            addDbcError, dbc, return SQL_ERROR);
     211           0 :                 n = SQL_NTS;
     212           0 :                 break;
     213             :         default:
     214             :                 ptr = ValuePtr;
     215             :                 n = StringLength;
     216             :                 break;
     217             :         }
     218             : 
     219           1 :         rc = MNDBSetConnectAttr(dbc, Attribute, ptr, n);
     220             : 
     221           1 :         if (ptr && ptr != ValuePtr)
     222           0 :                 free(ptr);
     223             : 
     224             :         return rc;
     225             : }

Generated by: LCOV version 1.14