LCOV - code coverage report
Current view: top level - src/interfaces/ecpg/preproc - typename.c (source / functions) Hit Total Coverage
Test: PostgreSQL 18devel Lines: 22 100 22.0 %
Date: 2024-11-21 09:14:53 Functions: 1 3 33.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* src/interfaces/ecpg/ecpglib/typename.c */
       2             : 
       3             : #define POSTGRES_ECPG_INTERNAL
       4             : #include "postgres_fe.h"
       5             : 
       6             : #include "catalog/pg_type_d.h"
       7             : #include "ecpglib.h"
       8             : #include "ecpglib_extern.h"
       9             : #include "ecpgtype.h"
      10             : #include "sql3types.h"
      11             : #include "sqltypes.h"
      12             : 
      13             : /*
      14             :  * This function is used to generate the correct type names.
      15             :  */
      16             : const char *
      17        1072 : ecpg_type_name(enum ECPGttype typ)
      18             : {
      19        1072 :     switch (typ)
      20             :     {
      21         208 :         case ECPGt_char:
      22             :         case ECPGt_string:
      23         208 :             return "char";
      24           0 :         case ECPGt_unsigned_char:
      25           0 :             return "unsigned char";
      26          90 :         case ECPGt_short:
      27          90 :             return "short";
      28           0 :         case ECPGt_unsigned_short:
      29           0 :             return "unsigned short";
      30         636 :         case ECPGt_int:
      31         636 :             return "int";
      32           0 :         case ECPGt_unsigned_int:
      33           0 :             return "unsigned int";
      34          42 :         case ECPGt_long:
      35          42 :             return "long";
      36           0 :         case ECPGt_unsigned_long:
      37           0 :             return "unsigned long";
      38           0 :         case ECPGt_long_long:
      39           0 :             return "long long";
      40           0 :         case ECPGt_unsigned_long_long:
      41           0 :             return "unsigned long long";
      42          12 :         case ECPGt_float:
      43          12 :             return "float";
      44          34 :         case ECPGt_double:
      45          34 :             return "double";
      46          34 :         case ECPGt_bool:
      47          34 :             return "bool";
      48           2 :         case ECPGt_varchar:
      49           2 :             return "varchar";
      50           2 :         case ECPGt_bytea:
      51           2 :             return "bytea";
      52           0 :         case ECPGt_char_variable:
      53           0 :             return "char";
      54          12 :         case ECPGt_decimal:
      55          12 :             return "decimal";
      56           0 :         case ECPGt_numeric:
      57           0 :             return "numeric";
      58           0 :         case ECPGt_date:
      59           0 :             return "date";
      60           0 :         case ECPGt_timestamp:
      61           0 :             return "timestamp";
      62           0 :         case ECPGt_interval:
      63           0 :             return "interval";
      64           0 :         case ECPGt_const:
      65           0 :             return "Const";
      66           0 :         default:
      67           0 :             abort();
      68             :     }
      69             :     return "";                    /* keep MSC compiler happy */
      70             : }
      71             : 
      72             : int
      73           0 : ecpg_dynamic_type(Oid type)
      74             : {
      75           0 :     switch (type)
      76             :     {
      77           0 :         case BOOLOID:
      78           0 :             return SQL3_BOOLEAN;    /* bool */
      79           0 :         case INT2OID:
      80           0 :             return SQL3_SMALLINT;   /* int2 */
      81           0 :         case INT4OID:
      82           0 :             return SQL3_INTEGER;    /* int4 */
      83           0 :         case TEXTOID:
      84           0 :             return SQL3_CHARACTER;  /* text */
      85           0 :         case FLOAT4OID:
      86           0 :             return SQL3_REAL;   /* float4 */
      87           0 :         case FLOAT8OID:
      88           0 :             return SQL3_DOUBLE_PRECISION;   /* float8 */
      89           0 :         case BPCHAROID:
      90           0 :             return SQL3_CHARACTER;  /* bpchar */
      91           0 :         case VARCHAROID:
      92           0 :             return SQL3_CHARACTER_VARYING;  /* varchar */
      93           0 :         case DATEOID:
      94           0 :             return SQL3_DATE_TIME_TIMESTAMP;    /* date */
      95           0 :         case TIMEOID:
      96           0 :             return SQL3_DATE_TIME_TIMESTAMP;    /* time */
      97           0 :         case TIMESTAMPOID:
      98           0 :             return SQL3_DATE_TIME_TIMESTAMP;    /* datetime */
      99           0 :         case NUMERICOID:
     100           0 :             return SQL3_NUMERIC;    /* numeric */
     101           0 :         default:
     102           0 :             return 0;
     103             :     }
     104             : }
     105             : 
     106             : int
     107           0 : sqlda_dynamic_type(Oid type, enum COMPAT_MODE compat)
     108             : {
     109           0 :     switch (type)
     110             :     {
     111           0 :         case CHAROID:
     112             :         case VARCHAROID:
     113             :         case BPCHAROID:
     114             :         case TEXTOID:
     115           0 :             return ECPGt_char;
     116           0 :         case INT2OID:
     117           0 :             return ECPGt_short;
     118           0 :         case INT4OID:
     119           0 :             return ECPGt_int;
     120           0 :         case FLOAT8OID:
     121           0 :             return ECPGt_double;
     122           0 :         case FLOAT4OID:
     123           0 :             return ECPGt_float;
     124           0 :         case NUMERICOID:
     125           0 :             return INFORMIX_MODE(compat) ? ECPGt_decimal : ECPGt_numeric;
     126           0 :         case DATEOID:
     127           0 :             return ECPGt_date;
     128           0 :         case TIMESTAMPOID:
     129             :         case TIMESTAMPTZOID:
     130           0 :             return ECPGt_timestamp;
     131           0 :         case INTERVALOID:
     132           0 :             return ECPGt_interval;
     133           0 :         case INT8OID:
     134             : #ifdef HAVE_LONG_LONG_INT_64
     135             :             return ECPGt_long_long;
     136             : #endif
     137             : #ifdef HAVE_LONG_INT_64
     138           0 :             return ECPGt_long;
     139             : #endif
     140             :             /* Unhandled types always return a string */
     141           0 :         default:
     142           0 :             return ECPGt_char;
     143             :     }
     144             : }

Generated by: LCOV version 1.14