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

Generated by: LCOV version 1.14