LCOV - code coverage report
Current view: top level - clients/odbc/driver - SQLSetStmtAttr.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 149 0.0 %
Date: 2021-10-13 02:24:04 Functions: 0 1 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             :  * SQLSetStmtAttr()
      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
      33           0 : MNDBSetStmtAttr(ODBCStmt *stmt,
      34             :                 SQLINTEGER Attribute,
      35             :                 SQLPOINTER ValuePtr,
      36             :                 SQLINTEGER StringLength)
      37             : {
      38             :         /* TODO: check parameters: ValuePtr and StringLength */
      39             : 
      40           0 :         if (Attribute == SQL_ATTR_CONCURRENCY ||
      41           0 :             Attribute == SQL_ATTR_CURSOR_SCROLLABLE ||
      42           0 :             Attribute == SQL_ATTR_CURSOR_SENSITIVITY ||
      43           0 :             Attribute == SQL_ATTR_CURSOR_TYPE ||
      44             :             Attribute == SQL_ATTR_USE_BOOKMARKS) {
      45           0 :                 if (stmt->State >= EXECUTED0) {
      46             :                         /* Invalid cursor state */
      47           0 :                         addStmtError(stmt, "24000", NULL, 0);
      48           0 :                         return SQL_ERROR;
      49             :                 }
      50           0 :                 if (stmt->State > INITED) {
      51             :                         /* Attribute cannot be set now */
      52           0 :                         addStmtError(stmt, "HY011", NULL, 0);
      53           0 :                         return SQL_ERROR;
      54             :                 }
      55             :         }
      56             : 
      57           0 :         switch (Attribute) {
      58             : #define desc ((ODBCDesc *) ValuePtr)    /* abbrev. */
      59           0 :         case SQL_ATTR_APP_PARAM_DESC:           /* SQLHANDLE */
      60           0 :                 if (ValuePtr == SQL_NULL_HDESC ||
      61           0 :                     desc == stmt->AutoApplParamDescr) {
      62           0 :                         stmt->ApplParamDescr = stmt->AutoApplParamDescr;
      63           0 :                         return SQL_SUCCESS;
      64             :                 }
      65           0 :                 if (!isValidDesc(desc)) {
      66             :                         /* Invalid attribute value */
      67           0 :                         addStmtError(stmt, "HY024", NULL, 0);
      68           0 :                         return SQL_ERROR;
      69             :                 }
      70           0 :                 if (desc->sql_desc_alloc_type == SQL_DESC_ALLOC_AUTO) {
      71             :                         /* Invalid use of an automatically allocated
      72             :                            descriptor handle */
      73           0 :                         addStmtError(stmt, "HY017", NULL, 0);
      74           0 :                         return SQL_ERROR;
      75             :                 }
      76           0 :                 stmt->ApplParamDescr = desc;
      77           0 :                 break;
      78           0 :         case SQL_ATTR_APP_ROW_DESC:             /* SQLHANDLE */
      79           0 :                 if (ValuePtr == SQL_NULL_HDESC ||
      80           0 :                     desc == stmt->AutoApplRowDescr) {
      81           0 :                         stmt->ApplRowDescr = stmt->AutoApplRowDescr;
      82           0 :                         return SQL_SUCCESS;
      83             :                 }
      84           0 :                 if (!isValidDesc(desc)) {
      85             :                         /* Invalid attribute value */
      86           0 :                         addStmtError(stmt, "HY024", NULL, 0);
      87           0 :                         return SQL_ERROR;
      88             :                 }
      89           0 :                 if (desc->sql_desc_alloc_type == SQL_DESC_ALLOC_AUTO) {
      90             :                         /* Invalid use of an automatically allocated
      91             :                            descriptor handle */
      92           0 :                         addStmtError(stmt, "HY017", NULL, 0);
      93           0 :                         return SQL_ERROR;
      94             :                 }
      95           0 :                 stmt->ApplRowDescr = desc;
      96           0 :                 break;
      97             : #undef desc
      98           0 :         case SQL_ATTR_CURSOR_SCROLLABLE:        /* SQLULEN */
      99           0 :                 switch ((SQLULEN) (uintptr_t) ValuePtr) {
     100           0 :                 case SQL_NONSCROLLABLE:
     101           0 :                         stmt->cursorType = SQL_CURSOR_FORWARD_ONLY;
     102           0 :                         break;
     103           0 :                 case SQL_SCROLLABLE:
     104           0 :                         stmt->cursorType = SQL_CURSOR_STATIC;
     105           0 :                         break;
     106           0 :                 default:
     107             :                         /* Invalid attribute value */
     108           0 :                         addStmtError(stmt, "HY024", NULL, 0);
     109           0 :                         return SQL_ERROR;
     110             :                 }
     111           0 :                 stmt->cursorScrollable = (SQLULEN) (uintptr_t) ValuePtr;
     112           0 :                 break;
     113           0 :         case SQL_ATTR_CURSOR_TYPE:              /* SQLULEN */
     114           0 :                 switch ((SQLULEN) (uintptr_t) ValuePtr) {
     115           0 :                 case SQL_CURSOR_KEYSET_DRIVEN:
     116             :                 case SQL_CURSOR_DYNAMIC:
     117             :                         /* Option value changed */
     118           0 :                         addStmtError(stmt, "01S02", NULL, 0);
     119             : 
     120             :                         /* fall through */
     121           0 :                 case SQL_CURSOR_STATIC:
     122           0 :                         stmt->cursorScrollable = SQL_SCROLLABLE;
     123           0 :                         stmt->cursorType = SQL_CURSOR_STATIC;
     124           0 :                         break;
     125           0 :                 case SQL_CURSOR_FORWARD_ONLY:
     126           0 :                         stmt->cursorScrollable = SQL_NONSCROLLABLE;
     127           0 :                         stmt->cursorType = SQL_CURSOR_FORWARD_ONLY;
     128           0 :                         break;
     129           0 :                 default:
     130             :                         /* Invalid attribute value */
     131           0 :                         addStmtError(stmt, "HY024", NULL, 0);
     132           0 :                         return SQL_ERROR;
     133             :                 }
     134             :                 break;
     135           0 :         case SQL_ATTR_ENABLE_AUTO_IPD:          /* SQLULEN */
     136           0 :                 switch ((SQLULEN) (uintptr_t) ValuePtr) {
     137             :                 case SQL_TRUE:
     138             :                 case SQL_FALSE:
     139             :                         break;
     140           0 :                 default:
     141             :                         /* Invalid attribute value */
     142           0 :                         addStmtError(stmt, "HY024", NULL, 0);
     143           0 :                         return SQL_ERROR;
     144             :                 }
     145             :                 /* ignore value, always treat as SQL_TRUE */
     146             :                 break;
     147           0 :         case SQL_ATTR_IMP_PARAM_DESC:           /* SQLHANDLE */
     148             :         case SQL_ATTR_IMP_ROW_DESC:             /* SQLHANDLE */
     149             :                 /* Invalid use of an automatically allocated
     150             :                    descriptor handle */
     151           0 :                 addStmtError(stmt, "HY017", NULL, 0);
     152           0 :                 return SQL_ERROR;
     153           0 :         case SQL_ATTR_MAX_LENGTH:               /* SQLULEN */
     154             :         case SQL_ATTR_MAX_ROWS:                 /* SQLULEN */
     155           0 :                 if ((SQLULEN) (uintptr_t) ValuePtr != 0 &&
     156           0 :                     (SQLULEN) (uintptr_t) ValuePtr != 2147483647)
     157           0 :                         addStmtError(stmt, "01S02", NULL, 0);
     158             :                 break;
     159           0 :         case SQL_ATTR_NOSCAN:                   /* SQLULEN */
     160           0 :                 switch ((SQLULEN) (uintptr_t) ValuePtr) {
     161             :                 case SQL_NOSCAN_ON:
     162             :                 case SQL_NOSCAN_OFF:
     163             :                         break;
     164           0 :                 default:
     165             :                         /* Invalid attribute value */
     166           0 :                         addStmtError(stmt, "HY024", NULL, 0);
     167           0 :                         return SQL_ERROR;
     168             :                 }
     169           0 :                 stmt->noScan = (SQLULEN) (uintptr_t) ValuePtr;
     170           0 :                 break;
     171           0 :         case SQL_ATTR_PARAM_BIND_OFFSET_PTR:    /* SQLULEN* */
     172           0 :                 return MNDBSetDescField(stmt->ApplParamDescr, 0,
     173             :                                         SQL_DESC_BIND_OFFSET_PTR, ValuePtr,
     174             :                                         StringLength);
     175           0 :         case SQL_ATTR_PARAM_BIND_TYPE:          /* SQLULEN */
     176             :         {
     177           0 :                 SQLUINTEGER v = (SQLUINTEGER) (SQLULEN) (uintptr_t) ValuePtr;
     178           0 :                 return MNDBSetDescField(stmt->ApplParamDescr, 0,
     179             :                                         SQL_DESC_BIND_TYPE, (SQLPOINTER) (uintptr_t) v,
     180             :                                         StringLength);
     181             :         }
     182           0 :         case SQL_ATTR_PARAM_OPERATION_PTR:      /* SQLUSMALLINT* */
     183           0 :                 return MNDBSetDescField(stmt->ApplParamDescr, 0,
     184             :                                         SQL_DESC_ARRAY_STATUS_PTR, ValuePtr,
     185             :                                         StringLength);
     186           0 :         case SQL_ATTR_PARAM_STATUS_PTR:         /* SQLUSMALLINT* */
     187           0 :                 return MNDBSetDescField(stmt->ImplParamDescr, 0,
     188             :                                         SQL_DESC_ARRAY_STATUS_PTR, ValuePtr,
     189             :                                         StringLength);
     190           0 :         case SQL_ATTR_PARAMS_PROCESSED_PTR:     /* SQLULEN* */
     191           0 :                 return MNDBSetDescField(stmt->ImplParamDescr, 0,
     192             :                                         SQL_DESC_ROWS_PROCESSED_PTR, ValuePtr,
     193             :                                         StringLength);
     194           0 :         case SQL_ATTR_PARAMSET_SIZE:            /* SQLULEN */
     195           0 :                 return MNDBSetDescField(stmt->ApplParamDescr, 0,
     196             :                                         SQL_DESC_ARRAY_SIZE, ValuePtr,
     197             :                                         StringLength);
     198           0 :         case SQL_ATTR_QUERY_TIMEOUT:            /* SQLULEN */
     199           0 :                 if ((uintptr_t) ValuePtr > 0x7FFFFFFF) {
     200           0 :                         stmt->qtimeout = 0x7FFFFFFF;
     201           0 :                         addStmtError(stmt, "01S02", NULL, 0);
     202             :                 } else {
     203           0 :                         stmt->qtimeout = (SQLULEN) (uintptr_t) ValuePtr;
     204             :                 }
     205             :                 break;
     206           0 :         case SQL_ATTR_RETRIEVE_DATA:            /* SQLULEN */
     207           0 :                 switch ((SQLULEN) (uintptr_t) ValuePtr) {
     208             :                 case SQL_RD_ON:
     209             :                 case SQL_RD_OFF:
     210             :                         break;
     211           0 :                 default:
     212             :                         /* Invalid attribute value */
     213           0 :                         addStmtError(stmt, "HY024", NULL, 0);
     214           0 :                         return SQL_ERROR;
     215             :                 }
     216           0 :                 stmt->retrieveData = (SQLULEN) (uintptr_t) ValuePtr;
     217           0 :                 break;
     218           0 :         case SQL_ATTR_ROW_ARRAY_SIZE:           /* SQLULEN */
     219             :         case SQL_ROWSET_SIZE:
     220           0 :                 return MNDBSetDescField(stmt->ApplRowDescr, 0,
     221             :                                         SQL_DESC_ARRAY_SIZE, ValuePtr,
     222             :                                         StringLength);
     223           0 :         case SQL_ATTR_ROW_BIND_OFFSET_PTR:      /* SQLULEN* */
     224           0 :                 return MNDBSetDescField(stmt->ApplRowDescr, 0,
     225             :                                         SQL_DESC_BIND_OFFSET_PTR, ValuePtr,
     226             :                                         StringLength);
     227           0 :         case SQL_ATTR_ROW_BIND_TYPE:            /* SQLULEN */
     228           0 :                 return MNDBSetDescField(stmt->ApplRowDescr, 0,
     229             :                                         SQL_DESC_BIND_TYPE, ValuePtr,
     230             :                                         StringLength);
     231           0 :         case SQL_ATTR_ROW_OPERATION_PTR:        /* SQLUSMALLINT* */
     232           0 :                 return MNDBSetDescField(stmt->ApplRowDescr, 0,
     233             :                                         SQL_DESC_ARRAY_STATUS_PTR, ValuePtr,
     234             :                                         StringLength);
     235           0 :         case SQL_ATTR_ROW_STATUS_PTR:           /* SQLUSMALLINT* */
     236           0 :                 return MNDBSetDescField(stmt->ImplRowDescr, 0,
     237             :                                         SQL_DESC_ARRAY_STATUS_PTR, ValuePtr,
     238             :                                         StringLength);
     239           0 :         case SQL_ATTR_ROWS_FETCHED_PTR:         /* SQLULEN* */
     240           0 :                 return MNDBSetDescField(stmt->ImplRowDescr, 0,
     241             :                                         SQL_DESC_ROWS_PROCESSED_PTR, ValuePtr,
     242             :                                         StringLength);
     243           0 :         case SQL_ATTR_METADATA_ID:              /* SQLULEN */
     244           0 :                 switch ((SQLULEN) (uintptr_t) ValuePtr) {
     245             :                 case SQL_TRUE:
     246             :                 case SQL_FALSE:
     247             :                         break;
     248           0 :                 default:
     249             :                         /* Invalid attribute value */
     250           0 :                         addStmtError(stmt, "HY024", NULL, 0);
     251           0 :                         return SQL_ERROR;
     252             :                 }
     253           0 :                 stmt->Dbc->sql_attr_metadata_id = (SQLUINTEGER) (SQLULEN) (uintptr_t) ValuePtr;
     254           0 :                 break;
     255             : 
     256           0 :         case SQL_ATTR_CONCURRENCY:              /* SQLULEN */
     257           0 :                 switch ((SQLULEN) (uintptr_t) ValuePtr) {
     258             :                 case SQL_CONCUR_READ_ONLY:
     259             :                         /* the only value we support */
     260             :                         break;
     261           0 :                 case SQL_CONCUR_LOCK:
     262             :                 case SQL_CONCUR_ROWVER:
     263             :                 case SQL_CONCUR_VALUES:
     264             :                         /* Optional feature not implemented */
     265           0 :                         addStmtError(stmt, "HYC00", NULL, 0);
     266           0 :                         return SQL_ERROR;
     267             :                 }
     268             :                 break;
     269             : 
     270           0 :         case SQL_ATTR_ROW_NUMBER:            /* SQLULEN */
     271             :                 /* read-only attribute */
     272             :         default:
     273             :                 /* Invalid attribute/option identifier */
     274           0 :                 addStmtError(stmt, "HY092", NULL, 0);
     275           0 :                 return SQL_ERROR;
     276             : 
     277             :                 /* TODO: implement requested behavior */
     278           0 :         case SQL_ATTR_ASYNC_ENABLE:             /* SQLULEN */
     279             : #ifdef SQL_ATTR_ASYNC_STMT_EVENT
     280             :         case SQL_ATTR_ASYNC_STMT_EVENT:         /* SQLPOINTER */
     281             : #endif
     282             : #ifdef SQL_ATTR_ASYNC_STMT_PCALLBACK
     283             :         case SQL_ATTR_ASYNC_PCALLBACK:          /* SQLPOINTER */
     284             : #endif
     285             : #ifdef SQL_ATTR_ASYNC_STMT_PCONTEXT
     286             :         case SQL_ATTR_ASYNC_PCONTEXT:           /* SQLPOINTER */
     287             : #endif
     288             :         case SQL_ATTR_CURSOR_SENSITIVITY:       /* SQLULEN */
     289             :         case SQL_ATTR_FETCH_BOOKMARK_PTR:       /* SQLLEN* */
     290             :         case SQL_ATTR_KEYSET_SIZE:              /* SQLULEN */
     291             :         case SQL_ATTR_SIMULATE_CURSOR:          /* SQLULEN */
     292             :         case SQL_ATTR_USE_BOOKMARKS:            /* SQLULEN */
     293             :                 /* Optional feature not implemented */
     294           0 :                 addStmtError(stmt, "HYC00", NULL, 0);
     295           0 :                 return SQL_ERROR;
     296             :         }
     297             : 
     298           0 :         return stmt->Error ? SQL_SUCCESS_WITH_INFO : SQL_SUCCESS;
     299             : }
     300             : 
     301             : SQLRETURN SQL_API
     302             : SQLSetStmtAttr(SQLHSTMT StatementHandle,
     303             :                SQLINTEGER Attribute,
     304             :                SQLPOINTER ValuePtr,
     305             :                SQLINTEGER StringLength)
     306             : {
     307             : #ifdef ODBCDEBUG
     308           0 :         ODBCLOG("SQLSetStmtAttr %p %s %p %d\n",
     309             :                 StatementHandle, translateStmtAttribute(Attribute),
     310             :                 ValuePtr, (int) StringLength);
     311             : #endif
     312             : 
     313           0 :         if (!isValidStmt((ODBCStmt *) StatementHandle))
     314             :                 return SQL_INVALID_HANDLE;
     315             : 
     316           0 :         clearStmtErrors((ODBCStmt *) StatementHandle);
     317             : 
     318           0 :         return MNDBSetStmtAttr((ODBCStmt *) StatementHandle,
     319             :                                Attribute,
     320             :                                ValuePtr,
     321             :                                StringLength);
     322             : }
     323             : 
     324             : SQLRETURN SQL_API
     325             : SQLSetStmtAttrW(SQLHSTMT StatementHandle,
     326             :                 SQLINTEGER Attribute,
     327             :                 SQLPOINTER ValuePtr,
     328             :                 SQLINTEGER StringLength)
     329             : {
     330             : #ifdef ODBCDEBUG
     331           0 :         ODBCLOG("SQLSetStmtAttrW %p %s %p %d\n",
     332             :                 StatementHandle, translateStmtAttribute(Attribute),
     333             :                 ValuePtr, (int) StringLength);
     334             : #endif
     335             : 
     336           0 :         if (!isValidStmt((ODBCStmt *) StatementHandle))
     337             :                 return SQL_INVALID_HANDLE;
     338             : 
     339           0 :         clearStmtErrors((ODBCStmt *) StatementHandle);
     340             : 
     341             :         /* there are no string-valued attributes */
     342             : 
     343           0 :         return MNDBSetStmtAttr((ODBCStmt *) StatementHandle,
     344             :                                Attribute,
     345             :                                ValuePtr,
     346             :                                StringLength);
     347             : }

Generated by: LCOV version 1.14