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

Generated by: LCOV version 1.14