LCOV - code coverage report
Current view: top level - clients/odbc/driver - ODBCGlobal.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 9 16 56.2 %
Date: 2024-10-07 21:21:43 Functions: 1 1 100.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             :  * ODBCGlobal.h
      25             :  *
      26             :  * Description:
      27             :  * The global MonetDB ODBC include file which
      28             :  * includes all needed external include files.
      29             :  *
      30             :  * Author: Martin van Dinther, Sjoerd Mullender
      31             :  * Date  : 30 aug 2002
      32             :  *
      33             :  **********************************************/
      34             : 
      35             : #ifndef _H_ODBCGLOBAL
      36             : #define _H_ODBCGLOBAL
      37             : 
      38             : #include "monetdb_config.h"
      39             : #include "mstring.h"
      40             : 
      41             : /**** Define the ODBC Version this ODBC driver complies with ****/
      42             : #define ODBCVER 0x0352          /* Important: this must be defined before include of sqlext.h */
      43             : 
      44             : /* some general defines */
      45             : #define MONETDB_ODBC_VER     "03.52"  /* must be synchronous with ODBCVER */
      46             : #define MONETDB_DRIVER_NAME  "MonetDBODBClib"
      47             : #define MONETDB_PRODUCT_NAME "MonetDB ODBC driver"
      48             : #define MONETDB_SERVER_NAME  "MonetDB"
      49             : 
      50             : #define ODBCDEBUG       1
      51             : 
      52             : /* standard ODBC driver include files */
      53             : #include <sqltypes.h>             /* ODBC C typedefs */
      54             : /* Note: sqlext.h includes sql.h so it is not needed here to be included */
      55             : /* Note2: if you include sql.h it will give an error because it will find
      56             :         src/sql/common/sql.h instead, which is not the one we need */
      57             : #include <sqlext.h>               /* ODBC API definitions and prototypes */
      58             : #include <sqlucode.h>             /* ODBC Unicode defs and prototypes */
      59             : 
      60             : /* standard ODBC driver installer & configurator include files */
      61             : #include <odbcinst.h>             /* ODBC installer definitions and prototypes */
      62             : 
      63             : /* standard C include files */
      64             : #include <string.h>               /* for strcpy() etc. */
      65             : #include <ctype.h>
      66             : 
      67             : #ifdef SQLLEN                   /* it's a define for 32, a typedef for 64 */
      68             : #define LENFMT          "%" PRId32
      69             : #define ULENFMT         "%" PRIu32
      70             : #define LENCAST         (int32_t)
      71             : #define ULENCAST        (uint32_t)
      72             : #else
      73             : #define LENFMT          "%" PRId64
      74             : #define ULENFMT         "%" PRIu64
      75             : #define LENCAST         (int64_t)
      76             : #define ULENCAST        (uint64_t)
      77             : #endif
      78             : 
      79             : #define SQL_HUGEINT     0x4000
      80             : 
      81             : /* these functions are called from within the library */
      82             : SQLRETURN MNDBAllocHandle(SQLSMALLINT nHandleType, SQLHANDLE nInputHandle, SQLHANDLE *pnOutputHandle);
      83             : SQLRETURN MNDBEndTran(SQLSMALLINT nHandleType, SQLHANDLE nHandle, SQLSMALLINT nCompletionType);
      84             : SQLRETURN MNDBFreeHandle(SQLSMALLINT handleType, SQLHANDLE handle);
      85             : SQLRETURN MNDBGetDiagRec(SQLSMALLINT handleType, SQLHANDLE handle, SQLSMALLINT recNumber, SQLCHAR *sqlState, SQLINTEGER *nativeErrorPtr, SQLCHAR *messageText, SQLSMALLINT bufferLength, SQLSMALLINT *textLengthPtr);
      86             : 
      87             : #ifdef ODBCDEBUG
      88             : #ifdef NATIVE_WIN32
      89             : extern const wchar_t *ODBCdebug;
      90             : #else
      91             : extern const char *ODBCdebug;
      92             : #endif
      93             : 
      94             : extern void setODBCdebug(const char *filename, bool overrideEnvVar);
      95             : 
      96             : static inline void ODBCLOG(_In_z_ _Printf_format_string_ const char *fmt, ...)
      97             :         __attribute__((__format__(__printf__, 1, 2)));
      98             : 
      99             : static inline void
     100       33960 : ODBCLOG(const char *fmt, ...)
     101             : {
     102       33960 :         va_list ap;
     103             : 
     104       33960 :         va_start(ap, fmt);
     105       33960 :         if (ODBCdebug == NULL) {
     106             : #ifdef NATIVE_WIN32
     107             :                 if ((ODBCdebug = _wgetenv(L"ODBCDEBUG")) == NULL)
     108             :                         ODBCdebug = _wcsdup(L"");
     109             :                 else
     110             :                         ODBCdebug = _wcsdup(ODBCdebug);
     111             : #else
     112          40 :                 if ((ODBCdebug = getenv("ODBCDEBUG")) == NULL)
     113          40 :                         ODBCdebug = strdup("");
     114             :                 else
     115           0 :                         ODBCdebug = strdup(ODBCdebug);
     116             : #endif
     117             :         }
     118       33960 :         if (ODBCdebug != NULL && *ODBCdebug != 0) {
     119           0 :                 FILE *f;
     120             : 
     121             : #ifdef NATIVE_WIN32
     122             :                 f = _wfopen(ODBCdebug, L"a");
     123             : #else
     124           0 :                 f = fopen(ODBCdebug, "a");
     125             : #endif
     126           0 :                 if (f) {
     127           0 :                         vfprintf(f, fmt, ap);
     128           0 :                         fclose(f);
     129             :                 } else
     130           0 :                         vfprintf(stderr, fmt, ap);
     131             :         }
     132       33960 :         va_end(ap);
     133       33960 : }
     134             : 
     135             : 
     136             : char *translateCType(SQLSMALLINT ValueType);
     137             : char *translateSQLType(SQLSMALLINT ParameterType);
     138             : char *translateFieldIdentifier(SQLSMALLINT FieldIdentifier);
     139             : char *translateFetchOrientation(SQLUSMALLINT FetchOrientation);
     140             : char *translateConnectAttribute(SQLINTEGER Attribute);
     141             : char *translateConnectOption(SQLUSMALLINT Option);
     142             : char *translateEnvAttribute(SQLINTEGER Attribute);
     143             : char *translateStmtAttribute(SQLINTEGER Attribute);
     144             : char *translateStmtOption(SQLUSMALLINT Option);
     145             : char *translateCompletionType(SQLSMALLINT CompletionType);
     146             : #endif
     147             : 
     148             : #endif

Generated by: LCOV version 1.14