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

Generated by: LCOV version 1.14