LCOV - code coverage report
Current view: top level - clients/odbc/driver - SQLSetConnectAttr.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 13 58 22.4 %
Date: 2021-10-13 02:24:04 Functions: 1 1 100.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             :  * SQLSetConnectAttr()
      21             :  * CLI Compliance: ISO 92
      22             :  *
      23             :  * Author: Martin van Dinther, Sjoerd Mullender
      24             :  * Date  : 30 Aug 2002
      25             :  *
      26             :  **********************************************************************/
      27             : 
      28             : #include "ODBCGlobal.h"
      29             : #include "ODBCDbc.h"
      30             : #include "ODBCUtil.h"
      31             : 
      32             : 
      33             : SQLRETURN
      34           2 : MNDBSetConnectAttr(ODBCDbc *dbc,
      35             :                    SQLINTEGER Attribute,
      36             :                    SQLPOINTER ValuePtr,
      37             :                    SQLINTEGER StringLength)
      38             : {
      39             :         (void) StringLength;    /* Stefan: unused!? */
      40             : 
      41           2 :         switch (Attribute) {
      42           2 :         case SQL_ATTR_AUTOCOMMIT:               /* SQLUINTEGER */
      43           2 :                 switch ((SQLUINTEGER) (uintptr_t) ValuePtr) {
      44           2 :                 case SQL_AUTOCOMMIT_ON:
      45             :                 case SQL_AUTOCOMMIT_OFF:
      46           2 :                         dbc->sql_attr_autocommit = (SQLUINTEGER) (uintptr_t) ValuePtr;
      47             : #ifdef ODBCDEBUG
      48           2 :                         ODBCLOG("SQLSetConnectAttr set autocommit %s\n",
      49             :                                 dbc->sql_attr_autocommit == SQL_AUTOCOMMIT_ON ? "on" : "off");
      50             : #endif
      51           2 :                         if (dbc->mid)
      52           2 :                                 mapi_setAutocommit(dbc->mid, dbc->sql_attr_autocommit == SQL_AUTOCOMMIT_ON);
      53             :                         break;
      54           0 :                 default:
      55             :                         /* Invalid attribute value */
      56           0 :                         addDbcError(dbc, "HY024", NULL, 0);
      57           0 :                         return SQL_ERROR;
      58             :                 }
      59             :                 return SQL_SUCCESS;
      60           0 :         case SQL_ATTR_CURRENT_CATALOG:          /* SQLCHAR* */
      61           0 :                 fixODBCstring(ValuePtr, StringLength, SQLINTEGER,
      62             :                               addDbcError, dbc, return SQL_ERROR);
      63           0 :                 if (dbc->Connected) {
      64             :                         /* Driver does not support this functions */
      65           0 :                         addDbcError(dbc, "IM001", NULL, 0);
      66           0 :                         return SQL_ERROR;
      67             :                 }
      68           0 :                 if (dbc->dbname)
      69           0 :                         free(dbc->dbname);
      70           0 :                 dbc->dbname = dupODBCstring(ValuePtr, StringLength);
      71           0 :                 if (dbc->dbname == NULL) {
      72             :                         /* Memory allocation error */
      73           0 :                         addDbcError(dbc, "HY001", NULL, 0);
      74           0 :                         return SQL_ERROR;
      75             :                 }
      76             :                 break;
      77           0 :         case SQL_ATTR_CONNECTION_TIMEOUT:       /* SQLUINTEGER */
      78           0 :                 dbc->sql_attr_connection_timeout = (SQLUINTEGER) (uintptr_t) ValuePtr;
      79           0 :                 if (dbc->mid)
      80           0 :                         mapi_timeout(dbc->mid, dbc->sql_attr_connection_timeout * 1000);
      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_LOGIN_TIMEOUT:            /* SQLUINTEGER */
     122             :         case SQL_ATTR_ODBC_CURSORS:             /* SQLULEN */
     123             :         case SQL_ATTR_PACKET_SIZE:              /* SQLUINTEGER */
     124             :         case SQL_ATTR_QUIET_MODE:               /* HWND (SQLPOINTER) */
     125             :         case SQL_ATTR_TRACE:                    /* SQLUINTEGER */
     126             :         case SQL_ATTR_TRACEFILE:                /* SQLCHAR* */
     127             :         case SQL_ATTR_TRANSLATE_LIB:            /* SQLCHAR* */
     128             :         case SQL_ATTR_TRANSLATE_OPTION:         /* SQLUINTEGER */
     129             :                 /* Optional feature not implemented */
     130           0 :                 addDbcError(dbc, "HYC00", NULL, 0);
     131           0 :                 return SQL_ERROR;
     132           0 :         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           0 :                 addDbcError(dbc, "HY092", NULL, 0);
     138           0 :                 break;
     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           2 :         ODBCLOG("SQLSetConnectAttr %p %s %p %d\n",
     152             :                 ConnectionHandle,
     153             :                 translateConnectAttribute(Attribute),
     154             :                 ValuePtr, (int) StringLength);
     155             : #endif
     156             : 
     157           2 :         if (!isValidDbc((ODBCDbc *) ConnectionHandle))
     158             :                 return SQL_INVALID_HANDLE;
     159             : 
     160           2 :         clearDbcErrors((ODBCDbc *) ConnectionHandle);
     161             : 
     162           2 :         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             :         ODBCDbc *dbc = (ODBCDbc *) ConnectionHandle;
     187             :         SQLPOINTER ptr;
     188             :         SQLINTEGER n;
     189             :         SQLRETURN rc;
     190             : 
     191             : #ifdef ODBCDEBUG
     192           0 :         ODBCLOG("SQLSetConnectAttrW %p %s %p %d\n",
     193             :                 ConnectionHandle,
     194             :                 translateConnectAttribute(Attribute),
     195             :                 ValuePtr, (int) StringLength);
     196             : #endif
     197             : 
     198           0 :         if (!isValidDbc(dbc))
     199             :                 return SQL_INVALID_HANDLE;
     200             : 
     201           0 :         clearDbcErrors(dbc);
     202             : 
     203           0 :         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             :                 n = SQL_NTS;
     212           0 :                 break;
     213             :         default:
     214             :                 ptr = ValuePtr;
     215             :                 n = StringLength;
     216             :                 break;
     217             :         }
     218             : 
     219           0 :         rc = MNDBSetConnectAttr(dbc, Attribute, ptr, n);
     220             : 
     221           0 :         if (ptr && ptr != ValuePtr)
     222           0 :                 free(ptr);
     223             : 
     224             :         return rc;
     225             : }

Generated by: LCOV version 1.14