LCOV - code coverage report
Current view: top level - clients/odbc/driver - SQLGetDescRec.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 55 0.0 %
Date: 2024-10-07 21:21:43 Functions: 0 1 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             :  * SQLGetDescRec()
      25             :  * CLI Compliance: ISO 92
      26             :  **********************************************************************/
      27             : 
      28             : #include "ODBCGlobal.h"
      29             : #include "ODBCStmt.h"
      30             : #include "ODBCUtil.h"
      31             : 
      32             : static SQLRETURN
      33           0 : MNDBGetDescRec(ODBCDesc *desc,
      34             :                SQLSMALLINT RecNumber,
      35             :                SQLCHAR *Name,
      36             :                SQLSMALLINT BufferLength,
      37             :                SQLSMALLINT *StringLengthPtr,
      38             :                SQLSMALLINT *TypePtr,
      39             :                SQLSMALLINT *SubTypePtr,
      40             :                SQLLEN *LengthPtr,
      41             :                SQLSMALLINT *PrecisionPtr,
      42             :                SQLSMALLINT *ScalePtr,
      43             :                SQLSMALLINT *NullablePtr)
      44             : {
      45           0 :         ODBCDescRec *rec;
      46             : 
      47           0 :         if (isIRD(desc)) {
      48           0 :                 if (desc->Stmt->State == INITED) {
      49             :                         /* Function sequence error */
      50           0 :                         addDescError(desc, "HY010", NULL, 0);
      51           0 :                         return SQL_ERROR;
      52             :                 }
      53           0 :                 if (desc->Stmt->State == EXECUTED0) {
      54             :                         /* Invalid cursor state */
      55           0 :                         addDescError(desc, "24000", NULL, 0);
      56           0 :                         return SQL_ERROR;
      57             :                 }
      58           0 :                 if (desc->Stmt->State == PREPARED0)
      59             :                         return SQL_NO_DATA;
      60             :         }
      61             : 
      62           0 :         if (RecNumber <= 0) {
      63             :                 /* Invalid descriptor index */
      64           0 :                 addDescError(desc, "07009", NULL, 0);
      65           0 :                 return SQL_ERROR;
      66             :         }
      67             : 
      68           0 :         if (RecNumber > desc->sql_desc_count)
      69             :                 return SQL_NO_DATA;
      70             : 
      71           0 :         rec = &desc->descRec[RecNumber];
      72             : 
      73           0 :         if (TypePtr)
      74           0 :                 *TypePtr = rec->sql_desc_type;
      75           0 :         if (SubTypePtr)
      76           0 :                 *SubTypePtr = rec->sql_desc_datetime_interval_code;
      77           0 :         if (LengthPtr)
      78           0 :                 *LengthPtr = rec->sql_desc_octet_length;
      79           0 :         if (PrecisionPtr)
      80           0 :                 *PrecisionPtr = rec->sql_desc_precision;
      81           0 :         if (ScalePtr)
      82           0 :                 *ScalePtr = rec->sql_desc_scale;
      83           0 :         if (NullablePtr && isID(desc))
      84           0 :                 *NullablePtr = rec->sql_desc_nullable;
      85             : 
      86           0 :         if (isID(desc)) {
      87           0 :                 copyString(rec->sql_desc_name,
      88             :                            strlen((char *) rec->sql_desc_name), Name,
      89             :                            BufferLength, StringLengthPtr, SQLSMALLINT,
      90             :                            addDescError, desc, return SQL_ERROR);
      91             :         }
      92             : 
      93           0 :         return desc->Error ? SQL_SUCCESS_WITH_INFO : SQL_SUCCESS;
      94             : }
      95             : 
      96             : SQLRETURN SQL_API
      97             : SQLGetDescRec(SQLHDESC DescriptorHandle,
      98             :               SQLSMALLINT RecNumber,
      99             :               SQLCHAR *Name,
     100             :               SQLSMALLINT BufferLength,
     101             :               SQLSMALLINT *StringLengthPtr,
     102             :               SQLSMALLINT *TypePtr,
     103             :               SQLSMALLINT *SubTypePtr,
     104             :               SQLLEN *LengthPtr,
     105             :               SQLSMALLINT *PrecisionPtr,
     106             :               SQLSMALLINT *ScalePtr,
     107             :               SQLSMALLINT *NullablePtr)
     108             : {
     109           0 :         ODBCDesc *desc = (ODBCDesc *) DescriptorHandle;
     110             : 
     111             : #ifdef ODBCDEBUG
     112           0 :         ODBCLOG("SQLGetDescRec %p %d %p %d %p %p %p %p %p %p %p\n",
     113             :                 DescriptorHandle, (int) RecNumber, Name,
     114             :                 (int) BufferLength, StringLengthPtr,
     115             :                 TypePtr, SubTypePtr,
     116             :                 LengthPtr, PrecisionPtr,
     117             :                 ScalePtr, NullablePtr);
     118             : #endif
     119             : 
     120           0 :         if (!isValidDesc(desc))
     121             :                 return SQL_INVALID_HANDLE;
     122             : 
     123           0 :         return MNDBGetDescRec(desc,
     124             :                               RecNumber,
     125             :                               Name,
     126             :                               BufferLength,
     127             :                               StringLengthPtr,
     128             :                               TypePtr,
     129             :                               SubTypePtr,
     130             :                               LengthPtr,
     131             :                               PrecisionPtr,
     132             :                               ScalePtr,
     133             :                               NullablePtr);
     134             : }
     135             : 
     136             : SQLRETURN SQL_API
     137             : SQLGetDescRecA(SQLHDESC DescriptorHandle,
     138             :                SQLSMALLINT RecNumber,
     139             :                SQLCHAR *Name,
     140             :                SQLSMALLINT BufferLength,
     141             :                SQLSMALLINT *StringLengthPtr,
     142             :                SQLSMALLINT *TypePtr,
     143             :                SQLSMALLINT *SubTypePtr,
     144             :                SQLLEN *LengthPtr,
     145             :                SQLSMALLINT *PrecisionPtr,
     146             :                SQLSMALLINT *ScalePtr,
     147             :                SQLSMALLINT *NullablePtr)
     148             : {
     149           0 :         return SQLGetDescRec(DescriptorHandle,
     150             :                              RecNumber,
     151             :                              Name,
     152             :                              BufferLength,
     153             :                              StringLengthPtr,
     154             :                              TypePtr,
     155             :                              SubTypePtr,
     156             :                              LengthPtr,
     157             :                              PrecisionPtr,
     158             :                              ScalePtr,
     159             :                              NullablePtr);
     160             : }
     161             : 
     162             : SQLRETURN SQL_API
     163             : SQLGetDescRecW(SQLHDESC DescriptorHandle,
     164             :                SQLSMALLINT RecNumber,
     165             :                SQLWCHAR *Name,
     166             :                SQLSMALLINT BufferLength,
     167             :                SQLSMALLINT *StringLengthPtr,
     168             :                SQLSMALLINT *TypePtr,
     169             :                SQLSMALLINT *SubTypePtr,
     170             :                SQLLEN *LengthPtr,
     171             :                SQLSMALLINT *PrecisionPtr,
     172             :                SQLSMALLINT *ScalePtr,
     173             :                SQLSMALLINT *NullablePtr)
     174             : {
     175           0 :         ODBCDesc *desc = (ODBCDesc *) DescriptorHandle;
     176           0 :         SQLRETURN rc;
     177           0 :         SQLCHAR *name;
     178           0 :         SQLSMALLINT n;
     179             : 
     180             : #ifdef ODBCDEBUG
     181           0 :         ODBCLOG("SQLGetDescRecW %p %d %p %d %p %p %p %p %p %p %p\n",
     182             :                 DescriptorHandle, (int) RecNumber, Name,
     183             :                 (int) BufferLength, StringLengthPtr,
     184             :                 TypePtr, SubTypePtr,
     185             :                 LengthPtr, PrecisionPtr,
     186             :                 ScalePtr, NullablePtr);
     187             : #endif
     188             : 
     189           0 :         if (!isValidDesc(desc))
     190             :                 return SQL_INVALID_HANDLE;
     191             : 
     192             :         /* dry run: figure out how much data we'll get */
     193           0 :         rc = MNDBGetDescRec(desc, RecNumber, NULL, 0, &n, TypePtr, SubTypePtr,
     194             :                             LengthPtr, PrecisionPtr, ScalePtr, NullablePtr);
     195             : 
     196             :         /* get the data */
     197           0 :         name = (SQLCHAR *) malloc(n + 1);
     198           0 :         if (name == NULL) {
     199             :                 /* Memory allocation error */
     200           0 :                 addDescError(desc, "HY001", NULL, 0);
     201           0 :                 return SQL_ERROR;
     202             :         }
     203           0 :         rc = MNDBGetDescRec(desc, RecNumber, name, n + 1, &n, TypePtr,
     204             :                             SubTypePtr, LengthPtr, PrecisionPtr, ScalePtr,
     205             :                             NullablePtr);
     206             : 
     207           0 :         if (SQL_SUCCEEDED(rc)) {
     208           0 :                 const char *e = ODBCutf82wchar(name, n, Name, BufferLength, &n,
     209             :                                                NULL);
     210             : 
     211           0 :                 if (e)
     212           0 :                         rc = SQL_ERROR;
     213           0 :                 if (StringLengthPtr)
     214           0 :                         *StringLengthPtr = n;
     215             :         }
     216           0 :         free(name);
     217             : 
     218           0 :         return rc;
     219             : }

Generated by: LCOV version 1.14