LCOV - code coverage report
Current view: top level - clients/odbc/driver - SQLFreeStmt.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 18 38 47.4 %
Date: 2021-10-13 02:24:04 Functions: 1 2 50.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             :  * SQLFreeStmt()
      21             :  * CLI Compliance: ISO 92
      22             :  *
      23             :  * Note: the option SQL_DROP is deprecated in ODBC 3.0 and replaced by
      24             :  * SQLFreeHandle(). It is provided here for old (pre ODBC 3.0) applications.
      25             :  *
      26             :  * Author: Martin van Dinther, Sjoerd Mullender
      27             :  * Date  : 30 Aug 2002
      28             :  *
      29             :  **********************************************************************/
      30             : 
      31             : #include "ODBCGlobal.h"
      32             : #include "ODBCStmt.h"
      33             : 
      34             : SQLRETURN
      35          14 : MNDBFreeStmt(ODBCStmt *stmt,
      36             :              SQLUSMALLINT Option)
      37             : {
      38          14 :         switch (Option) {
      39          13 :         case SQL_CLOSE:
      40             :                 /* Note: this option is also called from SQLCancel()
      41             :                  * and SQLCloseCursor(), so be careful when changing
      42             :                  * the code */
      43             :                 /* close cursor, discard result set, set to prepared */
      44          13 :                 setODBCDescRecCount(stmt->ImplRowDescr, 0);
      45          13 :                 stmt->currentRow = 0;
      46          13 :                 stmt->startRow = 0;
      47          13 :                 stmt->rowSetSize = 0;
      48             : 
      49          13 :                 if (stmt->State == EXECUTED0)
      50           4 :                         stmt->State = stmt->queryid >= 0 ? PREPARED0 : INITED;
      51           9 :                 else if (stmt->State >= EXECUTED1)
      52           4 :                         stmt->State = stmt->queryid >= 0 ? PREPARED1 : INITED;
      53             : 
      54             :                 /* Important: do not destroy the bind parameters and columns! */
      55             :                 return SQL_SUCCESS;
      56           0 :         case SQL_DROP:
      57           0 :                 return ODBCFreeStmt_(stmt);
      58           1 :         case SQL_UNBIND:
      59           1 :                 setODBCDescRecCount(stmt->ApplRowDescr, 0);
      60           1 :                 return SQL_SUCCESS;
      61           0 :         case SQL_RESET_PARAMS:
      62           0 :                 setODBCDescRecCount(stmt->ApplParamDescr, 0);
      63           0 :                 setODBCDescRecCount(stmt->ImplParamDescr, 0);
      64           0 :                 mapi_clear_params(stmt->hdl);
      65           0 :                 return SQL_SUCCESS;
      66           0 :         default:
      67             :                 /* Invalid attribute/option identifier */
      68           0 :                 addStmtError(stmt, "HY092", NULL, 0);
      69           0 :                 return SQL_ERROR;
      70             :         }
      71             : 
      72             :         /* not reached */
      73             : }
      74             : 
      75             : #ifdef ODBCDEBUG
      76             : static char *
      77           0 : translateOption(SQLUSMALLINT Option)
      78             : {
      79           0 :         switch (Option) {
      80             :         case SQL_CLOSE:
      81             :                 return "SQL_CLOSE";
      82           0 :         case SQL_DROP:
      83           0 :                 return "SQL_DROP";
      84           0 :         case SQL_UNBIND:
      85           0 :                 return "SQL_UNBIND";
      86           0 :         case SQL_RESET_PARAMS:
      87           0 :                 return "SQL_RESET_PARAMS";
      88           0 :         default:
      89           0 :                 return "unknown";
      90             :         }
      91             : }
      92             : #endif
      93             : 
      94             : SQLRETURN SQL_API
      95             : SQLFreeStmt(SQLHSTMT StatementHandle,
      96             :             SQLUSMALLINT Option)
      97             : {
      98             : #ifdef ODBCDEBUG
      99           1 :         ODBCLOG("SQLFreeStmt %p %s\n",
     100             :                 StatementHandle, translateOption(Option));
     101             : #endif
     102             : 
     103           1 :         if (!isValidStmt((ODBCStmt *) StatementHandle))
     104             :                 return SQL_INVALID_HANDLE;
     105             : 
     106           1 :         clearStmtErrors((ODBCStmt *) StatementHandle);
     107             : 
     108           1 :         return MNDBFreeStmt((ODBCStmt *) StatementHandle, Option);
     109             : }

Generated by: LCOV version 1.14