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

Generated by: LCOV version 1.14