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

Generated by: LCOV version 1.14