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

Generated by: LCOV version 1.14