LCOV - code coverage report
Current view: top level - clients/odbc/driver - SQLDisconnect.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 22 22 100.0 %
Date: 2024-11-14 20:04:02 Functions: 0 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 (that's 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             :  * SQLDisconnect
      25             :  * CLI Compliance: ISO 92
      26             :  *
      27             :  * Author: Martin van Dinther, Sjoerd Mullender
      28             :  * Date  : 30 aug 2002
      29             :  *
      30             :  **********************************************************************/
      31             : 
      32             : #include "ODBCGlobal.h"
      33             : #include "ODBCDbc.h"
      34             : #include "ODBCStmt.h"
      35             : 
      36             : SQLRETURN SQL_API
      37             : SQLDisconnect(SQLHDBC ConnectionHandle)
      38             : {
      39          34 :         ODBCDbc *dbc = (ODBCDbc *) ConnectionHandle;
      40             : 
      41             : #ifdef ODBCDEBUG
      42          34 :         ODBCLOG("SQLDisconnect %p\n", ConnectionHandle);
      43             : #endif
      44             : 
      45          34 :         if (!isValidDbc(dbc))
      46             :                 return SQL_INVALID_HANDLE;
      47             : 
      48          34 :         clearDbcErrors(dbc);
      49             : 
      50             :         /* check connection state, should be connected */
      51          34 :         if (!dbc->Connected) {
      52             :                 /* Connection does not exist */
      53           2 :                 addDbcError(dbc, "08003", NULL, 0);
      54           2 :                 return SQL_ERROR;
      55             :         }
      56             : 
      57          33 :         while (dbc->FirstStmt != NULL)
      58           1 :                 if (ODBCFreeStmt_(dbc->FirstStmt) == SQL_ERROR)
      59             :                         return SQL_ERROR;
      60             : 
      61             :         /* client waves goodbye */
      62          32 :         mapi_disconnect(dbc->mid);
      63          32 :         mapi_destroy(dbc->mid);
      64             : 
      65          32 :         dbc->mid = NULL;
      66          32 :         dbc->Connected = false;
      67          32 :         msettings_reset(dbc->settings);
      68          32 :         memset(dbc->setting_touched, 0, sizeof(dbc->setting_touched));
      69          32 :         dbc->cachelimit = 0;
      70          32 :         dbc->Mdebug = 0;
      71          32 :         dbc->has_comment = false;
      72          32 :         dbc->raw_strings = false;
      73          32 :         free(dbc->dsn);
      74          32 :         dbc->dsn = NULL;
      75             : 
      76          32 :         return SQL_SUCCESS;
      77             : }

Generated by: LCOV version 1.14