LCOV - code coverage report
Current view: top level - clients/odbc/driver - SQLSetPos.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 63 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             :  * SQLSetPos()
      21             :  * CLI Compliance: ODBC
      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             : #ifdef ODBCDEBUG
      32             : static char *
      33           0 : translateOperation(SQLUSMALLINT Operation)
      34             : {
      35           0 :         switch (Operation) {
      36             :         case SQL_POSITION:
      37             :                 return "SQL_POSITION";
      38           0 :         case SQL_REFRESH:
      39           0 :                 return "SQL_REFRESH";
      40           0 :         case SQL_UPDATE:
      41           0 :                 return "SQL_UPDATE";
      42           0 :         case SQL_DELETE:
      43           0 :                 return "SQL_DELETE";
      44           0 :         default:
      45           0 :                 return "unknown";
      46             :         }
      47             : }
      48             : 
      49             : static char *
      50             : translateLockType(SQLUSMALLINT LockType)
      51             : {
      52           0 :         switch (LockType) {
      53             :         case SQL_LOCK_NO_CHANGE:
      54             :                 return "SQL_LOCK_NO_CHANGE";
      55           0 :         case SQL_LOCK_EXCLUSIVE:
      56           0 :                 return "SQL_LOCK_EXCLUSIVE";
      57           0 :         case SQL_LOCK_UNLOCK:
      58           0 :                 return "SQL_LOCK_UNLOCK";
      59           0 :         default:
      60           0 :                 return "unknown";
      61             :         }
      62             : }
      63             : #endif
      64             : 
      65             : SQLRETURN SQL_API
      66             : SQLSetPos(SQLHSTMT StatementHandle,
      67             :           SQLSETPOSIROW RowNumber,
      68             :           SQLUSMALLINT Operation,
      69             :           SQLUSMALLINT LockType)
      70             : {
      71             :         ODBCStmt *stmt = (ODBCStmt *) StatementHandle;
      72             : 
      73             : #ifdef ODBCDEBUG
      74           0 :         ODBCLOG("SQLSetPos %p " ULENFMT " %s %s\n",
      75             :                 StatementHandle, ULENCAST RowNumber,
      76             :                 translateOperation(Operation), translateLockType(LockType));
      77             : #endif
      78             : 
      79           0 :         if (!isValidStmt(stmt))
      80             :                  return SQL_INVALID_HANDLE;
      81             : 
      82           0 :         clearStmtErrors(stmt);
      83             : 
      84             :         /* check the parameter values */
      85             : 
      86           0 :         if (stmt->State < EXECUTED0) {
      87             :                 /* Function sequence error */
      88           0 :                 addStmtError(stmt, "HY010", NULL, 0);
      89           0 :                 return SQL_ERROR;
      90             :         }
      91           0 :         if (stmt->State <= EXECUTED1) {
      92             :                 /* Invalid cursor state */
      93           0 :                 addStmtError(stmt, "24000", NULL, 0);
      94           0 :                 return SQL_ERROR;
      95             :         }
      96             : 
      97           0 :         if (RowNumber > (SQLSETPOSIROW) stmt->rowSetSize) {
      98             :                 /* Row value out of range */
      99           0 :                 addStmtError(stmt, "HY107", NULL, 0);
     100           0 :                 return SQL_ERROR;
     101             :         }
     102             : 
     103           0 :         if (stmt->cursorType == SQL_CURSOR_FORWARD_ONLY) {
     104             :                 /* Invalid cursor position */
     105           0 :                 addStmtError(stmt, "HY109", NULL, 0);
     106           0 :                 return SQL_ERROR;
     107             :         }
     108             : 
     109           0 :         switch (LockType) {
     110             :         case SQL_LOCK_NO_CHANGE:
     111             :                 /* the only value that we support */
     112             :                 break;
     113           0 :         case SQL_LOCK_EXCLUSIVE:
     114             :         case SQL_LOCK_UNLOCK:
     115             :                 /* Optional feature not implemented */
     116           0 :                 addStmtError(stmt, "HYC00", NULL, 0);
     117           0 :                 return SQL_ERROR;
     118           0 :         default:
     119             :                 /* Invalid attribute/option identifier */
     120           0 :                 addStmtError(stmt, "HY092", NULL, 0);
     121           0 :                 return SQL_ERROR;
     122             :         }
     123             : 
     124           0 :         switch (Operation) {
     125           0 :         case SQL_POSITION:
     126           0 :                 if (RowNumber == 0) {
     127             :                         /* Invalid cursor position */
     128           0 :                         addStmtError(stmt, "HY109", NULL, 0);
     129           0 :                         return SQL_ERROR;
     130             :                 }
     131           0 :                 if (mapi_seek_row(stmt->hdl, stmt->startRow + RowNumber - 1,
     132             :                                   MAPI_SEEK_SET) != MOK) {
     133             :                         /* Invalid cursor position */
     134           0 :                         addStmtError(stmt, "HY109", NULL, 0);
     135           0 :                         return SQL_ERROR;
     136             :                 }
     137           0 :                 stmt->currentRow = stmt->startRow + RowNumber - 1;
     138           0 :                 switch (mapi_fetch_row(stmt->hdl)) {
     139             :                 case MOK:
     140             :                         break;
     141           0 :                 case MTIMEOUT:
     142             :                         /* Connection timeout expired */
     143           0 :                         addStmtError(stmt, "HYT01", NULL, 0);
     144           0 :                         return SQL_ERROR;
     145           0 :                 default:
     146             :                         /* Invalid cursor position */
     147           0 :                         addStmtError(stmt, "HY109", NULL, 0);
     148           0 :                         return SQL_ERROR;
     149             :                 }
     150           0 :                 stmt->currentRow++;
     151             :                 break;
     152           0 :         case SQL_REFRESH:
     153             :         case SQL_UPDATE:
     154             :         case SQL_DELETE:
     155             :                 /* Optional feature not implemented */
     156           0 :                 addStmtError(stmt, "HYC00", NULL, 0);
     157           0 :                 return SQL_ERROR;
     158           0 :         default:
     159             :                 /* Invalid attribute/option identifier */
     160           0 :                 addStmtError(stmt, "HY092", NULL, 0);
     161           0 :                 return SQL_ERROR;
     162             :         }
     163             : 
     164           0 :         return SQL_SUCCESS;
     165             : }

Generated by: LCOV version 1.14