LCOV - code coverage report
Current view: top level - clients/odbc/driver - SQLGetStmtAttr.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 20 78 25.6 %
Date: 2024-04-26 00:35:57 Functions: 1 1 100.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             :  * SQLGetStmtAttr()
      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 "ODBCStmt.h"
      34             : #include "ODBCUtil.h"
      35             : 
      36             : 
      37             : SQLRETURN
      38          68 : MNDBGetStmtAttr(ODBCStmt *stmt,
      39             :                 SQLINTEGER Attribute,
      40             :                 SQLPOINTER ValuePtr,
      41             :                 SQLINTEGER BufferLength,
      42             :                 SQLINTEGER *StringLengthPtr)
      43             : {
      44             :         /* TODO: check parameters: ValuePtr, BufferLength and
      45             :          * StringLengthPtr */
      46             : 
      47          68 :         switch (Attribute) {
      48             : #ifndef __COVERITY__
      49             :         /* Coverity doesn't like the debug print in WriteData, so we
      50             :          * hide this whole thing */
      51          11 :         case SQL_ATTR_APP_PARAM_DESC:           /* SQLHANDLE */
      52          11 :                 WriteData(ValuePtr, stmt->ApplParamDescr, SQLHANDLE);
      53             :                 return SQL_SUCCESS;
      54          11 :         case SQL_ATTR_APP_ROW_DESC:             /* SQLHANDLE */
      55          11 :                 WriteData(ValuePtr, stmt->ApplRowDescr, SQLHANDLE);
      56             :                 return SQL_SUCCESS;
      57             : #endif
      58           0 :         case SQL_ATTR_ASYNC_ENABLE:             /* SQLULEN */
      59             :                 /* SQL_ASYNC_ENABLE */
      60           0 :                 WriteData(ValuePtr, SQL_ASYNC_ENABLE_OFF, SQLULEN);
      61             :                 break;
      62           0 :         case SQL_ATTR_ENABLE_AUTO_IPD:          /* SQLULEN */
      63           0 :                 WriteData(ValuePtr, SQL_TRUE, SQLULEN);
      64             :                 break;
      65           0 :         case SQL_ATTR_CONCURRENCY:              /* SQLULEN */
      66             :                 /* SQL_CONCURRENCY */
      67           0 :                 WriteData(ValuePtr, SQL_CONCUR_READ_ONLY, SQLULEN);
      68             :                 break;
      69           0 :         case SQL_ATTR_CURSOR_SCROLLABLE:        /* SQLULEN */
      70           0 :                 WriteData(ValuePtr, stmt->cursorScrollable, SQLULEN);
      71             :                 break;
      72           0 :         case SQL_ATTR_CURSOR_SENSITIVITY:       /* SQLULEN */
      73           0 :                 WriteData(ValuePtr, SQL_INSENSITIVE, SQLULEN);
      74             :                 break;
      75           0 :         case SQL_ATTR_CURSOR_TYPE:              /* SQLULEN */
      76             :                 /* SQL_CURSOR_TYPE */
      77           0 :                 WriteData(ValuePtr, stmt->cursorType, SQLULEN);
      78             :                 break;
      79             : #ifndef __COVERITY__
      80             :         /* Coverity doesn't like the debug print in WriteData, so we
      81             :          * hide this whole thing */
      82          11 :         case SQL_ATTR_IMP_PARAM_DESC:           /* SQLHANDLE */
      83          11 :                 WriteData(ValuePtr, stmt->ImplParamDescr, SQLHANDLE);
      84             :                 return SQL_SUCCESS;
      85          11 :         case SQL_ATTR_IMP_ROW_DESC:             /* SQLHANDLE */
      86          11 :                 WriteData(ValuePtr, stmt->ImplRowDescr, SQLHANDLE);
      87             :                 return SQL_SUCCESS;
      88             : #endif
      89           8 :         case SQL_ATTR_MAX_LENGTH:               /* SQLULEN */
      90             :                 /* SQL_MAX_LENGTH */
      91           8 :                 WriteData(ValuePtr, 0, SQLULEN);
      92             :                 break;
      93           8 :         case SQL_ATTR_MAX_ROWS:                 /* SQLULEN */
      94             :                 /* SQL_MAX_ROWS */
      95           8 :                 WriteData(ValuePtr, 0, SQLULEN);
      96             :                 break;
      97           0 :         case SQL_ATTR_METADATA_ID:              /* SQLULEN */
      98           0 :                 WriteData(ValuePtr, stmt->Dbc->sql_attr_metadata_id, SQLULEN);
      99             :                 break;
     100           0 :         case SQL_ATTR_NOSCAN:                   /* SQLULEN */
     101             :                 /* SQL_NOSCAN */
     102           0 :                 WriteData(ValuePtr, stmt->noScan, SQLULEN);
     103             :                 break;
     104           0 :         case SQL_ATTR_PARAM_BIND_OFFSET_PTR:    /* SQLULEN* */
     105           0 :                 return MNDBGetDescField(stmt->ApplParamDescr, 0,
     106             :                                         SQL_DESC_BIND_OFFSET_PTR, ValuePtr,
     107             :                                         BufferLength, StringLengthPtr);
     108           0 :         case SQL_ATTR_PARAM_BIND_TYPE:          /* SQLULEN */
     109             :                 /* SQL_BIND_TYPE */
     110           0 :                 WriteData(ValuePtr, stmt->ApplParamDescr->sql_desc_bind_type, SQLULEN);
     111             :                 break;
     112           0 :         case SQL_ATTR_PARAM_OPERATION_PTR:      /* SQLUSMALLINT* */
     113           0 :                 return MNDBGetDescField(stmt->ApplParamDescr, 0,
     114             :                                         SQL_DESC_ARRAY_STATUS_PTR, ValuePtr,
     115             :                                         BufferLength, StringLengthPtr);
     116           0 :         case SQL_ATTR_PARAMSET_SIZE:            /* SQLULEN */
     117           0 :                 return MNDBGetDescField(stmt->ApplParamDescr, 0,
     118             :                                         SQL_DESC_ARRAY_SIZE, ValuePtr,
     119             :                                         BufferLength, StringLengthPtr);
     120           0 :         case SQL_ATTR_PARAMS_PROCESSED_PTR:     /* SQLULEN* */
     121           0 :                 return MNDBGetDescField(stmt->ImplParamDescr, 0,
     122             :                                         SQL_DESC_ROWS_PROCESSED_PTR, ValuePtr,
     123             :                                         BufferLength, StringLengthPtr);
     124           0 :         case SQL_ATTR_PARAM_STATUS_PTR:         /* SQLUSMALLINT* */
     125           0 :                 return MNDBGetDescField(stmt->ImplParamDescr, 0,
     126             :                                         SQL_DESC_ARRAY_STATUS_PTR, ValuePtr,
     127             :                                         BufferLength, StringLengthPtr);
     128           8 :         case SQL_ATTR_QUERY_TIMEOUT:            /* SQLULEN */
     129             :                 /* SQL_QUERY_TIMEOUT */
     130           8 :                 WriteData(ValuePtr, stmt->qtimeout, SQLULEN);
     131             :                 break;
     132           0 :         case SQL_ATTR_RETRIEVE_DATA:            /* SQLULEN */
     133             :                 /* SQL_RETRIEVE_DATA */
     134           0 :                 WriteData(ValuePtr, stmt->retrieveData, SQLULEN);
     135             :                 break;
     136           0 :         case SQL_ATTR_ROW_ARRAY_SIZE:           /* SQLULEN */
     137             :         case SQL_ROWSET_SIZE:
     138           0 :                 return MNDBGetDescField(stmt->ApplRowDescr, 0,
     139             :                                         SQL_DESC_ARRAY_SIZE, ValuePtr,
     140             :                                         BufferLength, StringLengthPtr);
     141           0 :         case SQL_ATTR_ROW_BIND_OFFSET_PTR:      /* SQLULEN* */
     142           0 :                 return MNDBGetDescField(stmt->ApplRowDescr, 0,
     143             :                                         SQL_DESC_BIND_OFFSET_PTR, ValuePtr,
     144             :                                         BufferLength, StringLengthPtr);
     145           0 :         case SQL_ATTR_ROW_BIND_TYPE:            /* SQLULEN */
     146           0 :                 WriteData(ValuePtr, stmt->ApplRowDescr->sql_desc_bind_type, SQLULEN);
     147             :                 break;
     148           0 :         case SQL_ATTR_ROW_NUMBER:            /* SQLULEN */
     149           0 :                 if (stmt->State <= EXECUTED1) {
     150             :                         /* Invalid cursor state */
     151           0 :                         addStmtError(stmt, "24000", NULL, 0);
     152           0 :                         return SQL_ERROR;
     153             :                 }
     154           0 :                 WriteData(ValuePtr, (SQLULEN) stmt->currentRow, SQLULEN);
     155             :                 break;
     156           0 :         case SQL_ATTR_ROW_OPERATION_PTR:        /* SQLUSMALLINT* */
     157           0 :                 return MNDBGetDescField(stmt->ApplRowDescr, 0,
     158             :                                         SQL_DESC_ARRAY_STATUS_PTR, ValuePtr,
     159             :                                         BufferLength, StringLengthPtr);
     160           0 :         case SQL_ATTR_ROW_STATUS_PTR:           /* SQLUSMALLINT* */
     161           0 :                 return MNDBGetDescField(stmt->ImplRowDescr, 0,
     162             :                                         SQL_DESC_ARRAY_STATUS_PTR, ValuePtr,
     163             :                                         BufferLength, StringLengthPtr);
     164           0 :         case SQL_ATTR_ROWS_FETCHED_PTR:         /* SQLULEN* */
     165           0 :                 return MNDBGetDescField(stmt->ImplRowDescr, 0,
     166             :                                         SQL_DESC_ROWS_PROCESSED_PTR, ValuePtr,
     167             :                                         BufferLength, StringLengthPtr);
     168             : 
     169             :                 /* TODO: implement requested behavior */
     170             : #ifdef SQL_ATTR_ASYNC_STMT_EVENT
     171             :         case SQL_ATTR_ASYNC_STMT_EVENT:         /* SQLPOINTER */
     172             : #endif
     173             : #ifdef SQL_ATTR_ASYNC_STMT_PCALLBACK
     174             :         case SQL_ATTR_ASYNC_PCALLBACK:          /* SQLPOINTER */
     175             : #endif
     176             : #ifdef SQL_ATTR_ASYNC_STMT_PCONTEXT
     177             :         case SQL_ATTR_ASYNC_PCONTEXT:           /* SQLPOINTER */
     178             : #endif
     179           0 :         case SQL_ATTR_FETCH_BOOKMARK_PTR:       /* SQLLEN* */
     180             :         case SQL_ATTR_KEYSET_SIZE:              /* SQLULEN */
     181             :                 /* SQL_KEYSET_SIZE */
     182             :         case SQL_ATTR_SIMULATE_CURSOR:          /* SQLULEN */
     183             :         case SQL_ATTR_USE_BOOKMARKS:            /* SQLULEN */
     184             :                 /* Optional feature not implemented */
     185           0 :                 addStmtError(stmt, "HYC00", NULL, 0);
     186           0 :                 return SQL_ERROR;
     187           0 :         default:
     188             :                 /* Invalid attribute/option identifier */
     189           0 :                 addStmtError(stmt, "HY092", NULL, 0);
     190           0 :                 return SQL_ERROR;
     191             :         }
     192             : 
     193             :         return SQL_SUCCESS;
     194             : }
     195             : 
     196             : SQLRETURN SQL_API
     197             : SQLGetStmtAttr(SQLHSTMT StatementHandle,
     198             :                SQLINTEGER Attribute,
     199             :                SQLPOINTER ValuePtr,
     200             :                SQLINTEGER BufferLength,
     201             :                SQLINTEGER *StringLengthPtr)
     202             : {
     203             : #ifdef ODBCDEBUG
     204          68 :         ODBCLOG("SQLGetStmtAttr %p %s %p %d %p\n",
     205             :                 StatementHandle, translateStmtAttribute(Attribute),
     206             :                 ValuePtr, (int) BufferLength,
     207             :                 StringLengthPtr);
     208             : #endif
     209             : 
     210          68 :         if (!isValidStmt((ODBCStmt *) StatementHandle))
     211             :                 return SQL_INVALID_HANDLE;
     212             : 
     213          68 :         clearStmtErrors((ODBCStmt *) StatementHandle);
     214             : 
     215          68 :         return MNDBGetStmtAttr((ODBCStmt *) StatementHandle,
     216             :                                Attribute,
     217             :                                ValuePtr,
     218             :                                BufferLength,
     219             :                                StringLengthPtr);
     220             : }
     221             : 
     222             : SQLRETURN SQL_API
     223             : SQLGetStmtAttrA(SQLHSTMT StatementHandle,
     224             :                 SQLINTEGER Attribute,
     225             :                 SQLPOINTER ValuePtr,
     226             :                 SQLINTEGER BufferLength,
     227             :                 SQLINTEGER *StringLengthPtr)
     228             : {
     229           0 :         return SQLGetStmtAttr(StatementHandle,
     230             :                               Attribute,
     231             :                               ValuePtr,
     232             :                               BufferLength,
     233             :                               StringLengthPtr);
     234             : }
     235             : 
     236             : SQLRETURN SQL_API
     237             : SQLGetStmtAttrW(SQLHSTMT StatementHandle,
     238             :                 SQLINTEGER Attribute,
     239             :                 SQLPOINTER ValuePtr,
     240             :                 SQLINTEGER BufferLength,
     241             :                 SQLINTEGER *StringLengthPtr)
     242             : {
     243             : #ifdef ODBCDEBUG
     244           0 :         ODBCLOG("SQLGetStmtAttrW %p %s %p %d %p\n",
     245             :                 StatementHandle, translateStmtAttribute(Attribute),
     246             :                 ValuePtr, (int) BufferLength,
     247             :                 StringLengthPtr);
     248             : #endif
     249             : 
     250           0 :         if (!isValidStmt((ODBCStmt *) StatementHandle))
     251             :                 return SQL_INVALID_HANDLE;
     252             : 
     253           0 :         clearStmtErrors((ODBCStmt *) StatementHandle);
     254             : 
     255             :         /* there are no string-valued attributes */
     256             : 
     257           0 :         return MNDBGetStmtAttr((ODBCStmt *) StatementHandle,
     258             :                                Attribute,
     259             :                                ValuePtr,
     260             :                                BufferLength,
     261             :                                StringLengthPtr);
     262             : }

Generated by: LCOV version 1.14