LCOV - code coverage report
Current view: top level - clients/odbc/driver - SQLGetConnectAttr.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 92 0.0 %
Date: 2024-11-15 19:37:45 Functions: 0 1 0.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 (that's 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             :  * SQLGetConnectAttr()
      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           0 : MNDBGetConnectAttr(ODBCDbc *dbc,
      39             :                    SQLINTEGER Attribute,
      40             :                    SQLPOINTER ValuePtr,
      41             :                    SQLINTEGER BufferLength,
      42             :                    SQLINTEGER *StringLengthPtr)
      43             : {
      44           0 :         bool autocommit = false;
      45           0 :         long timeout;
      46             :         /* check input parameters */
      47           0 :         if (ValuePtr == NULL) {
      48             :                 /* Invalid use of null pointer */
      49           0 :                 addDbcError(dbc, "HY009", NULL, 0);
      50           0 :                 return SQL_ERROR;
      51             :         }
      52             : 
      53           0 :         switch (Attribute) {
      54           0 :         case SQL_ATTR_ACCESS_MODE:              /* SQLUINTEGER */
      55             :                 /* SQL_ACCESS_MODE */
      56           0 :                 WriteData(ValuePtr, SQL_MODE_READ_WRITE, SQLUINTEGER);
      57           0 :                 break;
      58           0 :         case SQL_ATTR_ASYNC_ENABLE:             /* SQLULEN */
      59           0 :                 WriteData(ValuePtr, SQL_ASYNC_ENABLE_OFF, SQLULEN);
      60           0 :                 break;
      61           0 :         case SQL_ATTR_AUTO_IPD:                 /* SQLUINTEGER */
      62             :                 /* See also SQLSetStmtAttr.c for
      63             :                  * SQL_ATTR_ENABLE_AUTO_IPD */
      64           0 :                 WriteData(ValuePtr, SQL_TRUE, SQLUINTEGER);
      65           0 :                 break;
      66           0 :         case SQL_ATTR_AUTOCOMMIT:               /* SQLUINTEGER */
      67             :                 /* SQL_AUTOCOMMIT */
      68           0 :                 autocommit = msetting_bool(dbc->settings, MP_AUTOCOMMIT);
      69           0 :                 WriteData(ValuePtr, autocommit, SQLUINTEGER);
      70           0 :                 break;
      71           0 :         case SQL_ATTR_CONNECTION_DEAD:          /* SQLUINTEGER */
      72           0 :                 WriteData(ValuePtr, dbc->mid && mapi_is_connected(dbc->mid) ? SQL_CD_FALSE : SQL_CD_TRUE, SQLUINTEGER);
      73           0 :                 break;
      74           0 :         case SQL_ATTR_CONNECTION_TIMEOUT:       /* SQLUINTEGER */
      75           0 :                 timeout = msetting_long(dbc->settings, MP_REPLY_TIMEOUT);
      76           0 :                 if (timeout < 0)
      77             :                         timeout = 0;
      78           0 :                 WriteData(ValuePtr, (SQLUINTEGER)timeout, SQLUINTEGER);
      79           0 :                 break;
      80           0 :         case SQL_ATTR_LOGIN_TIMEOUT:            /* SQLUINTEGER */
      81             :                 /* SQL_LOGIN_TIMEOUT */
      82           0 :                 WriteData(ValuePtr, 0, SQLUINTEGER);    /* no timeout */
      83           0 :                 break;
      84           0 :         case SQL_ATTR_METADATA_ID:              /* SQLUINTEGER */
      85           0 :                 WriteData(ValuePtr, dbc->sql_attr_metadata_id, SQLUINTEGER);
      86           0 :                 break;
      87           0 :         case SQL_ATTR_ODBC_CURSORS:             /* SQLULEN */
      88             :                 /* SQL_ODBC_CURSORS */
      89           0 :                 WriteData(ValuePtr, SQL_CUR_USE_DRIVER, SQLULEN);
      90           0 :                 break;
      91           0 :         case SQL_ATTR_TRACE:                    /* SQLUINTEGER */
      92             :                 /* SQL_OPT_TRACE */
      93           0 :                 WriteData(ValuePtr, SQL_OPT_TRACE_OFF, SQLUINTEGER);
      94           0 :                 break;
      95           0 :         case SQL_ATTR_CURRENT_CATALOG:          /* SQLCHAR* */
      96             :                 /* SQL_CURRENT_QUALIFIER */
      97             :                 /* MonetDB does NOT support SQL catalog qualifier, return empty string */
      98           0 :                 if (BufferLength <= 0) {
      99             :                         /* Invalid string or buffer length */
     100           0 :                         addDbcError(dbc, "HY090", NULL, 0);
     101           0 :                         return SQL_ERROR;
     102             :                 }
     103           0 :                 strcpy_len((char *) ValuePtr, "", BufferLength);
     104           0 :                 if (StringLengthPtr) {
     105           0 :                         *(StringLengthPtr) = (SQLINTEGER) 0;
     106             :                 }
     107             :                 break;
     108           0 :         case SQL_ATTR_TXN_ISOLATION:            /* SQLUINTEGER */
     109             :                 /* SQL_TXN_ISOLATION */
     110           0 :                 WriteData(ValuePtr, SQL_TXN_SERIALIZABLE, SQLUINTEGER);
     111           0 :                 break;
     112             : 
     113             : /* TODO: implement all the other Connection Attributes */
     114             : #ifdef SQL_ATTR_ASYNC_DBC_EVENT
     115             :         case SQL_ATTR_ASYNC_DBC_EVENT:          /* SQLPOINTER */
     116             : #endif
     117             : #ifdef SQL_ATTR_ASYNC_DBC_FUNCTIONS_ENABLE
     118             :         case SQL_ATTR_ASYNC_DBC_FUNCTIONS_ENABLE: /* SQLUINTEGER */
     119             : #endif
     120             : #ifdef SQL_ATTR_ASYNC_DBC_PCALLBACK
     121             :         case SQL_ATTR_ASYNC_DBC_PCALLBACK:      /* SQLPOINTER */
     122             : #endif
     123             : #ifdef SQL_ATTR_ASYNC_DBC_PCONTEXT
     124             :         case SQL_ATTR_ASYNC_DBC_PCONTEXT:       /* SQLPOINTER */
     125             : #endif
     126             : #ifdef SQL_ATTR_DBC_INFO_TOKEN
     127             :         case SQL_ATTR_DBC_INFO_TOKEN:           /* SQLPOINTER */
     128             : #endif
     129           0 :         case SQL_ATTR_DISCONNECT_BEHAVIOR:
     130             :         case SQL_ATTR_ENLIST_IN_DTC:            /* SQLPOINTER */
     131             :         case SQL_ATTR_ENLIST_IN_XA:
     132             :         case SQL_ATTR_PACKET_SIZE:              /* SQLUINTEGER */
     133             :                 /* SQL_PACKET_SIZE */
     134             :         case SQL_ATTR_QUIET_MODE:               /* HWND (SQLPOINTER) */
     135             :                 /* SQL_QUIET_MODE */
     136             :         case SQL_ATTR_TRACEFILE:                /* SQLCHAR* */
     137             :                 /* SQL_OPT_TRACEFILE */
     138             :         case SQL_ATTR_TRANSLATE_LIB:            /* SQLCHAR* */
     139             :                 /* SQL_TRANSLATE_DLL */
     140             :         case SQL_ATTR_TRANSLATE_OPTION:         /* SQLUINTEGER */
     141             :                 /* SQL_TRANSLATE_OPTION */
     142             :                 /* Optional feature not implemented */
     143           0 :                 addDbcError(dbc, "HYC00", NULL, 0);
     144           0 :                 return SQL_ERROR;
     145           0 :         default:
     146             :                 /* Invalid attribute/option identifier */
     147           0 :                 addDbcError(dbc, "HY092", NULL, 0);
     148           0 :                 return SQL_ERROR;
     149             :         }
     150             : 
     151           0 :         return dbc->Error ? SQL_SUCCESS_WITH_INFO : SQL_SUCCESS;
     152             : }
     153             : 
     154             : SQLRETURN SQL_API
     155             : SQLGetConnectAttr(SQLHDBC ConnectionHandle,
     156             :                   SQLINTEGER Attribute,
     157             :                   SQLPOINTER ValuePtr,
     158             :                   SQLINTEGER BufferLength,
     159             :                   SQLINTEGER *StringLengthPtr)
     160             : {
     161             : #ifdef ODBCDEBUG
     162           0 :         ODBCLOG("SQLGetConnectAttr %p %s %p %d %p\n",
     163             :                 ConnectionHandle,
     164             :                 translateConnectAttribute(Attribute),
     165             :                 ValuePtr, (int) BufferLength,
     166             :                 StringLengthPtr);
     167             : #endif
     168             : 
     169           0 :         if (!isValidDbc((ODBCDbc *) ConnectionHandle))
     170             :                 return SQL_INVALID_HANDLE;
     171             : 
     172           0 :         clearDbcErrors((ODBCDbc *) ConnectionHandle);
     173             : 
     174           0 :         return MNDBGetConnectAttr((ODBCDbc *) ConnectionHandle,
     175             :                                   Attribute,
     176             :                                   ValuePtr,
     177             :                                   BufferLength,
     178             :                                   StringLengthPtr);
     179             : }
     180             : 
     181             : SQLRETURN SQL_API
     182             : SQLGetConnectAttrA(SQLHDBC ConnectionHandle,
     183             :                    SQLINTEGER Attribute,
     184             :                    SQLPOINTER ValuePtr,
     185             :                    SQLINTEGER BufferLength,
     186             :                    SQLINTEGER *StringLengthPtr)
     187             : {
     188           0 :         return SQLGetConnectAttr(ConnectionHandle,
     189             :                                  Attribute,
     190             :                                  ValuePtr,
     191             :                                  BufferLength,
     192             :                                  StringLengthPtr);
     193             : }
     194             : 
     195             : SQLRETURN SQL_API
     196             : SQLGetConnectAttrW(SQLHDBC ConnectionHandle,
     197             :                    SQLINTEGER Attribute,
     198             :                    SQLPOINTER ValuePtr,
     199             :                    SQLINTEGER BufferLength,
     200             :                    SQLINTEGER *StringLengthPtr)
     201             : {
     202           0 :         ODBCDbc *dbc = (ODBCDbc *) ConnectionHandle;
     203           0 :         SQLRETURN rc;
     204           0 :         SQLPOINTER ptr = NULL;
     205           0 :         SQLINTEGER n;
     206             : 
     207             : #ifdef ODBCDEBUG
     208           0 :         ODBCLOG("SQLGetConnectAttrW %p %s %p %d %p\n",
     209             :                 ConnectionHandle,
     210             :                 translateConnectAttribute(Attribute),
     211             :                 ValuePtr, (int) BufferLength,
     212             :                 StringLengthPtr);
     213             : #endif
     214             : 
     215           0 :         if (!isValidDbc(dbc))
     216             :                 return SQL_INVALID_HANDLE;
     217             : 
     218           0 :         clearDbcErrors(dbc);
     219             : 
     220           0 :         switch (Attribute) {
     221             :         /* all string attributes */
     222           0 :         case SQL_ATTR_CURRENT_CATALOG:
     223             :         case SQL_ATTR_TRACEFILE:
     224             :         case SQL_ATTR_TRANSLATE_LIB:
     225           0 :                 if (BufferLength > 0) {
     226           0 :                         ptr = malloc(BufferLength);
     227           0 :                         if (ptr == NULL) {
     228             :                                 /* Memory allocation error */
     229           0 :                                 addDbcError(dbc, "HY001", NULL, 0);
     230           0 :                                 return SQL_ERROR;
     231             :                         }
     232             :                 }
     233             :                 break;
     234             :         default:
     235             :                 ptr = ValuePtr;
     236             :                 break;
     237             :         }
     238             : 
     239           0 :         rc = MNDBGetConnectAttr(dbc, Attribute, ptr, BufferLength, &n);
     240             : 
     241           0 :         if (ptr != ValuePtr) {
     242           0 :                 if (rc == SQL_SUCCESS_WITH_INFO) {
     243           0 :                         clearDbcErrors(dbc);
     244           0 :                         free(ptr);
     245           0 :                         ptr = malloc(++n); /* add one for NULL byte */
     246           0 :                         if (ptr == NULL) {
     247             :                                 /* Memory allocation error */
     248           0 :                                 addDbcError(dbc, "HY001", NULL, 0);
     249           0 :                                 return SQL_ERROR;
     250             :                         }
     251           0 :                         rc = MNDBGetConnectAttr(dbc, Attribute, ptr, n, &n);
     252             :                 }
     253           0 :                 if (SQL_SUCCEEDED(rc)) {
     254           0 :                         SQLSMALLINT nn = (SQLSMALLINT) n;
     255             : 
     256           0 :                         fixWcharOut(rc, ptr, nn, ValuePtr, BufferLength,
     257             :                                     StringLengthPtr, 2, addDbcError, dbc);
     258             :                 }
     259           0 :                 free(ptr);
     260           0 :         } else if (StringLengthPtr)
     261           0 :                 *StringLengthPtr = n;
     262             : 
     263             :         return rc;
     264             : }

Generated by: LCOV version 1.14