LCOV - code coverage report
Current view: top level - clients/odbc/driver - SQLColAttributes.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 37 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             :  * SQLColAttributes()
      21             :  * CLI Compliance: deprecated in ODBC 3.0 (replaced by SQLColAttribute())
      22             :  * Provided here for old (pre ODBC 3.0) applications and driver managers.
      23             :  **********************************************************************/
      24             : 
      25             : #include "ODBCGlobal.h"
      26             : #include "ODBCStmt.h"
      27             : #include "ODBCUtil.h"
      28             : 
      29             : static SQLRETURN
      30           0 : MNDBColAttributes(ODBCStmt *stmt,
      31             :                   SQLUSMALLINT ColumnNumber,
      32             :                   SQLUSMALLINT FieldIdentifier,
      33             :                   SQLPOINTER CharacterAttributePtr,
      34             :                   SQLSMALLINT BufferLength,
      35             :                   SQLSMALLINT *StringLengthPtr,
      36             :                   SQLLEN *NumericAttributePtr)
      37             : {
      38             :         SQLRETURN rc;
      39             :         SQLLEN value;
      40             : 
      41             :         /* use mapping as described in ODBC 3 SDK Help file */
      42           0 :         switch (FieldIdentifier) {
      43             :         case SQL_COLUMN_AUTO_INCREMENT: /* SQL_DESC_AUTO_UNIQUE_VALUE */
      44             :         case SQL_COLUMN_CASE_SENSITIVE: /* SQL_DESC_CASE_SENSITIVE */
      45             :         case SQL_COLUMN_COUNT:
      46             :         case SQL_COLUMN_DISPLAY_SIZE:   /* SQL_DESC_DISPLAY_SIZE */
      47             :         case SQL_COLUMN_LABEL:          /* SQL_DESC_LABEL */
      48             :         case SQL_COLUMN_LENGTH:
      49             :         case SQL_COLUMN_MONEY:          /* SQL_DESC_FIXED_PREC_SCALE */
      50             :         case SQL_COLUMN_NAME:
      51             :         case SQL_COLUMN_NULLABLE:
      52             :                 /* SQL_COLUMN_NULLABLE should be translated to
      53             :                  * SQL_DESC_NULLABLE, except in the 64 bit
      54             :                  * documentation, the former isn't mentioned as
      55             :                  * returning a 64 bit value whereas the latter is.
      56             :                  * Hence we don't translate but return differently
      57             :                  * sized values for the two */
      58             :         case SQL_COLUMN_OWNER_NAME:     /* SQL_DESC_SCHEMA_NAME */
      59             :         case SQL_COLUMN_PRECISION:
      60             :         case SQL_COLUMN_QUALIFIER_NAME: /* SQL_DESC_CATALOG_NAME */
      61             :         case SQL_COLUMN_SCALE:
      62             :         case SQL_COLUMN_SEARCHABLE:     /* SQL_DESC_SEARCHABLE */
      63             :         case SQL_COLUMN_TABLE_NAME:     /* SQL_DESC_TABLE_NAME */
      64             :         case SQL_COLUMN_TYPE:           /* SQL_DESC_CONCISE_TYPE */
      65             :         case SQL_COLUMN_TYPE_NAME:      /* SQL_DESC_TYPE_NAME */
      66             :         case SQL_COLUMN_UNSIGNED:       /* SQL_DESC_UNSIGNED */
      67             :         case SQL_COLUMN_UPDATABLE:      /* SQL_DESC_UPDATABLE */
      68             :                 break;
      69           0 :         default:
      70             :                 /* Invalid descriptor field identifier */
      71           0 :                 addStmtError(stmt, "HY091", NULL, 0);
      72           0 :                 return SQL_ERROR;
      73             :         }
      74           0 :         rc = MNDBColAttribute(stmt, ColumnNumber, FieldIdentifier, CharacterAttributePtr, BufferLength, StringLengthPtr, &value);
      75             : 
      76             :         /* TODO: implement special semantics for FieldIdentifiers:
      77             :          * SQL_COLUMN_TYPE, SQL_COLUMN_NAME, SQL_COLUMN_NULLABLE and
      78             :          * SQL_COLUMN_COUNT.  See ODBC 3 SDK Help file,
      79             :          * SQLColAttributes Mapping. */
      80             : /*
      81             :         if (FieldIdentifier == SQL_COLUMN_TYPE && value == concise datetime type) {
      82             :                 map return value for date, time, and timestamp codes;
      83             :         }
      84             : */
      85           0 :         if (NumericAttributePtr)
      86           0 :                 *NumericAttributePtr = value;
      87             :         return rc;
      88             : }
      89             : 
      90             : SQLRETURN SQL_API
      91             : SQLColAttributes(SQLHSTMT StatementHandle,
      92             :                  SQLUSMALLINT ColumnNumber,
      93             :                  SQLUSMALLINT FieldIdentifier,
      94             :                  SQLPOINTER CharacterAttributePtr,
      95             :                  SQLSMALLINT BufferLength,
      96             :                  SQLSMALLINT *StringLengthPtr,
      97             :                  SQLLEN *NumericAttributePtr)
      98             : {
      99             :         ODBCStmt *stmt = (ODBCStmt *) StatementHandle;
     100             : 
     101             : #ifdef ODBCDEBUG
     102           0 :         ODBCLOG("SQLColAttributes %p %u %s %p %d %p %p\n",
     103             :                 StatementHandle,
     104             :                 (unsigned int) ColumnNumber,
     105             :                 translateFieldIdentifier(FieldIdentifier),
     106             :                 CharacterAttributePtr, (int) BufferLength,
     107             :                 StringLengthPtr, NumericAttributePtr);
     108             : #endif
     109             : 
     110           0 :         if (!isValidStmt(stmt))
     111             :                  return SQL_INVALID_HANDLE;
     112             : 
     113           0 :         clearStmtErrors(stmt);
     114             : 
     115           0 :         return MNDBColAttributes(stmt,
     116             :                                  ColumnNumber,
     117             :                                  FieldIdentifier,
     118             :                                  CharacterAttributePtr,
     119             :                                  BufferLength,
     120             :                                  StringLengthPtr,
     121             :                                  NumericAttributePtr);
     122             : }
     123             : 
     124             : SQLRETURN SQL_API
     125             : SQLColAttributesA(SQLHSTMT StatementHandle,
     126             :                   SQLUSMALLINT ColumnNumber,
     127             :                   SQLUSMALLINT FieldIdentifier,
     128             :                   SQLPOINTER CharacterAttributePtr,
     129             :                   SQLSMALLINT BufferLength,
     130             :                   SQLSMALLINT *StringLengthPtr,
     131             :                   SQLLEN *NumericAttributePtr)
     132             : {
     133           0 :         return SQLColAttributes(StatementHandle,
     134             :                                 ColumnNumber,
     135             :                                 FieldIdentifier,
     136             :                                 CharacterAttributePtr,
     137             :                                 BufferLength,
     138             :                                 StringLengthPtr,
     139             :                                 NumericAttributePtr);
     140             : }
     141             : 
     142             : SQLRETURN SQL_API
     143             : SQLColAttributesW(SQLHSTMT StatementHandle,
     144             :                   SQLUSMALLINT ColumnNumber,
     145             :                   SQLUSMALLINT FieldIdentifier,
     146             :                   SQLPOINTER CharacterAttributePtr,
     147             :                   SQLSMALLINT BufferLength,
     148             :                   SQLSMALLINT *StringLengthPtr,
     149             :                   SQLLEN *NumericAttributePtr)
     150             : {
     151             :         ODBCStmt *stmt = (ODBCStmt *) StatementHandle;
     152             :         SQLPOINTER ptr;
     153             :         SQLRETURN rc;
     154             :         SQLSMALLINT n;
     155             : 
     156             : #ifdef ODBCDEBUG
     157           0 :         ODBCLOG("SQLColAttributesW %p %u %s %p %d %p %p\n",
     158             :                 StatementHandle,
     159             :                 (unsigned int) ColumnNumber,
     160             :                 translateFieldIdentifier(FieldIdentifier),
     161             :                 CharacterAttributePtr, (int) BufferLength,
     162             :                 StringLengthPtr, NumericAttributePtr);
     163             : #endif
     164             : 
     165           0 :         if (!isValidStmt(stmt))
     166             :                  return SQL_INVALID_HANDLE;
     167             : 
     168           0 :         clearStmtErrors(stmt);
     169             : 
     170           0 :         switch (FieldIdentifier) {
     171             :         /* all string atributes */
     172           0 :         case SQL_DESC_BASE_COLUMN_NAME:
     173             :         case SQL_DESC_BASE_TABLE_NAME:
     174             :         case SQL_DESC_CATALOG_NAME:     /* SQL_COLUMN_QUALIFIER_NAME */
     175             :         case SQL_DESC_LABEL:            /* SQL_COLUMN_LABEL */
     176             :         case SQL_DESC_LITERAL_PREFIX:
     177             :         case SQL_DESC_LITERAL_SUFFIX:
     178             :         case SQL_DESC_LOCAL_TYPE_NAME:
     179             :         case SQL_DESC_NAME:
     180             :         case SQL_DESC_SCHEMA_NAME:      /* SQL_COLUMN_OWNER_NAME */
     181             :         case SQL_DESC_TABLE_NAME:       /* SQL_COLUMN_TABLE_NAME */
     182             :         case SQL_DESC_TYPE_NAME:        /* SQL_COLUMN_TYPE_NAME */
     183           0 :                 ptr = malloc(BufferLength);
     184           0 :                 if (ptr == NULL) {
     185             :                         /* Memory allocation error */
     186           0 :                         addStmtError(stmt, "HY001", NULL, 0);
     187           0 :                         return SQL_ERROR;
     188             :                 }
     189             :                 break;
     190             :         default:
     191             :                 ptr = CharacterAttributePtr;
     192             :                 break;
     193             :         }
     194             : 
     195           0 :         rc = MNDBColAttributes(stmt, ColumnNumber, FieldIdentifier, ptr,
     196             :                                BufferLength, &n, NumericAttributePtr);
     197             : 
     198           0 :         if (ptr != CharacterAttributePtr) {
     199           0 :                 if (rc == SQL_SUCCESS_WITH_INFO) {
     200           0 :                         clearStmtErrors(stmt);
     201           0 :                         free(ptr);
     202           0 :                         ptr = malloc(++n); /* add one for NULL byte */
     203           0 :                         if (ptr == NULL) {
     204             :                                 /* Memory allocation error */
     205           0 :                                 addStmtError(stmt, "HY001", NULL, 0);
     206           0 :                                 return SQL_ERROR;
     207             :                         }
     208           0 :                         rc = MNDBColAttributes(stmt, ColumnNumber,
     209             :                                                FieldIdentifier, ptr, n, &n,
     210             :                                                NumericAttributePtr);
     211             :                 }
     212           0 :                 if (SQL_SUCCEEDED(rc)) {
     213           0 :                         fixWcharOut(rc, ptr, n, CharacterAttributePtr,
     214             :                                     BufferLength, StringLengthPtr, 2,
     215             :                                     addStmtError, stmt);
     216             :                 }
     217           0 :                 free(ptr);
     218           0 :         } else if (StringLengthPtr)
     219           0 :                 *StringLengthPtr = n;
     220             : 
     221             :         return rc;
     222             : }

Generated by: LCOV version 1.14