LCOV - code coverage report
Current view: top level - clients/odbc/driver - SQLGetConnectOption.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 43 0.0 %
Date: 2024-04-26 00:35:57 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             :  * SQLGetConnectOption()
      25             :  * CLI Compliance: deprecated in ODBC 3.0 (replaced by SQLGetConnectAttr())
      26             :  * Provided here for old (pre ODBC 3.0) applications and driver managers.
      27             :  **********************************************************************/
      28             : 
      29             : #include "ODBCGlobal.h"
      30             : #include "ODBCDbc.h"
      31             : #include "ODBCUtil.h"
      32             : 
      33             : #ifdef _MSC_VER
      34             : /* can't call them by their real name with Visual Studio 12.0 since we
      35             :  * would then get a warning which we translate to an error during
      36             :  * compilation (also see ODBC.syms) */
      37             : #define SQLGetConnectOption     SQLGetConnectOption_deprecated
      38             : #define SQLGetConnectOptionA    SQLGetConnectOptionA_deprecated
      39             : #define SQLGetConnectOptionW    SQLGetConnectOptionW_deprecated
      40             : #endif
      41             : 
      42             : static SQLRETURN
      43           0 : MNDBGetConnectOption(ODBCDbc *dbc,
      44             :                      SQLUSMALLINT Option,
      45             :                      SQLPOINTER ValuePtr)
      46             : {
      47           0 :         SQLLEN v;
      48           0 :         SQLRETURN r;
      49             : 
      50             :         /* use mapping as described in ODBC 3 SDK Help file */
      51           0 :         switch (Option) {
      52             :                 /* connection attributes (ODBC 1 and 2 only) */
      53           0 :         case SQL_ACCESS_MODE:
      54             :         case SQL_AUTOCOMMIT:
      55             :         case SQL_LOGIN_TIMEOUT:
      56             :         case SQL_OPT_TRACE:
      57             :         case SQL_PACKET_SIZE:
      58             :         case SQL_TRANSLATE_OPTION:
      59             :         case SQL_TXN_ISOLATION:
      60             :                 /* 32 bit integer argument */
      61           0 :                 return MNDBGetConnectAttr(dbc, Option, ValuePtr, 0, NULL);
      62           0 :         case SQL_ODBC_CURSORS:
      63             :                 /* 32 bit integer argument, but SQLGetConnectAttr returns 64 */
      64           0 :                 r = MNDBGetConnectAttr(dbc, Option, &v, 0, NULL);
      65           0 :                 if (SQL_SUCCEEDED(r))
      66           0 :                         WriteData(ValuePtr, (SQLUINTEGER) v, SQLUINTEGER);
      67             :                 return r;
      68           0 :         case SQL_QUIET_MODE:
      69             :                 /* 32/64 bit integer argument */
      70           0 :                 return MNDBGetConnectAttr(dbc, Option, ValuePtr, 0, NULL);
      71           0 :         case SQL_CURRENT_QUALIFIER:
      72             :         case SQL_OPT_TRACEFILE:
      73             :         case SQL_TRANSLATE_DLL:
      74             :                 /* null terminated string argument */
      75           0 :                 return MNDBGetConnectAttr(dbc, Option, ValuePtr,
      76             :                                           SQL_MAX_OPTION_STRING_LENGTH, NULL);
      77           0 :         default:
      78             :                 /* Invalid attribute/option identifier */
      79           0 :                 addDbcError(dbc, "HY092", NULL, 0);
      80           0 :                 break;
      81             :         }
      82             : 
      83           0 :         return SQL_ERROR;
      84             : }
      85             : 
      86             : SQLRETURN SQL_API
      87             : SQLGetConnectOption(SQLHDBC ConnectionHandle,
      88             :                     SQLUSMALLINT Option,
      89             :                     SQLPOINTER ValuePtr)
      90             : {
      91           0 :         ODBCDbc *dbc = (ODBCDbc *) ConnectionHandle;
      92             : 
      93             : #ifdef ODBCDEBUG
      94           0 :         ODBCLOG("SQLGetConnectOption %p %s %p\n",
      95             :                 ConnectionHandle, translateConnectOption(Option),
      96             :                 ValuePtr);
      97             : #endif
      98             : 
      99           0 :         if (!isValidDbc(dbc))
     100             :                 return SQL_INVALID_HANDLE;
     101           0 :         clearDbcErrors(dbc);
     102             : 
     103           0 :         return MNDBGetConnectOption(dbc, Option, ValuePtr);
     104             : }
     105             : 
     106             : SQLRETURN SQL_API
     107             : SQLGetConnectOptionA(SQLHDBC ConnectionHandle,
     108             :                      SQLUSMALLINT Option,
     109             :                      SQLPOINTER ValuePtr)
     110             : {
     111           0 :         return SQLGetConnectOption(ConnectionHandle, Option, ValuePtr);
     112             : }
     113             : 
     114             : SQLRETURN SQL_API
     115             : SQLGetConnectOptionW(SQLHDBC ConnectionHandle,
     116             :                      SQLUSMALLINT Option,
     117             :                      SQLPOINTER ValuePtr)
     118             : {
     119           0 :         ODBCDbc *dbc = (ODBCDbc *) ConnectionHandle;
     120           0 :         SQLRETURN rc;
     121           0 :         SQLPOINTER ptr;
     122             : 
     123             : #ifdef ODBCDEBUG
     124           0 :         ODBCLOG("SQLGetConnectOptionW %p %s %p\n",
     125             :                 ConnectionHandle, translateConnectOption(Option),
     126             :                 ValuePtr);
     127             : #endif
     128             : 
     129           0 :         if (!isValidDbc(dbc))
     130             :                 return SQL_INVALID_HANDLE;
     131             : 
     132           0 :         clearDbcErrors(dbc);
     133             : 
     134           0 :         switch (Option) {
     135             :         /* all string attributes */
     136           0 :         case SQL_CURRENT_QUALIFIER:
     137             :         case SQL_OPT_TRACEFILE:
     138             :         case SQL_TRANSLATE_DLL:
     139           0 :                 ptr = (SQLPOINTER) malloc(SQL_MAX_OPTION_STRING_LENGTH);
     140           0 :                 if (ptr == NULL) {
     141             :                         /* Memory allocation error */
     142           0 :                         addDbcError(dbc, "HY001", NULL, 0);
     143           0 :                         return SQL_ERROR;
     144             :                 }
     145             :                 break;
     146             :         default:
     147             :                 ptr = ValuePtr;
     148             :                 break;
     149             :         }
     150             : 
     151           0 :         rc = MNDBGetConnectOption(dbc, Option, ptr);
     152             : 
     153           0 :         if (ptr != ValuePtr) {
     154           0 :                 if (SQL_SUCCEEDED(rc)) {
     155           0 :                         SQLSMALLINT n = (SQLSMALLINT) strlen((char *) ptr);
     156           0 :                         SQLSMALLINT *nullp = NULL;
     157             : 
     158           0 :                         fixWcharOut(rc, ptr, n, ValuePtr,
     159             :                                     SQL_MAX_OPTION_STRING_LENGTH, nullp, 2,
     160             :                                     addDbcError, dbc);
     161             :                 }
     162           0 :                 free(ptr);
     163             :         }
     164             : 
     165             :         return rc;
     166             : }

Generated by: LCOV version 1.14