LCOV - code coverage report
Current view: top level - clients/odbc/driver - SQLNativeSql.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 36 0.0 %
Date: 2021-10-13 02:24:04 Functions: 0 1 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             :  * SQLNativeSql()
      21             :  * CLI Compliance: ODBC (Microsoft)
      22             :  *
      23             :  * Author: Martin van Dinther, Sjoerd Mullender
      24             :  * Date  : 30 aug 2002
      25             :  *
      26             :  **********************************************************************/
      27             : 
      28             : #include "ODBCGlobal.h"
      29             : #include "ODBCStmt.h"
      30             : #include "ODBCUtil.h"
      31             : 
      32             : static SQLRETURN
      33           0 : MNDBNativeSql(ODBCDbc *dbc,
      34             :               const SQLCHAR *InStatementText,
      35             :               SQLINTEGER TextLength1,
      36             :               SQLCHAR *OutStatementText,
      37             :               SQLINTEGER BufferLength,
      38             :               SQLINTEGER *TextLength2Ptr)
      39             : {
      40             :         char *query;
      41             : 
      42           0 :         fixODBCstring(InStatementText, TextLength1, SQLINTEGER,
      43             :                       addDbcError, dbc, return SQL_ERROR);
      44             : 
      45           0 :         if (InStatementText == NULL) {
      46             :                 /* Invalid use of null pointer */
      47           0 :                 addDbcError(dbc, "HY009", NULL, 0);
      48           0 :                 return SQL_ERROR;
      49             :         }
      50             : #ifdef ODBCDEBUG
      51           0 :         ODBCLOG("\"%.*s\"\n", (int) TextLength1, (char *) InStatementText);
      52             : #endif
      53             : 
      54           0 :         query = ODBCTranslateSQL(dbc, InStatementText, (size_t) TextLength1,
      55             :                                  SQL_NOSCAN_OFF);
      56           0 :         if (query == NULL) {
      57             :                 /* Memory allocation error */
      58           0 :                 addDbcError(dbc, "HY001", NULL, 0);
      59           0 :                 return SQL_ERROR;
      60             :         }
      61           0 :         copyString(query, strlen(query), OutStatementText, BufferLength,
      62             :                    TextLength2Ptr, SQLINTEGER, addDbcError, dbc,
      63             :                    free(query); return SQL_ERROR);
      64           0 :         free(query);
      65             : 
      66           0 :         return dbc->Error ? SQL_SUCCESS_WITH_INFO : SQL_SUCCESS;
      67             : }
      68             : 
      69             : SQLRETURN SQL_API
      70             : SQLNativeSql(SQLHDBC ConnectionHandle,
      71             :              SQLCHAR *InStatementText,
      72             :              SQLINTEGER TextLength1,
      73             :              SQLCHAR *OutStatementText,
      74             :              SQLINTEGER BufferLength,
      75             :              SQLINTEGER *TextLength2Ptr)
      76             : {
      77             :         ODBCDbc *dbc = (ODBCDbc *) ConnectionHandle;
      78             : 
      79             : #ifdef ODBCDEBUG
      80           0 :         ODBCLOG("SQLNativeSql %p ", ConnectionHandle);
      81             : #endif
      82             : 
      83           0 :         if (!isValidDbc(dbc))
      84             :                  return SQL_INVALID_HANDLE;
      85             : 
      86           0 :         clearDbcErrors(dbc);
      87             : 
      88           0 :         return MNDBNativeSql(dbc,
      89             :                              InStatementText,
      90             :                              TextLength1,
      91             :                              OutStatementText,
      92             :                              BufferLength,
      93             :                              TextLength2Ptr);
      94             : }
      95             : 
      96             : SQLRETURN SQL_API
      97             : SQLNativeSqlA(SQLHDBC ConnectionHandle,
      98             :               SQLCHAR *InStatementText,
      99             :               SQLINTEGER TextLength1,
     100             :               SQLCHAR *OutStatementText,
     101             :               SQLINTEGER BufferLength,
     102             :               SQLINTEGER *TextLength2Ptr)
     103             : {
     104           0 :         return SQLNativeSql(ConnectionHandle,
     105             :                             InStatementText,
     106             :                             TextLength1,
     107             :                             OutStatementText,
     108             :                             BufferLength,
     109             :                             TextLength2Ptr);
     110             : }
     111             : 
     112             : SQLRETURN SQL_API
     113             : SQLNativeSqlW(SQLHDBC ConnectionHandle,
     114             :               SQLWCHAR *InStatementText,
     115             :               SQLINTEGER TextLength1,
     116             :               SQLWCHAR *OutStatementText,
     117             :               SQLINTEGER BufferLength,
     118             :               SQLINTEGER *TextLength2Ptr)
     119             : {
     120             :         ODBCDbc *dbc = (ODBCDbc *) ConnectionHandle;
     121             :         SQLRETURN rc;
     122             :         SQLINTEGER n;
     123             :         SQLSMALLINT nn;
     124             :         SQLCHAR *sqlin, *sqlout;
     125             : 
     126             : #ifdef ODBCDEBUG
     127           0 :         ODBCLOG("SQLNativeSqlW %p ", ConnectionHandle);
     128             : #endif
     129             : 
     130           0 :         if (!isValidDbc(dbc))
     131             :                  return SQL_INVALID_HANDLE;
     132             : 
     133           0 :         clearDbcErrors(dbc);
     134             : 
     135           0 :         fixWcharIn(InStatementText, TextLength1, SQLCHAR, sqlin,
     136             :                    addDbcError, dbc, return SQL_ERROR);
     137             : 
     138           0 :         rc = MNDBNativeSql(dbc, sqlin, SQL_NTS, NULL, 0, &n);
     139           0 :         if (!SQL_SUCCEEDED(rc))
     140             :                 return rc;
     141           0 :         clearDbcErrors(dbc);
     142           0 :         n++;                    /* account for NUL byte */
     143           0 :         sqlout = malloc(n);
     144           0 :         if (sqlout == NULL) {
     145             :                 /* Memory allocation error */
     146           0 :                 addDbcError(dbc, "HY001", NULL, 0);
     147           0 :                 return SQL_ERROR;
     148             :         }
     149           0 :         rc = MNDBNativeSql(dbc, sqlin, SQL_NTS, sqlout, n, &n);
     150           0 :         nn = (SQLSMALLINT) n;
     151           0 :         if (SQL_SUCCEEDED(rc)) {
     152           0 :                 fixWcharOut(rc, sqlout, nn, OutStatementText, BufferLength,
     153             :                             TextLength2Ptr, 1, addDbcError, dbc);
     154             :         }
     155           0 :         free(sqlout);
     156             : 
     157           0 :         return rc;
     158             : }

Generated by: LCOV version 1.14