LCOV - code coverage report
Current view: top level - clients/odbc/driver - SQLError.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 29 0.0 %
Date: 2021-10-13 02:24:04 Functions: 0 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             :  * SQLError()
      21             :  * CLI Compliance: deprecated in ODBC 3.0 (replaced by SQLGetDiagRec())
      22             :  * Provided here for old (pre ODBC 3.0) applications and driver managers.
      23             :  *
      24             :  * Author: Martin van Dinther, Sjoerd Mullender
      25             :  * Date  : 30 aug 2002
      26             :  *
      27             :  **********************************************************************/
      28             : 
      29             : #include "ODBCGlobal.h"
      30             : #include "ODBCEnv.h"
      31             : #include "ODBCDbc.h"
      32             : #include "ODBCStmt.h"
      33             : #include "ODBCUtil.h"
      34             : 
      35             : SQLRETURN SQL_API
      36             : SQLError(SQLHENV EnvironmentHandle,
      37             :          SQLHDBC ConnectionHandle,
      38             :          SQLHSTMT StatementHandle,
      39             :          SQLCHAR *SQLState,
      40             :          SQLINTEGER *NativeErrorPtr,
      41             :          SQLCHAR *MessageText,
      42             :          SQLSMALLINT BufferLength,
      43             :          SQLSMALLINT *TextLengthPtr)
      44             : {
      45             : #ifdef ODBCDEBUG
      46           0 :         ODBCLOG("SQLError %p %p %p\n", EnvironmentHandle, ConnectionHandle, StatementHandle);
      47             : #endif
      48             : 
      49             :         /* use mapping as described in ODBC 3 SDK Help file */
      50           0 :         if (StatementHandle)
      51           0 :                 return MNDBGetDiagRec(SQL_HANDLE_STMT,
      52             :                                       StatementHandle,
      53           0 :                                       ++((ODBCStmt *) StatementHandle)->RetrievedErrors,
      54             :                                       SQLState,
      55             :                                       NativeErrorPtr,
      56             :                                       MessageText,
      57             :                                       BufferLength,
      58             :                                       TextLengthPtr);
      59           0 :         else if (ConnectionHandle)
      60           0 :                 return MNDBGetDiagRec(SQL_HANDLE_DBC,
      61             :                                       ConnectionHandle,
      62           0 :                                       ++((ODBCDbc *) ConnectionHandle)->RetrievedErrors,
      63             :                                       SQLState,
      64             :                                       NativeErrorPtr,
      65             :                                       MessageText,
      66             :                                       BufferLength,
      67             :                                       TextLengthPtr);
      68           0 :         else if (EnvironmentHandle)
      69           0 :                 return MNDBGetDiagRec(SQL_HANDLE_ENV,
      70             :                                       EnvironmentHandle,
      71           0 :                                       ++((ODBCEnv *) EnvironmentHandle)->RetrievedErrors,
      72             :                                       SQLState,
      73             :                                       NativeErrorPtr,
      74             :                                       MessageText,
      75             :                                       BufferLength,
      76             :                                       TextLengthPtr);
      77             :         else
      78             :                 return SQL_ERROR;
      79             : }
      80             : 
      81             : SQLRETURN SQL_API
      82             : SQLErrorA(SQLHENV EnvironmentHandle,
      83             :           SQLHDBC ConnectionHandle,
      84             :           SQLHSTMT StatementHandle,
      85             :           SQLCHAR *SQLState,
      86             :           SQLINTEGER *NativeErrorPtr,
      87             :           SQLCHAR *MessageText,
      88             :           SQLSMALLINT BufferLength,
      89             :           SQLSMALLINT *TextLengthPtr)
      90             : {
      91           0 :         return SQLError(EnvironmentHandle,
      92             :                         ConnectionHandle,
      93             :                         StatementHandle,
      94             :                         SQLState,
      95             :                         NativeErrorPtr,
      96             :                         MessageText,
      97             :                         BufferLength,
      98             :                         TextLengthPtr);
      99             : }
     100             : 
     101             : SQLRETURN SQL_API
     102             : SQLErrorW(SQLHENV EnvironmentHandle,
     103             :           SQLHDBC ConnectionHandle,
     104             :           SQLHSTMT StatementHandle,
     105             :           SQLWCHAR *SQLState,
     106             :           SQLINTEGER *NativeErrorPtr,
     107             :           SQLWCHAR *MessageText,
     108             :           SQLSMALLINT BufferLength,
     109             :           SQLSMALLINT *TextLengthPtr)
     110             : {
     111             :         SQLCHAR state[6];
     112             :         SQLRETURN rc;
     113             :         SQLSMALLINT n;
     114             :         SQLCHAR errmsg[512];
     115             : 
     116             : #ifdef ODBCDEBUG
     117           0 :         ODBCLOG("SQLErrorW %p %p %p\n", EnvironmentHandle, ConnectionHandle, StatementHandle);
     118             : #endif
     119             : 
     120             :         /* use mapping as described in ODBC 3 SDK Help file */
     121           0 :         if (StatementHandle)
     122           0 :                 rc = MNDBGetDiagRec(SQL_HANDLE_STMT,
     123             :                                     StatementHandle,
     124           0 :                                     ((ODBCStmt *) StatementHandle)->RetrievedErrors,
     125             :                                     state, NativeErrorPtr,
     126             :                                     errmsg, (SQLSMALLINT) sizeof(errmsg), &n);
     127           0 :         else if (ConnectionHandle)
     128           0 :                 rc = MNDBGetDiagRec(SQL_HANDLE_DBC,
     129             :                                     ConnectionHandle,
     130           0 :                                     ((ODBCDbc *) ConnectionHandle)->RetrievedErrors,
     131             :                                     state, NativeErrorPtr,
     132             :                                     errmsg, (SQLSMALLINT) sizeof(errmsg), &n);
     133           0 :         else if (EnvironmentHandle)
     134           0 :                 rc = MNDBGetDiagRec(SQL_HANDLE_ENV,
     135             :                                     EnvironmentHandle,
     136           0 :                                     ((ODBCEnv *) EnvironmentHandle)->RetrievedErrors,
     137             :                                     state, NativeErrorPtr,
     138             :                                     errmsg, (SQLSMALLINT) sizeof(errmsg), &n);
     139             :         else
     140             :                 return SQL_ERROR;
     141             : 
     142           0 :         if (SQL_SUCCEEDED(rc)) {
     143           0 :                 const char *e = ODBCutf82wchar(state, 5, SQLState, 6, NULL,
     144             :                                                NULL);
     145             : 
     146           0 :                 if (e)
     147             :                         rc = SQL_ERROR;
     148             :         }
     149             : 
     150           0 :         if (SQL_SUCCEEDED(rc)) {
     151           0 :                 const char *e = ODBCutf82wchar(errmsg, n,
     152             :                                                MessageText, BufferLength, &n,
     153             :                                                NULL);
     154             : 
     155           0 :                 if (e)
     156             :                         rc = SQL_ERROR;
     157           0 :                 if (TextLengthPtr)
     158           0 :                         *TextLengthPtr = n;
     159             :         }
     160             : 
     161             :         return rc;
     162             : }

Generated by: LCOV version 1.14