LCOV - code coverage report
Current view: top level - clients/odbc/driver - SQLBindCol.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 20 37 54.1 %
Date: 2021-10-13 02:24:04 Functions: 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             :  * SQLBindCol()
      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             : 
      31             : 
      32             : SQLRETURN SQL_API
      33             : SQLBindCol(SQLHSTMT StatementHandle,
      34             :            SQLUSMALLINT ColumnNumber,
      35             :            SQLSMALLINT TargetType,
      36             :            SQLPOINTER TargetValuePtr,
      37             :            SQLLEN BufferLength,
      38             :            SQLLEN *StrLen_or_Ind)
      39             : {
      40             :         ODBCStmt *stmt = (ODBCStmt *) StatementHandle;
      41             :         ODBCDesc *desc;         /* Application Row Descriptor */
      42             : 
      43             : #ifdef ODBCDEBUG
      44          12 :         ODBCLOG("SQLBindCol %p %u %s %p " LENFMT "\n",
      45             :                 StatementHandle, (unsigned int) ColumnNumber,
      46             :                 translateCType(TargetType), TargetValuePtr,
      47             :                 LENCAST BufferLength);
      48             : #endif
      49             : 
      50          12 :         if (!isValidStmt(stmt))
      51             :                  return SQL_INVALID_HANDLE;
      52             : 
      53          12 :         assert(stmt->Dbc);
      54             : 
      55          12 :         clearStmtErrors(stmt);
      56             : 
      57             :         /* check input parameters */
      58             :         /* column number 0 (Bookmark column) is not supported */
      59          12 :         if (ColumnNumber == 0) {
      60           0 :                 if (TargetType == SQL_C_BOOKMARK || TargetType == SQL_C_VARBOOKMARK) {
      61             :                         /* Optional feature not implemented */
      62           0 :                         addStmtError(stmt, "HYC00", NULL, 0);
      63             :                 } else {
      64             :                         /* Restricted data type attribute violation */
      65           0 :                         addStmtError(stmt, "07006", NULL, 0);
      66             :                 }
      67           0 :                 return SQL_ERROR;
      68             :         }
      69          12 :         if (stmt->State >= EXECUTED1 && ColumnNumber > stmt->ImplRowDescr->sql_desc_count) {
      70             :                 /* Invalid descriptor index */
      71           0 :                 addStmtError(stmt, "07009", NULL, 0);
      72           0 :                 return SQL_ERROR;
      73             :         }
      74             : 
      75             :         /* For safety: limit the maximum number of columns to bind */
      76          12 :         if (ColumnNumber > MONETDB_MAX_BIND_COLS) {
      77             :                 /* General error */
      78           0 :                 addStmtError(stmt, "HY000", "Maximum number of bind columns (8192) exceeded", 0);
      79           0 :                 return SQL_ERROR;
      80             :         }
      81             : 
      82             :         /* can't let SQLSetDescField below do this check since it
      83             :            returns the wrong error code if the type is incorrect */
      84          12 :         switch (TargetType) {
      85             :         case SQL_C_CHAR:
      86             :         case SQL_C_WCHAR:
      87             :         case SQL_C_BINARY:
      88             :         case SQL_C_BIT:
      89             :         case SQL_C_STINYINT:
      90             :         case SQL_C_UTINYINT:
      91             :         case SQL_C_TINYINT:
      92             :         case SQL_C_SSHORT:
      93             :         case SQL_C_USHORT:
      94             :         case SQL_C_SHORT:
      95             :         case SQL_C_SLONG:
      96             :         case SQL_C_ULONG:
      97             :         case SQL_C_LONG:
      98             :         case SQL_C_SBIGINT:
      99             :         case SQL_C_UBIGINT:
     100             :         case SQL_C_NUMERIC:
     101             :         case SQL_C_FLOAT:
     102             :         case SQL_C_DOUBLE:
     103             :         case SQL_C_TYPE_DATE:
     104             :         case SQL_C_TYPE_TIME:
     105             :         case SQL_C_TYPE_TIMESTAMP:
     106             :         case SQL_C_INTERVAL_YEAR:
     107             :         case SQL_C_INTERVAL_MONTH:
     108             :         case SQL_C_INTERVAL_YEAR_TO_MONTH:
     109             :         case SQL_C_INTERVAL_DAY:
     110             :         case SQL_C_INTERVAL_HOUR:
     111             :         case SQL_C_INTERVAL_MINUTE:
     112             :         case SQL_C_INTERVAL_SECOND:
     113             :         case SQL_C_INTERVAL_DAY_TO_HOUR:
     114             :         case SQL_C_INTERVAL_DAY_TO_MINUTE:
     115             :         case SQL_C_INTERVAL_DAY_TO_SECOND:
     116             :         case SQL_C_INTERVAL_HOUR_TO_MINUTE:
     117             :         case SQL_C_INTERVAL_HOUR_TO_SECOND:
     118             :         case SQL_C_INTERVAL_MINUTE_TO_SECOND:
     119             :         case SQL_C_GUID:
     120             :         case SQL_C_DEFAULT:
     121             :                 break;
     122           0 :         default:
     123             :                 /* Invalid application buffer type */
     124           0 :                 addStmtError(stmt, "HY003", NULL, 0);
     125           0 :                 return SQL_ERROR;
     126             :         }
     127             : 
     128          12 :         if (BufferLength < 0) {
     129             :                 /* Invalid string or buffer length */
     130           0 :                 addStmtError(stmt, "HY090", NULL, 0);
     131           0 :                 return SQL_ERROR;
     132             :         }
     133             : 
     134          12 :         desc = stmt->ApplRowDescr;
     135             : 
     136          12 :         if (TargetValuePtr == NULL && ColumnNumber == desc->sql_desc_count) {
     137           0 :                 int i = desc->sql_desc_count - 1;
     138             : 
     139           0 :                 while (i > 0 && desc->descRec[i].sql_desc_data_ptr == NULL)
     140           0 :                         i--;
     141           0 :                 setODBCDescRecCount(desc, i);
     142             :         } else {
     143             :                 ODBCDescRec *rec;
     144             :                 SQLRETURN rc;
     145             : 
     146          12 :                 if (ColumnNumber > desc->sql_desc_count)
     147          12 :                         setODBCDescRecCount(desc, ColumnNumber);
     148          12 :                 rc = MNDBSetDescField(desc, ColumnNumber, SQL_DESC_CONCISE_TYPE, (SQLPOINTER) (intptr_t) TargetType, 0);
     149          12 :                 if (!SQL_SUCCEEDED(rc))
     150             :                         return rc;
     151          12 :                 rec = &desc->descRec[ColumnNumber];
     152          12 :                 rec->sql_desc_octet_length = BufferLength;
     153          12 :                 rec->sql_desc_data_ptr = TargetValuePtr;
     154          12 :                 rec->sql_desc_indicator_ptr = StrLen_or_Ind;
     155          12 :                 rec->sql_desc_octet_length_ptr = StrLen_or_Ind;
     156             :         }
     157             : 
     158             :         return SQL_SUCCESS;
     159             : }

Generated by: LCOV version 1.14