LCOV - code coverage report
Current view: top level - clients/odbc/driver - SQLGetDescField.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 170 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             :  * SQLGetDescField()
      21             :  * CLI Compliance: ISO 92
      22             :  **********************************************************************/
      23             : 
      24             : #include "ODBCGlobal.h"
      25             : #include "ODBCStmt.h"
      26             : #include "ODBCUtil.h"
      27             : 
      28             : SQLRETURN
      29           0 : MNDBGetDescField(ODBCDesc *desc,
      30             :                  SQLSMALLINT RecordNumber,
      31             :                  SQLSMALLINT FieldIdentifier,
      32             :                  SQLPOINTER ValuePtr,
      33             :                  SQLINTEGER BufferLength,
      34             :                  SQLINTEGER *StringLengthPtr)
      35             : {
      36             :         ODBCDescRec *rec;
      37             : 
      38           0 :         if (isIRD(desc)) {
      39           0 :                 if (desc->Stmt->State == INITED) {
      40             :                         /* Function sequence error */
      41           0 :                         addDescError(desc, "HY010", NULL, 0);
      42           0 :                         return SQL_ERROR;
      43             :                 }
      44           0 :                 if (desc->Stmt->State == EXECUTED0) {
      45             :                         /* Invalid cursor state */
      46           0 :                         addDescError(desc, "24000", NULL, 0);
      47           0 :                         return SQL_ERROR;
      48             :                 }
      49           0 :                 if (desc->Stmt->State == PREPARED0)
      50             :                         return SQL_NO_DATA;
      51             :         }
      52             : 
      53             :         /* header fields ignore RecordNumber */
      54           0 :         switch (FieldIdentifier) {
      55           0 :         case SQL_DESC_ALLOC_TYPE:               /* SQLSMALLINT */
      56           0 :                 WriteData(ValuePtr, desc->sql_desc_alloc_type, SQLSMALLINT);
      57             :                 return SQL_SUCCESS;
      58           0 :         case SQL_DESC_ARRAY_SIZE:               /* SQLULEN */
      59           0 :                 if (isAD(desc))
      60           0 :                         WriteData(ValuePtr, desc->sql_desc_array_size, SQLULEN);
      61             :                 return SQL_SUCCESS;
      62           0 :         case SQL_DESC_ARRAY_STATUS_PTR:         /* SQLUSMALLINT * */
      63           0 :                 WriteData(ValuePtr, desc->sql_desc_array_status_ptr, SQLUSMALLINT *);
      64             :                 return SQL_SUCCESS;
      65           0 :         case SQL_DESC_BIND_OFFSET_PTR:          /* SQLLEN * */
      66           0 :                 if (isAD(desc))
      67           0 :                         WriteData(ValuePtr, desc->sql_desc_bind_offset_ptr, SQLLEN *);
      68             :                 return SQL_SUCCESS;
      69           0 :         case SQL_DESC_BIND_TYPE:                /* SQLINTEGER */
      70           0 :                 if (isAD(desc))
      71           0 :                         WriteData(ValuePtr, desc->sql_desc_bind_type, SQLINTEGER);
      72             :                 return SQL_SUCCESS;
      73           0 :         case SQL_DESC_COUNT:                    /* SQLSMALLINT */
      74           0 :                 WriteData(ValuePtr, desc->sql_desc_count, SQLSMALLINT);
      75             :                 return SQL_SUCCESS;
      76           0 :         case SQL_DESC_ROWS_PROCESSED_PTR:       /* SQLULEN * */
      77           0 :                 if (desc->Stmt)
      78           0 :                         WriteData(ValuePtr, desc->sql_desc_rows_processed_ptr, SQLULEN *);
      79             :                 return SQL_SUCCESS;
      80             :         }
      81             : 
      82           0 :         if (RecordNumber <= 0) {
      83             :                 /* Invalid descriptor index */
      84           0 :                 addDescError(desc, "07009", NULL, 0);
      85           0 :                 return SQL_ERROR;
      86             :         }
      87           0 :         if (RecordNumber > desc->sql_desc_count)
      88             :                 return SQL_NO_DATA;
      89             : 
      90           0 :         rec = &desc->descRec[RecordNumber];
      91             : 
      92           0 :         switch (FieldIdentifier) {
      93           0 :         case SQL_DESC_AUTO_UNIQUE_VALUE:        /* SQLINTEGER */
      94           0 :                 if (isIRD(desc))
      95           0 :                         WriteData(ValuePtr, rec->sql_desc_auto_unique_value, SQLINTEGER);
      96             :                 return SQL_SUCCESS;
      97           0 :         case SQL_DESC_BASE_COLUMN_NAME:         /* SQLCHAR * */
      98           0 :                 if (isIRD(desc))
      99           0 :                         copyString(rec->sql_desc_base_column_name,
     100             :                                    strlen((char *) rec->sql_desc_base_column_name),
     101             :                                    ValuePtr, BufferLength, StringLengthPtr,
     102             :                                    SQLINTEGER, addDescError, desc,
     103             :                                    return SQL_ERROR);
     104           0 :                 return desc->Error ? SQL_SUCCESS_WITH_INFO : SQL_SUCCESS;
     105           0 :         case SQL_DESC_BASE_TABLE_NAME:          /* SQLCHAR * */
     106           0 :                 if (isIRD(desc))
     107           0 :                         copyString(rec->sql_desc_base_table_name,
     108             :                                    strlen((char *) rec->sql_desc_base_table_name),
     109             :                                    ValuePtr, BufferLength, StringLengthPtr,
     110             :                                    SQLINTEGER, addDescError, desc,
     111             :                                    return SQL_ERROR);
     112           0 :                 return desc->Error ? SQL_SUCCESS_WITH_INFO : SQL_SUCCESS;
     113           0 :         case SQL_DESC_CASE_SENSITIVE:           /* SQLINTEGER */
     114           0 :                 if (isID(desc))
     115           0 :                         WriteData(ValuePtr, rec->sql_desc_case_sensitive, SQLINTEGER);
     116             :                 return SQL_SUCCESS;
     117           0 :         case SQL_DESC_CATALOG_NAME:             /* SQLCHAR * */
     118           0 :                 if (isIRD(desc))
     119           0 :                         copyString(rec->sql_desc_catalog_name,
     120             :                                    strlen((char *) rec->sql_desc_catalog_name),
     121             :                                    ValuePtr, BufferLength, StringLengthPtr,
     122             :                                    SQLINTEGER, addDescError, desc,
     123             :                                    return SQL_ERROR);
     124           0 :                 return desc->Error ? SQL_SUCCESS_WITH_INFO : SQL_SUCCESS;
     125           0 :         case SQL_DESC_CONCISE_TYPE:             /* SQLSMALLINT */
     126           0 :                 WriteData(ValuePtr, rec->sql_desc_concise_type, SQLSMALLINT);
     127             :                 return SQL_SUCCESS;
     128           0 :         case SQL_DESC_DATA_PTR:                 /* SQLPOINTER */
     129             : #ifndef __COVERITY__
     130             :                 /* Coverity doesn't like the debug print in WriteData,
     131             :                  * so we hide this whole thing */
     132           0 :                 if (!isIRD(desc))
     133           0 :                         WriteData(ValuePtr, rec->sql_desc_data_ptr, SQLPOINTER);
     134             : #endif
     135             :                 return SQL_SUCCESS;
     136           0 :         case SQL_DESC_DATETIME_INTERVAL_CODE:   /* SQLSMALLINT */
     137           0 :                 WriteData(ValuePtr, rec->sql_desc_datetime_interval_code, SQLSMALLINT);
     138             :                 return SQL_SUCCESS;
     139           0 :         case SQL_DESC_DATETIME_INTERVAL_PRECISION: /* SQLINTEGER */
     140           0 :                 WriteData(ValuePtr, rec->sql_desc_datetime_interval_precision, SQLINTEGER);
     141             :                 return SQL_SUCCESS;
     142           0 :         case SQL_DESC_DISPLAY_SIZE:             /* SQLLEN */
     143           0 :                 if (isIRD(desc))
     144           0 :                         WriteData(ValuePtr, (SQLINTEGER) rec->sql_desc_display_size, SQLLEN);
     145             :                 return SQL_SUCCESS;
     146           0 :         case SQL_DESC_FIXED_PREC_SCALE:         /* SQLSMALLINT */
     147           0 :                 if (isID(desc))
     148           0 :                         WriteData(ValuePtr, rec->sql_desc_fixed_prec_scale, SQLSMALLINT);
     149             :                 return SQL_SUCCESS;
     150           0 :         case SQL_DESC_INDICATOR_PTR:            /* SQLLEN * */
     151           0 :                 if (isAD(desc))
     152           0 :                         WriteData(ValuePtr, rec->sql_desc_indicator_ptr, SQLLEN *);
     153             :                 return SQL_SUCCESS;
     154           0 :         case SQL_DESC_LABEL:                    /* SQLCHAR * */
     155           0 :                 if (isIRD(desc))
     156           0 :                         copyString(rec->sql_desc_label,
     157             :                                    strlen((char *) rec->sql_desc_label),
     158             :                                    ValuePtr, BufferLength, StringLengthPtr,
     159             :                                    SQLINTEGER, addDescError, desc,
     160             :                                    return SQL_ERROR);
     161           0 :                 return desc->Error ? SQL_SUCCESS_WITH_INFO : SQL_SUCCESS;
     162           0 :         case SQL_DESC_LENGTH:                   /* SQLULEN */
     163           0 :                 WriteData(ValuePtr, (SQLUINTEGER) rec->sql_desc_length, SQLULEN);
     164             :                 return SQL_SUCCESS;
     165           0 :         case SQL_DESC_LITERAL_PREFIX:           /* SQLCHAR * */
     166           0 :                 if (isIRD(desc))
     167           0 :                         copyString(rec->sql_desc_literal_prefix,
     168             :                                    strlen((char *) rec->sql_desc_literal_prefix),
     169             :                                    ValuePtr, BufferLength, StringLengthPtr,
     170             :                                    SQLINTEGER, addDescError, desc,
     171             :                                    return SQL_ERROR);
     172           0 :                 return desc->Error ? SQL_SUCCESS_WITH_INFO : SQL_SUCCESS;
     173           0 :         case SQL_DESC_LITERAL_SUFFIX:           /* SQLCHAR * */
     174           0 :                 if (isIRD(desc))
     175           0 :                         copyString(rec->sql_desc_literal_suffix,
     176             :                                    strlen((char *) rec->sql_desc_literal_suffix),
     177             :                                    ValuePtr, BufferLength, StringLengthPtr,
     178             :                                    SQLINTEGER, addDescError, desc,
     179             :                                    return SQL_ERROR);
     180           0 :                 return desc->Error ? SQL_SUCCESS_WITH_INFO : SQL_SUCCESS;
     181           0 :         case SQL_DESC_LOCAL_TYPE_NAME:          /* SQLCHAR * */
     182           0 :                 if (isID(desc))
     183           0 :                         copyString(rec->sql_desc_local_type_name,
     184             :                                    strlen((char *) rec->sql_desc_local_type_name),
     185             :                                    ValuePtr, BufferLength, StringLengthPtr,
     186             :                                    SQLINTEGER, addDescError, desc,
     187             :                                    return SQL_ERROR);
     188           0 :                 return desc->Error ? SQL_SUCCESS_WITH_INFO : SQL_SUCCESS;
     189           0 :         case SQL_DESC_NAME:                     /* SQLCHAR * */
     190           0 :                 if (isID(desc))
     191           0 :                         copyString(rec->sql_desc_name,
     192             :                                    strlen((char *) rec->sql_desc_name),
     193             :                                    ValuePtr, BufferLength, StringLengthPtr,
     194             :                                    SQLINTEGER, addDescError, desc,
     195             :                                    return SQL_ERROR);
     196           0 :                 return desc->Error ? SQL_SUCCESS_WITH_INFO : SQL_SUCCESS;
     197           0 :         case SQL_DESC_NULLABLE:                 /* SQLSMALLINT */
     198           0 :                 if (isID(desc))
     199           0 :                         WriteData(ValuePtr, rec->sql_desc_nullable, SQLSMALLINT);
     200             :                 return SQL_SUCCESS;
     201           0 :         case SQL_DESC_NUM_PREC_RADIX:           /* SQLINTEGER */
     202           0 :                 WriteData(ValuePtr, rec->sql_desc_num_prec_radix, SQLINTEGER);
     203             :                 return SQL_SUCCESS;
     204           0 :         case SQL_DESC_OCTET_LENGTH:             /* SQLLEN */
     205           0 :                 WriteData(ValuePtr, rec->sql_desc_octet_length, SQLLEN);
     206             :                 return SQL_SUCCESS;
     207           0 :         case SQL_DESC_OCTET_LENGTH_PTR:         /* SQLLEN * */
     208           0 :                 if (isAD(desc))
     209           0 :                         WriteData(ValuePtr, rec->sql_desc_octet_length_ptr, SQLLEN *);
     210             :                 return SQL_SUCCESS;
     211           0 :         case SQL_DESC_PARAMETER_TYPE:           /* SQLSMALLINT */
     212           0 :                 if (isIPD(desc))
     213           0 :                         WriteData(ValuePtr, rec->sql_desc_parameter_type, SQLSMALLINT);
     214             :                 return SQL_SUCCESS;
     215           0 :         case SQL_DESC_PRECISION:                /* SQLSMALLINT */
     216           0 :                 WriteData(ValuePtr, rec->sql_desc_precision, SQLSMALLINT);
     217             :                 return SQL_SUCCESS;
     218           0 :         case SQL_DESC_ROWVER:                   /* SQLSMALLINT */
     219           0 :                 if (isID(desc))
     220           0 :                         WriteData(ValuePtr, rec->sql_desc_rowver, SQLSMALLINT);
     221             :                 return SQL_SUCCESS;
     222           0 :         case SQL_DESC_SCALE:                    /* SQLSMALLINT */
     223           0 :                 WriteData(ValuePtr, rec->sql_desc_scale, SQLSMALLINT);
     224             :                 return SQL_SUCCESS;
     225           0 :         case SQL_DESC_SCHEMA_NAME:              /* SQLCHAR * */
     226           0 :                 if (isIRD(desc))
     227           0 :                         copyString(rec->sql_desc_schema_name,
     228             :                                    strlen((char *) rec->sql_desc_schema_name),
     229             :                                    ValuePtr, BufferLength, StringLengthPtr,
     230             :                                    SQLINTEGER, addDescError, desc,
     231             :                                    return SQL_ERROR);
     232           0 :                 return desc->Error ? SQL_SUCCESS_WITH_INFO : SQL_SUCCESS;
     233           0 :         case SQL_DESC_SEARCHABLE:               /* SQLSMALLINT */
     234           0 :                 if (isIRD(desc))
     235           0 :                         WriteData(ValuePtr, rec->sql_desc_searchable, SQLSMALLINT);
     236             :                 return SQL_SUCCESS;
     237           0 :         case SQL_DESC_TABLE_NAME:               /* SQLCHAR * */
     238           0 :                 if (isIRD(desc))
     239           0 :                         copyString(rec->sql_desc_table_name,
     240             :                                    strlen((char *) rec->sql_desc_table_name),
     241             :                                    ValuePtr, BufferLength, StringLengthPtr,
     242             :                                    SQLINTEGER, addDescError, desc,
     243             :                                    return SQL_ERROR);
     244           0 :                 return desc->Error ? SQL_SUCCESS_WITH_INFO : SQL_SUCCESS;
     245           0 :         case SQL_DESC_TYPE:                     /* SQLSMALLINT */
     246           0 :                 WriteData(ValuePtr, rec->sql_desc_type, SQLSMALLINT);
     247             :                 return SQL_SUCCESS;
     248           0 :         case SQL_DESC_TYPE_NAME:                /* SQLCHAR * */
     249           0 :                 if (isID(desc))
     250           0 :                         copyString(rec->sql_desc_type_name,
     251             :                                    strlen((char *) rec->sql_desc_type_name),
     252             :                                    ValuePtr, BufferLength, StringLengthPtr,
     253             :                                    SQLINTEGER, addDescError, desc,
     254             :                                    return SQL_ERROR);
     255           0 :                 return desc->Error ? SQL_SUCCESS_WITH_INFO : SQL_SUCCESS;
     256           0 :         case SQL_DESC_UNNAMED:                  /* SQLSMALLINT */
     257           0 :                 if (isID(desc))
     258           0 :                         WriteData(ValuePtr, rec->sql_desc_unnamed, SQLSMALLINT);
     259             :                 return SQL_SUCCESS;
     260           0 :         case SQL_DESC_UNSIGNED:                 /* SQLSMALLINT */
     261           0 :                 if (isID(desc))
     262           0 :                         WriteData(ValuePtr, rec->sql_desc_unsigned, SQLSMALLINT);
     263             :                 return SQL_SUCCESS;
     264           0 :         case SQL_DESC_UPDATABLE:                /* SQLSMALLINT */
     265           0 :                 if (isIRD(desc))
     266           0 :                         WriteData(ValuePtr, rec->sql_desc_updatable, SQLSMALLINT);
     267             :                 return SQL_SUCCESS;
     268             :         }
     269             : 
     270             :         /* Invalid descriptor field identifier */
     271           0 :         addDescError(desc, "HY091", NULL, 0);
     272           0 :         return SQL_ERROR;
     273             : }
     274             : 
     275             : SQLRETURN SQL_API
     276             : SQLGetDescField(SQLHDESC DescriptorHandle,
     277             :                 SQLSMALLINT RecordNumber,
     278             :                 SQLSMALLINT FieldIdentifier,
     279             :                 SQLPOINTER ValuePtr,
     280             :                 SQLINTEGER BufferLength,
     281             :                 SQLINTEGER *StringLengthPtr)
     282             : {
     283             : #ifdef ODBCDEBUG
     284           0 :         ODBCLOG("SQLGetDescField %p %d %s %p %d %p\n",
     285             :                 DescriptorHandle, (int) RecordNumber,
     286             :                 translateFieldIdentifier(FieldIdentifier),
     287             :                 ValuePtr, (int) BufferLength,
     288             :                 StringLengthPtr);
     289             : #endif
     290             : 
     291           0 :         if (!isValidDesc((ODBCDesc *) DescriptorHandle))
     292             :                 return SQL_INVALID_HANDLE;
     293           0 :         clearDescErrors((ODBCDesc *) DescriptorHandle);
     294             : 
     295           0 :         return MNDBGetDescField((ODBCDesc *) DescriptorHandle,
     296             :                                 RecordNumber,
     297             :                                 FieldIdentifier,
     298             :                                 ValuePtr,
     299             :                                 BufferLength,
     300             :                                 StringLengthPtr);
     301             : }
     302             : 
     303             : SQLRETURN SQL_API
     304             : SQLGetDescFieldA(SQLHDESC DescriptorHandle,
     305             :                  SQLSMALLINT RecordNumber,
     306             :                  SQLSMALLINT FieldIdentifier,
     307             :                  SQLPOINTER ValuePtr,
     308             :                  SQLINTEGER BufferLength,
     309             :                  SQLINTEGER *StringLengthPtr)
     310             : {
     311           0 :         return SQLGetDescField(DescriptorHandle,
     312             :                                RecordNumber,
     313             :                                FieldIdentifier,
     314             :                                ValuePtr,
     315             :                                BufferLength,
     316             :                                StringLengthPtr);
     317             : }
     318             : 
     319             : SQLRETURN SQL_API
     320             : SQLGetDescFieldW(SQLHDESC DescriptorHandle,
     321             :                  SQLSMALLINT RecordNumber,
     322             :                  SQLSMALLINT FieldIdentifier,
     323             :                  SQLPOINTER ValuePtr,
     324             :                  SQLINTEGER BufferLength,
     325             :                  SQLINTEGER *StringLengthPtr)
     326             : {
     327             :         ODBCDesc *desc = (ODBCDesc *) DescriptorHandle;
     328             :         SQLRETURN rc;
     329             :         SQLPOINTER ptr;
     330             :         SQLINTEGER n;
     331             : 
     332             : #ifdef ODBCDEBUG
     333           0 :         ODBCLOG("SQLGetDescFieldW %p %d %s %p %d %p\n",
     334             :                 DescriptorHandle, (int) RecordNumber,
     335             :                 translateFieldIdentifier(FieldIdentifier),
     336             :                 ValuePtr, (int) BufferLength,
     337             :                 StringLengthPtr);
     338             : #endif
     339             : 
     340           0 :         if (!isValidDesc(desc))
     341             :                 return SQL_INVALID_HANDLE;
     342           0 :         clearDescErrors(desc);
     343             : 
     344           0 :         switch (FieldIdentifier) {
     345             :         /* all string attributes */
     346           0 :         case SQL_DESC_BASE_COLUMN_NAME:
     347             :         case SQL_DESC_BASE_TABLE_NAME:
     348             :         case SQL_DESC_CATALOG_NAME:
     349             :         case SQL_DESC_LABEL:
     350             :         case SQL_DESC_LITERAL_PREFIX:
     351             :         case SQL_DESC_LITERAL_SUFFIX:
     352             :         case SQL_DESC_LOCAL_TYPE_NAME:
     353             :         case SQL_DESC_NAME:
     354             :         case SQL_DESC_SCHEMA_NAME:
     355             :         case SQL_DESC_TABLE_NAME:
     356             :         case SQL_DESC_TYPE_NAME:
     357           0 :                 ptr = (SQLPOINTER) malloc(BufferLength);
     358           0 :                 if (ptr == NULL) {
     359             :                         /* Memory allocation error */
     360           0 :                         addDescError(desc, "HY001", NULL, 0);
     361           0 :                         return SQL_ERROR;
     362             :                 }
     363             :                 break;
     364             :         default:
     365             :                 ptr = ValuePtr;
     366             :                 break;
     367             :         }
     368             : 
     369           0 :         rc = MNDBGetDescField(desc, RecordNumber, FieldIdentifier, ptr,
     370             :                               BufferLength, &n);
     371             : 
     372           0 :         if (ptr != ValuePtr) {
     373           0 :                 if (rc == SQL_SUCCESS_WITH_INFO) {
     374           0 :                         clearDescErrors(desc);
     375           0 :                         free(ptr);
     376           0 :                         ptr = malloc(++n); /* add one for NULL byte */
     377           0 :                         if (ptr == NULL) {
     378             :                                 /* Memory allocation error */
     379           0 :                                 addDescError(desc, "HY001", NULL, 0);
     380           0 :                                 return SQL_ERROR;
     381             :                         }
     382           0 :                         rc = MNDBGetDescField(desc, RecordNumber,
     383             :                                               FieldIdentifier, ptr, n, &n);
     384             :                 }
     385           0 :                 if (SQL_SUCCEEDED(rc)) {
     386           0 :                         SQLSMALLINT nn = (SQLSMALLINT) n;
     387             : 
     388           0 :                         fixWcharOut(rc, ptr, nn, ValuePtr, BufferLength,
     389             :                                     StringLengthPtr, 2, addDescError, desc);
     390             :                 }
     391           0 :                 free(ptr);
     392           0 :         } else if (StringLengthPtr)
     393           0 :                 *StringLengthPtr = n;
     394             : 
     395             :         return rc;
     396             : }

Generated by: LCOV version 1.14