LCOV - code coverage report
Current view: top level - clients/odbc/driver - SQLSetEnvAttr.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 14 34 41.2 %
Date: 2024-10-07 21:21:43 Functions: 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             :  * SQLSetEnvAttr()
      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 "ODBCEnv.h"
      34             : #include <sys/types.h>            /* for ssize_t on Darwin */
      35             : 
      36             : 
      37             : SQLRETURN SQL_API
      38             : SQLSetEnvAttr(SQLHENV EnvironmentHandle,
      39             :               SQLINTEGER Attribute,
      40             :               SQLPOINTER ValuePtr,
      41             :               SQLINTEGER StringLength)
      42             : {
      43          41 :         ODBCEnv *env = (ODBCEnv *) EnvironmentHandle;
      44             : 
      45             : #ifdef ODBCDEBUG
      46          41 :         ODBCLOG("SQLSetEnvAttr %p %s %p %d\n",
      47             :                 EnvironmentHandle, translateEnvAttribute(Attribute),
      48             :                 ValuePtr, (int) StringLength);
      49             : #endif
      50             : 
      51          41 :         (void) StringLength;    /* Stefan: unused!? */
      52             : 
      53             :         /* global attribute */
      54          41 :         if (Attribute == SQL_ATTR_CONNECTION_POOLING && env == NULL) {
      55           0 :                 switch ((SQLUINTEGER) (uintptr_t) ValuePtr) {
      56             :                 case SQL_CP_OFF:
      57             :                 case SQL_CP_ONE_PER_DRIVER:
      58             :                 case SQL_CP_ONE_PER_HENV:
      59             :                         break;
      60             :                 default:
      61             :                         return SQL_INVALID_HANDLE;
      62             :                 }
      63             :                 return SQL_SUCCESS;
      64             :         }
      65             : 
      66          41 :         if (!isValidEnv(env))
      67             :                 return SQL_INVALID_HANDLE;
      68             : 
      69          41 :         clearEnvErrors(env);
      70             : 
      71             :         /* can only set environment attributes if no connection handle
      72             :            has been allocated */
      73          41 :         if (env->FirstDbc != NULL) {
      74             :                 /* Function sequence error */
      75           0 :                 addEnvError(env, "HY010", NULL, 0);
      76           0 :                 return SQL_ERROR;
      77             :         }
      78             : 
      79          41 :         switch (Attribute) {
      80          41 :         case SQL_ATTR_ODBC_VERSION:             /* SQLINTEGER */
      81          41 :                 switch ((SQLINTEGER) (intptr_t) ValuePtr) {
      82          41 :                 case SQL_OV_ODBC3:
      83             :                 case SQL_OV_ODBC2:
      84          41 :                         env->sql_attr_odbc_version = (SQLINTEGER) (intptr_t) ValuePtr;
      85          41 :                         break;
      86           0 :                 default:
      87             :                         /* Invalid attribute value */
      88           0 :                         addEnvError(env, "HY024", NULL, 0);
      89           0 :                         return SQL_ERROR;
      90             :                 }
      91          41 :                 break;
      92           0 :         case SQL_ATTR_CP_MATCH:                 /* SQLUINTEGER */
      93             :                 /* Optional feature not implemented */
      94           0 :                 addEnvError(env, "HYC00", NULL, 0);
      95           0 :                 return SQL_ERROR;
      96           0 :         case SQL_ATTR_OUTPUT_NTS:               /* SQLINTEGER */
      97           0 :                 switch ((SQLINTEGER) (intptr_t) ValuePtr) {
      98             :                 case SQL_TRUE:
      99             :                         break;
     100           0 :                 case SQL_FALSE:
     101             :                         /* Optional feature not implemented */
     102           0 :                         addEnvError(env, "HYC00", NULL, 0);
     103           0 :                         return SQL_ERROR;
     104           0 :                 default:
     105             :                         /* Invalid attribute/option identifier */
     106           0 :                         addEnvError(env, "HY092", NULL, 0);
     107           0 :                         return SQL_ERROR;
     108             :                 }
     109             :                 break;
     110           0 :         case SQL_ATTR_CONNECTION_POOLING:       /* SQLUINTEGER */
     111             :                 /* not valid with non-NULL environment handle parameter */
     112             :         default:
     113             :                 /* Invalid attribute/option identifier */
     114           0 :                 addEnvError(env, "HY092", NULL, 0);
     115           0 :                 return SQL_ERROR;
     116             :         }
     117             : 
     118             :         return SQL_SUCCESS;
     119             : }

Generated by: LCOV version 1.14