LCOV - code coverage report
Current view: top level - clients/odbc/driver - SQLColAttribute.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 142 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             :  * SQLColAttribute()
      21             :  * CLI Compliance: ISO 92
      22             :  *
      23             :  * Author: Martin van Dinther, Sjoerd Mullender
      24             :  * Date  : 30 aug 2002
      25             :  *
      26             :  **********************************************************************/
      27             : 
      28             : #include "ODBCGlobal.h"
      29             : #include "ODBCStmt.h"
      30             : #include "ODBCUtil.h"
      31             : 
      32             : 
      33             : SQLRETURN
      34           0 : MNDBColAttribute(ODBCStmt *stmt,
      35             :                  SQLUSMALLINT ColumnNumber,
      36             :                  SQLUSMALLINT FieldIdentifier,
      37             :                  SQLPOINTER CharacterAttributePtr,
      38             :                  SQLSMALLINT BufferLength,
      39             :                  SQLSMALLINT *StringLengthPtr,
      40             :                  LENP_OR_POINTER_T NumericAttributePtr)
      41             : {
      42             :         ODBCDescRec *rec;
      43             : 
      44             :         /* check statement cursor state, query should be prepared or executed */
      45           0 :         if (stmt->State == INITED) {
      46             :                 /* Function sequence error */
      47           0 :                 addStmtError(stmt, "HY010", NULL, 0);
      48           0 :                 return SQL_ERROR;
      49             :         }
      50           0 :         if (stmt->State == EXECUTED0) {
      51             :                 /* Invalid cursor state */
      52           0 :                 addStmtError(stmt, "24000", NULL, 0);
      53           0 :                 return SQL_ERROR;
      54             :         }
      55           0 :         if (stmt->State == PREPARED0 && FieldIdentifier != SQL_DESC_COUNT) {
      56             :                 /* Prepared statement not a cursor-specification */
      57           0 :                 addStmtError(stmt, "07005", NULL, 0);
      58           0 :                 return SQL_ERROR;
      59             :         }
      60             : 
      61           0 :         if (stmt->ImplRowDescr->descRec == NULL) {
      62             :                 /* General error */
      63           0 :                 addStmtError(stmt, "HY000", "Cannot return the column info. No result set is available", 0);
      64           0 :                 return SQL_ERROR;
      65             :         }
      66             : 
      67             :         /* check input parameter */
      68           0 :         if (ColumnNumber < 1 || ColumnNumber > stmt->ImplRowDescr->sql_desc_count) {
      69             :                 /* Invalid descriptor index */
      70           0 :                 addStmtError(stmt, "07009", NULL, 0);
      71           0 :                 return SQL_ERROR;
      72             :         }
      73             : 
      74             : /* TODO: finish implementation */
      75           0 :         rec = stmt->ImplRowDescr->descRec + ColumnNumber;
      76             : 
      77           0 :         switch (FieldIdentifier) {
      78           0 :         case SQL_DESC_AUTO_UNIQUE_VALUE:/* SQL_COLUMN_AUTO_INCREMENT */
      79           0 :                 if (NumericAttributePtr)
      80           0 :                         *(SQLLEN *) NumericAttributePtr = rec->sql_desc_auto_unique_value;
      81             :                 break;
      82           0 :         case SQL_DESC_BASE_COLUMN_NAME:
      83           0 :                 copyString(rec->sql_desc_base_column_name,
      84             :                            strlen((char *) rec->sql_desc_base_column_name),
      85             :                            CharacterAttributePtr, BufferLength,
      86             :                            StringLengthPtr, SQLSMALLINT, addStmtError,
      87             :                            stmt, return SQL_ERROR);
      88             :                 break;
      89           0 :         case SQL_DESC_BASE_TABLE_NAME:
      90           0 :                 copyString(rec->sql_desc_base_table_name,
      91             :                            strlen((char *) rec->sql_desc_base_table_name),
      92             :                            CharacterAttributePtr, BufferLength,
      93             :                            StringLengthPtr, SQLSMALLINT, addStmtError,
      94             :                            stmt, return SQL_ERROR);
      95             :                 break;
      96           0 :         case SQL_DESC_CASE_SENSITIVE:   /* SQL_COLUMN_CASE_SENSITIVE */
      97           0 :                 if (NumericAttributePtr)
      98           0 :                         *(SQLLEN *) NumericAttributePtr = rec->sql_desc_case_sensitive;
      99             :                 break;
     100           0 :         case SQL_DESC_CATALOG_NAME:     /* SQL_COLUMN_QUALIFIER_NAME */
     101           0 :                 copyString(rec->sql_desc_catalog_name,
     102             :                            strlen((char *) rec->sql_desc_catalog_name),
     103             :                            CharacterAttributePtr, BufferLength,
     104             :                            StringLengthPtr, SQLSMALLINT, addStmtError,
     105             :                            stmt, return SQL_ERROR);
     106             :                 break;
     107           0 :         case SQL_DESC_CONCISE_TYPE:     /* SQL_COLUMN_TYPE */
     108           0 :                 if (NumericAttributePtr)
     109           0 :                         *(SQLLEN *) NumericAttributePtr = rec->sql_desc_concise_type;
     110             :                 break;
     111           0 :         case SQL_COLUMN_COUNT:
     112             :         case SQL_DESC_COUNT:
     113           0 :                 if (NumericAttributePtr)
     114           0 :                         *(SQLLEN *) NumericAttributePtr = stmt->ImplRowDescr->sql_desc_count;
     115             :                 break;
     116           0 :         case SQL_DESC_DISPLAY_SIZE:     /* SQL_COLUMN_DISPLAY_SIZE */
     117           0 :                 if (NumericAttributePtr)
     118           0 :                         *(SQLLEN *) NumericAttributePtr = rec->sql_desc_display_size;
     119             :                 break;
     120           0 :         case SQL_DESC_FIXED_PREC_SCALE: /* SQL_COLUMN_MONEY */
     121           0 :                 if (NumericAttributePtr)
     122           0 :                         *(SQLLEN *) NumericAttributePtr = rec->sql_desc_fixed_prec_scale;
     123             :                 break;
     124           0 :         case SQL_DESC_LABEL:            /* SQL_COLUMN_LABEL */
     125           0 :                 copyString(rec->sql_desc_label,
     126             :                            strlen((char *) rec->sql_desc_label),
     127             :                            CharacterAttributePtr, BufferLength,
     128             :                            StringLengthPtr, SQLSMALLINT, addStmtError,
     129             :                            stmt, return SQL_ERROR);
     130             :                 break;
     131           0 :         case SQL_COLUMN_LENGTH:
     132             :         case SQL_DESC_LENGTH:
     133           0 :                 if (NumericAttributePtr)
     134           0 :                         *(SQLLEN *) NumericAttributePtr = rec->sql_desc_length;
     135             :                 break;
     136           0 :         case SQL_DESC_LITERAL_PREFIX:
     137           0 :                 copyString(rec->sql_desc_literal_prefix,
     138             :                            strlen((char *) rec->sql_desc_literal_prefix),
     139             :                            CharacterAttributePtr, BufferLength,
     140             :                            StringLengthPtr, SQLSMALLINT, addStmtError,
     141             :                            stmt, return SQL_ERROR);
     142             :                 break;
     143           0 :         case SQL_DESC_LITERAL_SUFFIX:
     144           0 :                 copyString(rec->sql_desc_literal_suffix, strlen((char *) rec->sql_desc_literal_suffix), CharacterAttributePtr, BufferLength, StringLengthPtr, SQLSMALLINT, addStmtError, stmt, return SQL_ERROR);
     145             :                 break;
     146           0 :         case SQL_DESC_LOCAL_TYPE_NAME:
     147           0 :                 copyString(rec->sql_desc_local_type_name,
     148             :                            strlen((char *) rec->sql_desc_local_type_name),
     149             :                            CharacterAttributePtr, BufferLength,
     150             :                            StringLengthPtr, SQLSMALLINT, addStmtError,
     151             :                            stmt, return SQL_ERROR);
     152             :                 break;
     153           0 :         case SQL_COLUMN_NAME:
     154             :         case SQL_DESC_NAME:
     155           0 :                 copyString(rec->sql_desc_name,
     156             :                            strlen((char *) rec->sql_desc_name),
     157             :                            CharacterAttributePtr, BufferLength,
     158             :                            StringLengthPtr, SQLSMALLINT, addStmtError,
     159             :                            stmt, return SQL_ERROR);
     160             :                 break;
     161           0 :         case SQL_COLUMN_NULLABLE:
     162           0 :                 if (NumericAttributePtr)
     163           0 :                         *(SQLINTEGER *) NumericAttributePtr = rec->sql_desc_nullable;
     164             :                 break;
     165           0 :         case SQL_DESC_NULLABLE:
     166           0 :                 if (NumericAttributePtr)
     167           0 :                         *(SQLLEN *) NumericAttributePtr = rec->sql_desc_nullable;
     168             :                 break;
     169           0 :         case SQL_DESC_NUM_PREC_RADIX:
     170           0 :                 if (NumericAttributePtr)
     171           0 :                         *(SQLLEN *) NumericAttributePtr = rec->sql_desc_num_prec_radix;
     172             :                 break;
     173           0 :         case SQL_DESC_OCTET_LENGTH:
     174           0 :                 if (NumericAttributePtr)
     175           0 :                         *(SQLLEN *) NumericAttributePtr = rec->sql_desc_octet_length;
     176             :                 break;
     177           0 :         case SQL_COLUMN_PRECISION:
     178           0 :                 if (NumericAttributePtr)
     179           0 :                         *(SQLINTEGER *) NumericAttributePtr = rec->sql_desc_precision;
     180             :                 break;
     181           0 :         case SQL_DESC_PRECISION:
     182           0 :                 if (NumericAttributePtr)
     183           0 :                         *(SQLLEN *) NumericAttributePtr = rec->sql_desc_precision;
     184             :                 break;
     185           0 :         case SQL_COLUMN_SCALE:
     186           0 :                 if (NumericAttributePtr)
     187           0 :                         *(SQLINTEGER *) NumericAttributePtr = rec->sql_desc_scale;
     188             :                 break;
     189           0 :         case SQL_DESC_SCALE:
     190           0 :                 if (NumericAttributePtr)
     191           0 :                         *(SQLLEN *) NumericAttributePtr = rec->sql_desc_scale;
     192             :                 break;
     193           0 :         case SQL_DESC_SCHEMA_NAME:      /* SQL_COLUMN_OWNER_NAME */
     194           0 :                 copyString(rec->sql_desc_schema_name,
     195             :                            strlen((char *) rec->sql_desc_schema_name),
     196             :                            CharacterAttributePtr, BufferLength,
     197             :                            StringLengthPtr, SQLSMALLINT, addStmtError,
     198             :                            stmt, return SQL_ERROR);
     199             :                 break;
     200           0 :         case SQL_DESC_SEARCHABLE:       /* SQL_COLUMN_SEARCHABLE */
     201           0 :                 if (NumericAttributePtr)
     202           0 :                         *(SQLLEN *) NumericAttributePtr = rec->sql_desc_searchable;
     203             :                 break;
     204           0 :         case SQL_DESC_TABLE_NAME:       /* SQL_COLUMN_TABLE_NAME */
     205           0 :                 copyString(rec->sql_desc_table_name,
     206             :                            strlen((char *) rec->sql_desc_table_name),
     207             :                            CharacterAttributePtr, BufferLength,
     208             :                            StringLengthPtr, SQLSMALLINT, addStmtError,
     209             :                            stmt, return SQL_ERROR);
     210             :                 break;
     211           0 :         case SQL_DESC_TYPE:
     212           0 :                 if (NumericAttributePtr)
     213           0 :                         *(SQLLEN *) NumericAttributePtr = rec->sql_desc_type;
     214             :                 break;
     215           0 :         case SQL_DESC_TYPE_NAME:        /* SQL_COLUMN_TYPE_NAME */
     216           0 :                 copyString(rec->sql_desc_type_name,
     217             :                            strlen((char *) rec->sql_desc_type_name),
     218             :                            CharacterAttributePtr, BufferLength,
     219             :                            StringLengthPtr, SQLSMALLINT, addStmtError,
     220             :                            stmt, return SQL_ERROR);
     221             :                 break;
     222           0 :         case SQL_DESC_UNNAMED:
     223           0 :                 if (NumericAttributePtr)
     224           0 :                         *(SQLLEN *) NumericAttributePtr = rec->sql_desc_unnamed;
     225             :                 break;
     226           0 :         case SQL_DESC_UNSIGNED:         /* SQL_COLUMN_UNSIGNED */
     227           0 :                 if (NumericAttributePtr)
     228           0 :                         *(SQLLEN *) NumericAttributePtr = rec->sql_desc_unsigned;
     229             :                 break;
     230           0 :         case SQL_DESC_UPDATABLE:        /* SQL_COLUMN_UPDATABLE */
     231           0 :                 if (NumericAttributePtr)
     232           0 :                         *(SQLLEN *) NumericAttributePtr = rec->sql_desc_updatable;
     233             :                 break;
     234           0 :         default:
     235             :                 /* Invalid descriptor field identifier */
     236           0 :                 addStmtError(stmt, "HY091", NULL, 0);
     237           0 :                 return SQL_ERROR;
     238             :         }
     239             : 
     240           0 :         return stmt->Error ? SQL_SUCCESS_WITH_INFO : SQL_SUCCESS;
     241             : }
     242             : 
     243             : SQLRETURN SQL_API
     244             : SQLColAttribute(SQLHSTMT StatementHandle,
     245             :                 SQLUSMALLINT ColumnNumber,
     246             :                 SQLUSMALLINT FieldIdentifier,
     247             :                 SQLPOINTER CharacterAttributePtr,
     248             :                 SQLSMALLINT BufferLength,
     249             :                 SQLSMALLINT *StringLengthPtr,
     250             :                 LENP_OR_POINTER_T NumericAttributePtr)
     251             : {
     252             : #ifdef ODBCDEBUG
     253           0 :         ODBCLOG("SQLColAttribute %p %d %s %p %d %p %p\n",
     254             :                 StatementHandle, (int) ColumnNumber,
     255             :                 translateFieldIdentifier(FieldIdentifier),
     256             :                 CharacterAttributePtr, (int) BufferLength,
     257             :                 StringLengthPtr,
     258             :                 (void *) NumericAttributePtr);
     259             : #endif
     260             : 
     261           0 :         if (!isValidStmt((ODBCStmt *) StatementHandle))
     262             :                 return SQL_INVALID_HANDLE;
     263             : 
     264           0 :         clearStmtErrors((ODBCStmt *) StatementHandle);
     265             : 
     266           0 :         switch (FieldIdentifier) {
     267             :         case SQL_DESC_AUTO_UNIQUE_VALUE:
     268             :         case SQL_DESC_BASE_COLUMN_NAME:
     269             :         case SQL_DESC_BASE_TABLE_NAME:
     270             :         case SQL_DESC_CASE_SENSITIVE:
     271             :         case SQL_DESC_CATALOG_NAME:
     272             :         case SQL_DESC_CONCISE_TYPE:
     273             :         case SQL_DESC_COUNT:
     274             :         case SQL_DESC_DISPLAY_SIZE:
     275             :         case SQL_DESC_FIXED_PREC_SCALE:
     276             :         case SQL_DESC_LABEL:
     277             :         case SQL_DESC_LENGTH:
     278             :         case SQL_DESC_LITERAL_PREFIX:
     279             :         case SQL_DESC_LITERAL_SUFFIX:
     280             :         case SQL_DESC_LOCAL_TYPE_NAME:
     281             :         case SQL_DESC_NAME:
     282             :         case SQL_DESC_NULLABLE:
     283             :         case SQL_DESC_NUM_PREC_RADIX:
     284             :         case SQL_DESC_OCTET_LENGTH:
     285             :         case SQL_DESC_PRECISION:
     286             :         case SQL_DESC_SCALE:
     287             :         case SQL_DESC_SCHEMA_NAME:
     288             :         case SQL_DESC_SEARCHABLE:
     289             :         case SQL_DESC_TABLE_NAME:
     290             :         case SQL_DESC_TYPE:
     291             :         case SQL_DESC_TYPE_NAME:
     292             :         case SQL_DESC_UNNAMED:
     293             :         case SQL_DESC_UNSIGNED:
     294             :         case SQL_DESC_UPDATABLE:
     295             :                 break;
     296           0 :         default:
     297             :                 /* Invalid descriptor field identifier */
     298           0 :                 addStmtError((ODBCStmt *) StatementHandle, "HY091", NULL, 0);
     299           0 :                 return SQL_ERROR;
     300             :         }
     301           0 :         return MNDBColAttribute((ODBCStmt *) StatementHandle,
     302             :                                 ColumnNumber,
     303             :                                 FieldIdentifier,
     304             :                                 CharacterAttributePtr,
     305             :                                 BufferLength,
     306             :                                 StringLengthPtr,
     307             :                                 NumericAttributePtr);
     308             : }
     309             : 
     310             : SQLRETURN SQL_API
     311             : SQLColAttributeA(SQLHSTMT StatementHandle,
     312             :                  SQLSMALLINT ColumnNumber,
     313             :                  SQLSMALLINT FieldIdentifier,
     314             :                  SQLPOINTER CharacterAttributePtr,
     315             :                  SQLSMALLINT BufferLength,
     316             :                  SQLSMALLINT *StringLengthPtr,
     317             :                  LENP_OR_POINTER_T NumericAttributePtr)
     318             : {
     319           0 :         return SQLColAttribute(StatementHandle,
     320           0 :                                (SQLUSMALLINT) ColumnNumber,
     321           0 :                                (SQLUSMALLINT) FieldIdentifier,
     322             :                                CharacterAttributePtr,
     323             :                                BufferLength,
     324             :                                StringLengthPtr,
     325             :                                NumericAttributePtr);
     326             : }
     327             : 
     328             : SQLRETURN SQL_API
     329             : SQLColAttributeW(SQLHSTMT StatementHandle,
     330             :                  SQLUSMALLINT ColumnNumber,
     331             :                  SQLUSMALLINT FieldIdentifier,
     332             :                  SQLPOINTER CharacterAttributePtr,
     333             :                  SQLSMALLINT BufferLength,
     334             :                  SQLSMALLINT *StringLengthPtr,
     335             :                  LENP_OR_POINTER_T NumericAttributePtr)
     336             : {
     337             :         ODBCStmt *stmt = (ODBCStmt *) StatementHandle;
     338             :         SQLPOINTER ptr;
     339             :         SQLRETURN rc;
     340             :         SQLSMALLINT n;
     341             : 
     342             : #ifdef ODBCDEBUG
     343           0 :         ODBCLOG("SQLColAttributeW %p %d %s %p %d %p %p\n",
     344             :                 StatementHandle, (int) ColumnNumber,
     345             :                 translateFieldIdentifier(FieldIdentifier),
     346             :                 CharacterAttributePtr, (int) BufferLength,
     347             :                 StringLengthPtr,
     348             :                 (void *) NumericAttributePtr);
     349             : #endif
     350             : 
     351           0 :         if (!isValidStmt(stmt))
     352             :                  return SQL_INVALID_HANDLE;
     353             : 
     354           0 :         clearStmtErrors(stmt);
     355             : 
     356           0 :         switch (FieldIdentifier) {
     357             :         /* all string atributes */
     358           0 :         case SQL_DESC_BASE_COLUMN_NAME:
     359             :         case SQL_DESC_BASE_TABLE_NAME:
     360             :         case SQL_DESC_CATALOG_NAME:     /* SQL_COLUMN_QUALIFIER_NAME */
     361             :         case SQL_DESC_LABEL:            /* SQL_COLUMN_LABEL */
     362             :         case SQL_DESC_LITERAL_PREFIX:
     363             :         case SQL_DESC_LITERAL_SUFFIX:
     364             :         case SQL_DESC_LOCAL_TYPE_NAME:
     365             :         case SQL_DESC_NAME:
     366             :         case SQL_DESC_SCHEMA_NAME:      /* SQL_COLUMN_OWNER_NAME */
     367             :         case SQL_DESC_TABLE_NAME:       /* SQL_COLUMN_TABLE_NAME */
     368             :         case SQL_DESC_TYPE_NAME:        /* SQL_COLUMN_TYPE_NAME */
     369           0 :                 ptr = malloc(BufferLength);
     370           0 :                 if (ptr == NULL) {
     371             :                         /* Memory allocation error */
     372           0 :                         addStmtError(stmt, "HY001", NULL, 0);
     373           0 :                         return SQL_ERROR;
     374             :                 }
     375             :                 break;
     376             :         /* all other attributes */
     377             :         case SQL_DESC_AUTO_UNIQUE_VALUE:
     378             :         case SQL_DESC_CASE_SENSITIVE:
     379             :         case SQL_DESC_CONCISE_TYPE:
     380             :         case SQL_DESC_COUNT:
     381             :         case SQL_DESC_DISPLAY_SIZE:
     382             :         case SQL_DESC_FIXED_PREC_SCALE:
     383             :         case SQL_DESC_LENGTH:
     384             :         case SQL_DESC_NULLABLE:
     385             :         case SQL_DESC_NUM_PREC_RADIX:
     386             :         case SQL_DESC_OCTET_LENGTH:
     387             :         case SQL_DESC_PRECISION:
     388             :         case SQL_DESC_SCALE:
     389             :         case SQL_DESC_SEARCHABLE:
     390             :         case SQL_DESC_TYPE:
     391             :         case SQL_DESC_UNNAMED:
     392             :         case SQL_DESC_UNSIGNED:
     393             :         case SQL_DESC_UPDATABLE:
     394             :                 ptr = CharacterAttributePtr;
     395             :                 break;
     396           0 :         default:
     397             :                 /* Invalid descriptor field identifier */
     398           0 :                 addStmtError(stmt, "HY091", NULL, 0);
     399           0 :                 return SQL_ERROR;
     400             :         }
     401             : 
     402           0 :         rc = MNDBColAttribute(stmt, ColumnNumber, FieldIdentifier, ptr,
     403             :                               BufferLength, &n, NumericAttributePtr);
     404             : 
     405           0 :         if (ptr != CharacterAttributePtr) {
     406           0 :                 if (rc == SQL_SUCCESS_WITH_INFO) {
     407           0 :                         clearStmtErrors(stmt);
     408           0 :                         free(ptr);
     409           0 :                         ptr = malloc(++n); /* add one for NULL byte */
     410           0 :                         if (ptr == NULL) {
     411             :                                 /* Memory allocation error */
     412           0 :                                 addStmtError(stmt, "HY001", NULL, 0);
     413           0 :                                 return SQL_ERROR;
     414             :                         }
     415           0 :                         rc = MNDBColAttribute(stmt, ColumnNumber,
     416             :                                               FieldIdentifier, ptr, n, &n,
     417             :                                               NumericAttributePtr);
     418             :                 }
     419           0 :                 if (SQL_SUCCEEDED(rc)) {
     420           0 :                         fixWcharOut(rc, ptr, n, CharacterAttributePtr,
     421             :                                     BufferLength, StringLengthPtr, 2,
     422             :                                     addStmtError, stmt);
     423             :                 }
     424           0 :                 free(ptr);
     425           0 :         } else if (StringLengthPtr)
     426           0 :                 *StringLengthPtr = n;
     427             : 
     428             :         return rc;
     429             : }

Generated by: LCOV version 1.14