LCOV - code coverage report
Current view: top level - clients/odbc/driver - SQLGetData.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 19 37 51.4 %
Date: 2024-04-25 20:03:45 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 (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             :  * SQLGetData()
      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             : SQLRETURN SQL_API
      37             : SQLGetData(SQLHSTMT StatementHandle,
      38             :            SQLUSMALLINT Col_or_Param_Num,
      39             :            SQLSMALLINT TargetType,
      40             :            SQLPOINTER TargetValuePtr,
      41             :            SQLLEN BufferLength,
      42             :            SQLLEN *StrLen_or_IndPtr)
      43             : {
      44        6420 :         ODBCStmt *stmt = (ODBCStmt *) StatementHandle;
      45             : 
      46             : #ifdef ODBCDEBUG
      47        6420 :         ODBCLOG("SQLGetData %p %u %s %p " LENFMT " %p\n",
      48             :                 StatementHandle, (unsigned int) Col_or_Param_Num,
      49             :                 translateCType(TargetType), TargetValuePtr,
      50             :                 LENCAST BufferLength, StrLen_or_IndPtr);
      51             : #endif
      52             : 
      53        6420 :         if (!isValidStmt(stmt))
      54             :                  return SQL_INVALID_HANDLE;
      55             : 
      56        6420 :         assert(stmt->Dbc);
      57        6420 :         assert(stmt->Dbc->mid);
      58        6420 :         assert(stmt->hdl);
      59             : 
      60        6420 :         clearStmtErrors(stmt);
      61             : 
      62             :         /* check statement cursor state, query should be executed */
      63        6420 :         if (stmt->State < EXECUTED0) {
      64             :                 /* Function sequence error */
      65           0 :                 addStmtError(stmt, "HY010", NULL, 0);
      66           0 :                 return SQL_ERROR;
      67             :         }
      68        6420 :         if (stmt->State <= EXECUTED1) {
      69             :                 /* Invalid cursor state */
      70           0 :                 addStmtError(stmt, "24000", NULL, 0);
      71           0 :                 return SQL_ERROR;
      72             :         }
      73        6420 :         if (stmt->rowSetSize == 0) {
      74             :                 /* SQLFetch failed */
      75             :                 /* General error */
      76           0 :                 addStmtError(stmt, "HY000", NULL, 0);
      77           0 :                 return SQL_ERROR;
      78             :         }
      79        6420 :         if (stmt->rowSetSize > 1 &&
      80           0 :             stmt->cursorType == SQL_CURSOR_FORWARD_ONLY) {
      81             :                 /* Invalid cursor position */
      82           0 :                 addStmtError(stmt, "HY109", NULL, 0);
      83           0 :                 return SQL_ERROR;
      84             :         }
      85        6420 :         if (Col_or_Param_Num <= 0 ||
      86        6420 :             Col_or_Param_Num > stmt->ImplRowDescr->sql_desc_count) {
      87             :                 /* Invalid descriptor index */
      88           0 :                 addStmtError(stmt, "07009", NULL, 0);
      89           0 :                 return SQL_ERROR;
      90             :         }
      91        6420 :         if (TargetValuePtr == NULL) {
      92             :                 /* Invalid use of null pointer */
      93           0 :                 addStmtError(stmt, "HY009", NULL, 0);
      94           0 :                 return SQL_ERROR;
      95             :         }
      96             : 
      97        6420 :         if (Col_or_Param_Num != stmt->currentCol)
      98        6414 :                 stmt->retrieved = 0;
      99        6420 :         stmt->currentCol = Col_or_Param_Num;
     100             : 
     101        6420 :         if (TargetType == SQL_ARD_TYPE) {
     102           0 :                 ODBCDesc *desc = stmt->ApplRowDescr;
     103             : 
     104           0 :                 if (Col_or_Param_Num > desc->sql_desc_count) {
     105             :                         /* Invalid descriptor index */
     106           0 :                         addStmtError(stmt, "07009", NULL, 0);
     107           0 :                         return SQL_ERROR;
     108             :                 }
     109           0 :                 TargetType = desc->descRec[Col_or_Param_Num].sql_desc_concise_type;
     110             :         }
     111             : 
     112        6420 :         return ODBCFetch(stmt, Col_or_Param_Num, TargetType, TargetValuePtr,
     113             :                          BufferLength, StrLen_or_IndPtr, StrLen_or_IndPtr,
     114             :                          UNAFFECTED, UNAFFECTED, UNAFFECTED, 0, 0);
     115             : }

Generated by: LCOV version 1.14