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 : * 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 6 : ODBCDbc *dbc = (ODBCDbc *) ConnectionHandle; 40 : 41 : #ifdef ODBCDEBUG 42 6 : ODBCLOG("SQLDisconnect %p\n", ConnectionHandle); 43 : #endif 44 : 45 6 : if (!isValidDbc(dbc)) 46 : return SQL_INVALID_HANDLE; 47 : 48 6 : clearDbcErrors(dbc); 49 : 50 : /* check connection state, should be connected */ 51 6 : if (!dbc->Connected) { 52 : /* Connection does not exist */ 53 0 : addDbcError(dbc, "08003", NULL, 0); 54 0 : return SQL_ERROR; 55 : } 56 : 57 7 : while (dbc->FirstStmt != NULL) 58 1 : if (ODBCFreeStmt_(dbc->FirstStmt) == SQL_ERROR) 59 : return SQL_ERROR; 60 : 61 : /* client waves goodbye */ 62 6 : mapi_disconnect(dbc->mid); 63 6 : mapi_destroy(dbc->mid); 64 : 65 6 : dbc->mid = NULL; 66 6 : dbc->cachelimit = 0; 67 6 : dbc->Mdebug = 0; 68 6 : dbc->Connected = false; 69 6 : dbc->has_comment = false; 70 6 : dbc->raw_strings = false; 71 : 72 6 : return SQL_SUCCESS; 73 : }