LCOV - code coverage report
Current view: top level - clients/odbc/driver - SQLDescribeCol.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 61 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             :  * SQLDescribeCol()
      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             : static SQLRETURN
      34           0 : MNDBDescribeCol(ODBCStmt *stmt,
      35             :                 SQLUSMALLINT ColumnNumber,
      36             :                 SQLCHAR *ColumnName,
      37             :                 SQLSMALLINT BufferLength,
      38             :                 SQLSMALLINT *NameLengthPtr,
      39             :                 SQLSMALLINT *DataTypePtr,
      40             :                 SQLULEN *ColumnSizePtr,
      41             :                 SQLSMALLINT *DecimalDigitsPtr,
      42             :                 SQLSMALLINT *NullablePtr)
      43             : {
      44             :         ODBCDescRec *rec = NULL;
      45             : 
      46             :         /* check statement cursor state, query should be executed */
      47           0 :         if (stmt->State == INITED) {
      48             :                 /* Function sequence error */
      49           0 :                 addStmtError(stmt, "HY010", NULL, 0);
      50           0 :                 return SQL_ERROR;
      51             :         }
      52           0 :         if (stmt->State == PREPARED0) {
      53             :                 /* Prepared statement not a cursor-specification */
      54           0 :                 addStmtError(stmt, "07005", NULL, 0);
      55           0 :                 return SQL_ERROR;
      56             :         }
      57           0 :         if (stmt->State == EXECUTED0) {
      58             :                 /* Invalid cursor state */
      59           0 :                 addStmtError(stmt, "24000", NULL, 0);
      60           0 :                 return SQL_ERROR;
      61             :         }
      62             : 
      63           0 :         if (ColumnNumber < 1 ||
      64           0 :             ColumnNumber > stmt->ImplRowDescr->sql_desc_count) {
      65             :                 /* Invalid descriptor index */
      66           0 :                 addStmtError(stmt, "07009", NULL, 0);
      67           0 :                 return SQL_ERROR;
      68             :         }
      69             : 
      70           0 :         rec = stmt->ImplRowDescr->descRec + ColumnNumber;
      71             : 
      72             :         /* now copy the data */
      73           0 :         copyString(rec->sql_desc_name, strlen((char *) rec->sql_desc_name),
      74             :                    ColumnName, BufferLength, NameLengthPtr, SQLSMALLINT,
      75             :                    addStmtError, stmt, return SQL_ERROR);
      76             : 
      77           0 :         if (DataTypePtr)
      78           0 :                 *DataTypePtr = rec->sql_desc_concise_type;
      79             : 
      80             :         /* also see SQLDescribeParam */
      81           0 :         if (ColumnSizePtr) {
      82           0 :                 *ColumnSizePtr = ODBCLength(rec, SQL_DESC_LENGTH);
      83           0 :                 if (*ColumnSizePtr == (SQLULEN) SQL_NO_TOTAL)
      84           0 :                         *ColumnSizePtr = 0;
      85             :         }
      86             : 
      87             :         /* also see SQLDescribeParam */
      88           0 :         if (DecimalDigitsPtr) {
      89           0 :                 switch (rec->sql_desc_concise_type) {
      90           0 :                 case SQL_DECIMAL:
      91             :                 case SQL_NUMERIC:
      92           0 :                         *DecimalDigitsPtr = rec->sql_desc_scale;
      93           0 :                         break;
      94           0 :                 case SQL_BIT:
      95             :                 case SQL_TINYINT:
      96             :                 case SQL_SMALLINT:
      97             :                 case SQL_INTEGER:
      98             :                 case SQL_BIGINT:
      99             :                 case SQL_HUGEINT:
     100           0 :                         *DecimalDigitsPtr = 0;
     101           0 :                         break;
     102           0 :                 case SQL_TYPE_TIME:
     103             :                 case SQL_TYPE_TIMESTAMP:
     104             :                 case SQL_INTERVAL_SECOND:
     105             :                 case SQL_INTERVAL_DAY_TO_SECOND:
     106             :                 case SQL_INTERVAL_HOUR_TO_SECOND:
     107             :                 case SQL_INTERVAL_MINUTE_TO_SECOND:
     108           0 :                         *DecimalDigitsPtr = rec->sql_desc_precision;
     109           0 :                         break;
     110           0 :                 default:
     111           0 :                         *DecimalDigitsPtr = 0;
     112           0 :                         break;
     113             :                 }
     114           0 :         }
     115             : 
     116           0 :         if (NullablePtr)
     117           0 :                 *NullablePtr = rec->sql_desc_nullable;
     118             : 
     119           0 :         return stmt->Error ? SQL_SUCCESS_WITH_INFO : SQL_SUCCESS;
     120             : }
     121             : 
     122             : SQLRETURN SQL_API
     123             : SQLDescribeCol(SQLHSTMT StatementHandle,
     124             :                SQLUSMALLINT ColumnNumber,
     125             :                SQLCHAR *ColumnName,
     126             :                SQLSMALLINT BufferLength,
     127             :                SQLSMALLINT *NameLengthPtr,
     128             :                SQLSMALLINT *DataTypePtr,
     129             :                SQLULEN *ColumnSizePtr,
     130             :                SQLSMALLINT *DecimalDigitsPtr,
     131             :                SQLSMALLINT *NullablePtr)
     132             : {
     133             :         ODBCStmt *stmt = (ODBCStmt *) StatementHandle;
     134             : 
     135             : #ifdef ODBCDEBUG
     136           0 :         ODBCLOG("SQLDescribeCol %p %u %p %d %p %p %p %p %p\n",
     137             :                 StatementHandle, (unsigned int) ColumnNumber,
     138             :                 ColumnName, (int) BufferLength,
     139             :                 NameLengthPtr, DataTypePtr,
     140             :                 ColumnSizePtr, DecimalDigitsPtr,
     141             :                 NullablePtr);
     142             : #endif
     143             : 
     144           0 :         if (!isValidStmt(stmt))
     145             :                  return SQL_INVALID_HANDLE;
     146             : 
     147           0 :         clearStmtErrors(stmt);
     148             : 
     149           0 :         return MNDBDescribeCol(stmt,
     150             :                                ColumnNumber,
     151             :                                ColumnName,
     152             :                                BufferLength,
     153             :                                NameLengthPtr,
     154             :                                DataTypePtr,
     155             :                                ColumnSizePtr,
     156             :                                DecimalDigitsPtr,
     157             :                                NullablePtr);
     158             : }
     159             : 
     160             : SQLRETURN SQL_API
     161             : SQLDescribeColA(SQLHSTMT StatementHandle,
     162             :                 SQLUSMALLINT ColumnNumber,
     163             :                 SQLCHAR *ColumnName,
     164             :                 SQLSMALLINT BufferLength,
     165             :                 SQLSMALLINT *NameLengthPtr,
     166             :                 SQLSMALLINT *DataTypePtr,
     167             :                 SQLULEN *ColumnSizePtr,
     168             :                 SQLSMALLINT *DecimalDigitsPtr,
     169             :                 SQLSMALLINT *NullablePtr)
     170             : {
     171           0 :         return SQLDescribeCol(StatementHandle,
     172             :                               ColumnNumber,
     173             :                               ColumnName,
     174             :                               BufferLength,
     175             :                               NameLengthPtr,
     176             :                               DataTypePtr,
     177             :                               ColumnSizePtr,
     178             :                               DecimalDigitsPtr,
     179             :                               NullablePtr);
     180             : }
     181             : 
     182             : SQLRETURN SQL_API
     183             : SQLDescribeColW(SQLHSTMT StatementHandle,
     184             :                 SQLUSMALLINT ColumnNumber,
     185             :                 SQLWCHAR *ColumnName,
     186             :                 SQLSMALLINT BufferLength,
     187             :                 SQLSMALLINT *NameLengthPtr,
     188             :                 SQLSMALLINT *DataTypePtr,
     189             :                 SQLULEN *ColumnSizePtr,
     190             :                 SQLSMALLINT *DecimalDigitsPtr,
     191             :                 SQLSMALLINT *NullablePtr)
     192             : {
     193             :         ODBCStmt *stmt = (ODBCStmt *) StatementHandle;
     194             :         SQLCHAR *colname;
     195             :         SQLSMALLINT n;
     196             :         SQLRETURN rc = SQL_ERROR;
     197             : 
     198             : #ifdef ODBCDEBUG
     199           0 :         ODBCLOG("SQLDescribeColW %p %u %p %d %p %p %p %p %p\n",
     200             :                 StatementHandle, (unsigned int) ColumnNumber,
     201             :                 ColumnName, (int) BufferLength,
     202             :                 NameLengthPtr, DataTypePtr,
     203             :                 ColumnSizePtr, DecimalDigitsPtr,
     204             :                 NullablePtr);
     205             : #endif
     206             : 
     207           0 :         if (!isValidStmt(stmt))
     208             :                  return SQL_INVALID_HANDLE;
     209             : 
     210           0 :         clearStmtErrors(stmt);
     211             : 
     212           0 :         rc = MNDBDescribeCol(stmt, ColumnNumber, NULL, 0, &n, DataTypePtr,
     213             :                              ColumnSizePtr, DecimalDigitsPtr, NullablePtr);
     214           0 :         if (!SQL_SUCCEEDED(rc))
     215             :                 return rc;
     216           0 :         clearStmtErrors(stmt);
     217           0 :         n++;                    /* account for NUL byte */
     218           0 :         colname = malloc(n);
     219           0 :         if (colname == NULL) {
     220             :                 /* Memory allocation error */
     221           0 :                 addStmtError(stmt, "HY001", NULL, 0);
     222           0 :                 return SQL_ERROR;
     223             :         }
     224           0 :         rc = MNDBDescribeCol(stmt,
     225             :                              ColumnNumber,
     226             :                              colname,
     227             :                              n,
     228             :                              &n,
     229             :                              DataTypePtr,
     230             :                              ColumnSizePtr,
     231             :                              DecimalDigitsPtr,
     232             :                              NullablePtr);
     233           0 :         if (SQL_SUCCEEDED(rc)) {
     234           0 :                 fixWcharOut(rc, colname, n, ColumnName, BufferLength,
     235             :                             NameLengthPtr, 1, addStmtError, stmt);
     236             :         }
     237           0 :         free(colname);
     238             : 
     239           0 :         return rc;
     240             : }

Generated by: LCOV version 1.14