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

Generated by: LCOV version 1.14